# rohitbattula/limitorderbook architecture

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

- Interactive diagram: https://gitdiagram.com/rohitbattula/limitorderbook
- Repository: https://github.com/rohitbattula/limitorderbook

## Overview

This C++20 limit order book accepts orders, matches crossing liquidity using price-time priority, records trades, and rests any remaining limit quantity. Its API also supports cancellation, modification, order lookup, best-price and price-level queries. The graph separates the public interface, matching and maintenance operations, and the book’s state. The README and sampled sources support these relationships; benchmark and test infrastructure is omitted because it is not part of the runtime product.

Main entry points: [`src/order_book.cpp`](https://github.com/rohitbattula/limitorderbook/blob/main/src/order_book.cpp) (Order book engine), [`include/order_book.h`](https://github.com/rohitbattula/limitorderbook/blob/main/include/order_book.h) (Bid/ask levels), [`main.cpp`](https://github.com/rohitbattula/limitorderbook/blob/main/main.cpp) (Console demo), [`include/trade.h`](https://github.com/rohitbattula/limitorderbook/blob/main/include/trade.h) (Trade records)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_interface["Runtime interface"]
  node_demo["Console demo<br/>[main.cpp]"]
  node_api["Order book API<br/>[order_book.h]"]
end

subgraph group_operations["Order operations"]
  node_engine["Order book engine<br/>[order_book.cpp]"]
  node_matching["Buy/sell matching<br/>[order_book.cpp]"]
  node_resting["Resting orders<br/>[order_book.cpp]"]
  node_cancel["Cancellation<br/>[order_book.cpp]"]
  node_modify["Order modification<br/>[order_book.cpp]"]
  node_queries["Book queries<br/>[order_book.cpp]"]
end

subgraph group_state["Book state"]
  node_sides[("Bid/ask levels<br/>[order_book.h]")]
  node_lookup[("Order lookup<br/>[order_book.h]")]
  node_order["Order model<br/>[order.h]"]
  node_trade["Trade records<br/>[trade.h]"]
end

node_incoming(("Incoming order"))

node_incoming -->|"submits"| node_engine
node_demo -->|"uses"| node_api
node_demo -->|"submits"| node_engine
node_api -->|"uses"| node_order
node_api -->|"uses"| node_trade
node_engine -->|"dispatches"| node_matching
node_engine -->|"rests remainder"| node_resting
node_matching -->|"matches against"| node_sides
node_matching -->|"updates"| node_lookup
node_matching -->|"records"| node_trade
node_resting -->|"inserts into"| node_sides
node_resting -->|"indexes"| node_lookup
node_engine -->|"supports"| node_cancel
node_engine -->|"supports"| node_modify
node_engine -->|"supports"| node_queries
node_cancel -->|"finds order"| node_lookup
node_cancel -->|"removes order"| node_sides
node_modify -->|"cancels"| node_cancel
node_modify -->|"resubmits"| node_engine
node_queries -->|"reads"| node_sides
node_queries -->|"reads"| node_lookup

click node_demo "https://github.com/rohitbattula/limitorderbook/blob/main/main.cpp"
click node_api "https://github.com/rohitbattula/limitorderbook/blob/main/include/order_book.h"
click node_engine "https://github.com/rohitbattula/limitorderbook/blob/main/src/order_book.cpp"
click node_matching "https://github.com/rohitbattula/limitorderbook/blob/main/src/order_book.cpp"
click node_resting "https://github.com/rohitbattula/limitorderbook/blob/main/src/order_book.cpp"
click node_cancel "https://github.com/rohitbattula/limitorderbook/blob/main/src/order_book.cpp"
click node_modify "https://github.com/rohitbattula/limitorderbook/blob/main/src/order_book.cpp"
click node_queries "https://github.com/rohitbattula/limitorderbook/blob/main/src/order_book.cpp"
click node_sides "https://github.com/rohitbattula/limitorderbook/blob/main/include/order_book.h"
click node_lookup "https://github.com/rohitbattula/limitorderbook/blob/main/include/order_book.h"
click node_order "https://github.com/rohitbattula/limitorderbook/blob/main/include/order.h"
click node_trade "https://github.com/rohitbattula/limitorderbook/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_demo,node_api toneBlue
class node_engine,node_matching,node_resting,node_cancel,node_modify,node_queries toneAmber
class node_sides,node_lookup,node_order,node_trade toneMint
class node_incoming toneIndigo
```

## Components

### Runtime interface

- [Console demo](https://github.com/rohitbattula/limitorderbook/blob/main/main.cpp): `main.cpp`
- [Order book API](https://github.com/rohitbattula/limitorderbook/blob/main/include/order_book.h): `include/order_book.h`

### Order operations

- [Order book engine](https://github.com/rohitbattula/limitorderbook/blob/main/src/order_book.cpp): `src/order_book.cpp`
- [Buy/sell matching](https://github.com/rohitbattula/limitorderbook/blob/main/src/order_book.cpp): `src/order_book.cpp`
- [Resting orders](https://github.com/rohitbattula/limitorderbook/blob/main/src/order_book.cpp): `src/order_book.cpp`
- [Cancellation](https://github.com/rohitbattula/limitorderbook/blob/main/src/order_book.cpp): `src/order_book.cpp`
- [Order modification](https://github.com/rohitbattula/limitorderbook/blob/main/src/order_book.cpp): `src/order_book.cpp`
- [Book queries](https://github.com/rohitbattula/limitorderbook/blob/main/src/order_book.cpp): `src/order_book.cpp`

### Book state

- [Bid/ask levels](https://github.com/rohitbattula/limitorderbook/blob/main/include/order_book.h): `include/order_book.h`
- [Order lookup](https://github.com/rohitbattula/limitorderbook/blob/main/include/order_book.h): `include/order_book.h`
- [Order model](https://github.com/rohitbattula/limitorderbook/blob/main/include/order.h): `include/order.h`
- [Trade records](https://github.com/rohitbattula/limitorderbook/blob/main/include/trade.h): `include/trade.h`

### Other components

- **Incoming order**

## Connections

- Incoming order → Order book engine: submits (evidence: `README.md`)
- Console demo → Order book API: uses (evidence: `main.cpp`)
- Console demo → Order book engine: submits (evidence: `main.cpp`)
- Order book API → Order model: uses (evidence: `include/order_book.h`)
- Order book API → Trade records: uses (evidence: `include/order_book.h`)
- Order book engine → Buy/sell matching: dispatches (evidence: `src/order_book.cpp`)
- Order book engine → Resting orders: rests remainder (evidence: `src/order_book.cpp`)
- Buy/sell matching → Bid/ask levels: matches against (evidence: `src/order_book.cpp`)
- Buy/sell matching → Order lookup: updates (evidence: `src/order_book.cpp`)
- Buy/sell matching → Trade records: records (evidence: `src/order_book.cpp`)
- Resting orders → Bid/ask levels: inserts into (evidence: `src/order_book.cpp`)
- Resting orders → Order lookup: indexes (evidence: `src/order_book.cpp`)
- Order book engine → Cancellation: supports (evidence: `src/order_book.cpp`)
- Order book engine → Order modification: supports (evidence: `src/order_book.cpp`)
- Order book engine → Book queries: supports (evidence: `src/order_book.cpp`)
- Cancellation → Order lookup: finds order (evidence: `src/order_book.cpp`)
- Cancellation → Bid/ask levels: removes order (evidence: `src/order_book.cpp`)
- Order modification → Cancellation: cancels (evidence: `src/order_book.cpp`)
- Order modification → Order book engine: resubmits (evidence: `src/order_book.cpp`)
- Book queries → Bid/ask levels: reads (evidence: `src/order_book.cpp`)
- Book queries → Order lookup: reads (evidence: `src/order_book.cpp`)
