Skip to main content

Bounded context canvas

Synced from returns-processing

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

ddd-crew Bounded Context Canvas v5, filled from the code on develop and ADRs 0001–0005. Same section set as the fleet's other canvases (the reference is inventory-storage's page).

Canvas at a glance​

Source: internal/adapters/inbound/{http,mcp}, internal/adapters/inbound/kafka/*, internal/adapters/outbound/kafka/encoder.go, ADR 0001's canvas. The analytics mirror feeds the service's OWN projector and reports, not a sibling (ADR 0007).

Name​

returns-processing — CloudEvents subdomain wms, source=/warehouse/returns-processing, type prefix com.warehouse.wms.returns-processing..

Purpose​

Authorize, receive, grade and disposition returned goods; put restockable units back into the ledger through the existing staged-receipt seam; keep every other outcome auditable. Returns get provenance, a grade and a defensible decision — a returned parcel is never hand-keyed as a supplier receipt nor lost.

Strategic classification​

DimensionClassificationJustification
DomainSupporting subdomainValue recovery is material (returns run 20–30 % of e-commerce volume) but the differentiator is the ledger it feeds; the disposition policy is a replaceable data object (ADR 0001)
Business modelCost reduction / value recoveryFewer lost restocks, no scrap re-entering sellable stock, every decision auditable
EvolutionCustom-built (genesis)The first owner of the reverse flow in the fleet; REST + events are versioned Published Language from day one
TierWMSReceipts and stock provenance are WMS work; the precedent is inbound-receiving

Domain roles​

RoleStance
System of recordFor the RMA, the ReturnReceipt and the Disposition. No other context writes any of them.
Open Host ServiceReturn facts on two surfaces: REST (apis/openapi.yaml) and events (apis/asyncapi.yaml), plus read-only MCP tools.
EnforcerRuns every invariant on every write: manifest + window + one-open-RMA, no silent third line state, grade-once, pure deterministic decision with hard guardrails.
ConformistTo product-master (classification), order-management (allocated lines) and fulfillment-execution (manifests) — consumed as event-fed local copies, never live calls.

Inbound communication​

MessageTypeSenderChannelCollaborator behaviour
POST /returnscommandoperators, consoleREST (Idempotency-Key)authorize an RMA against the local copies
GET /returns/{rmaId}, GET /returns?orderRef=queryoperators, console, agentRESTreads
POST /returns/{rmaId}/receiptscommandoperators, consoleREST (Idempotency-Key)open a receipt; UNEXPECTED lines raise the case event
POST /receipts/{receiptId}/lines/{lineNo}/inspectionscommandoperatorsREST (Idempotency-Key)grade; disposition decided in the same tx
POST /dispositions/{id}/overridescommandoperatorsREST (Idempotency-Key)supersede with a mandatory reason
PUT /disposition-policies/{version}, GET /disposition-policies/currentcommand / queryoperatorsREST (PUT takes Idempotency-Key)declare / read policy versions (append-only)
get_return, list_returns_by_order, get_disposition_policyqueryany MCP hostMCP, Streamable HTTP :8090, read-onlysame read use cases as REST (MCP tools)
com.warehouse.wms.product-master.product.ProductClassifiedeventproduct-masterKafka warehouse.product-master.eventsversion-guarded product_classes copy
com.warehouse.wes.order-management.order.OrderAllocatedeventorder-managementKafka warehouse.order-management.eventsallocated_lines copy (lines carry NO quantity)
com.warehouse.wes.order-management.order.OrderPartiallyAllocatedeventorder-managementKafka warehouse.order-management.eventssame copy, only the allocated lines
com.warehouse.wes.fulfillment-execution.package.PackageManifestedeventfulfillment-executionKafka warehouse.fulfillment.eventsmanifested_units copy (order_ref reversed)
Kubernetes liveness / readinessquerykubeletREST GET /healthz, GET /readyzdrain gate + Postgres ping + Kafka metadata

Outbound communication​

MessageTypeReceiverChannel
returnauthorization.ReturnAuthorized / ReturnAuthorizationRejectedeventanyoneKafka warehouse.returns-processing.events (key = rmaId)
returnreceipt.ReturnReceiptOpened / ReturnLineInspected / UnexpectedReturnReceivedeventexception-management consumes the unexpected oneKafka warehouse.returns-processing.events (key = receiptId)
disposition.DispositionDecidedeventanyoneKafka warehouse.returns-processing.events (key = dispositionId)
disposition.ReturnLineStagedeventinventory-storage (staged-receipt use case, its ADR 0044 — built)Kafka warehouse.returns-processing.events (key = dispositionId)
<topic>.dlq dead letterseventoperatorsKafka — inbound poison messages and outbox rows the encoder refuses
REST / MCP responsesquery resultsoperators, console, agentsREST / MCP

All messages are CloudEvents 1.0 structured mode and leave through the transactional outbox (ADR 0005). The analytics mirror (warehouse.returns-processing.analytics) is built: the relay writes it in the same outbox pass and this service's own projector consumes it (ADR 0007).

Ubiquitous language​

Full glossary: Ubiquitous language. The terms that carry the model: RMA, return receipt, grade, reason code, disposition, outcome, disposition policy, return window, unexpected return, staged line, local copy.

Business decisions​

DecisionSource
Authorizable only against a manifested work unit, inside the window, quantity ≤ policy maxADR 0002, AuthorizeReturn
One open RMA per (order, line) — aggregate rule + partial unique indexADR 0002, uq_rmas_one_open_per_order_line
Every received line is MATCHED or explicitly UNEXPECTED — no silent third stateADR 0002, returnreceipt constructor
A line is inspected exactly once; inspected qty ≤ received qtyADR 0002
Decide is a pure, total function of (grade, classification, policy version); every combination answers via the * defaultADR 0002
RESTOCK only grade A/B, never a DISPOSE-classified SKU, never hazmat without a DOT rating — demoted to the veto outcome, fail-closedADR 0002 guardrails
The disposition is immutable; an override is a NEW disposition with supersedes + reasonADR 0002
ReturnLineStaged once per RESTOCK disposition (idempotent on disposition id)ADR 0002/0004
The policy is data: a change is a new version, never a redeployADR 0002
Events leave through the outbox only; at-least-once with a stable idADR 0005
No auth on REST or MCPfleet decision 2026-09-11

Assumptions​

  • The shipped quantity per line is not on OrderAllocated today: the policy cap is the only ceiling (the shipped-quantity check is planned, not built — ADR 0003).
  • Hazmat/temperature classes come from ProductClassified; an unclassified SKU is treated as unclassified (fail-open for grading, fail-closed for RESTOCK of a hazmat SKU — ADR 0001).
  • Consumers dedupe on the CloudEvents id and tolerate at-least-once, per-aggregate-ordered delivery (ADR 0005).
  • Until a producer event arrives, the matching copy is empty and authorizations fail closed (LINE_NOT_MANIFESTED), never open.

Verification metrics​

Metric / gateSource
Coverage gate 90 % on internal/domain + internal/applicationmake coverage, CI test job
Mutation thresholds 95/95 on every domain package (measured 100/100).gremlins.yaml, mutation-fast CI job
15 BDD scenarios: RMA → receipt → inspect → disposition → staged, and the unexpected pathfeatures/*.feature
Golden exact-JSON per published typeinternal/adapters/outbound/kafka/testdata/
Catalogue fitness: every AsyncAPI type has an ADR 0004 lineinternal/architecture/catalogue_fitness_test.go
Hexagonal fitness: no memory adapters in cmd/**, no auth, no flat envelope, relay attempt capinternal/architecture/*

The service exports no runtime metrics today (the spec declares no /metrics route — see Observability); the verification above is build-time gates, not runtime signals.

Open questions​

  • Shipped-quantity check per line — waits on order-management adding quantity to its released line (additive producer change, asked separately; roadmap).
  • Restock loop closure — waits on inventory-storage promoting ItemStowed to its integration topic; until then a staged line's stow is invisible here (roadmap).
  • Analytics mirror + read side — its own later decision (ADR 0004 records it as planned).
  • Runtime metrics: none exported; GET /metrics was dropped from apis/openapi.yaml (ADR 0009) so the contract matches the binary. Add the route back to the spec only together with the handler.