Domain events
This bounded context emits fifteen past-tense domain events. Together they are its Published Language — the vocabulary downstream Conformists key off.
Every domain event is published to the
warehouse.facility.events integration topic
(ADR 0009) and, in the same
call, to the separate warehouse.facility.analytics topic that feeds the
analytical data product
(ADR 0010). The integration topic,
its CloudEvents 1.0 envelope
(ADR 0024) and all fifteen messages are specified in
apis/asyncapi.yaml
(AsyncAPI 2.6.0).
Publishing always goes
through the transactional outbox (outbox_events,
ADR 0018): the use case writes the
aggregate row and one outbox row per topic in one transaction, and the
in-process relay drains them onto Kafka. There is no log-only mode
(ADR 0039). The old events table was dropped by migration 0005_outbox. See
Publishers and the Context map
for who consumes what.
The type convention
Identical to the other warehouse-systems services: reverse-DNS, lowercase except the final PascalCase event name, and the entity segment carries no hyphen even for multi-word aggregate names.
com.warehouse.<subdomain>.<bounded-context>.<entity>.<EventName>
This service's subdomain segment is wms. "Bin-accurate location" is
classified WMS-tier in the e-commerce-fulfillment reference — the "Inventory &
Slotting" Core subdomain references it as WMS's Open Host Service — and this
service is the generalized, multi-consumer version of that same concern. The
wms segment is shared with inventory-storage and product-master; every
other fleet context uses wes.
com.warehouse.wms.facility-layout.site.SiteRegistered
com.warehouse.wms.facility-layout.site.SiteCapabilityChanged
com.warehouse.wms.facility-layout.site.SiteRoleChanged
com.warehouse.wms.facility-layout.zone.ZoneRegistered
com.warehouse.wms.facility-layout.aisle.AisleRegistered
com.warehouse.wms.facility-layout.locationtype.LocationTypeRegistered
com.warehouse.wms.facility-layout.placementrule.PlacementRuleDefined
com.warehouse.wms.facility-layout.locationslot.LocationSlotRegistered
com.warehouse.wms.facility-layout.locationslot.LocationSlotDecommissioned
com.warehouse.wms.facility-layout.locationslot.FacilityLayoutImported
com.warehouse.wms.facility-layout.locationslot.LocationSlotHandlingUnitDeclared
com.warehouse.wms.facility-layout.locationslot.LocationGeometryUpdated
com.warehouse.wms.facility-layout.aisle.AisleGeometryUpdated
com.warehouse.wms.facility-layout.structure.FixedStructureRegistered
com.warehouse.wms.facility-layout.crossaisle.CrossAisleRegistered
Entity segments in use: site, zone, aisle, locationtype,
placementrule, locationslot, structure, crossaisle.
The DomainEvent interface
// DomainEvent is a past-tense fact published by an aggregate. Adapters
// (outbound/events) serialize and publish these; the domain never depends
// on the publishing mechanism. EventType is this context's Published
// Language: downstream Conformists key off it.
type DomainEvent interface {
EventName() string
EventType() string
OccurredAt() time.Time
}
Every event embeds the same base, serialized as:
{
"eventName": "LocationSlotRegistered",
"eventType": "com.warehouse.wms.facility-layout.locationslot.LocationSlotRegistered",
"occurredAt": "2026-08-22T09:00:00Z"
}
OccurredAt comes from the injected Clock port, never from
time.Now() inside the domain — which is what makes event timestamps
deterministic in tests.
The fifteen events
SiteRegistered
A physical facility was added to the warehouse map.
| Field | Type |
|---|---|
siteCode | string |
siteName | string |
siteRole | string — the site's role in the fulfilment network, UNSPECIFIED when none was stated (additive, ADR 0037) |
gln | string — the site's GS1 Global Location Number (13 digits, mod-10 check digit); omitted when none was recorded (additive, ADR 0045) |
SiteRoleChanged
An operator changed a site's role in the fulfilment network
(ADR 0037), raised by PUT /sites/{siteCode}/role
(use case ChangeSiteRole) once per real change. It never implies a
transfer-capability change. The one-time backfill of migration 0009
publishes none.
| Field | Type |
|---|---|
siteCode | string |
siteRole | string — the new role |
previousSiteRole | string — the replaced role (UNSPECIFIED the first time) |
SiteCapabilityChanged
A site's transfer capability changed
(ADR 0035). A full
last-write-wins snapshot raised by PUT /sites/{siteCode}/transfer-capability
(use case ChangeSiteTransferCapability) once per real change, and re-emitted
by the periodic freshness heartbeat
(ADR 0041, use case
PublishSiteCapabilityHeartbeats) with the current values, a new CloudEvents
id, a fresh time (the consumers' as_of) and the revision advanced by one.
Its fields are
snake_case, unlike every other payload here: recasing them would be a
breaking .v2 for network-inventory-planning, so ADR 0035 keeps them.
| Field | Type |
|---|---|
site_code | string |
transfer_origin_enabled | boolean — the site may donate stock |
transfer_destination_enabled | boolean — the site may receive stock |
capability_revision | integer — 1 on the first change, +1 per later event of the same site, change or heartbeat (ADR 0041); keep the highest |
ZoneRegistered
A behavioral zone was added inside a Site's area.
| Field | Type |
|---|---|
zoneId | string (WH1-STOR-AMB) |
siteCode | string |
areaCode | string |
zoneCode | string |
temperatureClass | Ambient | Chilled | Frozen |
hazmat | boolean |
gln | string — the zone's GS1 Global Location Number; omitted when none was recorded (additive, ADR 0045) |
AisleRegistered
A physical corridor was added inside a Zone.
| Field | Type |
|---|---|
aisleId | string (WH1-STOR-AMB-A07) |
zoneId | string |
aisleCode | string |
sequenceHint | integer — walk-order position |
direction | OneWay | TwoWay |
This is the event a travel-path consumer cares about most: sequenceHint
and direction are the two structural inputs to walk-order reasoning.
LocationTypeRegistered
A reusable slot shape/kind was defined.
| Field | Type |
|---|---|
locationType | string (PalletRack) |
role | LocationRole — Storage (default), Dock, Yard, WorkCenter, Drop, Staging, QC, Consolidation, Shipping |
maxWeightKg | number — omitted when zero |
maxVolumeM3 | number — omitted when zero |
Capacity is optional for the roles that do not hold stock at rest (Dock,
Yard, WorkCenter, QC, Shipping), so the two capacity fields may be
absent (ADR 0016).
PlacementRuleDefined
A rule constraining which LocationTypes are legal in which Zones was declared.
| Field | Type |
|---|---|
ruleId | string |
locationType | string |
effect | Allow | Deny |
predicate | string — the human-readable predicate, e.g. temperatureClass=Frozen |
LocationSlotRegistered
A coded leaf slot now exists on the warehouse map. This is the event
inventory-storage consumes to learn that a new Bin location is legal to
stow into.
| Field | Type |
|---|---|
locationCode | string (WH1-STOR-AMB-A07-03-02-B) |
aisleId | string |
zoneId | string |
locationType | string |
role | LocationRole, inherited from the LocationType |
dockFlow | Inbound | Outbound | Both — only on a Dock slot |
activities | array of Pack | Sort | QC | VAS | Deconsolidate | Receive | Kit — only on a WorkCenter slot |
maxWeightKg | number — omitted when zero |
maxVolumeM3 | number — omitted when zero |
gln | string — the slot's GS1 Global Location Number; omitted when none was recorded (additive, ADR 0045) |
spotKind | PARKING | HOLDING | REEFER_PLUG | HAZMAT | STAGING_LANE — only on a Yard slot, omitted when none was recorded (additive, ADR 0045) |
aisleId and zoneId are denormalised into the payload deliberately: a
consumer should not have to know how to parse this context's code format to
route on zone. That is what makes it a Published Language rather than a
leaked internal representation.
LocationSlotDecommissioned
A coded slot was permanently retired. The signal for a downstream context to stop offering that location for new work.
| Field | Type |
|---|---|
locationCode | string |
FacilityLayoutImported
A bulk layout import completed. Emitted once per import call; the
individual LocationSlotRegistered events still fire per-slot within the
same import.
| Field | Type |
|---|---|
rowsSubmitted | integer |
slotsImported | integer |
rowsRejected | integer |
The summary event exists so that a consumer can distinguish "the building was loaded" from a burst of unrelated single registrations, without having to infer it from event volume.
LocationSlotHandlingUnitDeclared
A slot's handling unit was set or changed
(ADR 0040). LocationSlotRegistered
also carries handlingUnit, omitted when none was recorded.
| Field | Type |
|---|---|
locationCode | string — same identifier as in LocationSlotRegistered |
handlingUnit | string — EACH, CASE or PALLET |
declaredAt | string — RFC 3339 instant, equals occurredAt |
LocationGeometryUpdated
A slot's physical position and size were set (ADR 0017).
| Field | Type |
|---|---|
locationCode | string |
xM, yM, zM | number — position in metres |
widthM, depthM, heightM | number — dimensions in metres |
pickSequence | integer — optional |
AisleGeometryUpdated
An aisle's travel centreline was set.
| Field | Type |
|---|---|
aisleId | string |
startXM, startYM, startZM | number |
endXM, endYM, endZM | number |
lengthM | number |
FixedStructureRegistered
A non-slot physical obstacle was added to a site.
| Field | Type |
|---|---|
structureId | string |
siteCode | string |
kind | Wall | Column | Office | Conveyor | Other |
xM, yM, zM, widthM, depthM, heightM | number — footprint in metres |
label | string |
CrossAisleRegistered
A walkable connection between two aisles of the same zone was declared.
| Field | Type |
|---|---|
zoneId | string |
fromAisle | string |
toAisle | string |
atBay | string |
Catalogue at a glance
Every event is published to both topics:
warehouse.facility.events (integration, dataschema
urn:warehouse:facility-layout:events:<EventName>:v1) and
warehouse.facility.analytics (analytics, dataschema
urn:warehouse:facility-layout:analytics:<EventName>:v1), under the same
CloudEvents id. The Kafka key is the partition key; the CloudEvents
subject names the aggregate instance. Every event is keyed by its
aggregate's identity (so all events about one aggregate share a partition and
stay ordered); the only exception is FacilityLayoutImported, a batch outcome
with no aggregate, which is keyed by its CloudEvents id
(ADR 0032).
Decided 2026-10-06: kept — no consumer needs import ordering, and keying by
site would need an additive siteCode (a contract change) for no benefit
(ADR 0034).
CloudEvents type | Kafka key (partition) | subject | Producer use case(s) | Known consumers |
|---|---|---|---|---|
com.warehouse.wms.facility-layout.site.SiteRegistered | siteCode | siteCode | RegisterSite, ImportFacilityLayout | own projector |
com.warehouse.wms.facility-layout.site.SiteCapabilityChanged | site_code | site_code | ChangeSiteTransferCapability | network-inventory-planning (site_capability read model); own projector ignores it |
com.warehouse.wms.facility-layout.site.SiteRoleChanged | siteCode | siteCode | ChangeSiteRole | none; own projector ignores it |
com.warehouse.wms.facility-layout.zone.ZoneRegistered | zoneId | zoneId | RegisterZone, ImportFacilityLayout | inventory-storage, slotting-optimization, pick-face-replenishment, task-interleaving, dock-scheduling, yard-management, outbound-shipping, own projector |
com.warehouse.wms.facility-layout.aisle.AisleRegistered | aisleId | aisleId | RegisterAisle, ImportFacilityLayout | own projector |
com.warehouse.wms.facility-layout.locationtype.LocationTypeRegistered | locationType | locationType | RegisterLocationType | own projector |
com.warehouse.wms.facility-layout.placementrule.PlacementRuleDefined | ruleId | ruleId | DefinePlacementRule | own projector |
com.warehouse.wms.facility-layout.locationslot.LocationSlotRegistered | locationCode | locationCode | RegisterLocationSlot, ImportFacilityLayout | inventory-storage, warehouse-planning, inbound-receiving, slotting-optimization, pick-face-replenishment, task-interleaving, dock-scheduling, yard-management, outbound-shipping, own projector |
com.warehouse.wms.facility-layout.locationslot.LocationSlotDecommissioned | locationCode | locationCode | DecommissionLocationSlot | inventory-storage, warehouse-planning, inbound-receiving, slotting-optimization, pick-face-replenishment, task-interleaving, dock-scheduling, yard-management, own projector |
com.warehouse.wms.facility-layout.locationslot.FacilityLayoutImported | event id (batch outcome, no aggregate) | layout-import | ImportFacilityLayout | own projector |
com.warehouse.wms.facility-layout.locationslot.LocationSlotHandlingUnitDeclared | locationCode | locationCode | DeclareLocationHandlingUnit | inventory-storage |
com.warehouse.wms.facility-layout.locationslot.LocationGeometryUpdated | locationCode | locationCode | SetLocationGeometry, ImportFacilityLayout | task-interleaving |
com.warehouse.wms.facility-layout.aisle.AisleGeometryUpdated | aisleId | aisleId | SetAisleGeometry | none |
com.warehouse.wms.facility-layout.structure.FixedStructureRegistered | structureId | structureId | RegisterFixedStructure | none |
com.warehouse.wms.facility-layout.crossaisle.CrossAisleRegistered | zoneId/fromAisle-toAisle@atBay | zoneId/fromAisle-toAisle@atBay | RegisterCrossAisle | none |
Source: internal/domain/shared/events.go,
internal/adapters/outbound/kafka/publisher.go (aggregateKey,
partitionKey, SubjectOf), internal/adapters/inbound/kafka/analytics_consumer.go.
Which use case emits what
| Use case | Events emitted |
|---|---|
RegisterSite | SiteRegistered |
ChangeSiteTransferCapability | SiteCapabilityChanged (only when the snapshot changed or was never published) |
PublishSiteCapabilityHeartbeats (timer, not a route) | SiteCapabilityChanged heartbeat per active declared site every SITE_CAPABILITY_HEARTBEAT_INTERVAL (ADR 0041) |
ChangeSiteRole | SiteRoleChanged (only when the role changed) |
RegisterZone | ZoneRegistered |
RegisterAisle | AisleRegistered |
RegisterLocationType | LocationTypeRegistered |
DefinePlacementRule | PlacementRuleDefined |
RegisterLocationSlot | LocationSlotRegistered |
DecommissionLocationSlot | LocationSlotDecommissioned |
ImportFacilityLayout | per row: SiteRegistered / ZoneRegistered / AisleRegistered for each parent it creates on first sight, LocationSlotRegistered for each successful slot, LocationGeometryUpdated when the row carries geometry; then exactly one FacilityLayoutImported for the whole call |
SetLocationGeometry | LocationGeometryUpdated |
DeclareLocationHandlingUnit | LocationSlotHandlingUnitDeclared |
SetAisleGeometry | AisleGeometryUpdated |
RegisterFixedStructure | FixedStructureRegistered |
RegisterCrossAisle | CrossAisleRegistered |
GetSiteLayout, GetZoneGrid, GetZoneTravelGraph, EstimateTravelDistance, ListLocationsByRole and the other reads | none — read models never write and never publish |
Publishers
Only one publisher is wired by the composition root (cmd/facility/main.go,
buildAdapters): outbound/postgres OutboxPublisher — one outbox_events
row per topic, in the use case's transaction — drained by the outbox relay.
DATABASE_URL and KAFKA_BROKERS are mandatory (ADR 0039);
EVENT_PUBLISHER accepts only kafka.
| Adapter | Use |
|---|---|
outbound/kafka — Publisher | Encodes each event as a CloudEvents 1.0 event (structured mode, source=/warehouse/facility-layout, type = the event type, subject = aggregate id, dataschema=urn:warehouse:facility-layout:events:<EventName>:v1, data = the event's JSON wire DTO (cloudevents.WireData; domain events carry no struct tags); ADR-0024) for warehouse.facility.events. Writer: kafkago.Hash balancer (ADR 0021), RequireAll acks with a 10 ms batch timeout (ADR 0031); the W3C trace context of the publishing request is injected into the message headers. |
outbound/kafka — AnalyticsPublisher | The same occurrence (same type and id) with dataschema=urn:warehouse:facility-layout:analytics:<EventName>:v1, for warehouse.facility.analytics. |
outbound/kafka — FanOut | Test double / library only: mints one id and sends the event through both publishers above. Not wired by any binary (ADR 0039). |
outbound/postgres — OutboxPublisher + OutboxRelay | The only runtime path: enqueues both encodings into outbox_events inside the use case's UnitOfWork; the relay (OUTBOX_RELAY_INTERVAL, default 1s, batches of 100, FOR UPDATE SKIP LOCKED) sends them through RelaySink (ADR-0018). A row that fails OUTBOX_MAX_ATTEMPTS sends (default 20) is excluded and later rows with the same key overtake it (ADR 0036). Published rows are deleted after OUTBOX_RETENTION by the housekeeping sweeper (ADR 0026). |
outbound/events — log publisher | Test double (and a library for local experiments): writes each event to a log. Not wired by any binary (ADR 0039). |
outbound/events — buffered publisher | Tests. Collects events in memory for assertion. |
The EventPublisher port is one method —
Publish(ctx context.Context, event shared.DomainEvent) error — which is why
the Kafka adapters were a purely additive change.
Who consumes them
| Consumer | Topic | Group | Events used |
|---|---|---|---|
inventory-storage (internal/adapters/outbound/facilitycache, with LOCATION_LOOKUP_MODE=kafka) | warehouse.facility.events | process-unique group, replays from the first offset | ZoneRegistered, LocationSlotRegistered, LocationSlotDecommissioned, LocationSlotHandlingUnitDeclared — the rest are ignored (ADR 0013) |
warehouse-planning (internal/adapters/inbound/kafka/storage_capacity_consumer.go, started when KAFKA_BROKERS is set) | warehouse.facility.events | STORAGE_CAPACITY_CONSUMER_GROUP (default warehouse-planning-storage-capacity) | LocationSlotRegistered (Storage and WorkCenter roles), LocationSlotDecommissioned — folded into a storage-position / station tally |
network-inventory-planning (internal/adapters/inbound/kafka/consumers.go, SiteCapabilityConsumer) | warehouse.facility.events | env-configured (SITE_CAPABILITY_CONSUMER_GROUP) | SiteCapabilityChanged — upserted into its site_capability read model, last-write-wins on capability_revision |
inbound-receiving (internal/adapters/inbound/kafka/dock_door_consumer.go) | warehouse.facility.events | DOCK_DOOR_CONSUMER_GROUP (required; inbound-receiving-dock-doors) | LocationSlotRegistered (only role=Dock with dockFlow Inbound or Both), LocationSlotDecommissioned — kept in its dock_doors table |
slotting-optimization, pick-face-replenishment (internal/adapters/inbound/kafka/layout_consumer.go) | warehouse.facility.events | slotting-optimization-layout, pick-face-replenishment-layout | ZoneRegistered, LocationSlotRegistered, LocationSlotDecommissioned — local layout copies |
task-interleaving (internal/adapters/inbound/kafka/layout_consumer.go) | warehouse.facility.events | task-interleaving-layout | ZoneRegistered, LocationSlotRegistered, LocationSlotDecommissioned, LocationGeometryUpdated — local layout copy with positions |
dock-scheduling (internal/adapters/inbound/kafka/facility_consumer.go) | warehouse.facility.events | FACILITY_CONSUMER_GROUP (required) | ZoneRegistered, LocationSlotRegistered (only an explicit role=Dock slot becomes a bookable door), LocationSlotDecommissioned — zone-to-site join and dock-door view |
yard-management (internal/adapters/inbound/kafka/facility_consumer.go) | warehouse.facility.events | FACILITY_CONSUMER_GROUP (required) | ZoneRegistered, LocationSlotRegistered (only role=Yard spots and role=Dock doors are kept), LocationSlotDecommissioned — local zone and location copies |
outbound-shipping (internal/adapters/inbound/kafka/cpt_layout_consumers.go) | warehouse.facility.events | LAYOUT_CONSUMER_GROUP (required) | ZoneRegistered, LocationSlotRegistered (reads zoneId and role); it does not handle LocationSlotDecommissioned |
this repository's cmd/facility-projector | warehouse.facility.analytics | facility-analytics (DLQ warehouse.facility.analytics.dlq) | The original eight events (SiteRegistered … FacilityLayoutImported); the geometry events and SiteCapabilityChanged are ignored |
No other service consumes either topic today: ten contexts read
warehouse.facility.events (the rows above) and only this repository's
facility-projector reads warehouse.facility.analytics. AisleGeometryUpdated,
FixedStructureRegistered and CrossAisleRegistered are Published Language
with no consumer yet (LocationGeometryUpdated is applied by
task-interleaving only).