Skip to main content

Architecture

Shipping & Tracking follows the fleet's hexagonal (ports and adapters) layout: dependencies point inward, the domain imports nothing from the rest of the module, and only cmd/ wires the layers together. The fitness tests in internal/architecture enforce it (see Testing).

Layout​

LayerPathRole
Domaininternal/domain/labelShippingLabel aggregate (ISSUED, VOIDED): identity labelRef, tracking number, tier, carrier, opaque stopKey, postal prefix, optimistic version. Events LabelIssued, LabelVoided. Pure Go: clock and ids are arguments, Snapshot/Restore
Domaininternal/domain/journeyPackageJourney aggregate with its Scan entities: nine states, eight scan types, the edge table, the silence policy. Events PackageScanned, PackageHandedOver, PackageDelivered, PackageExceptionRaised, PackageReturned, PackageLost, PackageEtaWindowAssigned
Domaininternal/domain/sharedTier, TrackingNumber, id validation, ErrValidation, ErrIllegalTransition, the event header
Applicationinternal/application/usecasesThe use cases (see Use cases) and the writer skeleton that saves an aggregate and hands its events to the outbox inside one unit of work
Applicationinternal/application/{ports,repository,outbox,shipto,views}The OUT ports (ShipToGateway, ShipToSealer, StopKeyer, repositories, UnitOfWork, Clock, IDGenerator, LabelMetrics), the records they exchange, the already-encoded outbox Message, the shipto.Address value object that redacts itself, and the read views
Inbound adapterinternal/adapters/inbound/httpchi router for apis/openapi.yaml: handlers, RFC 9457 problem mapping (errors.go), the Idempotency-Key middleware, /healthz, /readyz. No auth middleware
Inbound adapterinternal/adapters/inbound/kafkaThe four consumers (vendor, linehaul, last-mile, catalog): CloudEvents decode, dispatch on the full type, retry with capped backoff, <topic>.dlq, consumer spans
Inbound adapterinternal/adapters/inbound/mcp, .../a2aThe read-only MCP tool and A2A skill get_journey
Inbound adapterinternal/adapters/inbound/requestlogAccess-log middleware shared by the REST, MCP and A2A routers
Schedulerinternal/schedulerRuns the three periodic jobs (silence-sweep, ship-to-purge, housekeeping)
Outbound adapterinternal/adapters/outbound/postgres (+ pgtx, migrations/)pgxpool repositories, unit of work, outbox repository, inbox (processed_events), housekeeping, embedded migrations
Outbound adapterinternal/adapters/outbound/outboxThe relay loop that drains outbox_events to a sink
Outbound adapterinternal/adapters/outbound/kafkaEvent Encoder (topic constant), RelaySink and BrokerCheck (the Kafka half of /readyz)
Outbound adapterinternal/adapters/outbound/customerorderingThe GetShipTo REST client
Outbound adapterinternal/adapters/outbound/cryptoAES-256-GCM Sealer for the ship-to snapshot and the HMAC-SHA-256 StopKeyer
Outbound adapterinternal/adapters/outbound/{ids,clock,telemetry}Random ids, the system clock, OpenTelemetry setup and the shipping.labels.issued counter
Outbound adapterinternal/adapters/outbound/memoryIn-memory implementation of every port: a test double for unit and godog suites. No binary imports it (TestRuntimeBinaryHasNoInMemoryAdapters)
Kafka envelopeinternal/adapters/kafka/cloudeventsThe only place a CloudEvents 1.0 envelope is built or decoded
Supportinternal/bootretryBackoff retry for the first outbound dials (migrations, Postgres ping)
Composition rootscmd/api, cmd/mcp, cmd/a2aEnvironment parsing, wiring, shutdown order
Test supportinternal/testing/{pgtest,kafkatest}, internal/adapters/outbound/repocontracttestcontainers helpers and the repository contract suite run against memory and Postgres
Fitness testsinternal/architectureDependency rules and contract guards

Binaries and ports​

BinaryRolePortProbes
cmd/apiREST API, outbox relay, the four Kafka consumers and the three periodic jobs in one process, all always on, on real Postgres and KafkaHTTP_ADDR, default :8080GET /healthz (liveness), GET /readyz (drain gate, Postgres ping, a Kafka broker answers a metadata request)
cmd/mcpRead-only MCP server, Streamable HTTP only, tool get_journey (ADR 0006). No Kafka, relay, consumer or jobMCP_ADDR, default :8090GET /healthz
cmd/a2aRead-only A2A agent: JSON-RPC 2.0 at / and /a2a, Agent Card at /.well-known/agent-card.json, skill get_journey (ADR 0009). No Kafka, relay, consumer or jobA2A_ADDR, default :8093GET /healthz

web/ is not a Go binary: it is the shipping_mfe Module Federation console remote (ADR 0007), a read-only screen over the journey API, served by its own nginx image. All three Go binaries ship in one image (Dockerfile, /app/<name>) and the chart picks one with command. How cmd/api boots and stops is in the Runbook; every variable is in Configuration.

Container diagram​

Source: cmd/api/main.go (buildDeps, buildServer, startConsumers, startJobs, startRelay), cmd/mcp/main.go, cmd/a2a/main.go, internal/application/ports/ports.go, internal/architecture/architecture_test.go. The in-memory adapters are not shown because no binary wires them.

Data stores​

The OLTP Postgres database, created by the embedded migrations 0001_schema and 0002_idempotency_key_global under internal/adapters/outbound/postgres/migrations/ and shared by the three binaries (cmd/api writes, cmd/mcp and cmd/a2a only read):

TableHolds
shipping_labelsThe ShippingLabel aggregate, unique on (po_number, package_no) and on tracking_number
ship_to_snapshotsThe AES-256-GCM sealed ship-to (key_id, nonce, ciphertext), one per label, deleted 30 days after the journey closes, never read back by a response
package_journeysThe PackageJourney aggregate with its optimistic version; partial indexes for the silence sweep and the ship-to purge
journey_scansThe append-only Scan entities (seq, unique (tracking_number, scan_id))
catalog_dimensionsLocal read model fed by CatalogItemCreated
node_destinationsLocal read model fed by node-topology's NodeRegistered (migration 0008, ADR 0018): per node, the destination prefix a return label carries when its destination is named by node
outbox_eventsThe transactional outbox, one already-encoded CloudEvents message per row, unique (event_id, topic)
processed_eventsThe inbox: (consumer, event_id) claims that make the consumers idempotent
idempotency_keysStored answers of the three POST routes, key key (global), 24 h retention

Postgres is the only store: cmd/api, cmd/mcp and cmd/a2a refuse to boot without DATABASE_URL. A second, separate Postgres database holds the analytics read model (analytics_processed_events, package_labels, journey_scans, package_outcomes; see the entity relationship page); it is written only by cmd/st-projector and read by cmd/st-reports. Kafka is the fleet's single broker: this service produces to retailnetwork.shipping-and-tracking.events and consumes retailnetwork.vendor-connectivity.events, retailnetwork.linehaul-transportation.events, retailnetwork.last-mile-delivery.events and retailnetwork.offer-availability.events (dead letters go to <topic>.dlq). Topics are created by the first writer; /readyz waits for a broker, not for topics.

Rules enforced by internal/architecture​

TestRule
TestHexagonalArchitectureDomain depends only on domain; application on domain and application; inbound and outbound adapters do not depend on each other; nothing under internal/ imports cmd
TestMCPAdapterDependencyRule, TestMCPServerIsReadOnly, TestA2AAdapterDependencyRule, TestA2AServerIsReadOnly, TestA2AHasNoOutboundClientMCP and A2A adapters depend only inward, reach read use cases only, and A2A has no client
TestRuntimeBinaryHasNoInMemoryAdaptersNo file under cmd/** imports the memory adapters
TestNoAuthMiddlewareReintroducedREST, MCP and A2A stay unauthenticated
TestCloudEventsOnly, TestNoEventEnvelopeToggleOrFlatEnvelopeCloudEvents 1.0 is the only envelope
TestContractsCarryNoShipToFieldNo ship-to field in any OpenAPI or AsyncAPI schema
TestEventCatalogueMatchesContract, TestConsumedTypesAreDocumentedAsyncAPI, ADR 0003 and ADR 0004 agree
TestKafkaWritersSetRequiredAcks, TestKafkaConsumerGroupNeverHardcodedInline, TestOutboxRelaysPassAttemptCap, TestDeadLetterCallsGuardCancellationKafka and outbox wiring rules