---
id: shopping
name: Shopping
summary: |
  Coordinates the customer basket and pre-purchase checkout intent, from selecting books
  through handing an accepted purchase to Ordering.
version: 1.0.0
owners:
  - commerce-fulfillment-team
systems:
  - id: cart-system
    version: 1.0.0
entities:
  - id: basket
    version: 1.0.0
  - id: basket-item
    version: 1.0.0
diagrams:
  - id: checkout-interaction
    version: 1.0.0
flows:
  - id: user-checkout
    version: 1.0.0
badges:
  - content: Core Domain
    backgroundColor: blue
    textColor: blue
    icon: RectangleGroupIcon
  - content: Business Critical
    backgroundColor: red
    textColor: red
    icon: ShieldCheckIcon
---

## Business Purpose & Boundary

[[domain|shopping]] is BookWorm's Core bounded context for pre-purchase customer intent, centered on the [[entity|basket]] and its [[entity|basket-item]] entries. It enables authenticated customers to create, inspect, replace, and clear their baskets with sub-millisecond reads, enriches basket items with live [[domain|catalog]] metadata at read time, and executes post-checkout basket cleanup once an order is accepted. Explicitly **out of scope** are owning canonical book details ([[domain|catalog]]), creating or managing accepted orders ([[domain|ordering]]), coordinating post-checkout workflows ([[domain|ordering]]), and external payment settlement.

:::warning
A [[entity|basket]] represents mutable shopping intent—**not** a confirmed order and **not** an inventory reservation. Basket items store only book identifiers and quantities, never copied catalog descriptions or locked order prices.
:::

## Core Responsibilities & Capabilities

| Capability                            | Owning Service / Agent  | Primary Entities                            |
| :------------------------------------ | :---------------------- | :------------------------------------------ |
| **Customer-Scoped Basket Management** | [[service\|basket-api]] | [[entity\|basket]], [[entity\|basket-item]] |
| **Read-Time Catalog Enrichment**      | [[service\|basket-api]] | [[entity\|basket-item]]                     |
| **Checkout Basket Read Contract**     | [[service\|basket-api]] | [[entity\|basket]]                          |
| **Idempotent Post-Checkout Cleanup**  | [[service\|basket-api]] | [[entity\|basket]]                          |

## Cross-Domain Interactions (Context Map)

| Neighboring Domain             | Direction                                  | Integration Mechanism     | Business Data Exchanged                                                                                                                                                           |
| :----------------------------- | :----------------------------------------- | :------------------------ | :-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| **[[domain\|catalog]]**        | Upstream (`Catalog` → `Shopping`)          | Sync (gRPC)               | Live book titles, unit prices, and discount prices to enrich basket reads                                                                                                         |
| **[[domain\|ordering]]**       | Downstream (`Shopping` → `Ordering`)       | Sync (gRPC)               | Customer basket book IDs and quantities read during checkout order creation                                                                                                       |
| **[[domain\|ordering]]**       | Upstream (`Ordering` → `Shopping`)         | Async (Commands & Events) | [[command\|PlaceOrderCommand]] triggers basket deletion; Shopping replies with [[event\|BasketDeletedCompleteIntegrationEvent]] or [[event\|BasketDeletedFailedIntegrationEvent]] |
| **[[domain\|conversational]]** | Downstream (`Shopping` ← `Conversational`) | User-confirmed UI action  | Conversational recommendations require explicit customer confirmation before mutating a basket                                                                                    |

:::note
**Explicit Cleanup Outcomes & Idempotency:** Duplicate cleanup commands during post-checkout retries are deduplicated by Shopping's idempotency guard. When cleanup fails, [[service|basket-api]] emits [[event|BasketDeletedFailedIntegrationEvent]] so [[domain|ordering]] can compensate explicitly—cleanup failure is never treated as a successful cleanup or payment status.
:::

## Ubiquitous Language Highlights

- **Basket:** A customer's mutable collection of items before purchase; updates replace the entire item collection as a set rather than merging partial diffs.
- **Basket Item:** A book identifier paired with a positive quantity, enriched from [[domain|catalog]] at read time.
- **Customer Identifier:** The authenticated identity used to scope a customer's basket, distinct from the [[entity|buyer]] identity managed inside [[domain|ordering]].
- **Checkout:** The cross-context action that hands basket contents to [[domain|ordering]] to initiate order placement.

## Architecture Visualizations

<NodeGraph />

<EntityMap />

### Shopping Context Overview

<LikeC4View viewId="basketContext" project="basket" />

## Related Governance & Documentation

- [[system|cart-system]] — System boundary, Redis persistence container, and [[service|basket-api]].
- [[flow|user-checkout]] — End-to-end checkout, basket cleanup, and compensation sequence.
- [[diagram|checkout-interaction]] — Checkout interaction between Shopping and Ordering.
- [[adr|adr-bw-004-explicit-http-and-grpc-contracts]] — Explicit HTTP and gRPC service contracts.
- [[adr|adr-bw-006-service-owned-business-state]] — Isolated basket state ownership.
- [[doc|arc42/12-glossary]] — Shared shopping and checkout terminology.
