Skip to main content

Sequence Diagrams

UML sequence diagrams of every command use case, following the code paths in internal/application/usecases and the adapters around them. Part of the DDD artifact pack. The diagrams show the production wiring, which is the only one: Postgres repositories, postgres.UnitOfWork and postgres.OutboxPublisher, with the relay always on (ADR 0037). Read queries (GetPath, ListPaths, GetCPTSchedule, the MCP tools) are single repository reads and are not drawn.

1. Define a process path​

Source: internal/adapters/inbound/http/idempotency.go (RequireIdempotencyKey, replayCachedResponse, runFreshRequest), internal/adapters/inbound/http/server.go (handleDefinePath), internal/application/usecases/define_path.go, internal/domain/processpath/process_path.go, internal/adapters/outbound/postgres/{process_path_repo.go,unit_of_work.go,outbox_publisher.go}. Omits: the PathMetrics accepted/rejected counter calls, the 400 for a malformed JSON body, and 500 branches. UnitOfWork.Execute reuses the transaction already in the context (txFrom) instead of opening its own, so the path row, both outbox rows and the idempotency row commit together. Creation is insert-only (ProcessPathRepo.Create), never the version-guarded upsert Save that revise and deactivate use: two defines of one id that both pass the FindByID check serialize on the primary key, and the loser gets the same 409 as a define of an existing id.

2. Revise a process path​

Source: internal/adapters/inbound/http/server.go (handleRevisePath), internal/application/usecases/revise_path.go, internal/domain/processpath/process_path.go (Revise), internal/adapters/outbound/postgres/process_path_repo.go (Save), internal/adapters/inbound/http/errors.go (statusFor). Omits: the 422 for an unparsable cycleTimeP95 (raised by the handler before the use case runs). PUT routes carry no idempotency middleware (ADR 0011).

3. Deactivate a process path​

Source: internal/application/usecases/deactivate_path.go, internal/domain/processpath/process_path.go (Deactivate), internal/adapters/outbound/postgres/process_path_repo.go (FindByIDForUpdate), internal/adapters/outbound/postgres/cpt_schedule_repo.go (ListSiteIDsReferencingPath), internal/adapters/inbound/http/server.go (handleDeactivatePath). Omits: 500 branches. The row is never deleted; DELETE is a soft deactivation. The path row is locked FOR UPDATE before the reference check, and DefineCPTSchedule holds FOR SHARE on every path it lists until it commits, so the two serialise: the race between a schedule listing the path and its deactivation is closed (ADR 0028, which closes the residual race ADR 0026 recorded).

4. Define or revise a site's CPT schedule​

Source: internal/adapters/inbound/http/server.go (handleDefineCPTSchedule, toCutoffs), internal/application/usecases/cpt_schedule.go (DefineCPTSchedule.Execute, lockAndValidateEligiblePathIds), internal/domain/cptschedule/cpt_schedule.go, internal/domain/cptschedule/events.go (ToSnapshot), internal/adapters/outbound/postgres/process_path_repo.go (LockByIDsForShare), internal/adapters/outbound/postgres/cpt_schedule_repo.go (Save). Omits: 500 branches. The whole use case runs in one unit of work and the share locks on the listed paths are held until COMMIT, which is what serialises it against DeactivatePath (ADR 0028).

5. Outbox relay to Kafka​

Source: internal/adapters/outbound/postgres/outbox_relay.go (RelayOnce), internal/adapters/outbound/kafka/publisher.go (NewPublisher, Send), internal/adapters/outbound/kafka/writer_config.go, cmd/pathmgmt/main.go. Omits: the outbox lag gauge and the sweeper (ADR 0018). A crash between send and commit re-sends the row with the same CloudEvents id; consumers dedupe on it.

6. Analytics projection (own topic)​

Source: internal/adapters/inbound/kafka/analytics_consumer.go, internal/adapters/outbound/analyticsstore/{consumed_events_repo.go,postgres_projection.go,unit_of_work.go}, cmd/pathmgmt-projector/main.go. Omits: retry backoff and the DLQ topic-readiness wait.