Digital storefront · Supporting domain · EventStorming board

shopping-cart

Holds a shopper's cart before checkout: lines, destination, chosen delivery offers and a non-binding estimate. Closes the cart once checkout completes.

GitHub ↗ · Documentation ↗ · Architecture check · Briefings

events published
4
commands
16
policies
7
read models
5
hot spots
4

The story in 4 key events

The pivotal events: the few that matter most, in the order they happen.

  1. Pivotal eventCartLineAdded
  2. Pivotal eventCartDeliveryQuoted
  3. Pivotal eventCartCheckedOut
  4. Pivotal eventCartAbandoned

Listens to (3): contexts whose events this one reacts to

Tells (0): contexts that react to its events

none

The board, row by row

16 rows, in the order the business story happens: the main path first, then how this context reacts to the others, then the clock. Rows are small stories; read each one left to right.

  • Event
  • Command
  • Actor
  • Aggregate
  • Policy
  • Read model
  • External system
  • Hot spot
  • Opportunity
  1. Start a cart

    A shopper, signed in or not, opens an empty cart. Nothing is announced to other contexts.

    ActorShopper
    CommandCreateCartPOST /carts
    AggregateCart

    Source: application/usecases/cart_commands.go · domain/cart/cart.go

  2. Add an item to the cart

    The shopper adds an item. It must be known, priced and not discontinued. Adding an item already in the cart merges the quantities, which must stay between 1 and 99.

    ActorShopper
    Read modelPurchasable items
    CommandAddLinePOST /carts/{cartId}/lines
    AggregateCart
    EventCartLineAddedanalytics stream only

    Source: application/usecases/cart_commands.go · domain/cart/lines.go · domain/cart/events.go

  3. Change a quantity

    The shopper sets a new quantity for a line. Any change to the lines throws away the delivery offers and selections, so they have to be asked for again.

    ActorShopper
    CommandSetLineQuantityPUT /carts/{cartId}/lines/{catalogItemId}
    AggregateCart

    Source: application/usecases/cart_commands.go · domain/cart/lines.go

  4. Remove an item

    The shopper removes a line. Like any change to the lines, it clears the delivery offers and selections. Nothing is announced.

    ActorShopper
    CommandRemoveLineDELETE /carts/{cartId}/lines/{catalogItemId}
    AggregateCart

    Source: application/usecases/cart_commands.go · domain/cart/lines.go

  5. Say where it should be delivered

    The shopper gives a destination postal prefix. Until then the estimate shows only the item total; delivery and tax appear once a destination is set.

    ActorShopper
    CommandSetDestinationPUT /carts/{cartId}/destination
    AggregateCart

    Source: application/usecases/cart_commands.go · domain/cart/cart.go · domain/estimate/estimate.go

  6. Get delivery offers

    The cart asks delivery-promise for delivery offers for its lines and destination, and keeps them. Offers hold no capacity, they are facts frozen at quote time.

    ActorShopper
    Read modelDelivery offers asked from delivery-promise
    CommandQuoteDeliveryPOST /carts/{cartId}/delivery-quotes
    AggregateCart
    EventCartDeliveryQuotedanalytics stream only

    Source: application/usecases/quote_delivery.go · domain/cart/quote.go · domain/cart/events.go

  7. Choose a delivery offer

    The shopper picks one offer for each shipment group. An offer that is not part of the current quote is refused. The cart is ready for checkout when every group has an offer and none has expired.

    ActorShopper
    CommandSelectDeliveryPUT /carts/{cartId}/delivery-selection
    AggregateCart

    Source: application/usecases/cart_commands.go · domain/cart/delivery.go

  8. Merge a guest cart after sign-in

    When a guest signs in, the guest cart's lines move into the shopper's open cart and the guest cart is closed as merged. Quantities add up, capped at 99.

    ActorShopper
    CommandMergeIntoPOST /carts/{cartId}/merges
    AggregateCart

    Source: application/usecases/cart_commands.go · domain/cart/lifecycle.go

  9. Take over the offers of a checkout requote

    When checkout finds that the offers have to be requoted, it can write the new ones into the cart. They replace the quote and are selected for every group, with no call to delivery-promise.

    ActorCheckout, for a shopper
    CommandAcceptRequotedOffersPOST /carts/{cartId}/delivery-requote-acceptances
    AggregateCart

    Source: application/usecases/cart_commands.go · domain/cart/requote.go

  10. Keep the item list

    offer-availability announces new and discontinued catalogue items. The cart keeps a copy of which items exist and which are discontinued, so adding an item needs no live call.

    Systemoffer-availability
    EventCatalogItemCreated
    PolicyWhenever an item is created or discontinued, update what the cart knows of it
    CommandApplyCatalogItemCreatedstarted by the policy
    Read model · kept up to datePurchasable items

    Source: application/usecases/consume.go · adapters/inbound/kafka/handlers.go

  11. Keep the item prices

    pricing announces each item's current price, and withdraws it when an item can no longer be sold. The cart keeps the newest price, and an item without a price cannot be added.

    Systempricing
    EventItemPriceChanged
    PolicyWhenever a price changes or is withdrawn, keep it if its version is newer
    CommandApplyItemPriceChangedstarted by the policy
    Read model · kept up to datePurchasable items
    Read model · kept up to dateEstimate prices

    Source: application/usecases/consume.go · adapters/inbound/kafka/handlers_pricing.go

  12. Keep the delivery charges

    pricing publishes the charge for each delivery speed. The cart replaces its copy and uses it to estimate the delivery cost. Only the estimate moves; the cart's own delivery offers are left alone.

    Systempricing
    EventDeliveryChargeScheduleChanged
    PolicyWhenever a charge schedule is published, replace the stored one if it is newer
    CommandApplyDeliveryChargeScheduleChangedstarted by the policy
    Read model · kept up to dateEstimate delivery charges

    Source: application/usecases/consume.go · adapters/inbound/kafka/handlers_pricing.go

  13. Keep the tax rates

    pricing publishes the tax rates by destination postal prefix. The cart replaces its copy and uses it for the estimate, which is labelled non-binding.

    Systempricing
    EventTaxTableChanged
    PolicyWhenever a tax table is published, replace the stored one if it is newer
    CommandApplyTaxTableChangedstarted by the policy
    Read model · kept up to dateEstimate tax rates

    Source: application/usecases/consume.go · adapters/inbound/kafka/handlers_pricing.go

  14. Close the cart when checkout completes

    checkout reports that the purchase went through. The open cart is closed as checked out. A cart that is unknown or not open only gets a warning in the log.

    Systemcheckout
    EventCheckoutCompleted
    PolicyWhenever a checkout completes, close the cart as checked out
    CommandCloseOnCheckoutCompletedstarted by the policy
    AggregateCart
    EventCartCheckedOutanalytics stream only

    Source: application/usecases/consume.go · domain/cart/lifecycle.go · adapters/inbound/kafka/handlers.go

  15. Abandon carts nobody touches

    A sweep closes every open cart that has not changed for 30 days as abandoned and announces it.

    TimeAbandon sweep
    PolicyEvery sweep, an open cart unchanged for 30 days is abandoned
    CommandAbandonInactivestarted by the clock
    AggregateCart
    EventCartAbandonedanalytics stream only

    Source: application/usecases/policies.go · domain/cart/lifecycle.go · adapters/inbound/scheduler/scheduler.go

  16. Delete old closed carts

    A second sweep deletes carts that are no longer open and have not changed for 30 days. Nothing is announced, so an idle cart is gone about 60 days after its last change.

    TimePurge sweep
    PolicyEvery sweep, a closed cart unchanged for 30 days is deleted
    CommandPurgeAbandonedCartsstarted by the clock

    Source: application/usecases/policies.go · adapters/inbound/scheduler/scheduler.go

Hot spots and opportunities

Open questions and known gaps, each taken from a decision record or a document in the repository, never invented. Opportunities are improvements the documentation already names.

  • Hot spotOnly adding a line, quoting, abandoning and checking out publish an event. Removals, quantity changes, destinations, selections and merges raise nothing.

    Source: docs/ddd/eventstorming.md

  • Hot spotThe cart accepts any known, priced, undiscontinued item without checking stock. It is lenient on purpose: checkout's binding price quote is the gate.

    Source: docs/ddd/eventstorming.md

  • Hot spotNo context reads the cart's events. Whether a sibling should ever consume one is undecided.

    Source: docs/ddd/bounded-context-canvas.md

  • Hot spotThe route that lets checkout write a requote into the cart has no caller yet in the local checkouts.

    Source: docs/ddd/bounded-context-canvas.md

Opportunities

This board is a reconstruction from the code and documentation of shopping-cart at origin/develop, not a workshop output. Roles are the ones the documentation names. How the boards were made.