Sequence diagrams
This page is a copy of docs/docs/ddd/sequence-diagrams.md on develop, derived from that repository's code. Edit it there, then re-sync.
The main runtime interactions inside cmd/api, drawn from the code with
their error branches. They show the only runtime, Postgres and Kafka (ADR 0011),
with the idempotency middleware always on.
Generate a plan
Source: internal/adapters/inbound/http/idempotency.go,
internal/adapters/inbound/http/handlers.go,
internal/application/usecases/generate_plan.go.
A 5xx from the handler rolls the whole transaction back and is not cached, so the same key can retry.
Approve a plan
Source: internal/application/usecases/decide_plan.go,
internal/adapters/outbound/postgres/slot_plan_repository.go.
Reject follows the same shape without the supersede step: Get,
plan.Reject(reason) (409 plan-not-draft, 400 reject-reason-too-long),
UPDATE ... WHERE version = loaded, outbox insert, commit.
Consume one message
Source: internal/adapters/inbound/kafka/{kafka,consumer,deadletter}.go,
internal/application/usecases/consumers.go.
Record a relocation (execution progress)
The StockRelocated consumer (ADR 0010) uses the same loop, with two
differences: a StockRelocated that can never be applied is dead-lettered at
once instead of skipped, and a relocation that matches no move is committed
as unmatched.
A cancelled context (shutdown) returns before any dead-letter call: the offset stays uncommitted and the message is redelivered.
Source: internal/adapters/inbound/kafka/stock_consumer.go,
internal/application/usecases/record_relocation.go,
internal/domain/slotplan/execution.go.
Relay the outbox
Source: internal/adapters/outbound/outbox/relay.go,
internal/adapters/outbound/postgres/outbox_repository.go,
internal/adapters/outbound/kafka/relay_sink.go.