Skip to main content

Bounded context canvas

Following the ddd-crew Bounded Context Canvas v5. Every message row below exists in the code: the routes in internal/adapters/inbound/http/server.go, the consumed types in internal/adapters/inbound/kafka/handlers.go, the published ones in internal/adapters/outbound/kafka/encoder.go and the single outbound call in internal/adapters/outbound/deliverypromise/gateway.go.

Canvas at a glance​

Arrows follow the message type: solid blue commands (cmd), dotted green queries (qry), thick orange events (evt). Box shapes mark the collaborator kind: rounded = people, UI or any client; blue = sibling bounded context; red = network context. The Inbound and Outbound Communication tables carry the exact route, topic and CloudEvents type for every message.

Inbound​

Source: internal/adapters/inbound/http/server.go (routes), internal/adapters/inbound/a2a/skills.go (skills), internal/adapters/inbound/kafka/handlers.go and handlers_pricing.go (consumed types), internal/domain/cart/cart.go (the invariants in the card).

Outbound​

Source: internal/adapters/outbound/deliverypromise/gateway.go (quotePath), internal/adapters/outbound/kafka/encoder.go (Topic, payloadFor).

The synchronous replies to the BFF and checkout, and the QuoteDeliveryOffers response, are the only synchronous traffic.

Name​

Shopping Cart (shopping-cart, code SC, CloudEvents tier storefront).

Purpose​

To hold a shopper's intent. The context:

  • keeps one line per catalogue item (re-adding merges quantities), bounded at 100 lines, purchasable against the local views;
  • holds the destination postal prefix, never an address;
  • quotes delivery through the network's delivery-promise and holds the result: one group per shipment, each offer with offerId, tier, window and expiry, plus the tiers that were unavailable;
  • holds the shopper's selection, one offer per group, and clears quote and selections on any line or destination change;
  • computes the labelled, non-binding estimate (effective prices plus selected tier charges plus tax band) so the total cost is visible up front; the binding total is the checkout session's PriceQuote.

Strategic classification​

AxisVerdict
DomainSupporting subdomain. See the Core domain chart.
Business modelConversion (holding intent without losing the total-cost-up-front rule).
EvolutionCustom-built.

Domain roles​

RoleApplies?Evidence in the code
Execution (cart lifecycle)Yes, primaryThe Cart aggregate: Create through CloseOnCheckoutCompleted, with ErrCartClosed guarding the terminal states.
Analysis (checkout readiness, estimate)YesCart.Readiness ("every group selected, no offer expired") and estimate.Compute.
SpecificationNoPrices, charges and tax bands are pricing's specification; the cart only projects them.
EnforcerNoThe enforcer roles sit in checkout and customer-payments.

Inbound communication​

CollaboratorMessageTypeChannelRelationship
Shopper via storefront-bffCreateCartCommandREST POST /cartsUI
Shopper via storefront-bffAddLineCommandREST POST /carts/{cartId}/linesUI
Shopper via storefront-bffSetLineQuantityCommandREST PUT /carts/{cartId}/lines/{catalogItemId}UI
Shopper via storefront-bffRemoveLineCommandREST DELETE /carts/{cartId}/lines/{catalogItemId}UI
Shopper via storefront-bffSetDestinationCommandREST PUT /carts/{cartId}/destinationUI
Shopper via storefront-bffQuoteDeliveryCommandREST POST /carts/{cartId}/delivery-quotesUI
Shopper via storefront-bffSelectDeliveryCommandREST PUT /carts/{cartId}/delivery-selectionUI
Shopper via storefront-bffMergeIntoCommandREST POST /carts/{cartId}/mergesUI
checkoutAcceptRequotedOffersCommandREST POST /carts/{cartId}/delivery-requote-acceptancesCustomer/Supplier (we are the Supplier); served, no caller found yet
Shopper via storefront-bffGetCartQueryREST GET /carts/{cartId}UI
Shopper via storefront-bffListCartsQueryREST GET /carts?shopperId=&state=UI
checkoutGetCartQueryREST GET /carts/{cartId}Customer/Supplier (we are the Supplier)
agentsget_cart, list_shopper_cartsQueryA2A JSON-RPC, cmd/a2aOpen Host Service for agents
offer-availability (network)CatalogItemCreatedEventKafka retailnetwork.offer-availability.events, com.retailnetwork.commerce.offer-availability.catalogitem.CatalogItemCreatedConformist
offer-availability (network)CatalogItemDiscontinuedEventsame topic, ...catalogitem.CatalogItemDiscontinuedConformist
pricingItemPriceChangedEventKafka retailnetwork.pricing.events, com.retailnetwork.storefront.pricing.itemprice.ItemPriceChangedCustomer/Supplier (we are the Customer)
pricingItemPriceWithdrawnEventsame topic, ...itemprice.ItemPriceWithdrawnCustomer/Supplier (Customer)
pricingDeliveryChargeScheduleChangedEventsame topic, com.retailnetwork.storefront.pricing.deliverychargeschedule.DeliveryChargeScheduleChangedCustomer/Supplier (Customer)
pricingTaxTableChangedEventsame topic, com.retailnetwork.storefront.pricing.taxtable.TaxTableChangedCustomer/Supplier (Customer)
checkoutCheckoutCompletedEventKafka retailnetwork.checkout.events, com.retailnetwork.storefront.checkout.checkoutsession.CheckoutCompletedCustomer/Supplier (we are the Customer)

Outbound communication​

CollaboratorMessageTypeChannelRelationship
delivery-promise (network)QuoteDeliveryOffersQueryREST POST /delivery-quotesOpen Host Service (the network publishes it); we are the Customer
analytics onlyCartLineAddedEventKafka retailnetwork.shopping-cart.analytics, com.retailnetwork.storefront.shopping-cart.cart.CartLineAddedanalytics stream
analytics onlyCartDeliveryQuotedEventsame topic, ...cart.CartDeliveryQuotedanalytics stream
analytics onlyCartAbandonedEventsame topic, ...cart.CartAbandonedanalytics stream
analytics onlyCartCheckedOutEventsame topic, ...cart.CartCheckedOutanalytics stream

Nobody in the storefront or the network consumes a cart event: all four are analytics-only. checkout takes the cart by the synchronous read instead. Relationship evidence: Context map.

Ubiquitous language​

Full glossary: Ubiquitous language. Top terms: Cart, Delivery Quote (a set of offers; not the network's one DeliveryOffer), Delivery Selection, Estimate (non-binding; not the checkout session's PriceQuote), Checkout Readiness.

Business decisions​

  1. One line per item; adding an item already in the cart merges quantities. There is no duplicate-line error: Cart.AddLine merges and bounds the merged quantity.
  2. A quote holds no capacity. It is exactly the set of offers delivery-promise returned; a selection must name an offer of the current quote (ErrStaleDeliverySelection).
  3. Any line or destination change clears the quote and the selections.
  4. The estimate is labelled non-binding; the binding total is the checkout session's PriceQuote.
  5. Guest-first: shopperId is optional; MergeInto unifies a guest cart with the shopper's open cart (ErrMergeTarget).
  6. A cart is bounded and checked: quantity in 1 to 99 (ErrQuantityOutOfRange), at most 100 lines (ErrTooManyLines), the item purchasable in the local views (ErrItemNotPurchasable).
  7. A closed cart never changes (ErrCartClosed): CHECKED_OUT, ABANDONED and MERGED are terminal.

Assumptions​

  • The BFF mints the Idempotency-Key for every /carts write and keeps the cart id in a cookie, which is state and not authentication.
  • QuoteDeliveryOffers returns the group shape the cart stores. Only offers in state QUOTED are kept.
  • Offer expiry is enforced locally: readiness compares expiresAt with the clock, because no event announces an offer's expiry.
  • The estimate tolerates event lag; pricing's binding answer comes later, at the checkout quote.
  • Every consumed event is applied once (inbox on the CloudEvents id), and consumers dispatch on the full type string.
  • One configured currency everywhere (CART_CURRENCY is the fallback before any price states one); money appears in the cart only inside the estimate.

Verification metrics​

What exists today versus what would be proposed:

MetricSource today
Share of AddLine rejected item-not-purchasable, and rejections by reasonOTel counter cart.lines.added (outcome, reason), dashboard warehouse-shopping-cart
REST success, 5xx ratio and latencyhttp.server.request.duration, Kong metrics, the warehouse-shopping-cart alert groups
delivery-quotes failuresaccess log http request lines with route /carts/{cartId}/delivery-quotes and status 503
OPEN carts older than 30 days after the sweepcarts.last_changed_at against AbandonInactive
Oldest unpublished outbox eventoutbox_events.created_at where published_at IS NULL (no metric yet)
View lag behind the topicsconsumer-group lag from the broker (no metric yet)

Open questions​

  • Only some commands publish. CartLineAdded, CartDeliveryQuoted, CartAbandoned and CartCheckedOut are the whole stream; removal, quantity changes, destination, selection, merge and creation raise nothing, so analytics sees adds, quotes, abandons and checkouts but never a removal or a merge (hotspot H1 on EventStorming).
  • PurchasabilityView is narrower than discovery's verdict. Its sources are catalogue and price events only (Item.Purchasable: catalogued, not discontinued, priced); product-discovery's Purchasable also requires content and a live listing with stock. The cart can accept an item discovery would refuse; checkout's quote is the gate (hotspot H3).
  • Nobody consumes a cart event. Whether any sibling should consume a cart fact is undecided (hotspot H4).
  • AcceptRequotedOffers has no caller yet in the local checkouts of checkout and storefront-bff.