Skip to main content

Architecture

network-fulfillment is a hexagonal (ports and adapters) Go service. One repository builds four binaries into one image; a Helm chart deploys them plus the web/ remote. Everything below is read from cmd/, internal/ and charts/network-fulfillment on develop.

Binaries​

BinaryRoleListens onReads / writesDeployment (chart)
cmd/netfulfilOLTP service: REST API, inbound poller, background tickers (sweep, overdue rejection, orphaned-hold sweep, reconciliation, recompute), outbox relay, capability-offer pipeline:8080 (PORT); Service 80 -> 8080OLTP Postgres (DATABASE_URL, required), Kafka (KAFKA_BROKERS, required), order-management, inventory-storagenetwork-fulfillment
cmd/mcpread-only MCP server, Streamable HTTP at / and /mcp, GET /healthz:8090 (MCP_ADDR)the same OLTP Postgres, read only; netfulfil-reports over RESTnetwork-fulfillment-mcp (mcp.enabled)
cmd/netfulfil-projectoranalytics writer: consumes warehouse.network-fulfillment.analytics into the analytical database, DLQ on failure:8091 (ADMIN_ADDR), GET /healthz onlyanalytical Postgres (ANALYTICS_DATABASE_URL), Kafkanetwork-fulfillment-projector (analytics.enabled)
cmd/netfulfil-reportsanalytics reader: GET /reports/acknowledgement, .../freshness:8092 (HTTP_ADDR); Service 80 -> 8092analytical Postgres, read-only poolnetwork-fulfillment-reports (analytics.enabled)
web/ (nginx)Module Federation remote for warehouse-console (ADR 0010)8080the REST API through Kongnetwork-fulfillment-frontend (frontend.enabled)

The image's entrypoint is ./netfulfil; the chart starts the other three with an explicit command. Probes, replicas and HPA are in the runbook; every env var is in configuration.

Containers​

Source: cmd/netfulfil/main.go, cmd/netfulfil/capability.go, cmd/netfulfil/publishing.go, cmd/mcp/main.go, cmd/netfulfil-projector/main.go, cmd/netfulfil-reports/main.go, migrations/, migrations/analytics/, charts/network-fulfillment/templates/. Both runtime dependencies are mandatory (ADR 0025). The gateway sits inside the netfulfil process because only the stub exists.

Hexagonal layout​

internal/
domain/ pure model, no I/O
networkorder/ NetworkOrder aggregate and its lifecycle
capabilityoffer/ CapabilityOffer aggregate (advertised quantity)
shared/ value types (NetworkRef, SKU, SiteId, ...) and domain events
application/
contract/ plain data crossing the ports (InboundDemand, HeldOrderRequest, NextCutoff, ...)
ports/ OUT ports, interfaces only
usecases/ the thirteen application services
adapters/
inbound/http/ REST routes, RFC 7807 errors, readiness, reports router
inbound/poller/ the inbound leg: polls the gateway, feeds ReceiveNetworkDemand
inbound/mcp/ MCP tools, resource, prompt
inbound/kafka/ analytics consumer (own topic), ShipmentConfirmed consumer (outbound-shipping), receipt consumer (inbound-receiving, live mode) + DLQ
kafka/cloudevents/ the CloudEvents 1.0 envelope, shared by every publisher and consumer
outbound/retailnetwork/ NETWORK_MODE switch, stub gateway, seed file, live Vendor API gateway (ADR 0026)
outbound/ordermanagement/ held-order REST client + circuit breaker
outbound/inventoryclient/ usable-quantity REST client
outbound/processpathcache/ Kafka cache: path cycle times + CPT schedule
outbound/pathcapacitycache/ Kafka cache: remaining path capacity
outbound/kafka/ integration + analytics publishers
outbound/eventwire/ JSON wire shape of each domain event
outbound/postgres/ repositories, outbox publisher and relay, unit of work, migrations runner
outbound/memory/ in-memory repositories (test doubles for unit and BDD tests only)
outbound/producttranslation/ product translation file dictionary
outbound/system/ system clock
outbound/analyticsstore/ analytical projection and report store
outbound/telemetry/ OTLP setup, circuit-breaker gauge
analytics/report/ report catalogue and ports for the reports binary
resilience/ breaker settings, call timeout
architecture/ fitness tests that enforce all of the above

Rules enforced by internal/architecture (run with make arch-test): the domain imports nothing from application or adapters; application imports no adapter; ports holds interfaces only; domain events carry no struct tags (their JSON lives in eventwire); the CloudEvents type service segment equals the module name. See testing.

Ports and their adapters​

Port (internal/application/ports)AdaptersChosen by
NetworkOrderRepopostgres.NetworkOrderRepo (memory is a test double)always
CapabilityOfferRepopostgres.CapabilityOfferRepoalways
NetworkGatewayretailnetwork.StubGateway (default) or retailnetwork.LiveGateway (demand loop, ADR 0026)NETWORK_MODE
FulfillmentPlannerordermanagement.BreakerClient wrapping Planneralways
ProductTranslationproducttranslation dictionary loaded from PRODUCT_TRANSLATION_FILEalways (empty without the file)
ProcessPathCapabilityprocesspathcache.Consumeralways
PathCapacitypathcapacitycache.Consumersame
InventoryAvailabilityinventoryclient.Clientsame
EventPublisherpostgres.OutboxPublisheralways
UnitOfWorkpostgres.UnitOfWorkalways (a real transaction, which also holds the outbox rows)
Clocksystem clock (UTC)always

Data stores​

OLTP Postgres (DATABASE_URL, required), migrations migrations/0001 to 0005, applied by netfulfil and by mcp at startup:

TableHolds
network_ordersone row per NetworkOrder (ref, site, deadlines, state, local order id, hold outcome and its settle time)
network_order_linesits lines, both vocabularies
outbox_eventsCloudEvent bytes waiting for (or already sent by) the relay
capability_offerslatest offer per (sku, site_id)

Analytical Postgres (ANALYTICS_DATABASE_URL, required by projector and reports), migrations migrations/analytics/0001 and 0002, applied by the projector:

TableHolds
acknowledgement_rollupper-day counters behind the acknowledgement report
analytics_processed_eventsevent ids the projection has applied, with each event's business time (the source of the freshness lag)
analytics_consumed_eventsthe consumer's own dedupe set, written in the same transaction as the projection write (ADR 0023)

Column-level ER diagrams: ddd/entity-relationship.md.

Kafka (one fleet broker): produces warehouse.network-fulfillment.events and warehouse.network-fulfillment.analytics, the projector produces warehouse.network-fulfillment.analytics.dlq, and netfulfil consumes warehouse.process-path-management.events, warehouse.work-planning.events and warehouse.outbound-shipping.events in every mode, plus warehouse.inbound-receiving.events in live mode. Topics and group ids: runbook.

Request and event flows​

  • Demand: poller -> ReceiveNetworkDemand -> order-management held order -> answer to the network. Settlement by ReconcileSubmittedOrders.
  • Shipment: a ShipmentConfirmed event from outbound-shipping (primary), or POST /network-orders/{networkRef}/shipment-confirmation (operator fallback) -> ConfirmNetworkOrderShipment.
  • Events: use case -> outbox_events (same transaction) -> relay -> both topics -> projector -> analytical tables -> reports API -> MCP report tool.

Per-use-case detail: ddd/use-cases.md and ddd/sequence-diagrams.md. Edges to other contexts: ecosystem/integration.md.

Telemetry​

Only netfulfil calls telemetry.Setup: OTLP/gRPC traces and metrics to OTEL_EXPORTER_OTLP_ENDPOINT (ADR 0019), plus the Prometheus circuit_breaker_state gauge on GET /metrics. The other three binaries log JSON and export nothing. See observability.