Skip to main content

Architecture

node-topology 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/nodeNode aggregate with its immutable OperationalProfile revisions, InboundLimits, the type table (typeRules: operators, capabilities, subtypes) and the transition table; events NodeRegistered, NodeOperationalProfileDeclared, NodeActivated, NodeSuspended, NodeRetired.
Domaininternal/domain/laneLane aggregate, the allowed type pairs (allowedPairs), events LaneOpened, LaneClosed.
Domaininternal/domain/serviceareaServiceArea aggregate keyed by PostalPrefix, event ServiceAreaAssigned.
Domaininternal/domain/regionRegion aggregate, event RegionDefined.
Domaininternal/domain/sharedEvent header, the shared errors (ErrValidation, ErrIllegalTransition, ErrInvalidSnapshot), id and text validators.
Applicationinternal/application/usecasesOne use case per operation of apis/openapi.yaml (see Use cases); writer.go holds the shared unit-of-work shape and the one-retry rule on ErrConcurrentUpdate; register_metrics.go records topology.nodes.registered.
Applicationinternal/application/ports, repository, outbox, viewsThe OUT ports (NodeRepository, LaneRepository, ServiceAreaRepository, RegionRepository, EventOutbox, UnitOfWork, Clock, IDGenerator, NodeMetrics), query filters, the already-encoded outbox Message and the read views. ports holds only interfaces.
Inbound adapterinternal/adapters/inbound/httpchi router for apis/openapi.yaml: handlers, RFC 9457 problem mapping (problems.go), the Idempotency-Key middleware, NUL rejection, /healthz and /readyz. No auth middleware.
Inbound adapterinternal/adapters/inbound/mcpSix read-only MCP tools over Streamable HTTP; depends on application and domain only.
Inbound adapterinternal/adapters/inbound/a2aThe A2A JSON-RPC handler, the Agent Card and two read skills; same dependency rule.
Inbound adapterinternal/adapters/inbound/requestlogThe one-line access log with route pattern and trace ids.
Outbound adapterinternal/adapters/outbound/postgrespgxpool repositories (MaxConns 10, statement_timeout 5 s), the unit of work (pgtx), the outbox repository and drain, trace propagation into outbox headers, embedded migrations.
Outbound adapterinternal/adapters/outbound/outboxThe relay loop that drains the outbox to a sink, with the attempt cap.
Outbound adapterinternal/adapters/outbound/kafkaNewWriter (acks=all, hash balancer, AllowAutoTopicCreation), the CloudEvents Encoder, RelaySink and BrokerCheck (the Kafka half of /readyz).
Outbound adapterinternal/adapters/outbound/telemetryOTLP set-up, the topology.nodes.registered counter and the slog trace-context wrapper.
Outbound adapterinternal/adapters/outbound/{clock,ids,memory}The production clock and UUID id generator; memory is an in-memory implementation of every port that serves unit and BDD tests only. The binaries never import it (TestRuntimeBinaryHasNoInMemoryAdapters).
Kafka envelopeinternal/adapters/kafka/cloudeventsThe only place a CloudEvents 1.0 envelope is built: Repo and Context node-topology, Tier logistics, Source /retailnetwork/node-topology, media type application/cloudevents+json; charset=UTF-8.
Supportinternal/bootretryExponential-backoff retry for the first outbound dials at boot (5 attempts, 1, 2, 4, 8 s).
Composition rootscmd/api, cmd/mcp, cmd/a2aEnv parsing, adapters, shutdown order.
Console remoteweb/The node_topology_mfe Module Federation remote (ADR 0009); its own image and no database.
Test supportinternal/testing/{pgtest,kafkatest}, internal/adapters/outbound/repocontractTestcontainers helpers and the repository contract suite run against the memory and Postgres adapters.
Fitness testsinternal/architectureDependency rules and source-scanning sensors; see below.

Binaries and ports​

BinaryRolePortProbes
cmd/apiREST API, boot migrations and the outbox relay in one process, on real Postgres and Kafka.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 at /mcp and /; Postgres only, no relay, no Kafka (ADR 0008).MCP_ADDR, default :8090GET /healthz
cmd/a2aRead-only A2A agent: JSON-RPC at / and /a2a, Agent Card at /.well-known/agent-card.json; Postgres only (ADR 0011).A2A_ADDR, default :8093GET /healthz

How cmd/api boots and in which order it stops is on Runtime and the runbook; every variable is in Configuration.

Container diagram​

Source: cmd/api/run.go (buildAdapters, buildServer, serveUntilSignal), cmd/api/relay.go, cmd/mcp/main.go, cmd/a2a/main.go (buildDeps), internal/adapters/inbound/http/server.go, internal/adapters/outbound/postgres/*, internal/adapters/outbound/outbox/relay.go, internal/architecture/architecture_test.go. cmd/mcp wires only the six read use cases and cmd/a2a only three of them (GetNode, ListNodes, ResolveServiceArea); neither wires a write use case, so neither can append to the outbox.

Data stores​

One Postgres database, owned by the context and migrated by all three binaries on boot (internal/adapters/outbound/postgres/migrations/, ADR 0003):

TableHolds
regionsOne row per region; a unique index on code.
nodesThe Node aggregate row, including the lifecycle timestamps, the vendor reference (unique per vendor and code) and a pointer to the current profile revision.
node_profile_revisionsOne immutable row per node and revision (append-only, enforced by a trigger); the optional inbound JSONB column was added in migration 0003.
lanesThe Lane aggregate; a partial unique index allows one OPEN lane per origin, destination and mode.
service_areasOne row per postal prefix with the current station, region and assignment_version.
outbox_eventsThe transactional outbox: the already-encoded CloudEvent, topic, key, headers, attempts, last_error and published_at.
idempotency_keysStored answers of keyed writes, primary key (route, key), purged after 24 h.

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; the api produces to retailnetwork.node-topology.events and consumes nothing. It never creates a topic through an admin API: the broker creates it on first write (the relay's writer allows auto-creation) and /readyz does not wait for any topic.

Rules enforced by internal/architecture​

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

TestRule
TestHexagonalArchitectureThe domain depends only on the domain; the application only on domain and application; inbound adapters do not depend on outbound adapters and vice versa; nothing under internal/ imports cmd; ports holds only interfaces.
TestMCPAdapterDependencyRule, TestMCPOptionalToolInputsCarryOmitemptyThe MCP adapter depends only on application and domain, nothing depends on it, and optional tool inputs carry omitempty.
TestA2AAdapterDependencyRule, TestA2ASDKIsImportedByTheAdapterAndItsBinaryOnly, TestA2ADepsHoldReadUseCasesOnly, TestNoOutboundA2AClientThe A2A adapter is inward-looking, its Deps hold read use cases only, and no file imports the A2A client: this context is delegated to and never delegates.
TestNoAuthMiddlewareReintroducedNo bearer, JWT or JWX code under internal/adapters/inbound: the surface is unauthenticated fleet-wide.
TestRuntimeBinaryHasNoInMemoryAdapters, TestRuntimeBinaryDoesNotImportTheRepositoryContractNo non-test file under cmd/** imports the memory adapters or the repository contract suite.
TestCloudEventsOnly, TestNoEventEnvelopeToggleOrFlatEnvelopeCloudEvents 1.0 is the only envelope.
TestKafkaWritersSetRequiredAcks, TestKafkaWriterTopicNotSetTwiceEvery kafka-go Writer sets RequiredAcks, and no writer sets a topic when messages carry one.
TestOutboxRelaysPassAttemptCapEvery relay is built with WithMaxAttempts.
TestEventCatalogueMatchesContractEvery CloudEvents type that apis/asyncapi.yaml declares appears in the CloudEvents ADR (ADR 0004).
TestKafkaIntegrationTestsUseTestcontainers, TestPostgresIntegrationTestsUseTestcontainersIntegration tests boot their own broker or database.
TestNoGoFilesAtRepoRootThe module root holds no Go file.

Commands and the full list are on Testing.