Skip to main content

ADR 0004: CloudEvents envelope and type catalogue

Status​

Accepted (2026-10-08). Per-key ordering amended by ADR 0007 (a row excluded by the relay attempt cap is overtaken). The four dockappointment types are retired (ADR 0019) and no longer declared in apis/asyncapi.yaml (ADR 0022); their rows below are kept, marked retired.

Context​

Every Kafka message in the fleet is a CloudEvents 1.0 event in structured mode (fleet rule .claude/rules/fleet/cloudevents.md, warehouse-docs docs/strategic-design/event-standard-cloudevents.md). This ADR is the catalogue of every type inbound-receiving publishes or consumes; TestEventCatalogueMatchesContract checks it against apis/asyncapi.yaml.

Decision​

Envelope​

  • specversion 1.0; id a UUID minted once per domain event and persisted with the outbox row (stable across relay retries; consumers dedupe on it); source /warehouse/inbound-receiving; subject the id of the aggregate instance; time the occurred-at instant in UTC; datacontenttype application/json; dataschema urn:warehouse:inbound-receiving:events:<EventName>:v1.
  • Kafka value = the JSON event format; header content-type: application/cloudevents+json; charset=UTF-8; message key as in the table below.
  • Built and decoded only through internal/adapters/kafka/cloudevents.
  • data is snake_case JSON; optional fields are omitted when unset; timestamps are RFC 3339 UTC.

Published on warehouse.inbound-receiving.events​

<entity> is the raising aggregate, lowercase, no separators: asn, dockappointment, policy (ADR 0026), receipt.

typesubjectKafka keyraised when
com.warehouse.wms.inbound-receiving.asn.ASNRegisteredasn_numberasn_numberan ASN is registered
com.warehouse.wms.inbound-receiving.asn.ASNCancelledasn_numberasn_numbera Registered ASN is cancelled
com.warehouse.wms.inbound-receiving.asn.AsnLateForArrivalasn_numberasn_numberat OpenReceipt, the ASN was registered after the visit it is received under had already arrived (ADR 0025)
com.warehouse.wms.inbound-receiving.dockappointment.DockAppointmentBookedappointment_idappointment_id(retired, ADR 0022) a door window is booked
com.warehouse.wms.inbound-receiving.dockappointment.DockAppointmentCheckedInappointment_idappointment_id(retired, ADR 0022) the carrier checks in
com.warehouse.wms.inbound-receiving.dockappointment.DockAppointmentCancelledappointment_idappointment_id(retired, ADR 0022) a Booked appointment is cancelled
com.warehouse.wms.inbound-receiving.dockappointment.DockAppointmentCompletedappointment_idappointment_id(retired, ADR 0022) the receipt opened from the appointment closes
com.warehouse.wms.inbound-receiving.receipt.ReceiptOpenedreceipt_idasn_numberreceiving of an ASN starts
com.warehouse.wms.inbound-receiving.receipt.ReceiptLineReceivedreceipt_idasn_numbera quantity is received against a line
com.warehouse.wms.inbound-receiving.receipt.ReceiptCartonReceivedreceipt_idasn_numbera carton (or one case) is received: identity only, never quantity (ADR 0012)
com.warehouse.wms.inbound-receiving.receipt.CartonDiscrepancyRaisedreceipt_idasn_numbera finding about a physical carton, one of the kinds of ADR 0012 and ADR 0014
com.warehouse.wms.inbound-receiving.receipt.ReceiptClosedreceipt_idasn_numberreceiving ends
com.warehouse.wms.inbound-receiving.receipt.ReceiptStowCompletedreceipt_idasn_numberthe last Good carton of a closed receipt opened from an appointment is stowed: the dock-to-stock fact (ADR 0021)
com.warehouse.wms.inbound-receiving.receipt.ReceivingAdviceIssuedreceipt_idasn_numbera receipt closes: the receiving advice for the supplier or depositor, with W13/CBV-coded discrepancies (ADR 0023)
com.warehouse.wms.inbound-receiving.receipt.ReceivingAdviceOverduereceipt_idasn_numberan Open receipt passed the advice SLA since its last unit was received (ADR 0023)
com.warehouse.wms.inbound-receiving.policy.ReceivingPolicyDeclaredsupplier_refsupplier_refa receiving tolerance policy is created or replaced (ADR 0026)

The receipt events are keyed by asn_number, so everything that happens while one ASN is received stays ordered on one partition. DockAppointmentCompleted is keyed by appointment_id, so its order relative to ReceiptClosed is not guaranteed; consumers must not depend on it.

Payloads (data)​

type (entity.Event)fields
asn.ASNRegisteredasn_number, supplier_ref, expected_arrival?, registered_at? (ADR 0025), lines[] = {line_no, sku, expected_qty}
asn.ASNCancelledasn_number, reason?
asn.AsnLateForArrivalasn_number, supplier_ref, appointment_id, visit_id, asn_registered_at, arrived_at, lateness_seconds (ADR 0025)
dockappointment.DockAppointmentBookedappointment_id, door_code, carrier, window_start, window_end, asn_numbers[]
dockappointment.DockAppointmentCheckedInappointment_id, door_code, checked_in_at
dockappointment.DockAppointmentCancelledappointment_id, door_code, reason?
dockappointment.DockAppointmentCompletedappointment_id, door_code, completed_at
receipt.ReceiptOpenedreceipt_id, asn_number, appointment_id?, door_code?, opened_at
receipt.ReceiptLineReceivedreceipt_id, asn_number, line_no, sku, quantity, condition (Good or Damaged), received_at
receipt.ReceiptCartonReceivedreceipt_id, asn_number, sscc?, parent_sscc?, sealed, lpn, contents[] (line_no, sku, gtin, qty, condition), received_at
receipt.CartonDiscrepancyRaisedreceipt_id, sscc?, kind, expected?, actual?, at
receipt.ReceiptClosedreceipt_id, asn_number, closed_at, discrepancies[] = {line_no, sku, kind, expected_qty, received_qty, damaged_qty}, kind in Short, Over, Damaged, OverTolerance, UnderTolerance (ADR 0026), plus reason_code on the two tolerance kinds and an optional tolerance object {over_tolerance, under_tolerance, over_hard_stop, under_hard_stop} present when a policy was applied
receipt.ReceiptStowCompletedreceipt_id, asn_number, appointment_id, arrived_at, closed_at, stowed_at, dock_to_stock_seconds, carton_count (ADR 0021)
receipt.ReceivingAdviceIssuedreceipt_id, asn_number, despatch_advice_ref, supplier_ref, owner_ref?, issued_at, last_carton_at, sla_seconds, within_sla, lines[], lines_total, carton_findings[], carton_findings_total (ADR 0023)
receipt.ReceivingAdviceOverduereceipt_id, asn_number, last_carton_at, due_at, sla_seconds, overdue_at (ADR 0023)
policy.ReceivingPolicyDeclaredsupplier_ref, owner_ref?, over_tolerance, under_tolerance, over_hard_stop, under_hard_stop, version, declared_at (ADR 0026)

Payload rules:

  • ReceiptClosed.discrepancies is present and empty ([]) when everything matched. A line can appear once per kind.
  • received_qty is good + damaged; damaged_qty is the damaged part.
  • ReceiptLineReceived is the handover event (ADR 0003): inventory-storage books condition=Good quantities only.
  • A breaking payload change is a new .v2 type and dataschema, never a mutation of v1.

Consumed (ADR 0003)​

typetopicconsumer group env
com.warehouse.wms.product-master.product.ProductRegisteredwarehouse.product-master.eventsPRODUCT_CONSUMER_GROUP
com.warehouse.wms.facility-layout.locationslot.LocationSlotRegisteredwarehouse.facility.eventsDOCK_DOOR_CONSUMER_GROUP
com.warehouse.wms.facility-layout.locationslot.LocationSlotDecommissionedwarehouse.facility.eventsDOCK_DOOR_CONSUMER_GROUP

Every other type on those topics is ignored. A message that is not a valid CloudEvent is logged and skipped, never retried forever.

Analytics topic (ADR 0006)​

Every published event above is ALSO written, in the same transaction and under the same id, to warehouse.inbound-receiving.analytics (dead-letter topic warehouse.inbound-receiving.analytics.dlq). The type, subject, Kafka key and payload are identical to the integration message; only the dataschema differs: urn:warehouse:inbound-receiving:analytics:<EventName>:v1. Only this service's cmd/inbound-projector consumes it (consumer group from env ANALYTICS_CONSUMER_GROUP); it is not an integration contract, and other contexts keep reading warehouse.inbound-receiving.events. The projection and its report are specified in ADR 0006.

Consequences​

  • Consumers need nothing but this catalogue and apis/asyncapi.yaml; there is no shared Go code.
  • The nine types are pinned: the fleet plan and inventory-storage's consumer build against these exact strings.