Skip to main content

Bounded context canvas

Following the ddd-crew Bounded Context Canvas v5, filled from the code on develop.

Source: docs/adr/0001-last-mile-delivery-bounded-context.md, 0002, 0003, 0004, internal/adapters/inbound/*, apis/openapi.yaml, apis/asyncapi.yaml.

1. Name​

Last-Mile Delivery (last-mile-delivery), area Network, tier logistics.

2. Purpose​

Runs each delivery station: publishes delivery waves (induct cutoff, delivery window, stop capacity) that the promise relies on, inducts arriving packages into them, plans routes for delivery service partners and records every delivery attempt.

3. Strategic classification​

AxisValue
DomainSupporting subdomain (why)
Business modelCost reducer, experience creator
EvolutionCustom-built, genesis (Core domain chart)

4. Domain roles​

RoleFit
Specification modelDeliveryWave: a published specification (cutoff, window, capacity) others plan on
Execution contextRoute and PackageAttemptHistory: what actually happened at the doorstep
Gateway contextthe local read models translate three upstream contexts' vocabularies
Audit contextthe attempt list and DeliveryAttempted events are the record of each try

5. Inbound communication​

MessageTypeFromCollaboration
ScheduleWave, CloseInduction, DispatchWave, CancelWave, PlanRoute, ContractPartner, DeactivatePartnercommand (REST)station plannerUI on Open Host
StartRoute, RecordAttemptcommand (REST)DSP driver appUI on Open Host
list waves, wave stops, routequery (REST, MCP, A2A)planner, console, agentsOpen Host
LoadArrivedevent (Kafka)linehaul-transportationCustomer/Supplier, we are the Customer
NodeRegistered, ServiceAreaAssignedevent (Kafka)node-topologyOHS + PL / Conformist
LabelIssuedevent (Kafka)shipping-and-trackingOHS + PL / Conformist

6. Outbound communication​

MessageTypeToCollaboration
DeliveryWaveScheduled, DeliveryWaveCapacityChanged, DeliveryWaveCancelledeventdelivery-promise, order-sourcingOHS + PL / Conformist
WaveCostDeclaredeventorder-sourcingOHS + PL / Conformist
PackageInductionDeferredeventdelivery-promiseOHS + PL / Conformist
PackageOutForDelivery, StopEtaWindowAssigned, DeliveryAttempted, PackageReturnInitiated, DeliveryPointFlaggedeventshipping-and-trackingOHS + PL / Conformist
RoutePlannedevent (analytics topic only)analyticsOHS + PL

No synchronous call to any context.

7. Ubiquitous language​

See Ubiquitous language: delivery wave, induct cutoff, delivery window, stop and stop capacity, induction, route, delivery service partner, van capacity, delivery attempt, return to sender.

8. Business decisions​

  1. A package joins the earliest wave whose cutoff it arrived before and that has stop capacity left (InductOnArrival; ErrInductionClosed, ErrWaveFull).
  2. A route never exceeds the van's stop capacity (ErrRouteOverCapacity), only uses an active partner of the wave's own station, and only packages inducted in the wave and on no other route.
  3. A package is delivered at most once (ErrAlreadyDelivered); a failed attempt sends it to the next wave; the third failure returns it to the sender (PackageReturnInitiated).
  4. A wave's times are ordered (ErrInvalidWaveTimes); an attempt is recorded only on a route out for delivery (ErrRouteNotStarted).
  5. Capacity is counted in stops: packages with one stopKey share a stop.
  6. Cancelling a wave re-inducts its packages; dispatching re-inducts the packages no route holds; a wave completes with its last route.
  7. A wave can only be scheduled and a partner only contracted at a known delivery station.

9. Assumptions​

A1 to A29 in ADR 0002 (for example A4 stop grouping and the pkg: fallback key, A6 earliest eligible wave, A8 station check, A9 wave completes with its last route, A11 dispatch leftovers, A12 route planning rules, A14 one out-for-delivery event per package, A18 and A19 retry and sweep); gap decisions G5, G11, G16, G17, G34 are recorded in the repository's CLAUDE.md and the ADRs.

10. Verification metrics​

MetricWhere
last_mile_delivery.package.attempted by outcome (and reason)counter, Observability
HTTP request duration by routehttp.server.request.duration
unpublished outbox rows, parked rowsSQL on outbox_events (Runbook)
packages waiting AT_STATIONSQL on package_histories

11. Open questions​

QuestionState in the code
What does the promise do when a wave is cancelled?DeliveryWaveCancelled is published (G5); delivery-promise consumes it and flags every confirmed promise whose witness wave it was as at risk (its apis/asyncapi.yaml, message DeliveryWaveCancelled); order-sourcing also consumes it
Who consumes PackageInductionDeferred and PackageReturnInitiated?delivery-promise consumes PackageInductionDeferred as a risk to the group's promise; shipping-and-tracking consumes PackageReturnInitiated and moves the package from AT_STATION to RETURNED
Is a route re-validated when its partner is later deactivated?no: only planning checks the partner
Route sequencing and optimisationnot modelled: the planner supplies the stops
Row cleanup of idempotency_keys and published outbox_eventsidempotency_keys: the retention loop of cmd/api deletes rows older than 24 h, hourly, 1000 per statement (ADR 0019 addendum); published outbox_events: no purge job exists