Skip to main content

Architecture

offer-availability 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; the rules are enforced by internal/architecture (Testing).

Layout​

LayerPathRole
Domaininternal/domain/catalogItem aggregate (CatalogItem): specification, state ACTIVE/DISCONTINUED, optional GTIN, the packaging hierarchy (packaging.go: EACH, INNER, CASE, PALLET) and its events
Domaininternal/domain/listingListing aggregate: LIVE/SUPPRESSED, suppression reason, availability (quantity, basis, asOf, feedId), optional OwnerRef, events
Domaininternal/domain/feedInventoryFeed aggregate: RECEIVED -> APPLIED/FAILED/SUPERSEDED, Apply over the listings of a node, MaxLines = 10000, events
Domaininternal/domain/nodestatusView: the local copy of a node's status (PROPOSED, ACTIVE, SUSPENDED, RETIRED) with its Observe rules (older observations ignored, RETIRED final)
Domaininternal/domain/shared (+ gs1)Event, Header, ErrValidation, ErrIllegalTransition; gs1 parses and checks GTIN, SSCC and scans
Applicationinternal/application/usecasesThe use cases (Use cases): CreateCatalogItem, DiscontinueItem, DeclarePackLevel, RetirePackLevel, CreateListing, ApplyInventoryFeed, ApplyNodeEvent, the four queries; writer (unit of work + outbox publish)
Applicationinternal/application/ports, repository, views, outboxThe OUT ports (CatalogRepository, ListingRepository, FeedRepository, NodeFeedMarks, NodeStatusRepository, ProcessedEvents, EventOutbox, EventEncoder, UnitOfWork, Clock, IDGenerator, FeedMetrics), page filters, the read views returned to adapters, the already-encoded outbox Message
Inbound adapterinternal/adapters/inbound/httpchi router for apis/openapi.yaml: handlers, RFC 9457 problem mapping (problems.go), the Idempotency-Key middleware, NUL rejection, /healthz, /readyz
Inbound adapterinternal/adapters/inbound/kafkaThe node-topology consumer: CloudEvents decode, dispatch on the full type, retry with backoff, dead-letter topic, consumer span
Inbound adapterinternal/adapters/inbound/mcpRead-only MCP server (four tools) over the read use cases
Inbound adapterinternal/adapters/inbound/a2aRead-only A2A agent (two skills, Agent Card) over the read use cases
Inbound adapterinternal/adapters/inbound/requestlogThe one-line http request access log shared by the three routers
Outbound adapterinternal/adapters/outbound/postgrespgxpool repositories, pgtx unit of work, outbox repository (with trace-context headers), retention janitor, embedded migrations
Outbound adapterinternal/adapters/outbound/outboxThe relay loop that drains the outbox to a sink
Outbound adapterinternal/adapters/outbound/kafkaEncoder (domain events to CloudEvents messages), the writer (acks=all, hash balancer, AllowAutoTopicCreation), RelaySink, BrokerCheck (the Kafka half of /readyz)
Outbound adapterinternal/adapters/outbound/telemetryOTel setup, the feed counter, slog trace correlation
Outbound adapterinternal/adapters/outbound/{clock,ids}The production clock and the UUID id generator
Outbound adapterinternal/adapters/outbound/memory, repocontractIn-memory doubles for the unit and BDD tests and the shared repository contract suite; never imported by cmd/** (TestRuntimeBinaryHasNoInMemoryAdapters)
Kafka envelopeinternal/adapters/kafka/cloudeventsThe only place a CloudEvents 1.0 envelope is built or decoded. Repo = "offer-availability", Tier = "commerce", Context = "offer-availability", Source = "/retailnetwork/offer-availability", type com.retailnetwork.commerce.offer-availability.<entity>.<Event>
Supportinternal/bootretryExponential-backoff retry for the first outbound dials at boot
Composition rootscmd/api, cmd/mcp, cmd/a2aEnv parsing, adapter wiring, workers, shutdown order
Consoleweb/Vite + React Module Federation remote offer_availability_mfe, served by its own nginx image (ADR 0008)

Binaries and ports​

BinaryRolePortProbes
cmd/apiREST API, outbox relay, node-topology consumer and retention janitor in one process, all always on, on real Postgres and Kafka. The only writer and the only process that dials KafkaHTTP_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) at /mcp and /, four tools (ADR 0007). No relay, consumer or KafkaMCP_ADDR, default :8090GET /healthz
cmd/a2aRead-only A2A agent: JSON-RPC 2.0 on / and /a2a, Agent Card at /.well-known/agent-card.json, two skills (ADR 0010). No relay, consumer or KafkaA2A_ADDR, default :8093GET /healthz

All three run the embedded migrations at boot. How cmd/api boots and stops is in Runtime and the Runbook; every variable is in Configuration.

Container diagram​

Source: cmd/api/run.go (buildAdapters, buildServer, the three workers), cmd/api/workers.go, cmd/mcp/main.go, cmd/a2a/main.go, internal/application/ports/ports.go, internal/adapters/outbound/kafka/encoder.go and internal/architecture/architecture_test.go. The in-memory adapters are not in the diagram because no binary wires them.

Data stores​

One Postgres database that this service alone owns (no shared tables). The three binaries share it; only cmd/api writes. Two embedded migrations (0001_offer_availability_schema, 0002_catalog_packaging_and_listing_owner) create:

TableHolds
catalog_itemsThe CatalogItem aggregate (state, optional gtin with a partial unique index, version)
catalog_item_pack_levelsEvery pack level an item ever declared, retired ones included; one GTIN identifies one level forever; at most one active definition per (item, level)
listingsThe Listing aggregate; unique on (catalog_item_id, node_id, owner_ref); owner_ref '' is operator-owned; no foreign key to catalog_items (aggregates reference each other by id)
inventory_feedsOne row per feed with counters, never the lines; retained 30 days
node_feed_marksPer node, the asOf of the last applied feed; also the row lock that serialises the feeds of a node
node_status_viewLocal copy of node-topology's node status (read model, ADR 0003)
processed_eventsThe consumer inbox, one row per CloudEvents id; retained 30 days
outbox_eventsThe transactional outbox, one row per encoded Kafka message. Nothing purges it: published rows stay (the retention janitor deletes only the three tables above)
idempotency_keysStored answers of keyed writes, 24 hours

Kafka is the fleet's single broker. This service produces to retailnetwork.offer-availability.events, consumes retailnetwork.node-topology.events and dead-letters to retailnetwork.node-topology.events.dlq. It never creates a topic through an admin API: the writers set AllowAutoTopicCreation, and /readyz does not wait for any topic. There is no analytics topic (ADR 0004). Entity-level detail: Entity relationship; layered types: Class diagram.