Skip to main content

Sequence diagrams

UML sequence diagrams for every command use case this context exposes, traced from the function bodies in internal/application/usecases/ and the inbound adapters. Participants follow the hexagon: client → inbound adapter → application service (use case) → aggregate → repository / outbox → broker.

Conventions used throughout:

  • The runtime is Postgres + Kafka only (ADR-0044), so that is what is drawn. (In unit tests the in-memory doubles leave UnitOfWork nil, atomically just calls the function and there is no outbox; no binary runs like that.)
  • atomically(...) is one Postgres transaction: aggregate rows and the outbox rows commit or roll back together (ADR-0014). Each domain event becomes two outbox rows: warehouse.work-planning.events and warehouse.wes.analytics.
  • retryOnPoolConflict re-runs the whole load-mutate-save attempt when WorkPoolRepo.Save reports ports.ErrConcurrentModification — up to 12 attempts with jittered backoff (2 ms doubling, capped at 100 ms) (ADR-0029).

1. Enqueue a work unit over REST (with Idempotency-Key)​

Source: internal/adapters/inbound/http/router.go, internal/adapters/inbound/http/idempotency.go, internal/adapters/inbound/http/handlers.go (postWorkUnit), internal/application/usecases/enqueue_work_unit.go, internal/application/usecases/pool_retry.go, internal/adapters/outbound/postgres/work_pool_repo.go. Omits: the NUL guard (404/400 malformed-request-body before the key is recorded), the 400 malformed-request-body and unknown-path-id branches before the middleware, and a handler panic (rolls back, never cached).

2. Release the next work unit (REST or MCP)​

Source: internal/application/usecases/release_next_work.go, internal/domain/release/release_policy.go, internal/domain/release/work_pool.go, internal/adapters/inbound/mcp/tools.go. Omits: the error-to-problem mapping (errors.go) and the WorkReleased payload enrichment, which happens when the outbox row is encoded (diagram 8).

3. Record a completion (REST or TaskCompleted)​

POST /work-units/{id}/completions calls the same RecordCompletion.Execute directly, without the processed-event mark.

Source: internal/adapters/inbound/kafka/consumer.go, internal/application/usecases/apply_task_completed.go, internal/application/usecases/apply_integration_event.go, internal/application/usecases/record_completion.go. Omits: the ReleaseProcessed path (a unit-test double) that undoes the mark on failure when there is no transaction.

3a. Plan an approved slot plan as RELOCATE work (SlotPlanApproved)​

Releasing a RELOCATE unit is diagram 2 unchanged; its WorkReleased carries the relocation object fulfillment-execution's RELOCATE task decodes. When that task's TaskCompleted arrives, diagram 3 runs and RecordCompletion additionally asks RelocationWorkRepo.PendingBlockedBy for the moves waiting on the completed unit, clears their blocked_by and enqueues them in the same transaction.

Source: internal/adapters/inbound/kafka/consumer.go (handleSlottingEvent), internal/application/usecases/apply_slot_plan_approved.go, internal/application/usecases/record_completion.go, internal/domain/relocation/plan.go (ADR-0040).

4. Commit a shift plan — removed (moved to warehouse-planning)​

Source: internal/adapters/inbound/http/router.go (no planning route under /paths/{pathId}). The shift plan, its plannedHeads ≤ installedStations invariant and the plan-vs-labour drift check moved to warehouse-planning (ADR-0049), which publishes LabourPlanDriftDetected. No use case, repository or outbox of this context is involved. The old route answered 410 shift-plan-moved for one release (v2.0.3); stage E removed POST /paths/{pathId}/plan, so a POST answers 404.

5. Receive a charge forecast — removed (moved to warehouse-planning)​

Same shape as section 4: the planner sends warehouse-planning's PUT /workload-forecasts/{site_id}/{path_id}. The old route answered 410 charge-forecast-moved for one release; stage E removed POST /paths/{pathId}/charge (a POST answers 404).

6. Sample backlog and decide a rebalance (REST or MCP)​

Source: internal/application/usecases/sample_backlog.go, internal/application/usecases/rebalance_decision.go, internal/adapters/inbound/mcp/tools.go. Omits: the MCP tools take no cutoffAt, so get_backlog_telemetry never raises PathCapacityChanged.

7. Apply OrderAllocated from order-management​

OrderPartiallyAllocated follows the same path. Source: internal/application/usecases/apply_order_allocated.go, internal/adapters/inbound/kafka/consumer.go. Omits: the inner EnqueueWorkUnit steps, shown in diagram 1.

8. Project ShiftPlanCommitted and inventory changes​

Source: internal/application/usecases/observe_labor_plan.go, internal/application/usecases/observe_inventory_change.go. ObserveLaborPlan publishes nothing: since ADR-0049 there is no plan of ours to compare with, and the save clears a drift recorded before it. Omits: the retry-then-DLQ handling common to every consumed event (diagram 3).

9. Outbox relay to Kafka​

Source: internal/adapters/outbound/postgres/outbox_publisher.go, internal/adapters/outbound/kafka/publisher.go, internal/adapters/outbound/kafka/encoded.go, internal/adapters/outbound/kafka/analytics_publisher.go, cmd/wes/main.go. Omits: the housekeeping sweeper that later deletes published rows older than OUTBOX_RETENTION (ADR-0032).

10. Configure a pool (REST)​

Source: internal/application/usecases/configure_pool.go, internal/domain/release/work_pool.go (Configure), internal/adapters/inbound/http/handlers.go (putPool), ADR-0034. Omits: any outbox write — the command raises no event, so no UnitOfWork is involved. Entries are never touched: lowering wipLimit below the current WIP evicts nothing, and ReleaseNextWork (diagram 2) answers 409 wip-limit-reached until completions bring WIP below the new limit.