Skip to main content

Architecture

The module is github.com/claudioed/pick-face-replenishment (Go 1.27.2 per go.mod). It is hexagonal: dependencies point inward, and internal/architecture fails CI when they do not.

Layout​

PathRole
internal/domain/policyReplenishmentPolicy: versioned min/max/multiple value object, RoundDown, the Declaration fact
internal/domain/replenishmentReplenishmentRequest aggregate (Plan, Complete, Cancel, Restore), states, priorities, cancel reasons, domain events
internal/domain/detectionthe pure Detect function and the SourceBinPolicy port (fullest-reserve-bin-v1)
internal/domain/sharedthe ECMA-262 blank-string rule shared by the contract's pattern: '\S'
internal/application/usecasesone type per use case plus the shared Evaluator and the Intake claim-and-apply skeleton
internal/application/ports, repository, outboxout ports, their error and value vocabulary, the outbox message type
internal/adapters/inbound/httpchi router, handlers, RFC 7807 problems, Idempotency-Key middleware, /healthz and /readyz
internal/adapters/inbound/kafkathe consume loop, dead-lettering and the inventory, slotting and layout consumers
internal/adapters/outbound/postgrespgx repositories, unit of work, outbox repository, embedded migration runner
internal/adapters/outbound/eventsmaps domain facts to CloudEvents outbox messages
internal/adapters/outbound/outboxthe relay loop that drains outbox_events
internal/adapters/outbound/kafkathe acks=all Kafka writer used by the relay
internal/adapters/outbound/memoryin-memory test doubles for the unit and BDD suites only; the shipped binary never imports them (ADR 0006)
internal/adapters/kafka/cloudeventsthe single home of the CloudEvents 1.0 envelope (New, Decode)
internal/bootretrystart-up retry with exponential backoff for the first outbound dial
migrations/embedded golang-migrate SQL (0001_replenishment_schema, 0002_forward_assignment_maps)

Binaries​

BinaryRolePorts
cmd/apiComposition root. Serves REST, runs the outbox relay and the three Kafka consumers, all always on, on real Postgres and Kafka (ADR 0006).HTTP :8080 (HTTP_ADDR)
cmd/mcpRead-only MCP server over Streamable HTTP (ADR 0007): list_policies, get_policy, list_pick_faces, list_replenishments, get_replenishment, over the same read use cases as REST. Builds no outbox, unit of work or event sink; never dials Kafka.:8090 (MCP_ADDR), /mcp, /healthz
cmd/pfr-projectorThe only writer of the analytical database (ADR 0008): consumes warehouse.pick-face-replenishment.analytics and folds it into fact tables; dead-letters deterministic poison; exits non-zero if its consumer loop stops.admin :8091 (ADMIN_ADDR): /healthz, /readyz
cmd/pfr-reportsRead-only reports over the analytical database through a read-only pool: GET /reports/replenishment-funnel, GET /reports/freshness.HTTP :8092 (HTTP_ADDR)

web/ is the operator Module Federation remote replenishment_mfe (policies, pick faces, replenishments); it calls only /api/pick-face-replenishment. The three background loops are goroutines of cmd/api, not separate deployables, so one process owns the HTTP server, the relay and the consumers and shuts them down in order (Runbook).

Containers and components​

Source: cmd/api/main.go, cmd/api/adapters.go, cmd/api/consumers.go, cmd/api/relay.go, internal/adapters/inbound/http/server.go.

Wiring​

cmd/api/adapters.go builds the adapters: it runs the embedded migrations (against MIGRATIONS_DATABASE_URL when set), opens a pgx pool and wires the Postgres repositories, the outbox repository and the Idempotency-Key middleware. DATABASE_URL is mandatory (ADR 0006): there is no in-memory mode and the memory package is a test double only. Use cases are built once and shared: the HTTP handlers, the consumers and the sweep all go through the same Evaluator, so they cannot disagree about when a request is raised.

Every write runs in one UnitOfWork: load, apply the aggregate command, save guarded by the loaded version, and hand the raised facts to the outbox in the same transaction. The consumers add the processed_events claim to that transaction.

Data stores​

StoreWhat lives there
PostgreSQLpolicies, replenishment_requests (aggregate state), the local copies bin_stock_levels, forward_assignments, forward_assignment_maps, zones, locations, and the plumbing outbox_events, processed_events, idempotency_keys. Diagram: Entity-relationship.
Kafkathe integration and analytics topics this service writes and the three topics it reads (Runbook)
Memorydevelopment mode only; lost on restart

Fitness tests that guard the layout​

TestHexagonalArchitecture (domain imports only domain, application only domain and application, inbound and outbound adapters do not import each other, only cmd wires layers), TestCloudEventsOnly, TestKafkaConsumerGroupNeverHardcodedInline, TestKafkaWritersSetRequiredAcks, TestOutboxRelaysPassAttemptCap, TestNoAuthMiddlewareReintroduced, TestEventCatalogueMatchesContract. The full list is on Testing.