Domain Message Flow
Following ddd-crew Domain Message Flow Modelling.
Five scenarios. Participants are contexts and actors. Every arrow is a
message of the code (a route, a gateway call or an event), prefixed cmd: (command), qry: (query) or evt:
(event). A Note names a command the session runs on itself. Kafka is drawn
as one participant. Event names are written entity.EventName; the full
type is com.retailnetwork.<tier>.<producer>.<entity>.<EventName> (see
Domain Events). REST path
parameters are written without braces. The storefront-wide flows follow from
the Context Map.
1. A shopper opens a session from a ready cart
Source: internal/adapters/inbound/http/handlers.go (handleOpen),
internal/application/usecases/open_session.go,
internal/domain/checkoutsession/open.go (CheckoutOpened) and the three
gateways shoppingcart, deliverypromise and pricing under
internal/adapters/outbound.
Omitted: the outbox write and relay (see
Sequence Diagrams); the
503 the REST contract names when one of the three dependencies is
unreachable (the shopper retries with the same Idempotency-Key); what
happens when an offer is no longer QUOTED at this pre-check: ErrOfferNotQuotable,
422 offer-not-quotable, no session is created (hotspot H3 on
EventStorming).
2. Confirm: authorize, place the order, complete
Source: internal/application/usecases/confirm_session.go,
internal/domain/checkoutsession/transitions.go and terminals.go,
internal/adapters/outbound/customerpayments/gateway.go and
customerordering/gateway.go, internal/adapters/outbound/kafka/encoder.go.
The two consumers (shopping-cart and customer-payments) are other services;
their reactions are described from their published contracts, not from this
repository.
The two consumers react independently; neither blocks the answer to the
shopper. Omitted: the transactional outbox, the replies' status codes on the
two network and payment calls beyond the success path, and the parked
fulfilment facts customer-payments applies after the bind (gap S4).
3. A decline, then another token
Source: internal/domain/checkoutsession/transitions.go (RecordDecline,
Confirm from DECLINED), internal/adapters/outbound/customerpayments/gateway.go
(Authorize: a 201 in any state but AUTHORIZED, or a 422, is a decline).
A decline from customer-payments voids nothing, because no authorization exists.
(An authorization whose amount or currency is not the quote's also ends in DECLINED,
but there an authorization does exist: RecordAuthorization sets it as the void owed,
ADR 0002 A4, internal/domain/checkoutsession/transitions.go.) The quote is the
clock: the session stays open for as long as the binding price quote is valid,
and ExpireOnQuoteExpiry ends it afterwards (DECLINED → EXPIRED, hotspot H1).
The second AuthorizePayment uses a new key, sessionId:auth:attempt with the
attempt counter raised by one, so it cannot replay the first, declined answer
(hotspot H2).
4. A late requote, or a contract failure
Source: internal/adapters/outbound/customerordering/gateway.go (Place:
which statuses are definitive), internal/application/usecases/settle.go
(settlePlacement, settleVoid), internal/domain/checkoutsession/terminals.go
(RecordRequoteRequired, RecordFailure).
The decision is recorded first, with the void owed in the same save; the void is
then attempted at once. When the void itself fails, the debt stays on the
session and RetryOwedVoids retries it every minute (hotspot H5). The shopper starts the
next attempt from the cart, with a new session. The REST contract says the BFF
writes the requoted offers into the cart as a new quote; the cart's
AcceptRequotedOffers (POST /carts/{cartId}/delivery-requote-acceptances, hotspot H10)
takes them, though storefront-bff has no route for it yet (both outside this
repository, not verified here). Omitted: the network's wire shapes
(offer-not-quotable, requotedOffers), which are the ACL's concern
(internal/adapters/outbound/customerordering, hotspot H8).
5. An in-doubt placement, resolved by replay
Source: internal/application/usecases/resolve_in_doubt.go,
settle.go, internal/domain/checkoutsession/transitions.go
(RecordPlacementInDoubt), internal/adapters/inbound/http/handlers.go
(handleConfirm answers 202 while Unsettled).
The replay is safe because the stored request is PII-free and byte for byte
the same, and customer-ordering is expected to replay its first response to a repeated
Idempotency-Key. A replay can end any of the three definitive ways: the
diagram shows the success; a 409, 400 or 422 on the replay takes scenario 4
from the void on. If the network is still unreachable the session stays
PLACING, and the alert at 20 h comes before the network's 24 h window.
Omitted: the BFF's polling cadence, which this service does not define; and the
interplay with customer-payments' own 24 h backstop, which voids an
authorization with no CheckoutCompleted (hotspot H6; that policy lives in
customer-payments, not here).