Skip to main content

Architecture

product-content follows the fleet's hexagonal (ports and adapters) layout: dependencies point inward, the domain imports only itself and the standard library, and only cmd/ wires the layers together. Everything on this page is on develop.

Layout​

LayerPathRole
Domaininternal/domain/contentThe ProductContent aggregate: Body (description, bullets, attributes, media, primary category), State (DRAFT, PUBLISHED, RETIRED), RetiredReason (MANUAL, DISCARDED, DISCONTINUED), Create, ReviseDraft, ReviseContent, Publish, Retire, DiscardDraft, RetireOnDiscontinue, the events ProductContentPublished and ProductContentRetired, and the domain errors.
Domaininternal/domain/categoryThe Tree aggregate (CategoryTree): CreateCategory, MoveCategory, RenameCategory, PublishCategoryTree, the event CategoryTreePublished. Implements content.Categories (Has).
Domaininternal/domain/sharedEvent, Header, ErrValidation, ErrIllegalTransition, id and text validation helpers.
Applicationinternal/application/usecasesOne struct per use case (see Use cases), Consumer (the consumed events), Deps, the transact retry wrapper.
Applicationinternal/application/portsThe OUT ports: ContentRepository, TreeRepository, CatalogItemRepository, Inbox, EventOutbox, UnitOfWork, IdempotencyStore, Clock, IDGenerator, ContentMetrics. Interfaces only.
Applicationinternal/application/readmodel, views, idempotency, outboxThe CatalogItem read model, the response views, the idempotency record, the already-encoded outbox Message.
Inbound adapterinternal/adapters/inbound/httpchi router for apis/openapi.yaml: handlers, RFC 9457 problem mapping (errors.go), the Idempotency-Key middleware, NUL rejection, /healthz and /readyz. No auth middleware.
Inbound adapterinternal/adapters/inbound/kafkaThe offer-availability consumer: CloudEvents decode, dispatch on the full type, retry with backoff, dead-letter topic. Decode only, every effect is a use case.
Inbound adapterinternal/adapters/inbound/mcpThe read-only MCP server: two L1 tools, one resource, one prompt, stateless Streamable HTTP handler (ADR 0008, MCP tools).
Inbound adapterinternal/adapters/inbound/a2aThe read-only A2A agent: Agent Card, two skills, JSON-RPC handler (ADR 0006).
Inbound adapterinternal/adapters/inbound/requestlogThe request-log middleware that carries trace_id and span_id.
Outbound adapterinternal/adapters/outbound/postgrespgxpool repositories, unit of work (pgtx), outbox and idempotency stores, inbox, embedded migrations (migrations/0001_product_content_schema.*.sql).
Outbound adapterinternal/adapters/outbound/kafkaEncoder (domain event to CloudEvents outbox message, topic retailnetwork.product-content.events), Sink, NewWriter, BrokerCheck (the Kafka half of /readyz).
Outbound adapterinternal/adapters/outbound/outboxThe relay loop that drains outbox_events to the sink.
Outbound adapterinternal/adapters/outbound/telemetryOTel setup, the content.products.published counter, the slog handler that adds trace ids.
Outbound adapterinternal/adapters/outbound/clock, idsThe production Clock and category id generator.
Outbound adapterinternal/adapters/outbound/memory, repocontractIn-memory port implementations, a test double for the unit and BDD suites, and the repository contract suite run against memory and Postgres. The shipped binaries never import memory (TestRuntimeBinaryHasNoInMemoryAdapters).
Kafka envelopeinternal/adapters/kafka/cloudeventsThe only place a CloudEvents 1.0 envelope is built or decoded: New, Decode, Type, DataSchema, ContentTypeHeader. Constants Tier = "storefront", Context = "product-content", Source = "/retailnetwork/product-content".
Supportinternal/bootretryExponential-backoff retry for the first outbound dials at boot.
Test supportinternal/testing/{kafkatest,pgtest}, internal/bddtestcontainers helpers and the godog wiring for features/.
Fitness testsinternal/architecturearch-go and source-scanning tests, listed below.

The domain asks the rest of the context two questions and gets plain values back: content.ItemStatus (ItemUnknown, ItemActive, ItemDiscontinued), read by the use case from CatalogItemView, and content.Categories (Has(categoryID)), implemented by the category tree. That is why the content package never imports the category package.

Binaries and ports​

BinaryRolePortProbes
cmd/apiREST API, the transactional outbox relay and the offer-availability consumer in one process, all always on, on real Postgres and real Kafka.HTTP_ADDR, default :8080GET /healthz (liveness), GET /readyz (drain gate, Postgres ping, a Kafka broker answers a topic-less metadata request)
cmd/mcpRead-only MCP server over GetProductContent and ListCategories: Streamable HTTP at /mcp and /, stateless, two tools, one resource, one prompt. No Kafka, no relay, no consumer, no write.MCP_ADDR, default :8090GET /healthz for liveness and readiness
cmd/a2aRead-only A2A server over GetProductContent and ListCategories: JSON-RPC 2.0 at / and /a2a, Agent Card at /.well-known/agent-card.json. No Kafka, no relay, no consumer, no write.A2A_ADDR, default :8093GET /healthz for liveness and readiness

How cmd/api boots, what it starts and in which order it stops is in the Runbook; every variable is in Configuration.

Container and component diagram​

Source: cmd/api/main.go (buildAdapters, buildServer, startConsumers, startOutboxRelay), cmd/a2a/main.go (readDeps), cmd/mcp/main.go (buildDeps), internal/application/ports/ports.go (the OUT ports), internal/adapters/outbound/kafka/encoder.go and internal/architecture/architecture_test.go. The in-memory adapters are not in the diagram because the binaries do not wire them.

Data stores​

One Postgres database, created by the single embedded migration internal/adapters/outbound/postgres/migrations/0001_product_content_schema.up.sql:

TableHolds
product_contentsOne row per catalogue item: state, retired reason, description, bullets, attributes and media as jsonb, primary category, revision, published_revision, timestamps and the version that guards every update.
category_treesThe one tree, stored whole as jsonb under tree_id = main, with its version.
catalog_item_viewThe event-fed local item copy: catalog_item_id, state (ACTIVE or DISCONTINUED).
processed_eventsThe inbox: one row per consumed CloudEvents id, so each event is applied once.
idempotency_keysStored answers per (route, key); records older than 24 h are treated as absent.
outbox_eventsThe transactional outbox: encoded CloudEvents bytes, topic, key, headers, attempts, last_error, published_at.

Postgres is the only store: the service refuses to boot without DATABASE_URL and nothing is served from process memory. Kafka is the fleet's single broker. cmd/api produces to retailnetwork.product-content.events and consumes retailnetwork.offer-availability.events; poison messages go to <topic>.dlq. It never calls a Kafka admin API: the relay's writer sets AllowAutoTopicCreation, and /readyz does not wait for any topic. See the Entity relationship page for the columns.

Rules enforced by internal/architecture​

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

TestRule
TestHexagonalArchitecture**.internal.domain.** depends only on domain, **.internal.application.** only on domain and application, inbound adapters do not depend on outbound adapters and vice versa, nothing under internal/ imports cmd, internal/application/ports holds only interfaces.
TestMCPAdapterDependencyRule, TestMCPOptionalToolInputsCarryOmitemptyThe MCP adapter depends only on application and domain (so it imports no inbound/http), nothing but cmd/mcp depends on it, and every optional tool input carries omitempty so the SDK publishes it as optional.
TestEveryMCPToolDeclaresAuthority, TestMCPWriteToolsAreAtLeastL3, TestA2ASkillsDeclareAuthority, TestMCPServerOffersResourceAndPromptAgentic Standard v2 (static go/ast sensors): every MCP tool and A2A skill declares exactly one authority level, a tool that is not provably read-only is L3 or above, and the MCP server offers at least one resource and one prompt.
TestA2AAdapterDependencyRule, TestA2AAgentIsReadOnlyWithNoOutboundClientThe A2A adapter depends only on application and domain, nothing depends on it, it reaches only the two read use cases and imports no A2A client: this context is delegated to, it never delegates.
TestNoAuthMiddlewareReintroducedNo bearer-token or JWT library in non-comment source under internal/adapters/inbound: REST is unauthenticated fleet-wide.
TestKafkaConsumerGroupNeverHardcodedInlineNo literal GroupID: the group comes from OFFER_AVAILABILITY_CONSUMER_GROUP.
TestRuntimeBinaryHasNoInMemoryAdapters, TestRuntimeBinarySensorBitesNo non-test file under cmd/** imports internal/adapters/outbound/memory.
TestNoEventEnvelopeToggleOrFlatEnvelope, TestCloudEventsOnlyCloudEvents 1.0 is the only envelope.
TestKafkaWritersSetRequiredAcks, TestKafkaWriterTopicNotSetTwiceEvery kafka-go Writer sets RequiredAcks, and a package that sets Message.Topic leaves Writer.Topic unset.
TestReplayConsumersSetCommitIntervalA reader with a process-unique group id sets CommitInterval.
TestDeadLetterCallsGuardCancellationEvery function that sends to a dead-letter topic checks cancellation, so shutdown never dead-letters a mid-flight message.
TestOutboxRelaysPassAttemptCapEvery relay is built with WithMaxAttempts(...).
TestEventCatalogueMatchesContractEvery full CloudEvents type in apis/asyncapi.yaml appears in ADR 0004.
TestKafkaIntegrationTestsUseTestcontainers, TestPostgresIntegrationTestsUseTestcontainersIntegration tests boot their own broker or database.
TestNoGoFilesAtRepoRootNo Go file at the repository root.

Details and commands are on Testing.