Skip to main content

Architecture — hexagonal layering and runtime view

The repository is organised strictly as ports & adapters. The dependency rule is non-negotiable and executable — it is asserted by architecture fitness tests in CI, not just documented (ADR-0007).

domain depends on nothing · application depends on domain · adapters depend on application and domain · only cmd/ wires everything

Source: internal/architecture/architecture_test.go (the enforced rule) and the package tree under internal/.

Runtime view: binaries, ports and data stores​

The layers above are compiled into five binaries (all in one image, see Dockerfile), each its own composition root under cmd/:

BinaryRoleListens onInbound adaptersOutbound adapters / stores
cmd/westhe OLTP service: every REST endpoint, all Kafka consumers, the outbox relay and the housekeeperHTTP_ADDR :8080 — REST, /healthz, /readyzinbound/http, inbound/kafka (integration consumer on 5 topics, ProductClassified consumer, pack-level consumer), outbound/kafkacatalog (catalogue replay)OLTP Postgres (or memory), Kafka publishers + relay, file catalogue
cmd/mcpMCP server over the same use cases (ADR-0008)MCP_ADDR :8090 — MCP at / and /mcp, /healthzinbound/mcpthe same OLTP Postgres (read/write, no migrations), Kafka publishers or outbox rows, reports REST client
cmd/a2aA2A agent over the same use cases (ADR-0046)A2A_ADDR :8093 — Agent Card at /.well-known/agent-card.json, JSON-RPC at / and /a2a, /healthzinbound/a2athe same OLTP Postgres (no migrations), Kafka publishers or outbox rows
cmd/wes-projectoranalytics writer (ADR-0011)ADMIN_ADDR :8091 — /healthz onlyanalytics consumer on warehouse.wes.analyticsanalytical Postgres (owns and migrates it)
cmd/wes-reportsanalytics readerHTTP_ADDR :8092 — /reports/throughput, /reports/throughput/freshness, /healthzinbound/http reports routeranalytical Postgres, read-only pool

Source: cmd/wes/serving.go, cmd/wes/publisher.go, cmd/mcp/main.go, cmd/wes-projector/main.go, cmd/wes-reports/main.go, charts/wes-work-planning/values.yaml. Since ADR-0049 cmd/wes makes no outbound REST call (the facility-layout travel-distance lookup is gone).

Data stores.

  • OLTP Postgres (DATABASE_URL, migrated by cmd/wes from migrations/): work_pools (+ version), work_pool_entries, work_units, processed_events, labor_plan_view, usable_inventory_view, outbox_events, idempotency_keys, product_classification_copy (and an unused events table from 0001_init, plus charge_forecasts and shift_plans, kept but no longer written since ADR-0049). DATABASE_URL is mandatory for both cmd/wes and cmd/mcp (ADR-0044); they share this one database.
  • Analytical Postgres (ANALYTICS_DATABASE_URL, a separate database migrated by the projector from migrations/analytics/): analytics_processed_events, analytics_consumed_events, throughput_rollup, plus schema_migrations_analytics.
  • Kafka: publishes warehouse.work-planning.events and warehouse.wes.analytics; consumes the topics listed on Integration events.

Deployment, ports and probes: Runbook; every variable: Configuration.

Package map​

cmd/wes/ OLTP composition root — the only place every layer meets
cmd/wes-projector/ analytics writer (ADR-0011)
cmd/wes-reports/ analytics read-only reports API (ADR-0011)
cmd/mcp/ MCP server (ADR-0008)
internal/
domain/ pure Go: aggregates, value objects, events, errors
release/ WorkPool aggregate + ReleasePolicy domain service
workunit/ WorkUnit aggregate
shared/ CPT, PathId, Quantity, DomainEvent
laborview/ LaborPlanObserved read-model value
inventoryview/ UsableInventoryObserved read-model value
pathcatalog/ process-path catalogue + prefix lookup (ADR-0012)
productclassificationview/ SKU classification read-model value (ADR-0009, ADR-0035)
analytics/report/ analytics report model (ADR-0011)
application/
ports/ driven-port interfaces (repos, publisher, clock)
usecases/ one struct per use case
adapters/
inbound/http/ chi router, DTOs, domain-error → HTTP mapping
inbound/kafka/ integration-event consumer (5 topics), ProductClassified consumer (ADR-0035), pack-level consumer (ADR-0045) + analytics consumer
inbound/mcp/ MCP tools, resources, prompts (ADR-0008)
outbound/postgres/ pgxpool repositories, UnitOfWork, outbox + relay (ADR-0014)
outbound/memory/ thread-safe in-memory repositories (test doubles only)
outbound/events/ log EventPublisher + MultiPublisher (test doubles only)
outbound/system/ production wall clock (ports.Clock)
outbound/kafka/ integration + analytics publishers, outbox encoders, RelaySink
outbound/filecatalog/ process-path catalogue from YAML (PATH_CATALOGUE_SOURCE=file)
outbound/kafkacatalog/ process-path catalogue from Kafka (PATH_CATALOGUE_SOURCE=kafka)
outbound/productclassificationcopy/ local copy of product-master's classification (ADR-0035)
outbound/analyticsstore/ analytics Postgres store
outbound/telemetry/ OpenTelemetry setup
kafka/cloudevents/ CloudEvents 1.0 envelope helpers (New/Decode), topics, consumed types
architecture/ arch-go fitness tests
migrations/ golang-migrate SQL files (analytics/ for the projector)
apis/ openapi.yaml + asyncapi.yaml (the published contracts)
features/ godog (Gherkin) acceptance specs

The driven ports​

Every outbound dependency is an interface owned by the application layer, so the domain never learns that Postgres or Kafka exist:

PortPurpose
WorkPoolRepopersist/retrieve WorkPool, one per path
WorkUnitRepopersist/retrieve WorkUnit by id and by path
EventPublisherpublish domain events (the Kafka outbox encoders in production; a log/multi publisher in unit tests only)
Clockabstract "now" so use cases and tests are deterministic
LaborPlanViewRepopersist the LaborPlanObserved projection, one per path
InventoryViewRepoatomically apply a delta to UsableInventoryObserved, keyed by SKU
ProcessedEventReporecord consumed CloudEvents ids so redelivery is a no-op
ProcessedEventReleaseroptional: undo a non-transactional (in-memory test double) mark when the effect fails (ADR-0028)
UnitOfWorkrun a use case's save + publish in one Postgres transaction (ADR-0014)
ReleaseMetricsrecord the wes.work_units.released business counter (ADR-0013)
PathCataloguelook up a pathId in the declared process-path catalogue (ADR-0012)
ProductClassificationLookupread a SKU's classification from the local copy of product-master's events (ADR-0009, ADR-0035)
ProductClassificationCopyRepoapply a ProductClassified to that copy, version-guarded (ADR-0035)

The composition root wires Postgres (DATABASE_URL) and Kafka (KAFKA_BROKERS) unconditionally (ADR-0044); the only choice left in environment variables is file vs Kafka catalogue (PATH_CATALOGUE_SOURCE). The ChargeRepo, PlanRepo and TravelDistanceLookup ports went with the charge forecast, the shift plan and the facility-layout lookup (ADR-0049).

Why this shape​

The reason is not tidiness — it is that the interesting rules of this domain (priority by CPT, at-most-once handout, WIP limits, no double completion) are decisions, and decisions belong somewhere with no infrastructure in it, so they can be exercised exhaustively and cheaply. The domain and application packages carry the bulk of the test suite precisely because they have no I/O to mock. See ADR-0001.