Skip to main content

Last-Mile Delivery

As built

Derived from network/model/model.yaml. This context's service is built; the model carries its as-built contracts, and identifiers (Err... names, routes, CloudEvents types) are the names the service uses. It also has an analytics read side (last-mile-delivery ADR 0012): cmd/lm-projector projects this context's own topics into a separate analytical database, and cmd/lm-reports serves the read-only /reports/... routes on :8092, including the day-of ETA-window report of ADR 0013.

Supporting   tier logistics · code LM

Last-Mile Delivery runs each delivery station of the network. A delivery station is a network-operated node (see ADR 0004). The context publishes delivery waves: dispatch slots with an induct cutoff, a delivery window and a stop capacity. delivery-promise and order-sourcing plan the last leg of every path on those waves. When a load arrives at a station from linehaul-transportation, the context inducts each package into the earliest wave that still has room. It plans routes for independent Delivery Service Partners (DSPs) within each van's stop capacity, and it records every delivery attempt as DELIVERED or FAILED, with an optional driver-reported category (outcomeDetail, last-mile-delivery ADR 0014). A failed package goes into the next wave. After three failures it goes back to the sender. At route start it assigns each stop a day-of ETA window of at most two hours, spread linearly over what is left of the wave's delivery window (ADR 0013), and it learns a delivery-point profile per opaque stop key that flags a point after two counted failed attempts. The context owns four aggregates: DeliveryWave, Route, DeliveryServicePartner and DeliveryPointProfile.

What its own pages describe
  • Inbound: REST commands from the station planner (/waves, /routes) and from the DSP driver app (/routes/{routeId}/starts, /routes/{routeId}/attempts); LoadArrived from linehaul-transportation; NodeRegistered and ServiceAreaAssigned from node-topology.
  • Outbound: eleven CloudEvents types on retailnetwork.last-mile-delivery.events. delivery-promise and order-sourcing consume the wave events. shipping-and-tracking consumes the out-for-delivery, stop-ETA-window, attempt and delivery-point-flag events. The context makes no synchronous call.
  • Not here: addresses and other PII (confined to customer-ordering and shipping-and-tracking, ADR 0006), the customer-visible timeline, and the promise itself. A flagged delivery point changes no route, no ETA and no promise, and the day-of window never reaches delivery-promise.

This context's pages​

Pageddd-crew tool / notationWhat it answers
Business ContextBusiness context (DDD Starter Modelling Process, Understand / Discover)Why the doorstep is its own context, who acts, what is out of scope
Ubiquitous LanguageGlossary (Bounded Context Canvas, Ubiquitous Language)Delivery Wave, Induction, Route, DSP, Delivery Attempt and the neighbour terms used here
Core Domain ChartCore Domain ChartsWhy the context is Supporting
Bounded Context CanvasBounded Context Canvas v5Purpose, roles, every inbound and outbound message, decisions, open questions
Context MapContext MappingEvery upstream and downstream neighbour, with pattern and channel
Aggregate Design CanvasAggregate Design Canvas v1.1DeliveryWave, Route, DeliveryServicePartner, DeliveryPointProfile: states, invariants, commands, events
Domain EventsCloudEvents catalogue (event standard)The eleven published and three consumed events, with full types and payloads
Domain Message FlowDomain Message Flow ModellingArrival to doorstep, and the failed-attempt path
EventStormingEventStorming glossary & cheat sheetProcess-level boards with policies, read models and hotspots
Use CasesApplication services (hexagonal)One section per command: trigger, adapter, flow, errors, events, idempotency
Class DiagramUML class diagram + ports and adaptersThe proposed Go domain model and package layout
Entity RelationshipER diagramThe proposed Postgres schema, outbox and inbox
Sequence DiagramsUML sequence diagramsAdapter → use case → aggregate → repository → outbox for every command

Service and operations​

  • Service: IQVO/last-mile-delivery on develop (f77cc6a, 2026-10-26): binaries cmd/api (REST) and cmd/mcp (read-only MCP), and the console remote in web/.
  • Deployment: wired in warehouse-infra develop: a terraform/apps.yaml entry (database: true, frontend_remote: last_mile_mfe) and helm-values/last-mile-delivery.yaml (MCP enabled, gateway path /api/mcp/last-mile-delivery). The cluster itself was not checked in this refresh.
  • Observability: service ADR 0008, Adopt the fleet observability standard, Accepted 2026-10-26. Logs, metrics and traces leave over OTLP to the otel-collector (OTEL_EXPORTER_OTLP_ENDPOINT, chart default otel-collector.observability.svc.cluster.local:4317; OTEL_SERVICE_NAME). The Tier-2 business counter is last_mile_delivery.package.attempted (unit {package}, in internal/adapters/outbound/telemetry/attempt_metrics.go), with attribute outcome = delivered, failed or rejected and reason on the outcomes that are not a success. The dashboard queries it as last_mile_delivery_package_attempted_total in warehouse-infra's terraform/dashboards/contexts/last-mile-delivery.json, by outcome.

Elsewhere​

  • Read-only MCP server (service ADR 0006): cmd/mcp, a second binary serving Streamable HTTP on :8090 with no auth; it sources this context's own reads and nothing that writes. Three tools: get_route, get_wave_stops, list_waves. The gateway (Kong) exposes it at /api/mcp/last-mile-delivery, rewritten to the server's /mcp mount.
  • Console remote (service ADR 0007): web/, a Vite + React Module Federation remote — federation container last_mile_mfe, gateway mount /mfes/last-mile-delivery/, dev/preview port 4014 — read-only screens over the existing REST reads, calling only this context's API.
  • REST contract (as built, from the service repository): apis/last-mile-delivery/openapi.yaml, listed under the API reference.
  • Strategic view: context map, subdomain classification, domain message flows.
  • How waves enter a promise: promise model and ADR 0008.
  • Station nodes and service areas: node model.