# switchboard-risk/small-order architecture

> Architecture diagram of the GitHub repository switchboard-risk/small-order, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-09). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/switchboard-risk/small-order
- Repository: https://github.com/switchboard-risk/small-order

## Overview

tiny-orders is a Ruby order-management app: users create orders, add catalog products, and move orders through submission, payment, fulfillment, or cancellation. The service coordinates the order state machine, inventory rules, and persistence; repositories map domain objects to SQLite. The README documents the CLI workflow and persistent database. Source excerpts show the service and repository calls; cancellation’s effect on reserved inventory is not established by the excerpt, so that relationship is omitted.

Main entry points: [`lib/order_service.rb`](https://github.com/switchboard-risk/small-order/blob/main/lib/order_service.rb) (Order service), [`lib/order_repository.rb`](https://github.com/switchboard-risk/small-order/blob/main/lib/order_repository.rb) (Order repository), [`lib/db.rb`](https://github.com/switchboard-risk/small-order/blob/main/lib/db.rb) (Database setup), [`lib/product_repository.rb`](https://github.com/switchboard-risk/small-order/blob/main/lib/product_repository.rb) (Product repository)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_entry["CLI entry"]
  node_cli["Orders CLI"]
end

subgraph group_coordination["Order coordination"]
  node_service["Order service<br/>[order_service.rb]"]
end

subgraph group_domain["Order and inventory domain"]
  node_order["Order state machine<br/>[order.rb]"]
  node_line_item["Line item<br/>[line_item.rb]"]
  node_product["Catalog product<br/>[product.rb]"]
  node_transition_error["Transition error"]
  node_stock_error["Stock error"]
end

subgraph group_persistence["SQLite persistence"]
  node_order_repo["Order repository"]
  node_product_repo["Product repository"]
  node_db["Database setup<br/>[db.rb]"]
  node_sqlite[("Orders database<br/>[orders.sqlite3]")]
end

node_user(("CLI user"))

node_user -->|"runs commands"| node_cli
node_cli -->|"requests operations"| node_service
node_service -->|"loads and saves"| node_order_repo
node_service -->|"looks up and saves"| node_product_repo
node_service -->|"changes state"| node_order
node_service -->|"creates items"| node_line_item
node_service -->|"adjusts inventory"| node_product
node_order -->|"raises on invalid state"| node_transition_error
node_product -->|"raises on short stock"| node_stock_error
node_order_repo -->|"reconstructs orders"| node_order
node_order_repo -->|"loads and saves items"| node_line_item
node_product_repo -->|"maps products"| node_product
node_order_repo -->|"executes SQL"| node_db
node_product_repo -->|"executes SQL"| node_db
node_service -->|"wraps transactions"| node_db
node_db -->|"persists records"| node_sqlite

click node_cli "https://github.com/switchboard-risk/small-order/blob/main/bin/orders"
click node_service "https://github.com/switchboard-risk/small-order/blob/main/lib/order_service.rb"
click node_order_repo "https://github.com/switchboard-risk/small-order/blob/main/lib/order_repository.rb"
click node_product_repo "https://github.com/switchboard-risk/small-order/blob/main/lib/product_repository.rb"
click node_order "https://github.com/switchboard-risk/small-order/blob/main/lib/order.rb"
click node_line_item "https://github.com/switchboard-risk/small-order/blob/main/lib/line_item.rb"
click node_product "https://github.com/switchboard-risk/small-order/blob/main/lib/product.rb"
click node_transition_error "https://github.com/switchboard-risk/small-order/blob/main/lib/illegal_transition.rb"
click node_stock_error "https://github.com/switchboard-risk/small-order/blob/main/lib/insufficient_stock.rb"
click node_db "https://github.com/switchboard-risk/small-order/blob/main/lib/db.rb"
click node_sqlite "https://github.com/switchboard-risk/small-order/blob/main/db/orders.sqlite3"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_cli,node_user toneBlue
class node_service toneAmber
class node_order,node_line_item,node_product,node_transition_error,node_stock_error toneMint
class node_order_repo,node_product_repo,node_db,node_sqlite toneRose
```

## Components

### CLI entry

- [Orders CLI](https://github.com/switchboard-risk/small-order/blob/main/bin/orders): `bin/orders`

### Order coordination

- [Order service](https://github.com/switchboard-risk/small-order/blob/main/lib/order_service.rb): `lib/order_service.rb`

### Order and inventory domain

- [Order state machine](https://github.com/switchboard-risk/small-order/blob/main/lib/order.rb): `lib/order.rb`
- [Line item](https://github.com/switchboard-risk/small-order/blob/main/lib/line_item.rb): `lib/line_item.rb`
- [Catalog product](https://github.com/switchboard-risk/small-order/blob/main/lib/product.rb): `lib/product.rb`
- [Transition error](https://github.com/switchboard-risk/small-order/blob/main/lib/illegal_transition.rb): `lib/illegal_transition.rb`
- [Stock error](https://github.com/switchboard-risk/small-order/blob/main/lib/insufficient_stock.rb): `lib/insufficient_stock.rb`

### SQLite persistence

- [Order repository](https://github.com/switchboard-risk/small-order/blob/main/lib/order_repository.rb): `lib/order_repository.rb`
- [Product repository](https://github.com/switchboard-risk/small-order/blob/main/lib/product_repository.rb): `lib/product_repository.rb`
- [Database setup](https://github.com/switchboard-risk/small-order/blob/main/lib/db.rb): `lib/db.rb`
- [Orders database](https://github.com/switchboard-risk/small-order/blob/main/db/orders.sqlite3): `db/orders.sqlite3`

### Other components

- **CLI user**

## Connections

- CLI user → Orders CLI: runs commands (evidence: `README.md`)
- Orders CLI → Order service: requests operations (evidence: `README.md`)
- Order service → Order repository: loads and saves (evidence: `lib/order_service.rb`)
- Order service → Product repository: looks up and saves (evidence: `lib/order_service.rb`)
- Order service → Order state machine: changes state (evidence: `lib/order_service.rb`)
- Order service → Line item: creates items (evidence: `lib/order_service.rb`)
- Order service → Catalog product: adjusts inventory (evidence: `lib/order_service.rb`)
- Order state machine → Transition error: raises on invalid state (evidence: `lib/order.rb`)
- Catalog product → Stock error: raises on short stock (evidence: `lib/product.rb`)
- Order repository → Order state machine: reconstructs orders (evidence: `lib/order_repository.rb`)
- Order repository → Line item: loads and saves items (evidence: `lib/order_repository.rb`)
- Product repository → Catalog product: maps products (evidence: `lib/product_repository.rb`)
- Order repository → Database setup: executes SQL (evidence: `lib/order_repository.rb`)
- Product repository → Database setup: executes SQL (evidence: `lib/product_repository.rb`)
- Order service → Database setup: wraps transactions (evidence: `lib/order_service.rb`)
- Database setup → Orders database: persists records (evidence: `README.md`)
