---
id: cart-system
name: Cart System
version: 1.0.0
summary: |
  Internal system that owns customer-scoped baskets throughout the pre-order
  journey, including basket management, Catalog-backed item presentation, and
  checkout cleanup coordination.
scope: internal
owners:
  - commerce-fulfillment-team
services:
  - id: basket-api
    version: 1.0.0
flows:
  - id: user-checkout
    version: 1.0.0
relationships:
  - id: identity-provider
    version: 1.0.0
    label: verifies customer identity for protected basket requests
actors:
  - id: customer
    name: Customer
    label: creates and manages a shopping basket
    direction: inbound
containers:
  - id: basket-database
    version: 1.0.0
entities:
  - id: basket
    version: 1.0.0
  - id: basket-item
    version: 1.0.0
badges:
  - content: Internal
    backgroundColor: gray
    textColor: gray
    icon: LockClosedIcon
---

## System Purpose & Boundary

The Cart System owns transient, customer-scoped shopping [[entity|basket]] state throughout the pre-order journey within the [[domain|shopping]] domain. It serves **Customers** creating, viewing, replacing, and clearing their active [[entity|basket-item]] selections. Product metadata and pricing ([[domain|catalog]]), accepted order history ([[domain|ordering]]), and post-checkout orchestration ([[system|finance-system]]) are explicitly out of scope.

:::note
[[container|basket-database]] is authoritative only for active pre-order shopping intent—never for reconstructing accepted orders. Basket updates replace the entire item list rather than merging partial edits, and read responses enrich items with live Catalog titles and prices.
:::

## Contained Capabilities

| Service / Agent         | Role in System                                                                                            | Primary Data Store             | Interaction Style (Sync / Async) |
| :---------------------- | :-------------------------------------------------------------------------------------------------------- | :----------------------------- | :------------------------------- |
| [[service\|basket-api]] | Serves customer HTTP basket endpoints, internal gRPC basket snapshots, and post-checkout cleanup handlers | [[container\|basket-database]] | Sync (HTTP/gRPC) & Async (Kafka) |

## External Interactions & Trust Boundaries

- **Customer entry point:** Authenticated customers manage their own basket through the API Gateway, with ownership derived strictly from the [[system|identity-provider]] token.
- **Catalog & Ordering sync calls:** [[service|basket-api]] batch-resolves book titles and prices from [[service|catalog-api]] over gRPC on read, and serves basket snapshots to [[service|order-api]] over gRPC during checkout.
- **Post-checkout cleanup:** Consumes [[command|PlaceOrderCommand]] from [[system|finance-system]] over Kafka and publishes [[event|BasketDeletedCompleteIntegrationEvent]] or [[event|BasketDeletedFailedIntegrationEvent]] so Finance and Ordering can track cleanup outcomes.

<Accordion title="Enrichment & Cleanup Notes">
	- **Read-time enrichment:** Distinct book IDs are batched into a single Catalog lookup; missing
	catalog items remain in the basket response without inventing metadata. - **Explicit cleanup
	outcomes:** Reporting deletion success or failure explicitly prevents stale baskets from being
	reused after checkout.
</Accordion>

## System Visualizations

### System Context

<ContextDiagram />

### Cart Context

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

### Component Topology

<NodeGraph mode="full" search="false" legend="false" />

### Architecture Decisions

<ADRTable />

## Related Documentation

- [[flow|user-checkout]] — End-to-end checkout and basket cleanup flow.
- [[diagram|checkout-interaction]] — Interaction between Shopping, Ordering, and Finance.
- [[doc|domains/bookworm/subdomains/shopping/engineering/basket-api-contracts]] — Basket API contracts and boundaries.
- [[doc|domains/bookworm/subdomains/shopping/guides/checkout-lifecycle]] — Pre-order to checkout handoff guide.
