Skip to main content

Aggregate design canvas

One ddd-crew Aggregate Design Canvas v1.1 per aggregate root in internal/domain/. The numbered invariants (T1, S1, P1, C1, ...) match Aggregates & invariants, which has the failing-path test for each. Throughput and size figures are estimates for a single mid-size fulfilment centre, labelled as such — the code holds no such numbers.

Task​

1. Name​

task.Task — internal/domain/task/task.go.

2. Description​

A unit of physical work (PICK, PACK, REBIN, SLAM) with a CPT deadline, an orderRef (the work unit id), an optional sourceOrderId (the upstream order id from WorkReleased.ref, published as TaskCompleted.order_ref — ADR-0040), an optional sourceLineNo (the order line from WorkReleased.line_no, order work only, range 1..2147483647 with anything larger left unknown (0), published as TaskCompleted.line_no — ADR-0041), required capabilities and two packing hints (fragile, giftWrap). It is the consistency boundary for "who holds this work right now": at most one active lease, owned by one station.

3. State Transitions​

Source: internal/domain/task/task.go (Pending, Claimed, Completed; Claim, RenewLease, ExpireLeaseIfDue, Complete). Omits the lazy expiry inside Claim / RenewLease / Complete (they run the same CLAIMED → PENDING edge before deciding) and the read-only predicates IsAvailable and IsCPTMissed.

4. Enforced Invariants​

#InvariantEnforced by
T1At most one active claim at a timeTask.Claim → task.ErrAlreadyClaimed; persisted by TaskRepo.SaveClaim compare-and-set (ADR-0034)
T2The claiming station must hold every required capabilityTask.Claim → task.ErrCapabilityMismatch (CapabilitySet.HasAll)
T3An expired lease frees the task before any further decisionTask.ExpireLeaseIfDue, called lazily from Claim, RenewLease, Complete
T4No double-complete: a completed task rejects every further operationTask.Claim / RenewLease / Complete → task.ErrAlreadyCompleted
T5Only the claim owner may renew or completeTask.RenewLease / Task.Complete → task.ErrNotOwner
T6Renew and complete require an active claimTask.RenewLease / Task.Complete → task.ErrNotClaimed

5. Corrective Policies​

  • Lease expiry sweep — ExpireLeases (POST /task-lease-expirations) frees every lapsed claim and raises LeaseExpired.
  • CPT-miss sweep — SweepCPTMisses (POST /cpt-miss-sweeps) reports open tasks at or past CPT as TaskCPTMissed; it changes nothing, so order-management re-promises.
  • Claim race — a station that loses the SaveClaim compare-and-set silently moves to the next candidate.

6. Handled Commands​

CreateTask (REST POST /tasks, the WorkReleased consumer, ArriveAtRebin), ClaimNext (POST /stations/{stationId}/task-claims), RenewLease (POST /tasks/{id}/lease-renewals), CompleteTask (POST /tasks/{id}/completions, MCP complete_task), ExpireLeases, SweepCPTMisses (reads only).

7. Created Events​

EventFull CloudEvents type
TaskCreatedcom.warehouse.wes.fulfillment-execution.task.TaskCreated
TaskClaimedcom.warehouse.wes.fulfillment-execution.task.TaskClaimed
LeaseExpiredcom.warehouse.wes.fulfillment-execution.task.LeaseExpired
TaskCompletedcom.warehouse.wes.fulfillment-execution.task.TaskCompleted
TaskCPTMissedcom.warehouse.wes.fulfillment-execution.task.TaskCPTMissed
ItemPicked (defined, never raised)com.warehouse.wes.fulfillment-execution.task.ItemPicked

8. Throughput (estimate)​

High. Every unit of work creates a task, and every task is touched by a claim, usually a renewal or two, and a completion — estimate: thousands of commands per hour per site at peak. Contention is per task and short: only concurrent claim-next calls on the same task type race, and the compare-and-set resolves them.

9. Size (estimate)​

Small and short-lived. Estimate: 3–6 events per instance (created, claimed, optionally one or two lease expiries and re-claims, completed, occasionally CPT-missed), lifetime minutes to hours, one row in tasks.

Station​

1. Name​

station.Station — internal/domain/station/station.go.

2. Description​

A work position with a fixed capability set, an optional facility-layout locationCode, and at most one occupant (an associate or a robot). ClaimNext reads its capabilities; CompleteTask's published event reads its occupant.

3. State Transitions​

Source: internal/domain/station/station.go (CheckIn, CheckOut, IsOccupied). There is no status enum: occupancy is the nil-ness of occupant. Omits re-registration (RegisterStation saves a fresh Station over an existing id).

4. Enforced Invariants​

#InvariantEnforced by
S1One occupant at a timeStation.CheckIn → station.ErrOccupied
S2Cannot check out an empty stationStation.CheckOut → station.ErrNotOccupied
S3A station can only accept tasks whose required capabilities it holdsStation.ValidateAccept → station.ErrCapabilityMismatch

Plus an application-level rule at registration: a locationCode that facility-layout knows must have role WorkCenter (usecases.ErrStationLocationNotWorkCenter, ADR-0024).

5. Corrective Policies​

None. A station left occupied stays occupied until someone checks it out; associate_id on TaskCompleted is best-effort for that reason.

6. Handled Commands​

RegisterStation (POST /stations), CheckInStation (POST /stations/{stationId}/check-ins), CheckOutStation (POST /stations/{stationId}/check-outs).

7. Created Events​

None — registration and occupancy are operational state, not domain facts.

8. Throughput (estimate)​

Low. Estimate: a handful of check-ins and check-outs per station per shift; registration only when the floor changes. Read on every claim.

9. Size (estimate)​

Tiny and long-lived: one row in stations, no events, lifetime months.

Package​

1. Name​

pack.Package — internal/domain/package/package.go (Go package pack, because package is a keyword).

2. Description​

The Pack output: one sealed carton for one PACK task, with its scanned contents, the DOT hazard classes of those contents, two handling flags derived from the task, a derived SortLane, and the SLAM outcome.

3. State Transitions​

Source: internal/domain/package/package.go (Open, Sealed, Labeled, Diverted; ScanItemWithClass, Seal, Weigh). Omits that the OPEN state never reaches the database: SealPackage builds, scans and seals in memory and saves the package already SEALED.

4. Enforced Invariants​

#InvariantEnforced by
P1Cannot seal without scanned contentsPackage.Seal → pack.ErrNoScannedContents
P2Cannot scan into or re-seal a sealed packagePackage.ScanItemWithClass / Seal → pack.ErrAlreadySealed
P3SLAM requires a sealed packagePackage.Weigh → pack.ErrNotSealed
P4SLAM runs oncePackage.Weigh → pack.ErrAlreadyProcessed
P5Outside WeightTolerance (0.05) the package is diverted, not labelledPackage.Weigh (returns labelApplied = false)
P6Incompatible DOT hazard classes may not share a packagePackage.ScanItemWithClass → pack.ErrPackageSegregationViolation (pack.IsSegregationIncompatible)

Plus application-level rules in SealPackage: the task must be a PACK task (usecases.ErrWrongTaskType) and the caller must hold an unexpired lease on it (Task.VerifyHeldBy → task.ErrNotClaimed for a missing or expired lease, task.ErrNotOwner for an active lease of another station; ADR-0038); one package per task (PackageRepo.FindByTaskId short-circuit, unique index idx_packages_task_id).

5. Corrective Policies​

  • A diverted package goes to manual handling; nothing in this context re-weighs it.
  • A hazard lookup failure is treated as "no hazard class" (fail-open), so sealing never blocks on the classification copy (product-master's ProductClassified, ADR-0039).

6. Handled Commands​

SealPackage (POST /tasks/{id}/package-seals), RunSlam (POST /packages/{id}/slam-runs). Reads: GetPackage, GetPackagesByOrderRef.

7. Created Events​

EventFull CloudEvents type
PackageSealedcom.warehouse.wes.fulfillment-execution.package.PackageSealed
LabelAppliedcom.warehouse.wes.fulfillment-execution.package.LabelApplied
PackageManifestedcom.warehouse.wes.fulfillment-execution.package.PackageManifested
WeightDiscrepancyDetectedcom.warehouse.wes.fulfillment-execution.package.WeightDiscrepancyDetected
PackageDivertedcom.warehouse.wes.fulfillment-execution.package.PackageDiverted

8. Throughput (estimate)​

Medium. Estimate: one seal and one SLAM per shipped carton, so roughly one package command per PACK task; no contention (one station holds the PACK task, one SLAM line weighs the carton).

9. Size (estimate)​

Small: exactly 3 events per instance (sealed, then labelled + manifested or discrepancy + diverted), lifetime minutes, one row in packages.

OrderConsolidation​

1. Name​

consolidation.OrderConsolidation — internal/domain/consolidation/order_consolidation.go.

2. Description​

Tracks which of an order's required lines have reached Rebin. When the set is complete, the order's PACK task is created exactly once. Lines are identified by string id only; it holds no reference to Task (ADR-0016).

3. State Transitions​

Source: internal/domain/consolidation/order_consolidation.go (RecordArrival, IsComplete), internal/application/usecases/arrive_at_rebin.go. There is no status enum: "complete" is IsComplete(). Omits the unknown-line rejection, which leaves the state unchanged.

4. Enforced Invariants​

#InvariantEnforced by
C1Only a line in the required set can arriveOrderConsolidation.RecordArrival → consolidation.ErrUnknownLine
C2Arrivals are idempotent, and the PACK task is created exactly once, on the arrival that completes the setRecordArrival (re-recording is a no-op); ArriveAtRebin (HasArrived check: a redelivered arrival returns before any save or publish, at any stage), serialized per order by FindByOrderRefForUpdate (ADR-0034)

5. Corrective Policies​

Redelivered arrivals are idempotent no-ops. There is no timeout for an order whose last line never arrives.

6. Handled Commands​

ArriveAtRebin (POST /rebin/arrivals).

7. Created Events​

ItemArrivedAtRebin and OrderConsolidated — domain events with no CloudEvents type: neither encoder's allowlist includes them, so they never leave the process. On completion the aggregate's use case also raises TaskCreated (com.warehouse.wes.fulfillment-execution.task.TaskCreated) through CreateTask.

8. Throughput (estimate)​

Medium, only for multi-line orders routed through Rebin. Estimate: one command per line. Contention is per order and serialized by the row lock.

9. Size (estimate)​

Small: one event per line plus one at completion, lifetime minutes, one row in order_consolidations.

WorkBatch​

1. Name​

workbatch.WorkBatch — internal/domain/workbatch/workbatch.go.

2. Description​

The PICK tasks one station holds for one walk, formed at assignment time inside one priority band; a batch of one is valid and nothing waits for a batch to fill (ADR-0063). Members are snapshots (task id, CPT instant, pick face, hazard class, hint rank, stop sequence, cart compartment, state).

3. State Transitions​

Source: internal/domain/workbatch/workbatch.go (Form, CompleteMember, DetachMember). Completed and Abandoned are terminal: any further member command is ErrBatchNotOpen.

4. Enforced Invariants​

W1–W8 on Aggregates & invariants: size 1..maximum, pickable members, one priority band, cart segregation, one open batch per station (partial unique index), anchor equivalence with ClaimNext, open-only changes, and the member lifecycle.

5. Corrective Policies​

An expired member lease detaches that member when ExpireLeases returns the task to the pool; the last detach abandons the batch. RenewWorkBatchLease renews every open member together so a long walk cannot expire mid-walk.

6. Handled Commands​

FormWorkBatch (POST /stations/{stationId}/work-batches), RenewWorkBatchLease (POST /work-batches/{batchId}/lease-renewals); member completion and detachment arrive through CompleteTask and ExpireLeases. The read is GetWorkBatch (GET /work-batches/{batchId}, MCP get_work_batch).

7. Created Events​

WorkBatchFormed, WorkBatchCompleted and WorkBatchAbandoned (com.warehouse.wes.fulfillment-execution.workbatch.*, key and subject = the batch id) on both topics, only with PICK_BATCH_MODE=on. TaskCompleted gains the optional batch_id and batch_size.

8. Throughput (estimate)​

Not estimated: the feature ships dark (PICK_BATCH_MODE defaults to off) and ADR-0063 records that no reliable saving figure exists yet.

9. Size (estimate)​

Not estimated. One work_batches row plus at most PICK_BATCH_MAXIMUM (default 4) work_batch_members rows per walk; no row is ever written while the mode is off.

Read models and projections (not aggregates)​

Read modelBuilt fromServed by
Queue depthTaskRepo.CountByTypeAndStatus(type, PENDING) on demandGetQueueDepth, GET /queues/{taskType}/depth, MCP get_queue_status
Installed capacityStationRepo.CountByCapability on demandGetInstalledCapacity, GET /capacity/{capability}
Tasks by orderTaskRepo.FindByOrderRefGET /tasks?orderRef=
Package read modelPackageRepo.FindById, FindByOrderRefGET /packages/{id}, GET /packages?orderRef= (ADR-0033)
Claimable work / stuck tasksTaskRepo through mcp.TaskQueriesMCP find_claimable_work, diagnose_stuck_tasks
Throughput and on-time-to-CPT rollupwarehouse.fulfillment.analytics → cmd/fulfillment-projector → throughput_rollupcmd/fulfillment-reports GET /reports/throughput, MCP report tools

pathcatalog.Catalogue is configuration, not an aggregate: it is loaded from YAML or replayed from Kafka and never changed by a command of this context.