# ad-kat/limit-order-book-and-matching-engine architecture

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

- Interactive diagram: https://gitdiagram.com/ad-kat/limit-order-book-and-matching-engine
- Repository: https://github.com/ad-kat/limit-order-book-and-matching-engine

## Overview

The product is a C++ price-time-priority limit order book and matching engine, with a FastAPI bridge and live React demo. A typical flow is market-feed data or an order request entering the API, passing through the serialized subprocess bridge to the C++ engine, then returning book/trade events over WebSockets to the dashboard. The README also documents periodic LLM commentary and a fallback chain. Relationships for unsampled subsystems are included only where the README describes them; this is not a claim that their source was inspected.

Main entry points: [`api/main.py`](https://github.com/ad-kat/limit-order-book-and-matching-engine/blob/main/api/main.py) (REST and WS routes), [`lob-dashboard/src/App.jsx`](https://github.com/ad-kat/limit-order-book-and-matching-engine/blob/main/lob-dashboard/src/App.jsx) (Dashboard app), [`src/main.cpp`](https://github.com/ad-kat/limit-order-book-and-matching-engine/blob/main/src/main.cpp) (Interactive engine), [`market_feed.py`](https://github.com/ad-kat/limit-order-book-and-matching-engine/blob/main/market_feed.py) (Market feed)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_engine["Matching engine"]
  node_cli["Interactive engine<br/>[main.cpp]"]
  node_book["Order book<br/>[order_book.cpp]"]
end

subgraph group_api["API and feed"]
  node_feed["Market feed<br/>[market_feed.py]"]
  node_routes["REST and WS routes<br/>[main.py]"]
  node_bridge["Subprocess bridge<br/>[engine.py]"]
  node_models["API models<br/>[models.py]"]
  node_broadcast["WS broadcast<br/>[ws_manager.py]"]
end

subgraph group_live["Live commentary"]
  node_commentary["Commentary agent<br/>[commentary.py]"]
end

subgraph group_ui["Dashboard"]
  node_hook["Live data hook<br/>[useLOB.js]"]
  node_app["Dashboard app<br/>[App.jsx]"]
  node_stats["Stats panel<br/>[StatsBar.jsx]"]
  node_orderbookview["Book view<br/>[OrderBook.jsx]"]
  node_tape["Trade tape<br/>[TradeTape.jsx]"]
  node_commentview["Commentary view<br/>[Commentary.jsx]"]
end

node_user(("Order client"))
node_marketdata(("Market data"))
node_llm["LLM providers"]

node_user -->|"submits orders"| node_routes
node_marketdata -->|"supplies ticks"| node_feed
node_feed -->|"posts orders"| node_routes
node_routes -->|"dispatches orders"| node_bridge
node_routes -->|"uses schemas"| node_models
node_bridge -->|"pipes commands"| node_cli
node_cli -->|"invokes matching"| node_book
node_routes -->|"broadcasts events"| node_broadcast
node_routes -->|"requests narration"| node_commentary
node_commentary -->|"requests narration"| node_llm
node_broadcast -->|"sends WebSocket events"| node_hook
node_hook -->|"provides live state"| node_app
node_app -->|"renders"| node_stats
node_app -->|"renders"| node_orderbookview
node_app -->|"renders"| node_tape
node_app -->|"renders"| node_commentview

click node_feed "https://github.com/ad-kat/limit-order-book-and-matching-engine/blob/main/market_feed.py"
click node_routes "https://github.com/ad-kat/limit-order-book-and-matching-engine/blob/main/api/main.py"
click node_bridge "https://github.com/ad-kat/limit-order-book-and-matching-engine/blob/main/api/engine.py"
click node_models "https://github.com/ad-kat/limit-order-book-and-matching-engine/blob/main/api/models.py"
click node_broadcast "https://github.com/ad-kat/limit-order-book-and-matching-engine/blob/main/api/ws_manager.py"
click node_cli "https://github.com/ad-kat/limit-order-book-and-matching-engine/blob/main/src/main.cpp"
click node_book "https://github.com/ad-kat/limit-order-book-and-matching-engine/blob/main/src/order_book.cpp"
click node_commentary "https://github.com/ad-kat/limit-order-book-and-matching-engine/blob/main/api/commentary.py"
click node_hook "https://github.com/ad-kat/limit-order-book-and-matching-engine/blob/main/lob-dashboard/src/hooks/useLOB.js"
click node_app "https://github.com/ad-kat/limit-order-book-and-matching-engine/blob/main/lob-dashboard/src/App.jsx"
click node_stats "https://github.com/ad-kat/limit-order-book-and-matching-engine/blob/main/lob-dashboard/src/components/StatsBar.jsx"
click node_orderbookview "https://github.com/ad-kat/limit-order-book-and-matching-engine/blob/main/lob-dashboard/src/components/OrderBook.jsx"
click node_tape "https://github.com/ad-kat/limit-order-book-and-matching-engine/blob/main/lob-dashboard/src/components/TradeTape.jsx"
click node_commentview "https://github.com/ad-kat/limit-order-book-and-matching-engine/blob/main/lob-dashboard/src/components/Commentary.jsx"

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_book,node_user toneBlue
class node_feed,node_routes,node_bridge,node_models,node_broadcast toneAmber
class node_commentary toneMint
class node_hook,node_app,node_stats,node_orderbookview,node_tape,node_commentview toneRose
class node_marketdata,node_llm toneIndigo
```

## Components

### Matching engine

- [Interactive engine](https://github.com/ad-kat/limit-order-book-and-matching-engine/blob/main/src/main.cpp): `src/main.cpp`
- [Order book](https://github.com/ad-kat/limit-order-book-and-matching-engine/blob/main/src/order_book.cpp): `src/order_book.cpp`

### API and feed

- [Market feed](https://github.com/ad-kat/limit-order-book-and-matching-engine/blob/main/market_feed.py): `market_feed.py`
- [REST and WS routes](https://github.com/ad-kat/limit-order-book-and-matching-engine/blob/main/api/main.py): `api/main.py`
- [Subprocess bridge](https://github.com/ad-kat/limit-order-book-and-matching-engine/blob/main/api/engine.py): `api/engine.py`
- [API models](https://github.com/ad-kat/limit-order-book-and-matching-engine/blob/main/api/models.py): `api/models.py`
- [WS broadcast](https://github.com/ad-kat/limit-order-book-and-matching-engine/blob/main/api/ws_manager.py): `api/ws_manager.py`

### Live commentary

- [Commentary agent](https://github.com/ad-kat/limit-order-book-and-matching-engine/blob/main/api/commentary.py): `api/commentary.py`

### Dashboard

- [Live data hook](https://github.com/ad-kat/limit-order-book-and-matching-engine/blob/main/lob-dashboard/src/hooks/useLOB.js): `lob-dashboard/src/hooks/useLOB.js`
- [Dashboard app](https://github.com/ad-kat/limit-order-book-and-matching-engine/blob/main/lob-dashboard/src/App.jsx): `lob-dashboard/src/App.jsx`
- [Stats panel](https://github.com/ad-kat/limit-order-book-and-matching-engine/blob/main/lob-dashboard/src/components/StatsBar.jsx): `lob-dashboard/src/components/StatsBar.jsx`
- [Book view](https://github.com/ad-kat/limit-order-book-and-matching-engine/blob/main/lob-dashboard/src/components/OrderBook.jsx): `lob-dashboard/src/components/OrderBook.jsx`
- [Trade tape](https://github.com/ad-kat/limit-order-book-and-matching-engine/blob/main/lob-dashboard/src/components/TradeTape.jsx): `lob-dashboard/src/components/TradeTape.jsx`
- [Commentary view](https://github.com/ad-kat/limit-order-book-and-matching-engine/blob/main/lob-dashboard/src/components/Commentary.jsx): `lob-dashboard/src/components/Commentary.jsx`

### Other components

- **Order client**
- **Market data**
- **LLM providers**

## Connections

- Order client → REST and WS routes: submits orders
- Market data → Market feed: supplies ticks
- Market feed → REST and WS routes: posts orders
- REST and WS routes → Subprocess bridge: dispatches orders (evidence: `api/main.py`)
- REST and WS routes → API models: uses schemas (evidence: `api/main.py`)
- Subprocess bridge → Interactive engine: pipes commands
- Interactive engine → Order book: invokes matching (evidence: `src/main.cpp`)
- REST and WS routes → WS broadcast: broadcasts events (evidence: `api/main.py`)
- REST and WS routes → Commentary agent: requests narration (evidence: `api/main.py`)
- Commentary agent → LLM providers: requests narration
- WS broadcast → Live data hook: sends WebSocket events
- Live data hook → Dashboard app: provides live state (evidence: `lob-dashboard/src/App.jsx`)
- Dashboard app → Stats panel: renders (evidence: `lob-dashboard/src/App.jsx`)
- Dashboard app → Book view: renders (evidence: `lob-dashboard/src/App.jsx`)
- Dashboard app → Trade tape: renders (evidence: `lob-dashboard/src/App.jsx`)
- Dashboard app → Commentary view: renders (evidence: `lob-dashboard/src/App.jsx`)
