Skip to main content

Architecture

Process Path Management is a hexagonal (ports and adapters) Go service. The dependency rule points inward only: domain depends on nothing, application depends on domain, adapters depend on application and domain. The rule is enforced by internal/architecture/architecture_test.go (arch-go, make arch-test) and by the fitness tests in internal/architecture/fitness_test.go, not by convention alone (ADR 0021).

Package layout​

PathLayerWhat lives there
internal/domain/processpathDomainProcessPath aggregate: Define, Revise, Deactivate, Rehydrate, its invariant errors
internal/domain/cptscheduleDomainCPTSchedule aggregate and Cutoff value object, CPTScheduleChanged event
internal/domain/processflowDomainProcessFlow aggregate (Define, Revise, Retire, Rehydrate), Stage and the closed ProcessType set, its invariant errors, and the ProcessFlowDefined / ProcessFlowRevised / ProcessFlowRetired events (ADR 0042)
internal/domain/sharedDomainPathId, Capability, SiteId, DestinationLocationRole, Eligibility, the ProcessPath* domain events
internal/application/portsApplicationOutbound ports: ProcessPathRepo, CPTScheduleRepo, ProcessFlowRepo, EventPublisher, UnitOfWork, Clock, PathMetrics, and ErrConcurrentModification / ErrAlreadyExists
internal/application/usecasesApplicationDefinePath, RevisePath, DeactivatePath, GetPath, ListPaths, DefineCPTSchedule, GetCPTSchedule, DefineProcessFlow, RetireProcessFlow, GetProcessFlow, ListProcessFlows (see Use cases)
internal/analytics/reportRead modelCatalogue-growth report shapes and the ReportStore / ProjectionStore ports. Imports nothing else in the module (ADR 0007)
internal/adapters/inbound/httpInbound adapterchi router, DTOs, RFC 7807 mapping, Idempotency-Key middleware, readiness gate, request logger, and the separate reports router
internal/adapters/inbound/mcpInbound adapterMCP server and its read-only tools, plus the REST client for pathmgmt-reports
internal/adapters/inbound/kafkaInbound adapterThe analytics consumer (this service's own analytics topic only) and its dead-letter writer
internal/adapters/outbound/postgresOutbound adapterpgxpool repos, UnitOfWork, OutboxPublisher, OutboxRelay, Sweeper, outbox lag gauge, golang-migrate runner
internal/adapters/outbound/memoryOutbound adapterIn-memory repos, test doubles only (no cmd/** binary imports them)
internal/adapters/outbound/systemOutbound adapterThe wall clock the binaries inject
internal/adapters/outbound/kafkaOutbound adapterIntegration and analytics encoders/publishers, fan-out publisher, W3C trace-context headers, writer settings
internal/adapters/outbound/eventsOutbound adapterLogPublisher, a test double / debugging aid that no binary wires
internal/adapters/outbound/analyticsstoreOutbound adapterAnalytics projection (writer), report reader, consumed-events gate, analytics pools
internal/adapters/outbound/telemetryOutbound adapterOTel trace and metric providers, PathMetrics counter, trace-correlating slog handler
internal/adapters/outbound/bootretryOutbound adapterBounded retry of the first Postgres dial at boot (ADR 0024)
internal/adapters/kafka/cloudeventsShared adapterThe only place a CloudEvents 1.0 envelope is built or decoded (ADR 0016)
internal/pgtxShared adapterTransaction-in-context slot shared by the idempotency middleware and the Postgres unit of work
cmd/*Composition rootsOne main.go per binary. Environment variables are read only here (plus CORS_ALLOWED_ORIGINS and ENVIRONMENT, see Configuration)
migrations/, migrations/analytics/Schemagolang-migrate SQL for the OLTP and analytical databases
web/Frontendprocess_path_mfe, the operator Module Federation remote (ADR 0022)

Binaries​

The binaries are built into one image (Dockerfile, entrypoint ./pathmgmt); the chart picks the binary with command:.

BinaryRolePort (default env)EndpointsHelm workload
cmd/pathmgmtOLTP REST API. Also runs the outbox relay and the housekeeping sweeper in-process when Postgres is configured:8080 (HTTP_ADDR)The 11 operations in apis/openapi.yaml, plus GET /healthz and GET /readyz<release> Deployment (component api), Service port 80 → 8080
cmd/mcpRead-only MCP server over Streamable HTTP:8090 (MCP_ADDR)MCP at /, /mcp and /mcp/; GET /healthz<release>-mcp (only with mcp.enabled=true), Service port 8090
cmd/a2aRead-only A2A agent (skills get_process_path, list_process_paths, get_process_flow, list_process_flows), JSON-RPC over HTTP (ADR 0039):8093 (A2A_ADDR)JSON-RPC at / and /a2a; Agent Card at /.well-known/agent-card.json; GET /healthz<release>-a2a (only with a2a.enabled=true), Service port 8093
cmd/pathmgmt-projectorAnalytics writer: consumes warehouse.process-path-management.analytics into the analytical database. Owns the analytical schema:8091 (ADMIN_ADDR)GET /healthz, GET /readyz only<release>-projector (only with analytics.enabled=true), no Service
cmd/pathmgmt-reportsAnalytics reader: serves the catalogue-growth report over a read-only pool:8092 (HTTP_ADDR)GET /reports/catalogue-growth, GET /reports/catalogue-growth/freshness, GET /healthz<release>-reports (only with analytics.enabled=true), Service port 80 → 8092

The reports routes are specified in their own contract, apis/openapi-reports.yaml (ADR 0031, rendered as the Reports API Reference), and described in the Runbook. The MCP routes are not in any OpenAPI file; see MCP tools.

Component diagram​

Source: cmd/pathmgmt/main.go, cmd/mcp/main.go, cmd/pathmgmt-projector/main.go, cmd/pathmgmt-reports/main.go, internal/adapters/inbound/http/server.go, internal/adapters/outbound/postgres/outbox_publisher.go, internal/adapters/outbound/postgres/outbox_relay.go. Omits: OTel export, the frontend pod and the five sibling consumers of the integration topic.

Delivery modes​

There is one: cmd/pathmgmt runs on real Postgres and real Kafka and has no in-memory, log-publisher or direct-publish path (ADR 0037). DATABASE_URL and KAFKA_BROKERS are mandatory (a missing one stops the boot and names the variable); EVENT_PUBLISHER is accepted only as unset or kafka. buildPersistence and buildEventPublisher in cmd/pathmgmt/main.go therefore always wire:

RepositoriesPublisherOutbox relay / sweeper
PostgresOutboxPublisher: one outbox_events row per topic, in the same transaction as the aggregate writerelay and sweeper always run in-process

The use cases wrap the aggregate write and the publish in one UnitOfWork transaction, so the store and the topics cannot diverge (ADR 0003). GET /readyz is 200 only while Postgres answers a ping and a Kafka broker answers a metadata request.

cmd/mcp requires the same DATABASE_URL but never publishes (it only wires the read use cases).

Data stores​

StoreUsed bySchema ownerTablesPool
OLTP Postgres (DATABASE_URL)pathmgmt, mcpBoth binaries run migrations/ at boot (idempotent)process_paths, cpt_schedules, cpt_schedule_cutoffs, outbox_events, idempotency_keysMaxConns=10, statement_timeout=5s per process (internal/adapters/outbound/postgres/pool.go)
Analytics Postgres (ANALYTICS_DATABASE_URL)pathmgmt-projector (read-write), pathmgmt-reports (read-only)pathmgmt-projector runs migrations/analytics/ at bootcatalogue_growth_rollup, analytics_processed_events, analytics_consumed_eventsprojector MaxConns=5, 10s; reports MaxConns=5, 15s, default_transaction_read_only=on (internal/adapters/outbound/analyticsstore/pool.go)
Kafka (one fleet broker)pathmgmt (producer), pathmgmt-projector (consumer)—Topics: warehouse.process-path-management.events, warehouse.process-path-management.analytics, warehouse.process-path-management.analytics.dlqWriters use the Hash balancer, RequireAll acks, 10 ms batch timeout

The full column-level schema is on Entity relationship.

Request path of a write​

  1. chi middleware: RequestID, otelchi span, http.server.request.duration histogram, RequestLogger, Recoverer, CORS.
  2. POST /process-paths only, and only when Postgres is configured: the Idempotency-Key middleware opens a transaction, records the key and binds the transaction into the request context (ADR 0011).
  3. The handler decodes the DTO and calls the use case.
  4. The use case validates through the aggregate, then runs Create/Save and Publish inside UnitOfWork.Execute. A transaction already in the context (from step 2) is joined, not nested.
  5. OutboxPublisher inserts one row per topic with the request's traceparent/tracestate (ADR 0027).
  6. Commit. The relay picks the rows up on its next pass (1 s idle interval by default) and marks them published after the broker acknowledges.

The Sequence diagrams page has the per-use-case detail.