---
id: ordering
name: Ordering
summary: |
  Creates durable Orders from a buyer's current basket, locks purchase-time pricing,
  and owns order lifecycle transitions from New to Completed or Cancelled.
version: 1.0.0
owners:
  - commerce-fulfillment-team
systems:
  - id: order-system
    version: 1.0.0
  - id: finance-system
    version: 1.0.0
flows:
  - id: order-lifecycle
    version: 1.0.0
  - id: user-checkout
    version: 1.0.0
diagrams:
  - id: order-lifecycle
    version: 1.0.0
  - id: checkout-interaction
    version: 1.0.0
entities:
  - id: order
    version: 1.0.0
  - id: buyer
    version: 1.0.0
  - id: order-item
    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|ordering]] is BookWorm's Core bounded context for committed customer purchases ([[entity|buyer]], [[entity|order]], [[entity|order-item]]) and their business lifecycle (`New` → `Completed` or `Cancelled`). It accepts checkouts by locking purchase-time pricing onto immutable order lines, maintains buyer profiles and delivery addresses, projects real-time order summaries, and orchestrates post-checkout basket cleanup and customer email triggers through [[service|order-orchestration]]. Explicitly **out of scope** are pre-order mutable baskets ([[domain|shopping]]), live catalog descriptions ([[domain|catalog]]), external payment settlement, physical shipping execution, and email rendering or transport ([[domain|platform]]).

:::warning
Only explicit Ordering commands transition an [[entity|order]]'s business status. Post-checkout orchestration retries, timeouts, and [[domain|platform]] email delivery outcomes never mark an order `Completed` or `Cancelled`.
:::

## Core Responsibilities & Capabilities

| Capability                                 | Owning Service / Agent           | Primary Entities                          |
| :----------------------------------------- | :------------------------------- | :---------------------------------------- |
| **Order Creation & Lifecycle Transitions** | [[service\|order-api]]           | [[entity\|order]], [[entity\|order-item]] |
| **Buyer & Delivery Address Management**    | [[service\|order-api]]           | [[entity\|buyer]]                         |
| **Order Summary Projections**              | [[service\|order-api]]           | [[entity\|order]]                         |
| **Post-Checkout Saga Orchestration**       | [[service\|order-orchestration]] | [[entity\|order]]                         |

## Cross-Domain Interactions (Context Map)

| Neighboring Domain       | Direction                            | Integration Mechanism     | Business Data Exchanged                                                                 |
| :----------------------- | :----------------------------------- | :------------------------ | :-------------------------------------------------------------------------------------- |
| **[[domain\|shopping]]** | Upstream (`Shopping` → `Ordering`)   | Sync (gRPC)               | Customer basket book IDs and quantities fetched at checkout                             |
| **[[domain\|catalog]]**  | Upstream (`Catalog` → `Ordering`)    | Sync (gRPC)               | Current unit and promotional prices locked onto [[entity\|order-item]] lines            |
| **[[domain\|shopping]]** | Downstream (`Ordering` → `Shopping`) | Async (Commands & Events) | [[command\|PlaceOrderCommand]] for basket cleanup; completion or failure outcome events |
| **[[domain\|platform]]** | Downstream (`Ordering` → `Platform`) | Async (Commands)          | Order placement, completion, and cancellation email notification commands               |

:::note
**Checkout Consistency & Compensation:** Concurrent checkout submissions are serialized using buyer-scoped distributed locking and request idempotency keys. If post-checkout basket cleanup fails after bounded retries, [[service|order-orchestration]] issues a compensation command so [[service|order-api]] soft-deletes the order and suppresses confirmation emails.
:::

## Ubiquitous Language Highlights

- **Buyer:** The named person associated with one or more orders, holding a delivery address distinct from [[domain|shopping]]'s customer identifier.
- **Order:** The durable purchase record beginning in `New` and transitioning once to a terminal state (`Completed` or `Cancelled`).
- **Order Item & Order Total:** Each line records a book identifier, positive quantity, and locked purchase-time price; the order total is strictly the sum of all line totals.
- **New / Completed / Cancelled:** Explicit lifecycle states governing when orders are active versus terminally closed.

## Architecture Visualizations

<NodeGraph />

<EntityMap />

### Ordering Context Overview

<LikeC4View viewId="orderingContext" project="ordering" />

### Checkout Handoff & Cleanup Interaction

<MermaidFileLoader file="mermaids/Ordering-diagram-2.mmd" />

## Related Governance & Documentation

- [[system|order-system]] — Authoritative order persistence and [[service|order-api]].
- [[system|finance-system]] — Durable post-checkout workflow and [[service|order-orchestration]].
- [[flow|order-lifecycle]] — Order state transitions and downstream triggers.
- [[flow|user-checkout]] — End-to-end checkout, cleanup, and notification workflow.
- [[diagram|order-lifecycle]] — Order status transition model.
- [[adr|adr-bw-006-service-owned-business-state]] — Service-owned persistence isolation.
- [[adr|adr-bw-008-durable-message-handoffs]] — Durable inbox/outbox message handoffs.
- [[doc|arc42/12-glossary]] — Canonical order, buyer, and lifecycle definitions.
