validate_order_status (scenarios/ecommerce.py)

ai-agent-book · chapter5/permission-embedded-data-objects/pedo/scenarios/ecommerce.py · python · Apache-2.0
pos

Case study: E-commerce orders. Architectural pattern demonstrated: **compound state machine + reactions**. An order moves through cart -> placed -> paid -> shipped -> delivered, with refund inverting the state from delivered back to refunded. Each transition has invariants (place

# Source: https://github.com/bojieli/ai-agent-book | License: Apache-2.0 | Copyright You must retain, in the Source form of any Derivative Works
# Provided via justclaw.it.com; keep this notice with the code.
"""Case study: E-commerce orders.

Architectural pattern demonstrated: **compound state machine + reactions**.
An order moves through cart -> placed -> paid -> shipped -> delivered, with
refund inverting the state from delivered back to refunded. Each transition
has invariants (placed orders cannot be modified; only paid orders can ship).
The state-machine validator + reactions handle the bookkeeping; the handler
just describes the user intent (place / pay / ship / refund).

Object types: customer, product, order, order_item, audit_log
Key invariants:
  - order status follows: cart ->

... (truncated -- full source via MCP)

See the full source, get the GitHub permalink, and search for more like it.

Get a free API key