Skip to main content

Domain events

Eight past-tense domain events are declared in internal/domain/shared/events.go. All implement one interface:

type DomainEvent interface {
EventName() string
OccurredAt() time.Time
}

OccurredAt comes from the injected Clock port, never from time.Now() inside the domain, so every event assertion in the test suite is exact.

Published​

All eight go to warehouse.work-planning.events (and a copy of each to warehouse.wes.analytics for this service's own analytics projector) as CloudEvents 1.0 structured-mode JSON. The Kafka partition key is the CloudEvents subject: the work unit id for workunit events, the path id for every other event (ADR-0024). dataschema is urn:warehouse:wes-work-planning:events:<EventName>:v1 (:analytics: on the analytics topic).

Full CloudEvents typeKey / subjectdata fieldsRaised byKnown consumers
com.warehouse.wes.work-planning.workunit.WorkUnitCreatedwork unit idpath_id, work_unit_id, optional reference and line_no (ADR-0041)EnqueueWorkUnit (REST, ApplyOrderAllocated, ApplyWorkDemandReleased) and ApplySlotPlanApprovedorder-management's release-confirmation consumer, opt-in (RELEASE_CONFIRMATION_MODE=kafka, off by default); it matches reference and line_no
com.warehouse.wes.work-planning.workunit.WorkReleasedwork unit idpath_id, work_unit_id, cpt, ref, optional required_capabilities, fragile, gift_wrap, line_no (ADR-0036), transfer fields (ADR-0033), relocation on RELOCATE units (ADR-0040), replenishment on REPLENISH units (ADR-0042)ReleaseNextWork (REST or MCP)fulfillment-execution — internal/adapters/inbound/kafka/consumer.go turns it into a Task
com.warehouse.wes.work-planning.workunit.WorkUnitCompletedwork unit idpath_id, work_unit_idRecordCompletion (REST or ApplyTaskCompleted)—
com.warehouse.wes.work-planning.workpool.BacklogThresholdBreachedpath idpath_idSampleBacklog when backlog depth exceeds the alarm threshold—
com.warehouse.wes.work-planning.workpool.RateDeviationDetectedpath idpath_idnothing — reserved for a future detection rule, not emitted (decided 2026-10-06: kept)—
com.warehouse.wes.work-planning.workpool.PathThrottledpath idpath_idRebalanceDecision, flow-fed pool over threshold—
com.warehouse.wes.work-planning.workpool.LaborReassignmentFlaggedpath idpath_idRebalanceDecision, release-fed pool at WIP limit with backlog—
com.warehouse.wes.work-planning.workpool.PathCapacityChangedpath idpath_id, cutoff_at, remaining_units, knownSampleBacklog, only when cutoffAt is supplied (ADR-0018)order-management — internal/adapters/outbound/kafkapathcapacity/consumer.go; network-fulfillment — internal/adapters/outbound/pathcapacitycache/consumer.go

com.warehouse.wes.work-planning.charge.ChargeForecastReceived, com.warehouse.wes.work-planning.plan.ShiftPlanCommitted and com.warehouse.wes.work-planning.pathplan.PathPlanDriftDetected are retired: no longer published, still acknowledged by the analytics projector for the topic's history (ADR-0049). warehouse-planning publishes the labour plan and LabourPlanDriftDetected now.

Every event also reaches cmd/wes-projector via warehouse.wes.analytics (consumer group wes-analytics); five of them move the release throughput report.

Source of the table: internal/domain/shared/events.go, internal/adapters/outbound/kafka/publisher.go (eventTypeEntity, subjectFor, dataFor), apis/asyncapi.yaml, and git grep of each sibling's origin/develop.

Stated honestly

RateDeviationDetected is declared in the domain, in apis/asyncapi.yaml and in the analytics rollup, but no use case raises it — computing rate deviation needs a time-windowed actual-rate projection that is not built. Decided 2026-10-06: kept reserved. It is declared for a future detection rule (ADR-0020 defers it), is not emitted today, and is not removed (removing a declared message would be a contract removal).

Every event above is written to the transactional outbox and published to Kafka by the always-on relay; EVENT_PUBLISHER accepts only kafka, there is no log-only publisher (ADR-0044).

Consumed​

Consumer group KAFKA_CONSUMER_GROUP (mandatory; the chart renders wes-work-planning), dispatching on the full type; unknown types are ignored; a non-CloudEvents message goes straight to <topic>.dlq; a handler error is tried 3 times in total (exponential backoff) and then dead-lettered. Each handler marks the CloudEvents id in processed_events atomically with its effect (ADR-0028).

TopicFull CloudEvents typeProducerHandled by
warehouse.workforce.eventscom.warehouse.wes.workforce-management.shiftplan.ShiftPlanCommittedworkforce-managementObserveLaborPlan → LaborPlanObserved (pure projection)
warehouse.inventory.eventscom.warehouse.wms.inventory-storage.reservation.StockReservedinventory-storageObserveInventoryChange, delta −quantity
warehouse.inventory.eventscom.warehouse.wms.inventory-storage.reservation.ReservationRevokedinventory-storageObserveInventoryChange, delta +quantity
warehouse.fulfillment.eventscom.warehouse.wes.fulfillment-execution.task.TaskCompletedfulfillment-executionApplyTaskCompleted → RecordCompletion
warehouse.order-management.eventscom.warehouse.wes.order-management.order.OrderAllocatedorder-managementApplyOrderAllocated → EnqueueWorkUnit per line
warehouse.order-management.eventscom.warehouse.wes.order-management.order.OrderPartiallyAllocatedorder-managementsame
warehouse.slotting-optimization.eventscom.warehouse.wms.slotting-optimization.slotplan.SlotPlanApprovedslotting-optimizationApplySlotPlanApproved → one RELOCATE unit per move, sequenced, superseding the site's older plan (ADR-0040)
warehouse.pick-face-replenishment.eventscom.warehouse.wms.pick-face-replenishment.replenishment.ReplenishmentRequested / ReplenishmentCancelledpick-face-replenishmentApplyReplenishmentRequested → ONE REPLENISH unit per request id; ApplyReplenishmentCancelled → cancels a still-Pending unit; only with REPLENISHMENT_MODE=kafka (ADR-0042)
warehouse.product-master.eventscom.warehouse.wms.product-master.product.ProductClassifiedproduct-masterObserveProductClassification → version-guarded upsert into product_classification_copy (ADR-0035); own group PRODUCT_CLASSIFICATION_CONSUMER_GROUP
warehouse.product-master.eventscom.warehouse.wms.product-master.product.ProductPackLevelDeclaredproduct-masterObservePackLevel → version-guarded upsert into product_pack_level_copy, keyed by GTIN (ADR-0045); own group PACK_VIEW_CONSUMER_GROUP
warehouse.product-master.eventscom.warehouse.wms.product-master.product.ProductPackLevelRetiredproduct-masterObservePackLevel → end-dates the level (effective_to); no-op for an unknown GTIN or an older version
warehouse.product-master.eventscom.warehouse.wms.product-master.product.ProductPackLevelMeasuredproduct-masterObservePackLevel → stores the measured dimensions; no-op for an unknown GTIN or an older version
warehouse.process-path-management.eventscom.warehouse.wes.process-path-management.processpath.ProcessPathCreated / ProcessPathUpdated / ProcessPathDeactivatedprocess-path-managementkafkacatalog.Consumer (process-unique group, replays from earliest), only with PATH_CATALOGUE_SOURCE=kafka

Event flow through a shift​

Source: the use cases in internal/application/usecases/. Omits: MCP entry points and analytics fan-out. The shift's forecast and labour plan are sent to warehouse-planning, not here (ADR-0049). Workforce's ShiftPlanCommitted is a different event from a different context from the retired plan.ShiftPlanCommitted that shared its name (ADR-0006).

Why events carry so little​

Most events carry only a path_id: a domain event is a fact that something happened, and the smallest payload that identifies the subject keeps consumers from treating the stream as data replication.

The exceptions are deliberate. WorkReleased is enriched in the adapter with cpt, ref, gift_wrap, line_no and classification hints so fulfillment-execution can build a Task without calling back. PathCapacityChanged is a report, so it carries the figures it reports.

Wire format​

Envelope, headers and examples: Events and .claude/rules/cloudevents-envelope.md (ADR-0027).