**LIFE** (LEGO Integrated Factory Execution) is a production-ready prototype that modernizes manufacturing operations through intelligent digital workflows. The platform provides:
- **Spring Boot** team for the excellent framework - **React** community for the vibrant ecosystem - **Docker** for simplifying deployment - LEGO Group for inspiration
This project is licensed under the **MIT License** - see the [LICENSE](LICENSE) file for details.
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Ut elit tellus, luctus nec ullamcorper mattis, pulvinar dapibus leo.
This document serves as a detailed specification for developing a digital control system for the LEGO Sample Factory, based on the requirements and analyses presented in the thesis “DATA FLOW DESIGN AND TESTING OF AN IOS BASED APPLICATION FOR DIGITAL INTEGRATED CONTROL IN THE ‘LEGO SAMPLE FACTORY’”. The primary goal is to replace the current paper-based and untraceable processes with a modern software application that enhances supply chain management through digital control, real-time monitoring, and optimized data flow.
Key Objectives:
The LEGO Sample Factory simulates a manufacturing supply chain process where LEGO blocks are used to produce seven variants of drills (A-G). The system involves various workstations, orders, and material flows.
2.1. Key Entities & Their Roles:
SimAL.Scheduler (external system) to plan production, scheduling start and finish times for module manufacturing and assembly.2.2. Order Types & Data Flow:
2.3. Key Business Rules/Scenarios:
The application will follow a microservice architecture, comprising:
SimAL.Scheduler (via REST API, as described in thesis).Development Environment: Visual Studio Code.
The backend will expose RESTful APIs for the frontend and integrate with SimAL.Scheduler.
4.1. Core Entities (Java Classes for Data Model)
These classes will represent the core business objects and map to database tables using Spring Data JPA.
Userid (Long)username (String)passwordHash (String)role (Enum: ADMIN, PLANT_WAREHOUSE, MODULES_SUPERMARKET, etc.)workstation (String/Enum, linked to Workstation)isEnabled (Boolean)Workstationid (Long)name (String: “Plant Warehouse”, “Modules Supermarket”, etc.)type (Enum: SUPPLY, PRODUCTION, ASSEMBLY, CONTROL)description (String)ProductVariant (e.g., Drill A, Drill B)id (Long)name (String: “Variant A”, “Variant G”)voltagePower (String)gear (String)colour (String)isPriority (Boolean, e.g., for G-variant)Part (Raw materials for modules)id (Long)name (String)description (String)Module (Components manufactured/assembled from parts)id (Long)name (String)description (String)requiredParts (Map<Part, Integer>) // Or a separate ModulePart entityStockRecordid (Long)itemType (Enum: PRODUCT_VARIANT, PART, MODULE)itemId (Long, foreign key to ProductVariant, Part, or Module)workstation (ManyToOne, linked to Workstation)quantity (Integer)lastUpdated (LocalDateTime)Order (Abstract base class or interface)id (Long)orderNumber (String)orderDate (LocalDateTime)status (Enum: PENDING, PLANNED, IN_PROGRESS, FULFILLED, CANCELED)sourceWorkstation (ManyToOne, linked to Workstation)targetWorkstation (ManyToOne, linked to Workstation)items (List)OrderItemid (Long)order (ManyToOne, linked to Order)itemType (Enum: PRODUCT_VARIANT, PART, MODULE)itemId (Long, foreign key to ProductVariant, Part, or Module)quantity (Integer)variant (String, e.g., “A”, “B”) – as per SimAL formatCustomerOrder (Extends Order)customerName (String)deliveryAddress (String)WarehouseOrder (Extends Order)thresholdLotSize (Integer)ProductionOrder (Extends Order)estimatedStartTime (LocalDateTime)estimatedFinishTime (LocalDateTime)actualStartTime (LocalDateTime)actualFinishTime (LocalDateTime)simALOrderId (String, for tracking with SimAL.Scheduler)SupplyOrder (Extends Order)supplyType (Enum: PRODUCTION_PART, ASSEMBLY_PART)4.2. Repository Layer (Spring Data JPA)
Interfaces extending JpaRepository for basic CRUD operations on all entities.
UserRepositoryWorkstationRepositoryProductVariantRepositoryPartRepositoryModuleRepositoryStockRecordRepositoryOrderRepository (and specific repositories for CustomerOrder, ProductionOrder, etc.)OrderItemRepository4.3. Service Layer (Spring @Service Classes)
These classes encapsulate the business logic and orchestrate data access.
UserServicecreateUser(User user)updateUser(User user)deleteUser(Long userId)getUserByUsername(String username)assignWorkstation(Long userId, Long workstationId)WorkstationServicegetAllWorkstations()getWorkstationById(Long id)ProductCatalogServicegetAllProductVariants()getProductVariantById(Long id)StockServicegetStockForWorkstation(Long workstationId)updateStock(Long stockRecordId, Integer quantityChange)checkStockAvailability(Long workstationId, Long itemId, Integer quantity)OrderService (General operations for all orders)createOrder(Order order)updateOrderStatus(Long orderId, OrderStatus newStatus)getOrderById(Long orderId)getOrdersByWorkstation(Long workstationId)cancelOrder(Long orderId)CustomerOrderServiceplaceCustomerOrder(CustomerOrder customerOrder)fulfillCustomerOrder(Long customerOrderId) (checks stock, updates, generates Warehouse/Production Orders if needed)WarehouseOrderServicecreateWarehouseOrder(WarehouseOrder order)processWarehouseOrder(Long warehouseOrderId) (checks Modules Supermarket stock, generates Production Order if needed)ProductionPlanningServiceplanProduction(ProductionOrder order) (communicates with SimAL.Scheduler)updateProductionTimes(Long productionOrderId, LocalDateTime actualStart, LocalDateTime actualFinish)getPlannedOrdersForWorkstation(Long workstationId)ProductionControlServicecreateProductionSupplyOrders(Long productionControlOrderId)createManufacturingOrders(Long productionControlOrderId)updateManufacturingStatus(Long manufacturingOrderId, Status newStatus)AssemblyControlServicecreateAssemblySupplyOrders(Long assemblyControlOrderId)createAssemblyOrders(Long assemblyControlOrderId)updateAssemblyStatus(Long assemblyOrderId, Status newStatus)SimALSchedulerAdapter (Responsible for integration with SimAL.Scheduler)sendWarehouseOrder(WarehouseOrder order) (POST, maps to SimAL JSON format)getScheduledOrders(Long workstationId) (GET, parses SimAL JSON response)updateTimeStatus(Long simALOrderId, LocalDateTime timestamp, Integer amount, Integer status) (POST, maps to SimAL JSON format)4.4. REST API Endpoints (Spring @RestController Classes)
These controllers will expose the functionality of the service layer via HTTP endpoints.
AuthController (/api/auth)POST /login: Authenticates user, returns JWT.POST /register: Creates a new user (admin only).UserController (/api/users)GET /: Get all users (admin only)GET /{id}: Get user by IDPUT /{id}/workstation: Assign workstation to user (admin only)WorkstationController (/api/workstations)GET /: Get all workstationsProductController (/api/products)GET /variants: Get all product variantsStockController (/api/stock)GET /workstation/{workstationId}: Get stock for a specific workstationPUT /workstation/{workstationId}/update: Update stock quantity (authenticated users)OrderController (/api/orders)POST /customer: Place new customer order (Plant Warehouse role)POST /warehouse: Create warehouse order (Plant Warehouse role)POST /production: Create production order (Modules Supermarket role)GET /mine: Get orders relevant to the authenticated user’s workstationPUT /{orderId}/status: Update order statusPUT /{orderId}/times: Update actual start/finish times (manufacturing/assembly roles)SimALIntegrationController (/api/simal)POST /order: Send order to SimAL (internal, Production Planning role)GET /schedule: Get schedule from SimAL (internal, Production Planning role)POST /update-time: Update SimAL with actual times (internal, triggered by workstations)4.5. Authentication and Authorization (Spring Security)
X-API-Key header.SimAL.Scheduler integration if it were to authenticate with our system./api/auth/login).Authorization: Bearer <token> header for subsequent requests.jjwt library, ensure secure secret key, configure token expiration, and handle token refresh if needed.The React frontend will provide user interfaces for each workstation and user role.
5.1. Key Components/Pages:
fulfillCustomerOrder API).SimAL.SchedulerAdapter (e.g., “Plan Production” button).5.2. Frontend Technologies:
Containerized microservices demo for a LEGO sample factory, with a React frontend, an API Gateway, and Spring Boot backend services orchestrated via Docker Compose.
.env file consumed by Docker Compose..env.example serves as the blueprint for local .env creation.create-drop for clean local runs. Do not use in production.Prerequisites:
– Windows with Docker Desktop running.
– VS Code recommended.
Create your local environment file from the blueprint:
– Copy the example:
“`
Copy-Item .env.example .env
“`
– Open .env and set values. At minimum, set a secure SECURITY_JWT_SECRET (32+ chars).
– Keep .env private. It should be ignored by Git.
“`
docker compose up –build
“`
Access the app:
– Frontend via Nginx root proxy: http://localhost:80
– API Gateway (direct dev port): http://localhost:8011
– H2 console (per service, if enabled): http://localhost:/h2-console
Tear down:
“`bash
docker compose down
“`
.env.example is committed and pushed to the repo so collaborators can see required variables..env and customize for local development: – Security:
– SECURITY_JWT_SECRET: long random string (32+ chars).
– SECURITY_JWT_EXPIRATION: default PT1H.
– Networking:
– NGINX_ROOT_PROXY_EXTERNAL_PORT: default 80.
– DOCKER_NETWORK_NAME: default lego-network.
– Frontend:
– VITE_API_GATEWAY_URL: default http://localhost:8011.
– FRONTEND_SERVE_PORT: default 5173.
– Gateway CORS:
– API_GATEWAY_CORS_ALLOWED_ORIGINS: restrict as needed.
– Microservice internal ports:
– API_GATEWAY_PORT, USER_SERVICE_PORT, MASTERDATA_SERVICE_PORT, INVENTORY_SERVICE_PORT, ORDER_PROCESSING_SERVICE_PORT, SIMAL_INTEGRATION_SERVICE_PORT.
– Databases (H2 in-memory):
– H2_DB_* JDBC URLs with DB_CLOSE_DELAY=-1.
– Spring Boot common:
– SPRING_JPA_HIBERNATE_DDL_AUTO=create-drop (dev only).
– SPRING_JPA_SHOW_SQL=true.
– SPRING_H2_CONSOLE_ENABLED=true.
– SPRING_H2_CONSOLE_PATH=/h2-console.
– SPRING_JMX_ENABLED=false.
– Logging:
– LOGGING_LEVEL_IO_LIFE=DEBUG, LOG_LEVEL_ROOT=INFO.
– Management:
– MANAGEMENT_ENDPOINTS_WEB_EXPOSURE_INCLUDE="health,info,metrics".
– MANAGEMENT_ENDPOINT_HEALTH_SHOW_DETAILS=always.
– Internal service URLs for Gateway routing:
– API_GATEWAY_*_SERVICE_URL using Docker service names and ports.
– Docker Compose defaults:
– DOCKER_RESTART_POLICY=unless-stopped, DOCKER_MEMORY_LIMIT=512m, DOCKER_CPU_LIMIT=1.0, DOCKER_TAG=latest.
npm run dev --prefix frontend
Ensure VITE_API_GATEWAY_URL points to the gateway.
docker compose logs -f