Skip to main content

Sequence diagrams

Synced from inbound-receiving

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.

DockAppointment moved (ADR 0019)

The dock appointment is owned by dock-scheduling since ADR 0019. This context keeps a read-only local copy fed by dock-scheduling's DockAppointmentBooked / DockAppointmentCancelled, no longer books, checks in, cancels or completes appointments, and no longer raises the four DockAppointment* events (the one-shot api republish-appointments backfill that re-announced them was removed, ADR 0022). Where this page describes those commands, rules or events, read it as the pre-transfer design; the page is not yet rewritten.

One diagram per command use case plus the local-copy consumers and the outbox relay: inbound adapter, application service, aggregate, repository, outbox. The Idempotency-Key middleware wraps the creating POSTs and is drawn once, in the first diagram. UoW is ports.UnitOfWork (one Postgres transaction).

Register an ASN​

Source: internal/adapters/inbound/http/{server,idempotency}.go, internal/application/usecases/asn.go, internal/domain/asn/asn.go. Omits: the other POSTs behave the same way in the middleware; the response is stored with the key in the same transaction.

Appointment writes (moved to dock-scheduling)​

Source: internal/adapters/inbound/http/handlers_appointment.go (appointmentWriteMoved), server.go. There is no use case, aggregate call or outbox row behind these three routes: they answer 410 whatever the request, and this context raises no appointment event (ADR 0019; the encoders, Replay and the republish-appointments command were removed by ADR 0022). The deprecated GET /appointments and GET /appointments/{appointmentId} stay and read the local copy fed by dock-scheduling; removing them is a decision not taken yet (ADR 0022). ASN cancel follows the shape of the other creating POSTs (CancelAsn, ErrAsnInProgress / ErrAsnTerminal on refusal).

Open a receipt​

Source: internal/application/usecases/receipt.go (OpenReceipt.open), internal/domain/receipt/receipt.go. The ASN save raises no event; the partial unique index receipts_one_open_per_asn closes the race the OpenByAsn read cannot.

Receive a line​

Source: internal/application/usecases/receipt.go (ReceiveLine.Handle), internal/domain/receipt/receipt.go.

Close a receipt​

Source: internal/application/usecases/receipt.go (CloseReceipt.Handle, completeAsn), internal/application/usecases/stow.go (completeStow). The ASN completion raises no event, and the use case no longer completes the appointment (ADR 0019). The ASN and receipt saves and every outbox row commit together or not at all. Each Insert(encoded ...) writes two rows, one per topic (FanoutEncoder, ADR 0006).

Local-copy consumer (product and dock door)​

Source: internal/adapters/inbound/kafka/{kafka,product_consumer,dock_door_consumer}.go, internal/application/usecases/consumers.go. A transient error from the use case retries the same message with capped backoff and never commits past it.

Outbox relay​

Source: internal/adapters/outbound/outbox/relay.go, internal/adapters/outbound/postgres/outbox_repository.go, internal/adapters/outbound/kafka/relay_sink.go. A full batch is followed immediately by another pass. A crash between send and update republishes the row with the same CloudEvents id, which is what lets consumers dedupe.