# samridhirastogi/order-matching-engine architecture

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

- Interactive diagram: https://gitdiagram.com/samridhirastogi/order-matching-engine
- Repository: https://github.com/samridhirastogi/order-matching-engine

## Overview

This is a C++ limit-order-matching engine. The executable creates a Book and sends order-command files through OrderPipeline, which dispatches market, limit, stop, and stop-limit operations to the book. The book maintains price levels and orders, with matching and AVL-tree balancing implemented in its core. Order generation can create sample command files; processing also writes timing and balance metrics, and the repository includes a visualization script. The visualization script’s data dependency is not established by the shown source, so that connection is omitted.

Main entry points: [`limit-order-book-main/Process_Orders/OrderPipeline.cpp`](https://github.com/samridhirastogi/order-matching-engine/blob/main/limit-order-book-main/Process_Orders/OrderPipeline.cpp) (Order dispatcher), [`limit-order-book-main/Limit_Order_Book/Book.cpp`](https://github.com/samridhirastogi/order-matching-engine/blob/main/limit-order-book-main/Limit_Order_Book/Book.cpp) (Order book), [`limit-order-book-main/Limit_Order_Book/Limit.cpp`](https://github.com/samridhirastogi/order-matching-engine/blob/main/limit-order-book-main/Limit_Order_Book/Limit.cpp) (Price levels), [`limit-order-book-main/Limit_Order_Book/Order.cpp`](https://github.com/samridhirastogi/order-matching-engine/blob/main/limit-order-book-main/Limit_Order_Book/Order.cpp) (Order records)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_runtime["Order processing"]
  node_main["Executable entry<br/>[main.cpp]"]
  node_pipeline["Order dispatcher<br/>[OrderPipeline.cpp]"]
end

subgraph group_engine["Matching engine"]
  node_book["Order book<br/>[Book.cpp]"]
  node_limit["Price levels<br/>[Limit.cpp]"]
  node_order["Order records<br/>[Order.cpp]"]
end

subgraph group_generation["Order generation"]
  node_generator["Order generator<br/>[GenerateOrders.cpp]"]
  node_initialorders["Initial orders<br/>[initialOrders.txt]"]
end

subgraph group_analytics["Performance analysis"]
  node_metrics["Processing metrics CSV"]
  node_visualizer["Metrics visualization"]
end

node_operator(("Operator"))
node_orderfiles["Order command files"]

node_operator -->|"starts"| node_main
node_main -->|"processes commands"| node_pipeline
node_pipeline -->|"reads"| node_orderfiles
node_pipeline -->|"dispatches orders"| node_book
node_pipeline -->|"writes timings"| node_metrics
node_book -->|"manages levels"| node_limit
node_book -->|"creates and matches"| node_order
node_limit -->|"queues orders"| node_order
node_order -->|"updates parent level"| node_limit
node_generator -->|"queries and mutates"| node_book
node_generator -->|"writes commands"| node_initialorders

click node_main "https://github.com/samridhirastogi/order-matching-engine/blob/main/limit-order-book-main/main.cpp"
click node_pipeline "https://github.com/samridhirastogi/order-matching-engine/blob/main/limit-order-book-main/Process_Orders/OrderPipeline.cpp"
click node_metrics "https://github.com/samridhirastogi/order-matching-engine/blob/main/limit-order-book-main/Process_Orders/order_processing_times.csv"
click node_book "https://github.com/samridhirastogi/order-matching-engine/blob/main/limit-order-book-main/Limit_Order_Book/Book.cpp"
click node_limit "https://github.com/samridhirastogi/order-matching-engine/blob/main/limit-order-book-main/Limit_Order_Book/Limit.cpp"
click node_order "https://github.com/samridhirastogi/order-matching-engine/blob/main/limit-order-book-main/Limit_Order_Book/Order.cpp"
click node_generator "https://github.com/samridhirastogi/order-matching-engine/blob/main/limit-order-book-main/Generate_Orders/GenerateOrders.cpp"
click node_initialorders "https://github.com/samridhirastogi/order-matching-engine/blob/main/limit-order-book-main/Generate_Orders/initialOrders.txt"
click node_visualizer "https://github.com/samridhirastogi/order-matching-engine/blob/main/limit-order-book-main/Process_Orders/data_visualisation.py"

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_main,node_pipeline toneBlue
class node_book,node_limit,node_order toneAmber
class node_generator,node_initialorders toneMint
class node_metrics,node_visualizer toneRose
class node_operator,node_orderfiles toneIndigo
```

## Components

### Order processing

- [Executable entry](https://github.com/samridhirastogi/order-matching-engine/blob/main/limit-order-book-main/main.cpp): `limit-order-book-main/main.cpp`
- [Order dispatcher](https://github.com/samridhirastogi/order-matching-engine/blob/main/limit-order-book-main/Process_Orders/OrderPipeline.cpp): `limit-order-book-main/Process_Orders/OrderPipeline.cpp`

### Matching engine

- [Order book](https://github.com/samridhirastogi/order-matching-engine/blob/main/limit-order-book-main/Limit_Order_Book/Book.cpp): `limit-order-book-main/Limit_Order_Book/Book.cpp`
- [Price levels](https://github.com/samridhirastogi/order-matching-engine/blob/main/limit-order-book-main/Limit_Order_Book/Limit.cpp): `limit-order-book-main/Limit_Order_Book/Limit.cpp`
- [Order records](https://github.com/samridhirastogi/order-matching-engine/blob/main/limit-order-book-main/Limit_Order_Book/Order.cpp): `limit-order-book-main/Limit_Order_Book/Order.cpp`

### Order generation

- [Order generator](https://github.com/samridhirastogi/order-matching-engine/blob/main/limit-order-book-main/Generate_Orders/GenerateOrders.cpp): `limit-order-book-main/Generate_Orders/GenerateOrders.cpp`
- [Initial orders](https://github.com/samridhirastogi/order-matching-engine/blob/main/limit-order-book-main/Generate_Orders/initialOrders.txt): `limit-order-book-main/Generate_Orders/initialOrders.txt`

### Performance analysis

- [Processing metrics CSV](https://github.com/samridhirastogi/order-matching-engine/blob/main/limit-order-book-main/Process_Orders/order_processing_times.csv): `limit-order-book-main/Process_Orders/order_processing_times.csv`
- [Metrics visualization](https://github.com/samridhirastogi/order-matching-engine/blob/main/limit-order-book-main/Process_Orders/data_visualisation.py): `limit-order-book-main/Process_Orders/data_visualisation.py`

### Other components

- **Operator**
- **Order command files**

## Connections

- Operator → Executable entry: starts (evidence: `limit-order-book-main/main.cpp`)
- Executable entry → Order dispatcher: processes commands (evidence: `limit-order-book-main/main.cpp`)
- Order dispatcher → Order command files: reads (evidence: `limit-order-book-main/Process_Orders/OrderPipeline.cpp`)
- Order dispatcher → Order book: dispatches orders (evidence: `limit-order-book-main/Process_Orders/OrderPipeline.cpp`)
- Order dispatcher → Processing metrics CSV: writes timings (evidence: `limit-order-book-main/Process_Orders/OrderPipeline.cpp`)
- Order book → Price levels: manages levels (evidence: `limit-order-book-main/Limit_Order_Book/Book.cpp`)
- Order book → Order records: creates and matches (evidence: `limit-order-book-main/Limit_Order_Book/Book.cpp`)
- Price levels → Order records: queues orders (evidence: `limit-order-book-main/Limit_Order_Book/Limit.cpp`)
- Order records → Price levels: updates parent level (evidence: `limit-order-book-main/Limit_Order_Book/Order.cpp`)
- Order generator → Order book: queries and mutates (evidence: `limit-order-book-main/Generate_Orders/GenerateOrders.cpp`)
- Order generator → Initial orders: writes commands (evidence: `limit-order-book-main/Generate_Orders/GenerateOrders.cpp`)
