Skip to main content

Sequence diagrams

Synced from product-master

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.

UML sequence diagrams of every command use case, derived from the use-case bodies in internal/application/usecases, the inbound adapters and the Postgres adapters. Every write runs in one unit of work (one Postgres transaction): load, aggregate command, version-guarded save, encode, outbox insert (writer.go). There is no Idempotency-Key middleware: every write is an idempotent PUT.

1. Register a product (REST)​

Source: internal/application/usecases/register_product.go, writer.go, internal/adapters/inbound/http/handlers.go (handleRegisterProduct), internal/adapters/outbound/postgres/product_repository.go (Save). Omits: 400 malformed-request for a bad body and the telemetry middleware.

2. Classify a product (REST)​

Source: internal/application/usecases/classify_product.go, writer.go (change), internal/adapters/inbound/http/handlers.go (handleClassifyProduct), internal/domain/product/classification.go, product.go (setClassification). Omits: the 409 concurrent-modification branch on Save (same as diagram 1).

3. Declare dimensions and record a measurement (REST)​

Source: internal/application/usecases/physical_profile.go, writer.go, internal/adapters/inbound/http/handlers.go (dimensions, handleDeclareDimensions, handleRecordMeasurement), internal/domain/product/physical.go, product.go. Omits: the 409 concurrent-modification branch on Save.

4. Outbox relay to Kafka​

Source: internal/adapters/outbound/outbox/relay.go (Run, RelayOnce), internal/adapters/outbound/postgres/outbox_repository.go (Drain, claim), internal/adapters/outbound/kafka/relay_sink.go, cmd/api/relay.go (startOutboxRelay). Omits: the in-memory OutboxRepo.Drain (a test double), and the shutdown order (the relay stops last).

There is no inbound Kafka diagram for cmd/api: the ADR 0003 legacy importer, its only consumer, was removed at stage E (2026-10-17). The analytics projector's consumer is described on Runtime.