---
id: order-item
name: Order Item
version: 1.0.0
identifier: id
aggregateRoot: false
summary: Child entity within an Order capturing a purchased book identifier, positive quantity, and locked checkout-time unit price.
owners:
  - commerce-fulfillment-team
badges:
  - content: Child Entity
    backgroundColor: teal
    textColor: teal
properties:
  - name: id
    type: UUID
    required: true
    description: Globally unique UUIDv7 identifier for the order line item.
  - name: orderId
    type: UUID
    required: true
    description: Identifier of the parent Order aggregate.
    references: order
    referencesIdentifier: id
    relationType: belongsTo
  - name: bookId
    type: UUID
    required: true
    description: Cross-context identifier of the Catalog Book purchased on this line.
    references: book
    referencesIdentifier: id
    relationType: references
  - name: quantity
    type: integer
    required: true
    description: Positive number of copies purchased (must be greater than zero).
  - name: price
    type: decimal
    required: true
    description: Non-negative per-unit price locked at checkout time.
---

## Domain Role & Boundary

**Order Item** is a child Entity owned by the [[entity|order]] Aggregate Root in the [[domain|ordering]] bounded context. Persisted by [[service|order-api]], it records a single purchased title, its quantity, and its immutable checkout-time unit price. It explicitly does **not** own live book titles, descriptions, or promotional pricing (owned by [[domain|catalog]] and referenced strictly by `bookId`).

## Entity Profile

| Property                      | Value                                                                                                   |
| :---------------------------- | :------------------------------------------------------------------------------------------------------ |
| **Bounded Context / Domain**  | [[domain\|ordering]]                                                                                    |
| **Owning Service**            | [[service\|order-api]]                                                                                  |
| **DDD Role**                  | Child Entity (owned by [[entity\|order]])                                                               |
| **Identifier Strategy**       | UUIDv7 generated at persistence                                                                         |
| **Persistence Store**         | Ordering relational database (`order_items`)                                                            |
| **Deletion Semantics**        | Cascade-deleted if parent is purged; hidden automatically when parent [[entity\|order]] is soft-deleted |
| **Concurrency Control**       | Governed by parent [[entity\|order]] aggregate concurrency token                                        |
| **PII / Data Classification** | Internal transactional record (non-PII)                                                                 |

## Attributes & Constraints

<EntityPropertiesTable />

| Attribute  | Business Rule / Constraint                                                                 | Sensitivity / Notes        |
| :--------- | :----------------------------------------------------------------------------------------- | :------------------------- |
| `orderId`  | Required foreign key to parent [[entity\|order]].                                          | Aggregate containment      |
| `bookId`   | Required; unique per `(bookId, orderId)` so each book appears at most once per order.      | Cross-context ID reference |
| `quantity` | Required; must be strictly greater than zero (`> 0`).                                      | Domain invariant           |
| `price`    | Required; must be non-negative (`>= 0`), snapshotted from [[domain\|catalog]] at checkout. | Immutable after creation   |

## Domain Invariants & Lifecycle

- **Positive quantity:** Zero or negative item quantities are rejected at creation.
- **Non-negative price snapshot:** Unit prices must be zero or greater and remain immutable even when [[entity|book]] prices later change in [[domain|catalog]].
- **One line per book:** An [[entity|order]] cannot contain duplicate line items for the same `bookId`.
- **Parent visibility coupling:** Order items have no independent lifecycle; soft-deleting the parent [[entity|order]] excludes all of its items from standard queries.

:::note
Order Item calculates its line subtotal (`price * quantity`), which the parent [[entity|order]] sums to derive `totalPrice`.
:::

## Relationships & Associated Operations

| Category                     | Resource                                           | Role / Interaction                                                    |
| :--------------------------- | :------------------------------------------------- | :-------------------------------------------------------------------- |
| **Parent Aggregate**         | [[entity\|order]]                                  | Owned child collection (`orderItems`)                                 |
| **Cross-Context References** | [[entity\|book]]                                   | Referenced strictly by `bookId` (no database foreign key)             |
| **Mutating Commands**        | [[command\|CreateOrder]], [[command\|DeleteOrder]] | Created atomically with the parent order; hidden on order soft-delete |
| **Read Queries**             | [[query\|GetOrder]], [[query\|ListOrders]]         | Included as part of parent order projections                          |
