# bozoslav/order-book architecture

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

- Interactive diagram: https://gitdiagram.com/bozoslav/order-book
- Repository: https://github.com/bozoslav/order-book

## Overview

This is a C++ price-time-priority matching engine for exchange simulations. A caller submits orders to the order book; the engine checks FOK fillability when requested, matches eligible opposing orders, records trades, and rests any remaining GTC quantity. It also supports cancellation, modification, and book printing. The map separates matching and lifecycle stages from the price-level and order-storage structures. Evidence is limited to the README and sampled headers/source; no external exchange integration or runtime service is shown.

Main entry points: [`src/OrderBook.cpp`](https://github.com/bozoslav/order-book/blob/main/src/OrderBook.cpp) (Order Processing), [`include/OrderPool.h`](https://github.com/bozoslav/order-book/blob/main/include/OrderPool.h) (Order Pool), [`include/PriceArray.h`](https://github.com/bozoslav/order-book/blob/main/include/PriceArray.h) (Price Levels), [`include/OrderBook.h`](https://github.com/bozoslav/order-book/blob/main/include/OrderBook.h) (Order Book API)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_matching["Matching Engine"]
  node_book["Order Book API<br/>[OrderBook.h]"]
  node_engine["Order Processing<br/>[OrderBook.cpp]"]
  node_fok["FOK Check<br/>[OrderBook.cpp]"]
  node_matching_stage["Price-Time Matching<br/>[OrderBook.cpp]"]
  node_resting["GTC Resting<br/>[OrderBook.cpp]"]
  node_lifecycle["Cancel / Modify<br/>[OrderBook.cpp]"]
  node_display["Book Display<br/>[OrderBook.cpp]"]
end

subgraph group_storage["Book Storage"]
  node_levels["Price Levels<br/>[PriceArray.h]"]
  node_fifo["FIFO Queues<br/>[OrderQueue.h]"]
  node_pool[("Order Pool<br/>[OrderPool.h]")]
end

subgraph group_domain["Order Data"]
  node_order["Order Record<br/>[Order.h]"]
  node_price["Price Value<br/>[Price.h]"]
  node_trade["Trade Record<br/>[Trade.h]"]
end

node_caller(("Trading Caller"))

node_caller -->|"submits orders"| node_book
node_book -->|"declares operations"| node_engine
node_engine -->|"checks FOK"| node_fok
node_engine -->|"matches orders"| node_matching_stage
node_engine -->|"rests GTC remainder"| node_resting
node_engine -->|"cancels or modifies"| node_lifecycle
node_engine -->|"prints book"| node_display
node_engine -->|"reads and updates"| node_levels
node_engine -->|"allocates and releases"| node_pool
node_engine -->|"emits trades"| node_trade
node_levels -->|"maintains levels"| node_fifo
node_levels -->|"reads order nodes"| node_pool
node_fifo -->|"links pooled nodes"| node_pool
node_pool -->|"stores orders"| node_order
node_order -->|"contains price"| node_price
node_trade -->|"contains price"| node_price

click node_book "https://github.com/bozoslav/order-book/blob/main/include/OrderBook.h"
click node_engine "https://github.com/bozoslav/order-book/blob/main/src/OrderBook.cpp"
click node_fok "https://github.com/bozoslav/order-book/blob/main/src/OrderBook.cpp"
click node_matching_stage "https://github.com/bozoslav/order-book/blob/main/src/OrderBook.cpp"
click node_resting "https://github.com/bozoslav/order-book/blob/main/src/OrderBook.cpp"
click node_lifecycle "https://github.com/bozoslav/order-book/blob/main/src/OrderBook.cpp"
click node_display "https://github.com/bozoslav/order-book/blob/main/src/OrderBook.cpp"
click node_levels "https://github.com/bozoslav/order-book/blob/main/include/PriceArray.h"
click node_fifo "https://github.com/bozoslav/order-book/blob/main/include/OrderQueue.h"
click node_pool "https://github.com/bozoslav/order-book/blob/main/include/OrderPool.h"
click node_order "https://github.com/bozoslav/order-book/blob/main/include/Order.h"
click node_price "https://github.com/bozoslav/order-book/blob/main/include/Price.h"
click node_trade "https://github.com/bozoslav/order-book/blob/main/include/Trade.h"

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_book,node_engine,node_fok,node_matching_stage,node_resting,node_lifecycle,node_display toneBlue
class node_levels,node_fifo,node_pool toneAmber
class node_order,node_price,node_trade toneMint
class node_caller toneIndigo
```

## Components

### Matching Engine

- [Order Book API](https://github.com/bozoslav/order-book/blob/main/include/OrderBook.h): `include/OrderBook.h`
- [Order Processing](https://github.com/bozoslav/order-book/blob/main/src/OrderBook.cpp): `src/OrderBook.cpp`
- [FOK Check](https://github.com/bozoslav/order-book/blob/main/src/OrderBook.cpp): `src/OrderBook.cpp`
- [Price-Time Matching](https://github.com/bozoslav/order-book/blob/main/src/OrderBook.cpp): `src/OrderBook.cpp`
- [GTC Resting](https://github.com/bozoslav/order-book/blob/main/src/OrderBook.cpp): `src/OrderBook.cpp`
- [Cancel / Modify](https://github.com/bozoslav/order-book/blob/main/src/OrderBook.cpp): `src/OrderBook.cpp`
- [Book Display](https://github.com/bozoslav/order-book/blob/main/src/OrderBook.cpp): `src/OrderBook.cpp`

### Book Storage

- [Price Levels](https://github.com/bozoslav/order-book/blob/main/include/PriceArray.h): `include/PriceArray.h`
- [FIFO Queues](https://github.com/bozoslav/order-book/blob/main/include/OrderQueue.h): `include/OrderQueue.h`
- [Order Pool](https://github.com/bozoslav/order-book/blob/main/include/OrderPool.h): `include/OrderPool.h`

### Order Data

- [Order Record](https://github.com/bozoslav/order-book/blob/main/include/Order.h): `include/Order.h`
- [Price Value](https://github.com/bozoslav/order-book/blob/main/include/Price.h): `include/Price.h`
- [Trade Record](https://github.com/bozoslav/order-book/blob/main/include/Trade.h): `include/Trade.h`

### Other components

- **Trading Caller**

## Connections

- Trading Caller → Order Book API: submits orders (evidence: `README.md`)
- Order Book API → Order Processing: declares operations (evidence: `include/OrderBook.h`)
- Order Processing → FOK Check: checks FOK (evidence: `src/OrderBook.cpp`)
- Order Processing → Price-Time Matching: matches orders (evidence: `src/OrderBook.cpp`)
- Order Processing → GTC Resting: rests GTC remainder (evidence: `src/OrderBook.cpp`)
- Order Processing → Cancel / Modify: cancels or modifies (evidence: `src/OrderBook.cpp`)
- Order Processing → Book Display: prints book (evidence: `src/OrderBook.cpp`)
- Order Processing → Price Levels: reads and updates (evidence: `src/OrderBook.cpp`)
- Order Processing → Order Pool: allocates and releases (evidence: `src/OrderBook.cpp`)
- Order Processing → Trade Record: emits trades (evidence: `src/OrderBook.cpp`)
- Price Levels → FIFO Queues: maintains levels (evidence: `include/PriceArray.h`)
- Price Levels → Order Pool: reads order nodes (evidence: `include/PriceArray.h`)
- FIFO Queues → Order Pool: links pooled nodes (evidence: `include/OrderQueue.h`)
- Order Pool → Order Record: stores orders (evidence: `include/OrderPool.h`)
- Order Record → Price Value: contains price (evidence: `include/Order.h`)
- Trade Record → Price Value: contains price (evidence: `include/Trade.h`)
