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
| Path | Layer | What lives there |
|---|---|---|
internal/domain/processpath | Domain | ProcessPath aggregate: Define, Revise, Deactivate, Rehydrate, its invariant errors |
internal/domain/cptschedule | Domain | CPTSchedule aggregate and Cutoff value object, CPTScheduleChanged event |
internal/domain/processflow | Domain | ProcessFlow aggregate (Define, Revise, Retire, Rehydrate), Stage and the closed ProcessType set, its invariant errors, and the ProcessFlowDefined / ProcessFlowRevised / ProcessFlowRetired events (ADR 0042) |
internal/domain/shared | Domain | PathId, Capability, SiteId, DestinationLocationRole, Eligibility, the ProcessPath* domain events |
internal/application/ports | Application | Outbound ports: ProcessPathRepo, CPTScheduleRepo, ProcessFlowRepo, EventPublisher, UnitOfWork, Clock, PathMetrics, and ErrConcurrentModification / ErrAlreadyExists |
internal/application/usecases | Application | DefinePath, RevisePath, DeactivatePath, GetPath, ListPaths, DefineCPTSchedule, GetCPTSchedule, DefineProcessFlow, RetireProcessFlow, GetProcessFlow, ListProcessFlows (see Use cases) |
internal/analytics/report | Read model | Catalogue-growth report shapes and the ReportStore / ProjectionStore ports. Imports nothing else in the module (ADR 0007) |
internal/adapters/inbound/http | Inbound adapter | chi router, DTOs, RFC 7807 mapping, Idempotency-Key middleware, readiness gate, request logger, and the separate reports router |
internal/adapters/inbound/mcp | Inbound adapter | MCP server and its read-only tools, plus the REST client for pathmgmt-reports |
internal/adapters/inbound/kafka | Inbound adapter | The analytics consumer (this service's own analytics topic only) and its dead-letter writer |
internal/adapters/outbound/postgres | Outbound adapter | pgxpool repos, UnitOfWork, OutboxPublisher, OutboxRelay, Sweeper, outbox lag gauge, golang-migrate runner |
internal/adapters/outbound/memory | Outbound adapter | In-memory repos, test doubles only (no cmd/** binary imports them) |
internal/adapters/outbound/system | Outbound adapter | The wall clock the binaries inject |
internal/adapters/outbound/kafka | Outbound adapter | Integration and analytics encoders/publishers, fan-out publisher, W3C trace-context headers, writer settings |
internal/adapters/outbound/events | Outbound adapter | LogPublisher, a test double / debugging aid that no binary wires |
internal/adapters/outbound/analyticsstore | Outbound adapter | Analytics projection (writer), report reader, consumed-events gate, analytics pools |
internal/adapters/outbound/telemetry | Outbound adapter | OTel trace and metric providers, PathMetrics counter, trace-correlating slog handler |
internal/adapters/outbound/bootretry | Outbound adapter | Bounded retry of the first Postgres dial at boot (ADR 0024) |
internal/adapters/kafka/cloudevents | Shared adapter | The only place a CloudEvents 1.0 envelope is built or decoded (ADR 0016) |
internal/pgtx | Shared adapter | Transaction-in-context slot shared by the idempotency middleware and the Postgres unit of work |
cmd/* | Composition roots | One main.go per binary. Environment variables are read only here (plus CORS_ALLOWED_ORIGINS and ENVIRONMENT, see Configuration) |
migrations/, migrations/analytics/ | Schema | golang-migrate SQL for the OLTP and analytical databases |
web/ | Frontend | process_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:.
| Binary | Role | Port (default env) | Endpoints | Helm workload |
|---|---|---|---|---|
cmd/pathmgmt | OLTP 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/mcp | Read-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/a2a | Read-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-projector | Analytics 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-reports | Analytics 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:
| Repositories | Publisher | Outbox relay / sweeper |
|---|---|---|
| Postgres | OutboxPublisher: one outbox_events row per topic, in the same transaction as the aggregate write | relay 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
| Store | Used by | Schema owner | Tables | Pool |
|---|---|---|---|---|
OLTP Postgres (DATABASE_URL) | pathmgmt, mcp | Both binaries run migrations/ at boot (idempotent) | process_paths, cpt_schedules, cpt_schedule_cutoffs, outbox_events, idempotency_keys | MaxConns=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 boot | catalogue_growth_rollup, analytics_processed_events, analytics_consumed_events | projector 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.dlq | Writers use the Hash balancer, RequireAll acks, 10 ms batch timeout |
The full column-level schema is on Entity relationship.
Request path of a write
- chi middleware:
RequestID,otelchispan,http.server.request.durationhistogram,RequestLogger,Recoverer, CORS. POST /process-pathsonly, 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).- The handler decodes the DTO and calls the use case.
- The use case validates through the aggregate, then runs
Create/SaveandPublishinsideUnitOfWork.Execute. A transaction already in the context (from step 2) is joined, not nested. OutboxPublisherinserts one row per topic with the request'straceparent/tracestate(ADR 0027).- 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.