Skip to main content

Architecture

vendor-connectivity 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. Three binaries share one application service (usecases.Service); they differ in which inbound adapters and background workers they start.

Layout​

LayerPathRole
Domaininternal/domain/vendorAccount aggregate (VendorAccount): Onboard, Suspend, Reinstate, EnsureActive; events VendorOnboarded, VendorSuspended, VendorReinstated.
Domaininternal/domain/purchaseorderPurchaseOrder aggregate: Issue, SubmitAcknowledgement, ApplyAckOutcome, AddLabels, SubmitShipmentConfirmation, ApplyShipmentOutcome, Expire, Cancel; ComputeAckBy; NumberFor.
Domaininternal/domain/submissionSubmission aggregate: Receive, RecordAttempt, Complete; the six Kinds; event SubmissionProcessed.
Domaininternal/domain/networkNode and Listing value types of the local read models; EnsureOwnedBy, VendorMayRegister.
Domaininternal/domain/inboundShipment, Carton, Receipt, PackLevel and their rules; event InboundReceiptSubmitted.
Domaininternal/domain/shared, shared/gs1Event, Header, validation helpers; GS1 GTIN and SSCC parsing and check digits.
Applicationinternal/application/usecasesThe use cases (see Use cases).
Applicationinternal/application/ports, repository, outbox, gateway, requests, viewsThe OUT ports (UnitOfWork, the repositories and view repositories, EventOutbox, ProcessedEvents, Clock, IDGenerator, Random, NodeTopology, OfferAvailability, ShippingTracking, NodePerformance, SubmissionMetrics), repository filters, the outbox Message, the neighbours' answer vocabulary and refusals, and the request and view DTOs. ports holds only interfaces.
Inbound adapterinternal/adapters/inbound/httpchi router for apis/openapi.yaml: handlers, RFC 9457 problem mapping (errors.go), the transactional Idempotency-Key middleware, the RATE_LIMIT_RPS token bucket, NUL rejection, /healthz and /readyz. No auth middleware.
Inbound adapterinternal/adapters/inbound/kafkaFive consumers (node, listing, sourcing, inbound, packaging): CloudEvents decode, dispatch on the full type, retry with backoff, dead-letter topic, trace spans. Decode only; every effect is a use case.
Inbound adapterinternal/adapters/inbound/mcpThe read-only MCP server (nine tools) behind a Reads interface.
Inbound adapterinternal/adapters/inbound/a2aThe read-only A2A agent (two skills, Agent Card).
Inbound adapterinternal/adapters/inbound/requestlogOne structured log line per request.
Outbound adapterinternal/adapters/outbound/postgrespgxpool repositories, unit of work (pgtx), outbox repository, event outbox, embedded migrations (migrate.go, migrations/).
Outbound adapterinternal/adapters/outbound/httpclientThe four neighbour REST clients (5 s timeout).
Outbound adapterinternal/adapters/outbound/kafkaEncoder (domain events to CloudEvents outbox messages), RelaySink, BrokerCheck (the Kafka half of /readyz), writer settings.
Outbound adapterinternal/adapters/outbound/outboxThe relay loop that drains outbox_events to the sink.
Outbound adapterinternal/adapters/outbound/telemetryOTel providers, the vendor.submissions.processed counter, trace-aware slog handler.
Outbound adapterinternal/adapters/outbound/clock, idsProduction clock, id generators, random source.
Outbound adapterinternal/adapters/outbound/memory, repocontractIn-memory implementation of every port and the shared repository contract suite: test doubles. No cmd/** file imports them (TestRuntimeBinaryHasNoInMemoryAdapters).
Kafka envelopeinternal/adapters/kafka/cloudeventsThe only place a CloudEvents 1.0 envelope is built or decoded: New(Spec), Decode, Type, DataSchema, ContentTypeHeader. Tier = "partner", Context = "vendor-connectivity", Source = "/retailnetwork/vendor-connectivity".
Supportinternal/bootretryExponential-backoff retry for the first outbound dials at boot.
Composition rootscmd/api, cmd/mcp, cmd/a2acmd/api: main.go (run, shutdown order), config.go (env parsing), wire_adapters.go (Postgres adapters, readiness), background.go (consumers, loops, relay, watchWorkers), telemetry.go.
Test supportinternal/testing/{kafkatest,pgtest}Testcontainers helpers.
Fitness testsinternal/architecturearch-go and source-scanning tests; see Testing.

Binaries and ports​

BinaryRolePortProbes
cmd/apiVendor REST API, outbox relay, five Kafka consumers and three loops (submission processor, expiry sweeper, retention sweeper) in one process, all always on, on real Postgres and Kafka. Exits non-zero when any worker dies.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 over Streamable HTTP at /mcp and /; same Service, only the read methods reachable; no relay, consumer, loop or Kafka client. Runs the embedded migrations at boot, so it can start on a fresh database.MCP_ADDR, default :8090GET /healthz
cmd/a2aRead-only A2A (Agent2Agent) agent: JSON-RPC at / and /a2a, Agent Card at /.well-known/agent-card.json; same constraints as cmd/mcp.A2A_ADDR, default :8093GET /healthz

web/ is not a Go binary: the vendor_connectivity_mfe Module Federation remote (ADR 0007), served by its own nginx image under /mfes/vendor-connectivity/ (dev and preview port 4021), with four read-only screens (orders, order detail, nodes, inbound) over the existing REST reads. The Helm chart renders mcp, a2a and frontend only when enabled (off by default); see the Runbook. Boot order and shutdown order are in Runtime; every variable is in Configuration.

Container diagram​

Source: cmd/api/main.go, cmd/api/background.go and cmd/api/wire_adapters.go (wiring and workers), cmd/mcp/main.go, cmd/a2a/main.go, internal/application/usecases/service.go (Deps) and internal/adapters/inbound/kafka/consumers.go. cmd/mcp and cmd/a2a build the same Service over the same Postgres repositories and the same four neighbour clients but never start a consumer or the relay, so for them the Kafka edges do not exist.

Data stores​

One Postgres database owned by this context, created by two embedded migrations (internal/adapters/outbound/postgres/migrations/0001_vendor_connectivity_schema.up.sql and 0002_inbound_shipments_and_packaging.up.sql):

TableHolds
vendor_accountsThe VendorAccount aggregate; version guards updates.
purchase_ordersThe PurchaseOrder aggregate; lines, labels and tracking numbers are JSONB value objects; unique on (assignment_id, release_no).
submissionsThe Submission aggregate: the vendor body verbatim (BYTEA), kind, status, not_before, attempts, errors.
vendor_nodes, listingsLocal read models of node-topology's nodes and offer-availability's listings.
inbound_shipments, catalog_packagingLocal read models of seller-inbound's shipments (manifest as JSONB) and offer-availability's packaging hierarchy.
outbox_eventsThe transactional outbox: one already-encoded Kafka message per row, with attempts and last_error.
processed_eventsThe consumers' inbox: the CloudEvents id is claimed in the same transaction as the effect.
idempotency_keysStored answers of the write routes, keyed by (route, key), 24 h.

Postgres is the only store: the service refuses to boot without DATABASE_URL. Kafka is the fleet's single broker; this service produces to retailnetwork.vendor-connectivity.events and retailnetwork.vendor-connectivity.analytics, consumes retailnetwork.node-topology.events, retailnetwork.offer-availability.events (two consumer groups), retailnetwork.order-sourcing.events, retailnetwork.seller-inbound.events and retailnetwork.customer-returns.events, and dead-letters to <topic>.dlq. It never creates a topic through an admin API: the broker auto-creates each on first write (AllowAutoTopicCreation), and /readyz does not wait for any topic.

Rules enforced by internal/architecture​

The tests run on every PR (arch-test job, make arch-test):

TestRule
TestHexagonalArchitectureDomain depends only on domain; application only on domain and application; inbound adapters do not depend on outbound adapters and the reverse; nothing under internal/ imports cmd; internal/application/ports holds only interfaces.
TestMCPAdapterDependencyRule, TestMCPOptionalToolInputsCarryOmitemptyThe MCP adapter depends only on application and domain, nothing depends on it, optional tool inputs stay optional.
TestA2AAdapterDependencyRule, TestA2AAgentIsReadOnly, TestA2AAdapterHasNoOutboundA2AClientThe A2A adapter depends only on application and domain, reaches only read use cases, and there is no outbound A2A client: this context is delegated to and never delegates.
TestNoAuthMiddlewareReintroducedNo bearer or JWT code in the inbound adapters: REST, MCP and A2A are unauthenticated fleet-wide.
TestRuntimeBinaryHasNoInMemoryAdaptersNo non-test file under cmd/** imports the memory adapter or repocontract.
TestCloudEventsOnly, TestNoEventEnvelopeToggleOrFlatEnvelope, TestEventCatalogueMatchesContractCloudEvents 1.0 is the only envelope and the published catalogue equals apis/asyncapi.yaml.
TestKafkaConsumerGroupNeverHardcodedInline, TestKafkaWritersSetRequiredAcks, TestKafkaWriterTopicNotSetTwice, TestDeadLetterCallsGuardCancellation, TestOutboxRelaysPassAttemptCapKafka hygiene.
TestNoGoFilesAtRepoRootGo files live under cmd/ and internal/.
TestPostgresIntegrationTestsUseTestcontainers, TestKafkaIntegrationTestsUseTestcontainersIntegration tests boot their own containers.