Task 13 — Manufacturing and Production Line Management
Objective
Create a manufacturing and production-line management system.
The system manages factories, production lines, machines, products, raw materials, bills of materials, work orders, production batches, workers, maintenance, quality checks, warehouses, and finished-goods inventory.
The implementation must model the complete production lifecycle:
Production Request
↓
Material Validation
↓
Material Reservation
↓
Work Order
↓
Production Line Assignment
↓
Batch Production
↓
Quality Control
↓
Accepted / Rejected Units
↓
Finished Goods Inventory
The system must also react to:
- insufficient materials
- machine failures
- production-line downtime
- rejected quality samples
- partial batch completion
- maintenance
- delayed work orders
- warehouse capacity limits
Domain Overview
Conceptually:
Factory
|
+-- ProductionLine
| |
| +-- Machine
| +-- Worker
|
+-- RawMaterialWarehouse
|
+-- FinishedGoodsWarehouse
Product relationships:
Product
|
+-- BillOfMaterials
|
+-- MaterialRequirement
Production relationships:
ProductionRequest
|
v
WorkOrder
|
+-- ProductionLine
+-- MaterialReservation
|
v
ProductionBatch
|
+-- MachineUsage
+-- WorkerAssignment
+-- QualityCheck
|
v
FinishedGoods
Factory
Each factory contains:
- ID
- Name
- Location
- Production Lines
- Raw Material Warehouse
- Finished Goods Warehouse
A possible model is:
type Factory struct {
ID string
Name string
RawMaterialWarehouseID string
FinishedGoodsWarehouseID string
}
Production Line
A production line belongs to a factory. Each line contains:
- ID
- Factory ID
- Name
- Supported Product Types
- Maximum Units Per Hour
- Status
- Machines
For example:
type ProductionLine struct {
ID string
FactoryID string
Name string
SupportedProductTypes []string
MaxUnitsPerHour int
Status ProductionLineStatus
}
Production Line Status
Possible states:
- available
- running
- maintenance
- failed
- disabled
Only an available line may receive a new work order.
Machine
Each machine belongs to a production line. A machine contains:
- ID
- Production Line ID
- Machine Type
- Supported Operations
- Maximum Throughput
- Status
- Last Maintenance
For example:
type Machine struct {
ID string
ProductionLineID string
Type string
SupportedOperations []string
MaxUnitsPerHour int
Status MachineStatus
}
Possible machine states:
- available
- running
- maintenance
- failed
- disabled
Product
Each product contains:
- ID
- Name
- Product Type
- Unit Weight
- Unit Volume
For example:
type Product struct {
ID string
Name string
ProductType string
UnitWeight float64
UnitVolume float64
}
Raw Material
A raw material contains:
- ID
- Name
- Unit
- Current Stock
- Reserved Stock
- Minimum Stock
For example:
type RawMaterial struct {
ID string
Name string
Unit string
CurrentStock float64
ReservedStock float64
MinimumStock float64
}
Available quantity is:
Available = CurrentStock - ReservedStock
Reserved stock must never exceed current stock.
Bill of Materials
Every manufactured product has a bill of materials. For example:
type BillOfMaterials struct {
ProductID string
Requirements []MaterialRequirement
}
with:
type MaterialRequirement struct {
MaterialID string
QuantityPerUnit float64
}
Example Product
Create:
Product ID: product-x100
Name: Industrial Control Unit X100
Product Type: electronic-control-unit
Bill of materials per unit:
Aluminum Housing = 1 unit
Control Board = 1 unit
Power Module = 1 unit
Cooling Fan = 2 units
Copper Wire = 4.5 meters
Mounting Screw = 8 units
Thermal Compound = 12 grams
Packaging Box = 1 unit
Production Request
A production request contains:
- Request ID
- Product ID
- Requested Quantity
- Priority
- Deadline
For example:
type ProductionRequest struct {
RequestID string
ProductID string
Quantity int
Priority ProductionPriority
Deadline time.Time
}
Possible priorities:
- normal
- high
- critical
Material Requirement Calculation
For:
Requested Quantity = Q
Material Per Unit = M
required quantity is:
Required = Q * M
For 100 X100 units:
Aluminum Housing = 100
Control Board = 100
Power Module = 100
Cooling Fan = 200
Copper Wire = 450 meters
Mounting Screw = 800
Thermal Compound = 1200 grams
Packaging Box = 100
Material Validation
Before production starts, verify that all required materials are available.
The system must report all shortages.
For example:
Control Board:
required = 100
available = 82
missing = 18
Cooling Fan:
required = 200
available = 190
missing = 10
The implementation must not stop at the first missing material.
Material Reservation
If all required materials are available:
reserve all required materials
A material reservation may use:
type MaterialReservation struct {
ID string
WorkOrderID string
MaterialID string
Quantity float64
Status ReservationStatus
}
Possible states:
- reserved
- consumed
- released
The same stock must not be reserved twice.
Atomic Reservation
For the base task, material reservation is atomic.
Either:
all materials are reserved
or:
none are reserved
if any requirement cannot be satisfied.
Work Order
A production request that passes validation becomes a work order. For example:
type WorkOrder struct {
ID string
ProductionRequestID string
ProductID string
Quantity int
ProductionLineID string
Status WorkOrderStatus
}
Possible states:
- created
- materials_reserved
- scheduled
- running
- paused
- completed
- failed
- cancelled
Production Line Assignment
A work order may only be assigned to a production line when:
- line supports product type
- line status = available
- required machines are available
- line has sufficient throughput
- deadline can reasonably be satisfied
Machine Requirements
A product may require multiple manufacturing operations. For example:
- assembly
- soldering
- cooling-installation
- testing
- packaging
The selected production line must contain machines capable of all required operations.
Worker
A worker contains:
- ID
- Name
- Skills
- Shift
- Status
For example:
type Worker struct {
ID string
Name string
Skills []string
ShiftStart time.Time
ShiftEnd time.Time
Status WorkerStatus
}
Possible worker states:
- available
- assigned
- off_shift
- suspended
Worker Assignment
Some production operations require qualified workers. For example:
assembly:
skill = assembly
electrical testing:
skill = electrical-test
quality inspection:
skill = quality-control
A work order must not assign a worker who lacks the required skill.
Production Batch
A work order may be divided into batches. For example:
type ProductionBatch struct {
ID string
WorkOrderID string
PlannedQuantity int
ProducedQuantity int
AcceptedQuantity int
RejectedQuantity int
Status BatchStatus
}
Possible states:
created
running
quality_check
completed
failed
Batch Scenario
For:
Work Order Quantity = 100
split production into:
Batch 1 = 40
Batch 2 = 40
Batch 3 = 20
Each batch must be tracked independently.
Production Progress
The implementation must preserve:
- planned quantity
- produced quantity
- accepted quantity
- rejected quantity
For every batch.
The following must always hold:
accepted + rejected <= produced
produced <= planned
Material Consumption
Materials should be consumed according to actual produced quantity. For example:
40 units produced
means that material consumption corresponds to 40 units, not the entire work order.
Unused reserved material must eventually be released.
Machine Usage
Record which machines were used for every batch. A possible model:
type MachineUsage struct {
BatchID string
MachineID string
StartTime time.Time
EndTime time.Time
}
Machine Failure
During production, a machine may fail. Example:
machine-solder-02 failed
The implementation must determine:
- which batch is affected
- which work order is affected
- whether the production line can continue
- whether an alternative machine exists
- whether production must pause
Machine Failure Scenario
Assume Batch 2 is running. At 13:20 machine-solder-02 fails.
If another compatible machine exists on the same line:
batch may continue after reassignment
Otherwise:
- batch becomes paused
- work order becomes paused
Maintenance
Machines have planned maintenance windows.
A possible model:
type MaintenanceWindow struct {
ID string
MachineID string
StartTime time.Time
EndTime time.Time
Reason string
}
Machines under active maintenance cannot be assigned to production.
Quality Check
Every batch must pass quality control. For example:
type QualityCheck struct {
ID string
BatchID string
InspectedUnits int
PassedUnits int
FailedUnits int
Result QualityResult
}
Possible results:
- passed
- partially_passed
- failed
Quality Scenario
Batch:
Produced = 40
Quality result:
Accepted = 37
Rejected = 3
Only the accepted units may enter finished-goods inventory.
Quality Failure Threshold
For the base task:
if more than 10% of inspected units fail,
the batch requires manual review
For:
40 inspected
5 failed
failure percentage is:
12.5%
Therefore:
manual review required
Rejected Units
Rejected products must not enter normal finished-goods inventory. They may enter:
- scrap
- rework
- manual_review
A possible model:
type RejectedUnitRecord struct {
BatchID string
Quantity int
Reason string
Action string
}
Rework
Some rejected units may be eligible for rework. For example:
- 3 rejected units
- 2 can be reworked
- 1 must be scrapped
If rework succeeds:
reworked accepted units
may enter finished-goods inventory.
Finished Goods Inventory
Accepted units are added to finished-goods inventory. For example:
type FinishedGoodsInventory struct {
ProductID string
Quantity int
}
After:
37 accepted units
inventory increases by:
+37
Finished Goods Warehouse Capacity
The finished-goods warehouse may have limited capacity. A possible model:
type WarehouseCapacity struct {
MaximumUnits int
CurrentUnits int
}
Production completion must not silently exceed warehouse capacity.
If there is insufficient warehouse capacity:
- batch may complete production
- but finished goods cannot be fully stored
The system must report the blocked quantity.
Work Order Completion
A work order is complete when:
- all batches are completed
- all accepted units are processed
- all remaining reserved materials are consumed or released
The final work-order result should include:
- requested quantity
- produced quantity
- accepted quantity
- rejected quantity
- scrapped quantity
- reworked quantity
- final inventory increase
Production Shortfall
It is possible for:
accepted quantity < requested quantity
because of rejected or scrapped units. The implementation must report the shortfall. For example:
requested = 100
accepted = 94
shortfall = 6
The source system may then create a follow-up production request.
Cancellation
A work order may be cancelled before production begins. Allowed:
created -> cancelled
materials_reserved -> cancelled
scheduled -> cancelled
When cancellation occurs:
reserved materials must be released
A running work order should not be cancelled without an explicit stop policy. For the base task:
running work orders cannot be directly cancelled
Priority Scheduling
When several work orders compete for the same production line, process priority in this order:
- critical
- high
- normal
Within the same priority:
earlier deadline first
Then:
WorkOrder ID ascending
Multiple Factory Scenario
Create at least two factories. For example:
- factory-1
- factory-2
Both factories may manufacture the same product but have:
- different line capacity
- different material inventory
- different machine availability
The system should determine which factory can fulfill a production request.
Factory Selection
For a new production request, evaluate:
- material availability
- compatible production line
- machine availability
- worker availability
- estimated completion time
- warehouse capacity
The selected factory must satisfy all required conditions.
Supply Delivery
Raw materials may arrive from suppliers. A material delivery contains:
- Delivery ID
- Material ID
- Warehouse ID
- Quantity
- Timestamp
For example:
type MaterialDelivery struct {
ID string
MaterialID string
WarehouseID string
Quantity float64
Timestamp time.Time
}
Delivery increases raw-material stock.
Material Delivery Scenario
Example:
Control Board +100
Cooling Fan +250
Copper Wire +1000 meters
The update must target the correct warehouse and material.
Low Stock Warning
When:
CurrentStock - ReservedStock < MinimumStock
the system should report a low-stock condition.
This warning does not automatically block production unless the required quantity is unavailable.
Audit History
Every important state-changing operation should generate an audit event. Examples:
- production request created
- materials reserved
- work order scheduled
- batch started
- machine failed
- batch paused
- quality check completed
- units rejected
- units reworked
- finished goods stored
- work order completed
A possible model:
type AuditEvent struct {
ID string
Timestamp time.Time
EntityType string
EntityID string
Action string
Details string
}
Idempotency
Production requests should contain:
RequestID
If the same request is processed twice, the system must not create duplicate work orders or reserve materials twice.
Material deliveries should also have unique delivery IDs. Processing the same delivery twice must not duplicate stock.
Queries
The system should support queries such as:
- get available materials
- get material shortages
- get production-line status
- get machine status
- get active work orders
- get batches for work order
- get quality results
- get finished-goods inventory
- get low-stock materials
- get machine failure history
- get production history for product
Queries must not mutate production state.
Commands
State-changing operations include:
- create production request
- reserve materials
- create work order
- schedule work order
- start batch
- pause batch
- resume batch
- record machine failure
- complete batch production
- perform quality check
- record rework
- store finished goods
- cancel work order
- process material delivery
Validation
The implementation should validate:
- duplicate IDs
- unknown factory
- unknown production line
- unknown machine
- unknown product
- unknown material
- unknown worker
- invalid quantity
- negative inventory
- reserved stock greater than current stock
- unsupported product type
- missing required machine operation
- worker missing required skill
- invalid state transition
- maintenance conflict
- warehouse capacity exceeded
- duplicate request ID
- duplicate delivery ID
Required Test Scenarios
Create tests for at least:
- successful production request
- material shortage
- atomic reservation rollback
- successful work-order scheduling
- unsupported product on production line
- machine failure with replacement machine
- machine failure without replacement machine
- maintenance machine excluded
- worker skill mismatch
- successful batch production
- quality check passed
- quality check partially passed
- manual review threshold
- rework
- scrap
- finished-goods inventory update
- warehouse capacity exceeded
- work-order cancellation
- reserved material release
- priority scheduling
- factory selection
- material delivery
- duplicate production request
- duplicate material delivery
- low-stock warning
Modeling Goal
The purpose of this task is to model a production system where inventory, machines, workers, quality control, and production state all interact.
A useful conceptual architecture is:
Product Catalog
|
+-- Product
+-- Bill of Materials
|
v
Material Service
|
+-- Stock
+-- Reservation
+-- Delivery
|
v
Production Planner
|
+-- Factory Selection
+-- Line Selection
+-- Scheduling
|
v
Work Order Service
|
+-- Batches
+-- Machine Usage
+-- Worker Assignment
|
v
Quality Service
|
+-- Inspection
+-- Rework
+-- Scrap
|
v
Finished Goods Inventory
|
v
Audit History
The main challenge is keeping production state, material state, machine state, worker assignments, quality results, and warehouse inventory consistent throughout the complete manufacturing lifecycle.