Sequence Diagrams
One UML sequence diagram per command use case on Use Cases. Participant names are the packages and ports of the code, from the Class Diagram:
httpandkafkaare the inbound adapters;scheduleris the policy loop ofcmd/api(cmd/api/policies.go).- The use case is in
internal/application/usecases. Postgresstands for the repositories, the outbox, the inbox and the idempotency store. They share one transaction throughUnitOfWork.Relay / Kafkais the outbox relay. It reads committedoutbox_eventsrows and publishes them toretailnetwork.pricing.events(orretailnetwork.pricing.analytics).
Every save is conditional on the loaded version (optimistic concurrency).
Full CloudEvents types are on Domain Events.
1. CreateItemPrice (REST POST /item-prices)
Source: internal/application/usecases/itemprice.go (CreateItemPrice), internal/adapters/inbound/http/{handlers,idempotency}.go.
SetListPrice (PUT /item-prices/{catalogItemId}/list-price) is not drawn: it is idempotent
by method, so it skips the key lookup; it loads the stored price, checks the optional version
and calls ItemPrice.SetListPrice on it instead of Create, and answers 200
(usecases/itemprice.go, apis/openapi.yaml setListPrice). Where the diagram says "store key response, COMMIT" the key
row, the aggregate change and the outbox rows are one transaction, and a key reused
with another request is 409 idempotency-key-reused.
Derived from: model.yaml → contexts[pricing].aggregates[ItemPrice]
(SetListPrice, invariants), .read_models[CatalogItemView],
.publishes[ItemPriceChanged]; conventions.integration_rules.
Omitted: the version-conflict retry on update (as in diagram 2). On a
create there is no conflict: the catalogItemId is the key and a second
insert is a unique violation mapped to 409 concurrent-update.
2. ScheduleSale (REST POST /item-prices/catalogItemId/sales)
Source: internal/application/usecases/itemprice.go (ScheduleSale), internal/domain/itemprice/itemprice.go.
Derived from: model.yaml → contexts[pricing].aggregates[ItemPrice]
(ScheduleSale, invariants), .publishes[ItemPriceChanged].
Omitted: ErrNegativeAmount and ErrCurrencyMismatch (422, same branch as
the sale rules). A future window emits nothing now; the boundary policy
publishes when it opens (diagram 8).
3. CancelSale (REST POST .../sales/saleId/cancellations)
Source: internal/application/usecases/itemprice.go (CancelSale).
Derived from: model.yaml → contexts[pricing].aggregates[ItemPrice].commands,
.publishes. The event choice is this pack's reading (open question on the
canvas).
Omitted: the version-conflict retry (as in diagram 2) and the relay.
4. WithdrawPrice (merchandiser, REST)
Source: internal/application/usecases/itemprice.go (WithdrawPrice).
Derived from: model.yaml → contexts[pricing].aggregates[ItemPrice]
(WithdrawPrice, transitions), .publishes[ItemPriceWithdrawn].
Omitted: the HTTP adapter detail. The route is
POST /item-prices/{catalogItemId}/withdrawals.
5. WithdrawPrice by policy WithdrawOnDiscontinue (Kafka)
Source: internal/application/usecases/consume.go (CatalogItemDiscontinued), internal/adapters/inbound/kafka/consumer.go.
Derived from: model.yaml → contexts[pricing].policies[WithdrawOnDiscontinue],
.consumes (CatalogItemDiscontinued), .read_models.
Omitted: the version-conflict retry (redeliver). View update, aggregate save, outbox and inbox share one transaction, so a crash anywhere replays the whole event safely.
6. PublishChargeSchedule and PublishTaxTable (REST)
Source: internal/application/usecases/publish.go (PublishChargeSchedule, PublishTaxTable).
Derived from: model.yaml → contexts[pricing].aggregates[DeliveryChargeSchedule],
.aggregates[TaxTable] (commands, invariants, transitions), .publishes.
One diagram covers both aggregates: the shape is identical, only the rules differ. Omitted: nothing else; the model gives both aggregates the same lifecycle.
7. IssuePriceQuote (REST POST /price-quotes)
Source: internal/application/usecases/quote.go (IssuePriceQuote), internal/domain/quote/quote.go.
Derived from: model.yaml → contexts[pricing].aggregates[PriceQuote]
(IssuePriceQuote, invariants, description), .policies[QuoteTtl],
.publishes[PriceQuoteIssued]; contexts[checkout].sync_calls.
Omitted: the request's field list, which the model gives (cartId, lines,
groups, destinationPostalPrefix). There is no version conflict on an insert: the quoteId is minted
here. The reads of prices, schedule and table are store reads through
ports, not aggregate method calls; the quote pins their versions so a later
change never rewrites it.
8. ExpireQuote and the sale-boundary policy (scheduler)
Source: cmd/api/policies.go, internal/application/usecases/{consume,quote}.go (PublishBoundaries, ExpireQuotes).
Derived from: model.yaml → contexts[pricing].policies[QuoteTtl],
.policies[PublishEffectivePriceOnWindowBoundary],
.aggregates[PriceQuote].transitions.
Omitted: the boundary bookkeeping. item_prices.evaluated_at, the published_*
columns and the indexed next_boundary_at find the due items and make the
publication idempotent per boundary: Reevaluate raises an event only when the
published view moved. Expiry needs no marker: the state flip is itself
idempotent.
9. Project CatalogItemView (Kafka)
Source: internal/application/usecases/consume.go (CatalogItemCreated).
Derived from: model.yaml → contexts[pricing].consumes, .read_models.
Omitted: nothing. The view holds id and the discontinued flag only; per-item
order comes from the producer keying both types by catalogItemId.