Domain message flow
This page is a copy of docs/docs/ddd/domain-message-flow.md on develop, derived from that repository's code. Edit it there, then re-sync.
Following ddd-crew Domain Message Flow Modelling.
Each arrow is numbered and prefixed cmd: (command), evt: (event) or qry:
(query). Only real messages appear: REST routes from NewRouter, MCP tools from
tools.go, and CloudEvents types from the consumers and the encoder.
1. Capacity is known, a plan reveals a shortage, order-management is told
A shift plan is committed, the facility registers packing stations, a planner declares the per-station standard, then creates and publishes a plan whose demand exceeds the path capacity.
Source: internal/adapters/inbound/kafka/labor_capacity_consumer.go,
storage_capacity_consumer.go, internal/adapters/inbound/http/process_capacity_handler.go,
internal/domain/capacityplan/capacity_plan.go, internal/adapters/outbound/kafka/encoder.go;
order-management's planned_capacity_consumer.go.
Omits: the outbox relay hop between the commit and Kafka, the analytics copy of
every event, and the order-management consumer being opt-in.
2. Demand is defaulted from order-management's orders
The demand consumer is always on (DEMAND_CONSUMER_GROUP, DEMAND_SITE_ID=SIM1, both required).
A planner checks the expected demand and creates a plan without stating it.
Source: internal/adapters/inbound/kafka/order_demand_consumer.go,
internal/application/usecases/expected_demand.go,
internal/application/usecases/create_capacity_plan.go (resolveDemand),
internal/domain/demand/order.go, docs/adr/0004-demand-ingestion-from-order-management.md.
Omits: OrderRepromised and every other ignored type, and the events the
created plan emits (scenario 1).
3. The ops agent reads the capacity outlook over MCP
warehouse-ops-agent builds its daily brief from this context's read tools; it
never writes.
Source: internal/adapters/inbound/mcp/tools.go, cmd/mcp/main.go;
warehouse-ops-agent's internal/adapters/outbound/mcpclient/warehouse_planning.go
and its ADR 0013.
Omits: the agent's other wired-but-unused read tools (get_capacity_plan,
get_storage_capacity, list_station_standards) and the agent's own LLM
steps.
4. The planner's morning: requirement here, supply in workforce-management
ADR 0023. The planner sends the forecast and commits the labour plan here; workforce-management reads the published requirement, commits the supply, and this context compares the two. The walkthrough with request and response bodies is How-to: a planner's morning.
Source: internal/application/usecases/workload_forecast.go, labour_plan.go,
labour_plan_drift.go, internal/adapters/inbound/kafka/labor_capacity_consumer.go,
features/labour_plan.feature, features/labour_plan_drift.feature;
workforce-management's ADR 0043 and cmd/workforce/labour_plan.go; e2e-tests
cmd/warehouse-day/sim.go.
Omits: the outbox relay hop, the analytics copies, the planner revising the
plan after a drift (which re-runs the comparison, trigger B), and
workforce-management's own proposal and staffing-gap routes (its API).