Skip to main content

Architecture

network-inventory-planning (NIP) is one Go module (github.com/claudioed/network-inventory-planning) built into four binaries that share one container image, plus an optional console remote (web/, the nip_mfe Module Federation remote of ADR 0010). Everything below is read from cmd/*/main.go, the Dockerfile and charts/network-inventory-planning.

Hexagonal layout​

LayerPackageWhat lives there
Domaininternal/domain/transferThe InterWarehouseTransfer saga aggregate (12 states), the deterministic Planner, ValidateApproval, the stuck-transfer check and the domain events (TransferPlanApproved, TransferAllocationRequested, WorkDemandReleased, the three saga-health occurrences).
Domaininternal/domain/planningThe three local facts (SiteCapability, SiteSkuDemand, PublishedCapacityPlan) and the fail-closed BuildSnapshot.
Domain-like read modelinternal/analytics/reportPure report rules for the analytics read side: half-open ranges, percentiles, rejection rates, freshness.
Applicationinternal/application/usecases, internal/application/portsOne use case per trigger (see Use cases); ports for repositories, the query side, the unit of work and the event publisher.
Inbound adaptersinternal/adapters/inbound/httpREST handler (Handler.Routes) and the reports handler (ReportsServer.Routes).
Inbound adaptersinternal/adapters/inbound/kafkaSeven consumers: three read-model consumers, the inventory reply consumer, the fulfillment fact consumer, the product-master pack-level consumer and the analytics projector consumer.
Inbound adaptersinternal/adapters/inbound/mcpThe read-only MCP server (four tools).
Inbound adaptersinternal/adapters/inbound/a2aThe read-only A2A agent (two skills, ADR 0020).
Outbound adaptersinternal/adapters/outbound/postgrespgx repositories, the unit of work, the transactional outbox writer and relay, golang-migrate runner and the OLTP migrations.
Outbound adaptersinternal/adapters/outbound/kafkaThe CloudEvents encoders (integration and analytics) and the relay sink.
Outbound adaptersinternal/adapters/outbound/analyticsstoreThe analytical database projection (writer) and report reader.
Outbound adaptersinternal/adapters/outbound/telemetryOTLP/gRPC trace + metric export (ADR 0012).
Sharedinternal/adapters/kafka/cloudeventsThe single CloudEvents 1.0 envelope (structured mode).
Sharedinternal/bootretryStartup retry used by the two analytics binaries.

internal/architecture holds the fitness tests that pin these dependency rules (see Testing).

Binaries​

Binary (cmd/)RoleListens onDeployment (chart component)Talks to
network-inventory-planningREST API, the five OLTP Kafka consumers, the outbox relay, the saga-health ticker and the scheduled-rebalance tickerHTTP_ADDR, default :8080api (Service port 80 → 8080), image entrypointOLTP Postgres, Kafka, OTel Collector
mcpRead-only MCP server, Streamable HTTP only, served at / and /mcp plus GET /healthzMCP_ADDR, default :8090mcp (Service port 8090), disabled by defaultOLTP Postgres (read; it also applies migrations)
a2aRead-only A2A agent (JSON-RPC over HTTP), Agent Card at /.well-known/agent-card.json, served at / and /a2a plus GET /healthzA2A_ADDR, default :8093a2a (Service port 8093), disabled by defaultOLTP Postgres (read; it also applies migrations)
nip-projectorThe only writer of the analytical database: consumes warehouse.network-inventory-planning.analytics and projects itadmin ADMIN_ADDR, default :8091 (/healthz, /readyz)analytics-projector, disabled by defaultKafka, analytical Postgres
nip-reportsRead-only reports over the analytical database (GET /reports/...)HTTP_ADDR, default :8092analytics-reports (Service port 80 → 8092), disabled by defaultanalytical Postgres (read-only pool)

The image (Dockerfile) builds all five into /app, copies the OLTP migrations to /app/migrations (and sets MIGRATIONS_PATH=migrations) and the analytical migrations to /app/analytics/migrations; it exposes 8080 8090 8091 8092 8093 and its entrypoint is ./network-inventory-planning. The chart's other Deployments override the command with /app/mcp, /app/a2a, /app/nip-projector and /app/nip-reports.

The console remote is a separate image (warehouse/network-inventory-planning-frontend, built from web/Dockerfile), deployed by the chart's optional frontend component (ClusterIP, port 80 → 8080) and routed by the warehouse-infra Nginx gateway under /mfes/network-inventory-planning/.

Container diagram​

Source: cmd/network-inventory-planning/main.go, cmd/mcp/main.go, cmd/nip-projector/main.go, cmd/nip-reports/main.go, charts/network-inventory-planning/values.yaml

Component view of the API binary​

Source: cmd/network-inventory-planning/main.go (wire, wireSagas, wireOutbox, startConsumers, wireHealthTicker, wireRebalanceTicker)

Startup modes of the API binary​

wire in cmd/network-inventory-planning/main.go decides what exists:

ConfigurationWhat runs
DATABASE_URL unsetOnly GET /healthz and POST /v1/transfer-proposal-runs work. Every other route answers a 503 problem (read-models-unavailable, saga-unavailable, rebalance-runs-unavailable, read-side-unavailable, catalogue-unavailable). No migrations, no consumers.
DATABASE_URL setMigrations run (refuse to boot on failure), the pool is pinged, simulation and the read side are wired.
+ KAFKA_BROKERSThe outbox writer exists, so POST /v1/transfer-approvals is wired; each consumer whose *_CONSUMER_GROUP is set starts; the saga-health ticker starts (default every 5 m).
+ OUTBOX_RELAY_ENABLED non-emptyThe relay drains outbox_events onto Kafka. Without it the rows wait.
+ TRANSFER_PICK_PATH_ID and a valid pick CPT offsetApproval is accepted; otherwise it answers 503 config-incomplete.
+ NIP_REBALANCE_SCHEDULEThe observe-only rebalance ticker starts.

Data stores​

StoreOwner binaryTablesMigrations
OLTP Postgres (DATABASE_URL)network-inventory-planning (writes), mcp (reads)processed_events, site_capability, site_sku_demand, published_capacity_plan, inter_warehouse_transfer, transfer_audit, outbox_events, rebalance_runs, rebalance_policies, transfer_lanes, pack_levels, idempotency_keysinternal/adapters/outbound/postgres/migrations/0001–0009, applied at startup by both network-inventory-planning and mcp (golang-migrate's advisory lock serialises concurrent starts)
Analytical Postgres (ANALYTICS_DATABASE_URL)nip-projector (only writer), nip-reports (read-only pool, default_transaction_read_only=on)analytics_processed_events, transfer_state_advances, transfer_stuck_detections, rebalance_run_factsanalytics/migrations/0001_saga_facts, applied at startup by nip-projector only

The entity-relationship view is on Entity relationship.

Connection pools: OLTP MaxConns = 10 with statement_timeout = 5s (internal/adapters/outbound/postgres/pool.go); analytical writer and reader MaxConns = 5 each (internal/adapters/outbound/analyticsstore/pool.go).

Integration style​

  • All cross-context traffic is Kafka with CloudEvents 1.0 in structured mode (content-type: application/cloudevents+json; charset=UTF-8). NIP makes no synchronous call to any sibling context.
  • Everything NIP publishes goes through the transactional outbox (outbox_events), drained one row at a time in id order.
  • REST and MCP are unauthenticated; the fitness test TestNoAuthMiddlewareReintroduced keeps it that way.

See Integration for every topic and type.