Application use cases
internal/application/usecases holds one struct per use case. Each is wired
in a composition root (cmd/wes/handlers.go, cmd/wes/serving.go,
cmd/mcp/main.go) and runs its saves and publishes inside one
UnitOfWork — the outbox rows commit with the
state change (ADR-0014). Unit tests that
use the in-memory doubles run the same steps back to back.
Source: cmd/wes/handlers.go, cmd/wes/serving.go, cmd/mcp/main.go,
internal/application/usecases/*.go.
Commands
ReceiveChargeForecast and CommitShiftPlan are gone: the charge forecast
and the shift plan moved to warehouse-planning
(ADR-0049).
The planner sends PUT /workload-forecasts/{site_id}/{path_id} and
PUT /labour-plans/{site_id}/{shift_id}/{path_id} there. The old routes answered
410 (charge-forecast-moved, shift-plan-moved) for one release (v2.0.3) and were
removed in stage E: POST /paths/{pathId}/charge and POST /paths/{pathId}/plan were removed (a POST answers 404).
EnqueueWorkUnit
- Trigger:
POST /paths/{pathId}/work-units→201(behind theIdempotency-Keymiddleware when Postgres is configured, ADR-0022); internally byApplyOrderAllocatedandApplyWorkDemandReleased. - Inputs:
workUnitId,cpt,reference(required);sku,giftWrap,lineNo(optional); transfer fieldstransferRef,workKind,siteId,quantityonly viaWorkDemandReleased. - Invariants: catalogue (REST handler); non-empty id and reference;
lineNoin 1..2147483647 when given; the id is not already in the path's pool (409 work-unit-already-enqueued). The first enqueue on a path creates itsWorkPoolasReleaseFedwith WIP limit and alarm threshold 1000. The pool save is retried on optimistic-concurrency conflicts (12 attempts, ADR-0029). - Events:
WorkUnitCreated.
ReleaseNextWork
- Trigger:
POST /paths/{pathId}/work-releases→200; MCP toolrelease_next_work. - Inputs:
pathId. - Invariants: the pool exists (
404); it has a pending entry (409 work-pool-empty); aReleaseFedpool is below its WIP limit (409 wip-limit-reached); the earliest CPT goes first (insertion order breaks ties); each entry is released at most once. A pending entry whose work unit already moved on (left by a pre-versioning lost update) is healed and skipped, and so is a leftover entry of aCancelledRELOCATE unit (ADR-0040). Optimistic retry as above. - Events:
WorkReleased(the integration publisher enriches it with CPT, reference,gift_wrap,line_no, transfer fields, the RELOCATErelocationobject and — from the classification copy —required_capabilities/fragile). Also incrementswes.work_units.released.
RecordCompletion
- Trigger:
POST /work-units/{id}/completions→200; internally byApplyTaskCompleted. - Inputs: work-unit id.
- Invariants: the unit exists (
404), was released (work-unit-not-released) and is not already completed (work-unit-already-completed). Its pool entry is reconciled to completed, which frees the WIP slot; a path with no pool or a pool that never held the unit is not an error. Completing a RELOCATE unit also admits, in the same atomic scope, every Pending RELOCATE unit blocked by it (blocked_byis cleared and the unit enters the RELOCATE pool), so a fill never runs before the vacate of its slot (ADR-0040). - Events:
WorkUnitCompleted.
SampleBacklog
- Trigger:
GET /paths/{pathId}/telemetry[?cutoffAt=<RFC3339>]→200; MCP toolget_backlog_telemetry; MCP resourcetelemetry://{pathId}/backlog. - Inputs:
pathId; optionalcutoffAt(REST only). - Output:
backlogDepth(pending),wip(released, not completed),mode,overAlarmThreshold; withcutoffAtalsoremainingCapacityKnownandremainingCapacityUnits(WIP limit minus WIP; unknown forFlowFed). - Invariants: the pool exists (
404); a present-but-empty or malformedcutoffAtis400. - Events:
BacklogThresholdBreachedwhenever the backlog exceeds the alarm threshold (so this read publishes — including through the MCP tool and resource; the tool is therefore annotated non-read-only, destructive, ADR-0037);PathCapacityChangedwhencutoffAtis supplied (ADR-0018).
RebalanceDecision
- Trigger:
POST /paths/{pathId}/rebalance-decisions(keyed) →201; MCP toolget_rebalance_recommendation. - Output:
NoActionNeeded,ThrottleUpstream(aFlowFedpool over its alarm threshold) orReassignLabor(aReleaseFedpool at its WIP limit with backlog waiting) (ADR-0003). - Events:
PathThrottledwithThrottleUpstream;LaborReassignmentFlaggedwithReassignLabor(so the MCP tool is annotated non-read-only, destructive, ADR-0037).
ConfigurePool
- Trigger:
PUT /paths/{pathId}/pool→200. - Inputs:
mode(ReleaseFedorFlowFed),wipLimit(required). - Invariants: catalogue; known mode (
unknown-feed-mode);wipLimit > 0(invalid-wip-limit). Creates the pool when missing. Lowering the limit below current WIP evicts nothing; an identical repeat writes nothing (ADR-0034). It is the only way to get aFlowFedpool. - Events: none.
Queries
| Use case | Trigger | Returns | Not found |
|---|---|---|---|
GetWorkUnit | GET /work-units/{id} | one work unit (id, pathId, cpt, reference, state, giftWrap, sku, lineNo, releasedAt, completedAt, cancelledAt; RELOCATE units add relocation = planId, moveSeq, kind, siteId, fromSlot, toSlot, blockedBy) | 404 |
GetWorkUnitsByReference | GET /work-units?reference= | every work unit with that reference, keyset-paged ({items,nextCursor}; items empty when none) | 400 reference-required when the parameter is missing |
LaborPlanView | GET /paths/{pathId}/labor-plan-view | the LaborPlanObserved projection; its drift fields are deprecated read-backs (ADR-0049) | 404 until a ShiftPlanCommitted for the path arrives |
InventoryView | GET /inventory-view/{sku} | the UsableInventoryObserved projection | 404 until an inventory event for the SKU arrives |
Inbound-event use cases
All ten claim the CloudEvents id in processed_events inside the same
atomic scope as their effect (onceAtomically,
ADR-0028): a
redelivery is a no-op, and a failure rolls the mark back so the retry
re-applies the event. The consumer that calls them is described on
Integration events.
| Use case | Event (topic) | Effect | Invariants / failure | Events raised |
|---|---|---|---|---|
ObserveLaborPlan | ShiftPlanCommitted (warehouse.workforce.events) | upserts LaborPlanObserved for path_id as reported; a pure projection since ADR-0049 | the adapter rejects a path_id outside the catalogue (retried, then DLQ) | none |
ObserveInventoryChange | StockReserved / ReservationRevoked (warehouse.inventory.events) | applies -quantity / +quantity to UsableInventoryObserved for the SKU | — | none |
ApplyTaskCompleted | TaskCompleted (warehouse.fulfillment.events) | runs RecordCompletion for work_unit_id | an unknown work unit is a logged skip (still marked processed); any other error is retried, then DLQ | WorkUnitCompleted (via RecordCompletion) |
ApplyOrderAllocated | OrderAllocated / OrderPartiallyAllocated (warehouse.order-management.events) | one EnqueueWorkUnit per line: id {order_id}-line-{line_no}, CPT = promise_date, reference = order_id, plus sku, gift_wrap, line_no (ADR-0031, ADR-0036) | every line's path_id checked against the catalogue before anything is enqueued; an out-of-range line_no is stored as unknown; a line already in the pool is skipped | WorkUnitCreated per new line |
ApplyWorkDemandReleased | WorkDemandReleased (warehouse.network-inventory-planning.events) | one EnqueueWorkUnit with id = reference = demand_id, CPT = cpt, and the transfer fields (ADR-0033) | work_kind must be TRANSFER_PICK, TRANSFER_DISPATCH or TRANSFER_ARRIVAL; path_id in the catalogue; an existing demand_id is a no-op | WorkUnitCreated |
ApplySlotPlanApproved | SlotPlanApproved (warehouse.slotting-optimization.events) | one RELOCATE unit per move: id {plan_id}-move-{seq} (seq = 0-based position in moves), reference = plan_id, CPT = approved_at + RELOCATION_CPT_HORIZON, path RELOCATE. A move into a slot another move of the plan vacates gets blocked_by and stays out of the pool until that unit completes (swap cycles broken at the lowest seq). A newer plan for the site cancels the other plans' Pending units (state Cancelled, pool entry withdrawn); released work runs to completion (ADR-0040) | move kind must be Relocate, Assign or Vacate with the slots that kind needs; RELOCATE must be in the catalogue and, when it declares an intake, admit SLOT_RELOCATION (process-path-management ADR 0034); all retried, then DLQ. An older plan than the site's latest, or the same plan again, is a no-op | WorkUnitCreated per planned unit |
ObserveProductClassification | ProductClassified (warehouse.product-master.events) | version-guarded upsert into product_classification_copy (ADR-0035) | an older or equal version is a stale no-op (id still recorded) | none |
ObservePackLevel | ProductPackLevelDeclared / ProductPackLevelRetired / ProductPackLevelMeasured (warehouse.product-master.events) | Declared: version-guarded upsert into product_pack_level_copy; Retired: sets effective_to; Measured: stores the measured dimensions (ADR-0045) | an older or equal version, or a Retired / Measured for an unknown GTIN, is a stale no-op (id still recorded); a redelivered CloudEvents id is a no-op | none |
ApplyReplenishmentRequested | ReplenishmentRequested (warehouse.pick-face-replenishment.events) | one REPLENISH unit per request: id replenish-{request_id}, reference = request_id, path REPLENISH, CPT = requested_at + REPLENISHMENT_CPT_HORIZON (8h, NORMAL) or REPLENISHMENT_URGENT_CPT_HORIZON (1h, URGENT; capped at the normal horizon), carrying the move (SKU, source_bin as from-bin, forward_bin as to-bin, quantity, priority) (ADR-0042) | request_id, sku and both bins required, the bins differ, quantity at least 1, priority exactly NORMAL or URGENT, site_id and requested_at present, REPLENISH in the catalogue (no intake is evaluated); a request id whose unit already exists is a no-op, never a second unit | WorkUnitCreated |
ApplyReplenishmentCancelled | ReplenishmentCancelled (warehouse.pick-face-replenishment.events) | cancels the request's unit only while it is Pending (state Cancelled, pool entry withdrawn); a released, completed or already cancelled unit runs on, and a request this context never planned is a no-op (ADR-0042) | a blank request_id is refused (dead-lettered, never retried) | none |
Events no use case raises
RateDeviationDetected has a constructor in
internal/domain/shared/events.go, an outbound encoding and a column in the
analytics throughput_rollup, but no production use case creates it, so the
report's rateDeviationDetected count stays 0.
Not use cases
- The process-path catalogue (
filecatalog,kafkacatalog) is an outbound adapter behindports.PathCatalogue, read by the handlers and the inbound-event use cases. - The analytics projection (
internal/analytics/report,internal/adapters/outbound/analyticsstore) is driven directly by the projector's consumer and read by the reports handlers — it bypasses this package by design (ADR-0011).