# Routing

## Description

Routing defines the ordered manufacturing process used to build one produced item or item family. It owns operation sequencing, standard setup and run assumptions, work-center assignment, operator instructions, and the revision that production orders later freeze into executable work orders.

## Domain Model Definitions

### Model type

Stateful

#### State Transitions

```mermaid
stateDiagram-v2
    [*] --> Draft: createRouting
    Draft --> Draft: updateRouting
    Draft --> Active: activateRouting
    Active --> Inactive: deactivateRouting
```

| Operation | From | To | Command |
|-----------|------|----|---------|
| activate | DRAFT | ACTIVE | [activateRouting](../command/ActivateRouting.md) |
| deactivate | ACTIVE | INACTIVE | [deactivateRouting](../command/DeactivateRouting.md) |

### Command Definitions

- [createRouting](../command/CreateRouting.md) - Create a draft routing for one manufactured item or scope.
- [updateRouting](../command/UpdateRouting.md) - Revise operation order, instructions, and work-center assignments while mutable.
- [activateRouting](../command/ActivateRouting.md) - Validate ordered operations and make the routing eligible for production-order release.
- [deactivateRouting](../command/DeactivateRouting.md) - Remove the routing from future selection without mutating released snapshots.

### Query Definitions

- [getRouting](../query/GetRouting.md) - Retrieve one routing revision with ordered operations.
- [listRoutingsByItem](../query/ListRoutingsByItem.md) - List routing revisions available for one parent item and scope.

### Models

- Routing
- RoutingOperation

### Invariants

- Every routing belongs to one company and targets one manufactured item or item family within an optional site scope.
- The produced item must be ACTIVE and manufacturable when the routing is activated.
- A draft or active routing contains at least one operation with a unique sequence number inside the routing.
- Standard setup and run time values are always zero or greater.
- Each operation references a work center that is valid for the same company and effective scope.
- An active routing must not reference an inactive work center.
- Active routing operations may only reference ACTIVE work centers.
- Revisions for future orders may be created or activated without mutating any routing snapshot already frozen onto released production orders.
- Deterministic sequencing is part of the routing definition in the initial scope, so operations execute in one ordered path rather than parallel branches.

### Relationships

- **References Item (cross-module)**: the produced parent item is an [Item](../../../item-management/docs/model/Item.md).
- **Has Many RoutingOperations**: ordered step definitions live under the routing aggregate.
- **References WorkCenter**: each operation is assigned to one [WorkCenter](./WorkCenter.md).
- **Referenced By ProductionOrder**: [ProductionOrder](./ProductionOrder.md) snapshots one routing revision at release.
- **Materializes Into WorkOrder**: released operation snapshots become [WorkOrder](./WorkOrder.md) records.
