Skip to main content

Architecture

node-performance 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/scorecardNodeScorecard aggregate (Open, Restore, RecordObservation, Recompute, DueForRecompute), Observation and its constructors, Metrics and Compute, the grading table (GradeFor), the alert table (Thresholds, Breaches), PurchaseOrderFacts, the inbound join (InboundShipment, InboundReceipt, ComputeInbound) and the two domain events. Window (7d, 30d), NodeID.
Domaininternal/domain/sharedEvent interface, Header, ErrValidation, ErrIllegalTransition, ErrInvalidSnapshot, Instant (UTC at microsecond precision), id and text validators.
Applicationinternal/application/usecasesIntake (one method per consumed event type, claim-and-apply in one unit of work), Recompute (the scheduler's use case), Queries (GetScorecard, ListScorecardsByGrade), the shared writer. See Use cases.
Applicationinternal/application/ports, repository, outbox, viewsThe OUT ports (ScorecardRepository, ScorecardReader, PurchaseOrderFactsRepository, ProcessedEvents, EventOutbox, UnitOfWork, Clock, InboundRepository, InboundReader, ScorecardMetrics), the list filter, the outbox Message/Encoder, and the read models the API serves. ports holds only interfaces.
Inbound adapterinternal/adapters/inbound/httpchi router for apis/openapi.yaml: handlers, RFC 9457 problem mapping (problems.go), NUL rejection, /healthz and /readyz (readiness.go). No auth, no write route, no Idempotency-Key.
Inbound adapterinternal/adapters/inbound/kafkaThe six consumers: CloudEvents decode, dispatch on the full type (handlers.go), retry with backoff, dead-letter topic <topic>.dlq, consumer span (tracing.go).
Inbound adapterinternal/adapters/inbound/mcpThe two MCP tools over the read use cases.
Inbound adapterinternal/adapters/inbound/a2aThe two A2A skills and the Agent Card.
Inbound adapterinternal/adapters/inbound/requestlogAccess-log middleware shared by the REST, MCP and A2A routers.
Kafka envelopeinternal/adapters/kafka/cloudeventsThe ONLY place a CloudEvents 1.0 envelope is built or decoded. Repo = "node-performance", Tier = "partner", Context = "node-performance", Source = "/retailnetwork/node-performance".
Outbound adapterinternal/adapters/outbound/postgrespgxpool repositories, reader, relay store, unit of work (pgtx), embedded migrations, trace-header stamping of outbox rows.
Outbound adapterinternal/adapters/outbound/outboxThe relay loop that drains the outbox to a sink, with the attempt cap.
Outbound adapterinternal/adapters/outbound/kafkaEncoder (domain event to CloudEvents outbox message), RelaySink (acks=all, hash balancer on the key, auto topic creation), BrokerCheck (the Kafka half of /readyz).
Outbound adapterinternal/adapters/outbound/telemetryOTel setup, the slog trace-context handler and the ScorecardMetrics counter.
Outbound adapterinternal/adapters/outbound/clockThe system Clock.
Outbound adapterinternal/adapters/outbound/memory, repocontractTest doubles and the repository contract suite; never linked into a binary.
Supportinternal/bootretry, internal/testing/{pgtest,kafkatest}Boot retry; testcontainers helpers.
Composition rootscmd/api, cmd/mcp, cmd/a2aSee below.
Fitness testsinternal/architecturearch-go and source-scanning tests; see Testing.

Binaries and ports​

BinaryRolePortProbes
cmd/apiREST, six Kafka consumers, recompute scheduler and outbox relay in ONE process, all always on, on real Postgres and Kafka. Files: main.go, run.go (boot and shutdown order), config.go, workers.go, telemetry.go.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, Streamable HTTP on /mcp and /; no relay, consumer, scheduler or Kafka (ADR 0007).MCP_ADDR, default :8090GET /healthz
cmd/a2aRead-only A2A agent: JSON-RPC at / and /a2a, Agent Card at /.well-known/agent-card.json; no relay, consumer, scheduler or Kafka (ADR 0011).A2A_ADDR, default :8093GET /healthz

web/ is not a Go binary: the node_performance_mfe Module Federation remote (ADR 0008), served by its own nginx image. How cmd/api boots, what it starts and in which order it stops is in Runtime; every variable is in Configuration.

Container diagram​

Source: cmd/api/run.go (wiring and shutdown order), cmd/api/workers.go (consumers, scheduler and relay), cmd/mcp/main.go and cmd/a2a/main.go (buildDeps), internal/application/ports/ports.go (the OUT ports), internal/adapters/inbound/kafka/handlers.go (NewConsumers) and internal/architecture/architecture_test.go. The MCP and A2A roots reach Postgres through the same postgres.NewReader as the REST adapter, which the diagram shortens to a single arrow. The in-memory adapters are not in the diagram because no binary wires them.

Data stores​

One Postgres database, created by three embedded migrations (internal/adapters/outbound/postgres/migrations/), owned and written by cmd/api; cmd/mcp and cmd/a2a read it:

TableHolds
scorecardsOne row per nodeId:window: state, grade, the six metrics, observations, computed_at, dirty, expires_at, version.
scorecard_observationsThe observations inside the window, keyed by (scorecard_id, source_event_id), with kind, observed_at, late, on_time.
purchase_order_factsLocal copy per purchase order: issued_at, ack_by, required_ship_by, node_id.
inbound_shipments, inbound_receiptsShipped instants and carton counts, joined at read time by shipment_id.
processed_eventsThe inbox: one row per consumed CloudEvents id (event_id, event_type, processed_at).
outbox_eventsThe transactional outbox, with published_at, attempts, last_error, headers (trace context).
idempotency_keysReserved for a future write route; no route uses it.

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 service produces to retailnetwork.node-performance.events and retailnetwork.node-performance.analytics, consumes six topics and writes <topic>.dlq for failed messages. It never creates a topic through an admin API: the broker auto-creates each on first write, and /readyz does not wait for any topic.

Rules enforced by internal/architecture​

Run by make arch-test and the arch-test CI job: the dependency rule (TestHexagonalArchitecture), read-only MCP and A2A adapters with no outbound client, no auth middleware, cmd/** never importing the memory adapter or repocontract, no .go file at the repo root, consumer groups only from environment variables, CloudEvents as the only envelope, Kafka writers always setting RequiredAcks, every relay passing the attempt cap, and the ADR 0004 event catalogue matching apis/asyncapi.yaml. The full table is on Testing.