Skip to main content

Architecture

seller-inbound 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. Everything on this page is on develop.

Layout​

LayerPathRole
Domaininternal/domain/sellerSellerAccount aggregate (ACTIVE or SUSPENDED), events SellerOnboarded, SellerSuspended, SellerReinstated.
Domaininternal/domain/inboundplanInboundPlan aggregate (DRAFT, CONFIRMED, CANCELLED), event InboundPlanConfirmed.
Domaininternal/domain/inboundshipmentInboundShipment aggregate with Carton entities (six states), the receipt reconciliation, and the events InboundShipmentLabelled, InboundShipmentShipped, InboundShipmentReceived, InboundDiscrepancyRecorded, SellerComplianceViolationRecorded.
Domaininternal/domain/networkThe two local read-model rows: Node (NodeInboundView) and PackLevel (CatalogPackagingView), folded from neighbours' events.
Domaininternal/domain/scorecardThe pure computation of the seller compliance scorecard from recorded facts.
Domaininternal/domain/shared, shared/gs1ErrValidation, ErrIllegalTransition; GS1 GTIN, SSCC and element-string parsing with mod-10 check digits.
Applicationinternal/application/usecasesOne method of Service per command, query or consumed event (Use cases).
Applicationinternal/application/{ports,requests,views,outbox}The out ports (SellerRepository, PlanRepository, ShipmentRepository, NodeViewRepository, PackagingViewRepository, ScorecardFacts, EventOutbox, ProcessedEvents, UnitOfWork, Clock, IDGenerator, SsccIssuer, ShipmentMetrics), the request and view structs, and the already-encoded outbox Message.
Inbound adapterinternal/adapters/inbound/httpchi router for apis/openapi.yaml: handlers, problem mapping (errors.go), the Idempotency-Key middleware, /healthz, /readyz. No auth middleware.
Inbound adapterinternal/adapters/inbound/kafkaThe node, catalog, receipt and sourcing consumers: CloudEvents decode, dispatch on the full type, retry with backoff, dead-letter topic, consumer span.
Inbound adapterinternal/adapters/inbound/mcpThe six read-only MCP tools.
Inbound adapterinternal/adapters/inbound/a2aThe two read-only A2A skills and the Agent Card.
Inbound adapterinternal/adapters/inbound/requestlogThe access-log middleware shared by the three routers.
Outbound adapterinternal/adapters/outbound/postgrespgxpool repositories, unit of work (pgtx), outbox repository, scorecard facts, embedded migrations.
Outbound adapterinternal/adapters/outbound/kafkaEncoder (domain event to CloudEvents outbox message), NewWriter, RelaySink, BrokerCheck (the Kafka half of /readyz).
Outbound adapterinternal/adapters/outbound/outboxThe relay loop that drains outbox_events.
Outbound adapterinternal/adapters/outbound/ssccThe SSCC issuer over the Postgres sequence sscc_serial_seq.
Outbound adapterinternal/adapters/outbound/telemetryOpenTelemetry setup, the seller_inbound.shipment.shipped counter, the trace-correlating slog handler.
Outbound adapterinternal/adapters/outbound/{clock,ids}Clock and id generation (pln-, shp- prefixes).
Outbound adapterinternal/adapters/outbound/memoryIn-memory implementation of the ports: a test double for the unit and BDD suites. No cmd/** binary imports it (TestRuntimeBinaryHasNoInMemoryAdapters).
Kafka envelopeinternal/adapters/kafka/cloudeventsThe only place a CloudEvents 1.0 envelope is built or decoded.
Supportinternal/bootretryExponential-backoff retry for the first outbound dials at boot.
Composition rootscmd/api, cmd/mcp, cmd/a2aSee below.
Test supportinternal/testing/{kafkatest,pgtest}Shared testcontainers helpers.
Fitness testsinternal/architecturearch-go and source-scanning tests.

The out ports are interfaces in internal/application/ports/ports.go; the SSCC issuer, the clock, id generation and the shipment counter are ports too, so the use cases never touch infrastructure.

Binaries and ports​

BinaryRolePortProbes
cmd/apiREST API, the node, catalog, receipt and sourcing consumers, the outbox relay and the retention sweeper in one process, all always on, on real Postgres and Kafka. Files: main.go (run and shutdown order), config.go (env parsing, loadRuntime), wire_adapters.go, wire_background.go, telemetry.go.HTTP_ADDR, default :8080GET /healthz (liveness), GET /readyz (drain gate, Postgres ping, a Kafka broker answers a metadata request; never topics)
cmd/mcpRead-only MCP server (Streamable HTTP) over the read use cases; no relay, consumer or Kafka (ADR 0006).MCP_ADDR, default :8090GET /healthz
cmd/a2aRead-only A2A (Agent2Agent) agent: JSON-RPC 2.0 at / and /a2a, Agent Card at /.well-known/agent-card.json; no relay, consumer or Kafka (ADR 0009).A2A_ADDR, default :8093GET /healthz

web/ is not a Go binary: it is the seller_inbound_mfe Module Federation remote (Vite and React) shipped in its own nginx image (ADR 0007). There is no projector, reports or analytical-database binary. How cmd/api boots and stops is in Runtime; every variable is in Configuration.

Container diagram​

Source: cmd/api/{main,wire_adapters,wire_background}.go (wiring and workers), cmd/mcp/main.go, cmd/a2a/main.go, internal/application/ports/ports.go (the out ports), internal/adapters/outbound/postgres/repositories.go, internal/adapters/outbound/kafka/encoder.go, internal/adapters/outbound/outbox/relay.go and internal/architecture/architecture_test.go. The in-memory adapters are not in the diagram because no binary wires them. cmd/mcp and cmd/a2a run the same embedded migrations at boot and read through the same repositories.

Data stores​

One Postgres database owned by this context, created by the embedded migrations (internal/adapters/outbound/postgres/migrations/: 0001_seller_inbound_schema, 0002_seller_scorecard, 0003_idempotency_key_global, 0004_placement_advisory):

TableHolds
sellersThe SellerAccount aggregate: state, name, suspension, version.
inbound_plansThe InboundPlan aggregate; the lines live in JSONB.
inbound_shipmentsThe InboundShipment aggregate; its cartons and the unexpected SSCCs are JSONB (a shipment is always read and written whole).
sscc_registryEvery carton SSCC of every shipment, unique network-wide; registered in the shipment's save transaction.
node_inbound_viewsLocal copy of the nodes: type, status, profile revision, inbound limits, and (0004) the operator and region.
catalog_pack_levelsLocal copy of the packaging hierarchy: item, level, GTIN, units per pack, active flag.
outbox_eventsThe transactional outbox; one row per message and destination topic, with attempts and last_error.
processed_eventsThe consumers' inbox: CloudEvents ids already applied.
idempotency_keysStored answers of the POST routes (a 2xx or a FINAL refusal; a RETRYABLE one is released, ADR 0018), keyed by the global Idempotency-Key (since migration 0003; route holds method and path for the fingerprint), kept 24 h.
seller_scorecard_receipts, seller_scorecard_occurrencesThe append-only facts the scorecard is computed from.
demand_heat_lines, listing_availabilityThe two halves of the DemandHeatView read model of the placement advisory: live released order lines per assignment group, and the latest listing availability per item and node (ADR 0012).
placement_plansThe PlacementPlan aggregate; the per-node suggestions live in JSONB.

Plus the sequence sscc_serial_seq. Postgres is the only store: the binaries refuse to boot without DATABASE_URL and nothing is served from process memory. Kafka is the fleet's single broker; cmd/api produces to retailnetwork.seller-inbound.events and retailnetwork.seller-inbound.analytics, consumes retailnetwork.node-topology.events, retailnetwork.offer-availability.events and retailnetwork.vendor-connectivity.events, and never creates a topic through an admin API.

Rules enforced by internal/architecture​

The tests run on every PR (arch-test job, make arch-test); the full list is on Testing. The load-bearing ones:

RuleTest
Domain depends only on domain; application only on domain and application; inbound and outbound adapters do not import each otherTestHexagonalArchitecture (6 subtests)
The MCP and A2A adapters depend only on application and domain, nothing depends on them, and they reach read use cases onlyTestMCPAdapterDependencyRule, TestA2AAdapterDependencyRule, TestA2AAgentIsReadOnlyAndHasNoOutboundClient
No authentication middlewareTestNoAuthMiddlewareReintroduced
No binary imports the in-memory adaptersTestRuntimeBinaryHasNoInMemoryAdapters
CloudEvents 1.0 is the only envelopeTestNoEventEnvelopeToggleOrFlatEnvelope, TestCloudEventsOnly
Every outbox relay passes an attempt capTestOutboxRelaysPassAttemptCap