Skip to main content

Domain events

Synced from slotting-optimization

This page is a copy of docs/docs/ddd/domain-events.md on develop, derived from that repository's code. Edit it there, then re-sync.

Every event slotting-optimization publishes or consumes, with its full CloudEvents type, topic, key and payload. The published payloads are the structs in internal/adapters/outbound/kafka/encoder.go; the consumed ones are the restated structs in internal/adapters/inbound/kafka/*_consumer.go. Both are pinned in apis/asyncapi.yaml (TestEventCatalogueMatchesContract).

Envelope​

AttributeValue for published events
specversion1.0
idUUID v4, minted once at encode time and stored in outbox_events.event_id: a resend carries the same id
source/warehouse/slotting-optimization
typecom.warehouse.wms.slotting-optimization.slotplan.<EventName>
subjectthe plan id
timethe domain occurred-at (UTC)
datacontenttypeapplication/json
dataschemaurn:warehouse:slotting-optimization:events:<EventName>:v1
Kafka keythe plan id (one plan's events stay ordered on one partition; a row the relay excluded after OUTBOX_MAX_ATTEMPTS failures is overtaken, ADR 0008)
Kafka headercontent-type: application/cloudevents+json; charset=UTF-8
Optional Kafka headerstraceparent (and tracestate / baggage when present): the W3C trace context of the request that wrote the outbox row (ADR 0009). Consumers may extract it and must not require it

Mode: structured (the whole envelope is the Kafka value), built only by cloudevents.New; consumers only accept what cloudevents.Decode accepts.

Published on warehouse.slotting-optimization.events​

SlotPlanGenerated​

com.warehouse.wms.slotting-optimization.slotplan.SlotPlanGenerated, raised by slotplan.Generate through POST /slot-plans.

FieldTypeMeaning
plan_idstringplan-<uuid>
site_idstringsite of the plan
window_from, window_toRFC 3339 UTCthe demand window
policystringabc-velocity-v1
assignment_count, move_count, unassigned_countintegersize of the proposal

SlotPlanApproved​

com.warehouse.wms.slotting-optimization.slotplan.SlotPlanApproved, raised by SlotPlan.Approve through POST /slot-plans/{planId}/approvals. It carries the full map so a consumer needs no lookup.

FieldTypeMeaning
plan_id, site_idstring
approved_atRFC 3339 UTC
supersedes_plan_idstring, omitted when nonethe site's previous Approved plan, now Superseded
assignmentsarray of {sku, slot}, never nullthe new forward-slot map
movesarray of {sku, from_slot?, to_slot?, kind}, never nullAssign (to only), Relocate (both), Vacate (from only)
{
"specversion": "1.0",
"id": "bfa2833a-...",
"source": "/warehouse/slotting-optimization",
"type": "com.warehouse.wms.slotting-optimization.slotplan.SlotPlanApproved",
"subject": "plan-ee0b77f6-...",
"time": "2026-10-09T11:50:02Z",
"datacontenttype": "application/json",
"dataschema": "urn:warehouse:slotting-optimization:events:SlotPlanApproved:v1",
"data": {
"plan_id": "plan-ee0b77f6-...",
"site_id": "WH1",
"approved_at": "2026-10-09T11:50:02Z",
"assignments": [{"sku": "SKU-A", "slot": "FWD-01-01"}, {"sku": "SKU-B", "slot": "FWD-01-02"}],
"moves": [{"sku": "SKU-A", "to_slot": "FWD-01-01", "kind": "Assign"}, {"sku": "SKU-B", "to_slot": "FWD-01-02", "kind": "Assign"}]
}
}

(Illustrative values in the shape encoder.go produces; ids shortened.)

SlotPlanRejected​

com.warehouse.wms.slotting-optimization.slotplan.SlotPlanRejected, raised by SlotPlan.Reject through POST /slot-plans/{planId}/rejections.

FieldTypeMeaning
plan_id, site_idstring
rejected_atRFC 3339 UTC
reasonstring, omitted when emptytrimmed, at most 500 characters

Supersede raises no event: consumers learn it from supersedes_plan_id on the newer SlotPlanApproved.

Consumers: wes-work-planning consumes SlotPlanApproved and plans one RELOCATE work unit per move (its ADR 0040; move_seq = the move's 0-based position in moves), executed by fulfillment-execution and recorded by inventory-storage (ADR 0010, Integration). Nothing consumes SlotPlanGenerated or SlotPlanRejected.

Consumed​

TypeTopicProducerFields acted onUse case
com.warehouse.wes.order-management.siteskudemand.SiteSkuDemandChangedwarehouse.order-management.eventsorder-managementsource_order_id, line_no, site_id, sku, demanded_units, due_at, state (assignment_version is decoded and ignored)ApplyDemandChanged
com.warehouse.wms.product-master.product.ProductClassifiedwarehouse.product-master.eventsproduct-mastersku, handling_tags, temperature_class, versionApplyProductClassified
com.warehouse.wms.product-master.product.ProductDimensionsDeclaredwarehouse.product-master.eventsproduct-mastersku, effective.volume_mm3, effective.weight_g, effective_source, versionApplyPhysicalProfile
com.warehouse.wms.product-master.product.ProductMeasuredwarehouse.product-master.eventsproduct-mastersame as aboveApplyPhysicalProfile
com.warehouse.wms.facility-layout.zone.ZoneRegisteredwarehouse.facility.eventsfacility-layoutzoneId, siteCode, areaCode, zoneCode, temperatureClass, hazmatApplyZoneRegistered
com.warehouse.wms.facility-layout.locationslot.LocationSlotRegisteredwarehouse.facility.eventsfacility-layoutlocationCode, zoneId, role, maxWeightKg, maxVolumeM3 (aisleId, locationType, dockFlow, activities ignored)ApplyLocationSlotRegistered
com.warehouse.wms.facility-layout.locationslot.LocationSlotDecommissionedwarehouse.facility.eventsfacility-layoutlocationCodeApplyLocationSlotDecommissioned
com.warehouse.wms.inventory-storage.stock.StockRelocatedwarehouse.inventory.eventsinventory-storage (its ADR 0039)relocation_id, site_code, sku, from_bin, to_bin, quantity, source_ref, occurred_at (reason decoded, not acted on)RecordRelocation (ADR 0010)

Dispatch is on the full type string; every other type on those topics is ignored. Note the casing: order-management, product-master and inventory-storage payloads are snake_case, facility-layout payloads are camelCase, exactly as each producer publishes them.

StockRelocated and the execution progress​

A relocation executes a move of a plan when its source_ref is the move reference <plan_id>:<move_seq> of an Approved or Superseded plan of site_code whose move at move_seq is for sku; when source_ref is no move reference (empty, a task id), the move of the site's Approved plan with that sku whose bins agree with its kind matches (Relocate: both slots, Assign: to_bin, Vacate: from_bin). A match is recorded once per relocation_id in slot_plan_move_executions; anything else is unmatched with a reason (unknown-plan, no-current-plan, plan-not-approved, site-mismatch, unknown-move, sku-mismatch, no-matching-move), counted and logged, never dead-lettered. A StockRelocated missing a required field is dead-lettered at once. Nothing is published in response: the progress is a read model, shown on GET /slot-plans/{planId} and the MCP get_slot_plan tool.

Event flow​

Source: internal/adapters/inbound/kafka/*_consumer.go, internal/application/usecases/*.go, internal/adapters/outbound/kafka/encoder.go.