Overview

The Basket domain is responsible for managing the shopping basket of a customer throughout their shopping journey. It serves as a temporary storage for items that customers intend to purchase before proceeding to checkout and placing an order.

Key Responsibilities

  • Managing the addition, removal, and updating of items in a customer’s basket
  • Maintaining quantity information for each basket item
  • Calculating pricing including subtotals, discounts, and estimated taxes
  • Supporting the transition from anonymous to authenticated baskets when users log in
  • Providing persistence for basket state between sessions
  • Implementing basket expiration and cleanup processes
  • Validating product availability and price consistency with the Catalog service
  • Facilitating the checkout process by transferring basket data to the Ordering service

The domain uses an Active Record pattern for simplicity and performance, as basket operations need to be fast and highly available. The basket data is temporarily stored and doesn’t require complex domain modeling as found in other services.

Bounded context

Messages for this domain

Sends messages (2)

Quickly find the message you need by searching for the name, type, or summary.
NameVersionTypeSummary
Deleted Basket Complete
v1.0.0eventRepresents a domain event that is published when reverse basket is completed
Deleted Basket Fail
v1.0.0eventRepresents a failed basket deletion event in the system

Receives messages (5)

Quickly find the message you need by searching for the name, type, or summary.
NameVersionTypeSummary
Update Basket
v1.0.0commandUpdate a basket
Get Basket
v1.0.0queryGet a basket by user
Delete Basket
v1.0.0commandDelete a basket by its unique identifier
Create Basket
v1.0.0commandCreate a new basket for a user

Data Model

The Basket domain uses a simple data model optimized for Redis storage with the following structure:

Customer Basket

Basket
{
"id": "string",
"items": [
{
"id": "string",
"quantity": "number"
}
],
"createdAt": "datetime",
"updatedAt": "datetime"
}

Storage Details

  • Storage Type: Redis Hash
  • Key Pattern: /basket
  • Hash Field: Customer ID
  • Value: Serialized CustomerBasket object

Key Properties

  • id: Unique identifier for the customer’s basket
  • items: Collection of basket items
  • createdAt: Timestamp of basket creation
  • updatedAt: Timestamp of last update

BasketItem Properties

  • id: Product identifier
  • quantity: Number of items (must be greater than 0)

Validation Rules

  • Customer ID cannot be null
  • Basket must contain at least one item
  • Item quantity must be greater than zero

Serialization

  • Uses System.Text.Json with camelCase naming policy
  • Case-insensitive property matching
  • Optimized serialization context for performance