# programmeradi-369/low-latency-order-matching-engine architecture

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

- Interactive diagram: https://gitdiagram.com/programmeradi-369/low-latency-order-matching-engine
- Repository: https://github.com/programmeradi-369/low-latency-order-matching-engine

## Overview

This C++ order-matching engine accepts limit and market orders, validates their IDs and quantities, matches incoming orders by price-time priority, and retains unfilled limit orders in the book. Its executable demonstrates cancellation, partial and cascading fills, then reports latency and throughput; trade records can also be exported as CSV. The graph follows the documented API and sampled calls. TradeLogger implementation was not sampled, so its internal storage and CSV-writing details are represented only at the documented interface level.

Main entry points: [`src/main.cpp`](https://github.com/programmeradi-369/low-latency-order-matching-engine/blob/main/src/main.cpp) (Scenario runner), [`src/MatchingEngine.cpp`](https://github.com/programmeradi-369/low-latency-order-matching-engine/blob/main/src/MatchingEngine.cpp) (Matching engine), [`include/TradeLogger.h`](https://github.com/programmeradi-369/low-latency-order-matching-engine/blob/main/include/TradeLogger.h) (Trade logger), [`src/OrderManager.cpp`](https://github.com/programmeradi-369/low-latency-order-matching-engine/blob/main/src/OrderManager.cpp) (Order validation)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_orchestration["Runtime orchestration"]
  node_main["Scenario runner<br/>[main.cpp]"]
  node_manager["Order validation<br/>[OrderManager.cpp]"]
  node_order["Order model<br/>[Order.h]"]
end

subgraph group_matching["Order matching"]
  node_engine["Matching engine<br/>[MatchingEngine.cpp]"]
  node_book[("Price-level book<br/>[OrderBook.cpp]")]
end

subgraph group_outputs["Trade and metrics"]
  node_trade["Trade record<br/>[Trade.h]"]
  node_logger["Trade logger<br/>[TradeLogger.h]"]
  node_csv["CSV export<br/>[trades.csv]"]
  node_performance["Performance analytics"]
end

node_user(("Operator"))

node_user -->|"runs scenarios"| node_main
node_main -->|"creates orders"| node_manager
node_manager -->|"constructs"| node_order
node_main -->|"submits orders"| node_engine
node_engine -->|"reads and updates"| node_book
node_engine -->|"records trades"| node_logger
node_engine -->|"creates records"| node_trade
node_main -->|"cancels orders"| node_engine
node_main -->|"prints book"| node_book
node_main -->|"prints and exports"| node_logger
node_logger -->|"exports CSV"| node_csv
node_main -->|"records latency"| node_performance

click node_main "https://github.com/programmeradi-369/low-latency-order-matching-engine/blob/main/src/main.cpp"
click node_manager "https://github.com/programmeradi-369/low-latency-order-matching-engine/blob/main/src/OrderManager.cpp"
click node_order "https://github.com/programmeradi-369/low-latency-order-matching-engine/blob/main/include/Order.h"
click node_engine "https://github.com/programmeradi-369/low-latency-order-matching-engine/blob/main/src/MatchingEngine.cpp"
click node_book "https://github.com/programmeradi-369/low-latency-order-matching-engine/blob/main/src/OrderBook.cpp"
click node_trade "https://github.com/programmeradi-369/low-latency-order-matching-engine/blob/main/include/Trade.h"
click node_logger "https://github.com/programmeradi-369/low-latency-order-matching-engine/blob/main/include/TradeLogger.h"
click node_csv "https://github.com/programmeradi-369/low-latency-order-matching-engine/blob/main/trades.csv"
click node_performance "https://github.com/programmeradi-369/low-latency-order-matching-engine/blob/main/src/PerformanceAnalyzer.cpp"

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_manager,node_order toneBlue
class node_engine,node_book toneAmber
class node_trade,node_logger,node_csv,node_performance toneMint
class node_user toneIndigo
```

## Components

### Runtime orchestration

- [Scenario runner](https://github.com/programmeradi-369/low-latency-order-matching-engine/blob/main/src/main.cpp): `src/main.cpp`
- [Order validation](https://github.com/programmeradi-369/low-latency-order-matching-engine/blob/main/src/OrderManager.cpp): `src/OrderManager.cpp`
- [Order model](https://github.com/programmeradi-369/low-latency-order-matching-engine/blob/main/include/Order.h): `include/Order.h`

### Order matching

- [Matching engine](https://github.com/programmeradi-369/low-latency-order-matching-engine/blob/main/src/MatchingEngine.cpp): `src/MatchingEngine.cpp`
- [Price-level book](https://github.com/programmeradi-369/low-latency-order-matching-engine/blob/main/src/OrderBook.cpp): `src/OrderBook.cpp`

### Trade and metrics

- [Trade record](https://github.com/programmeradi-369/low-latency-order-matching-engine/blob/main/include/Trade.h): `include/Trade.h`
- [Trade logger](https://github.com/programmeradi-369/low-latency-order-matching-engine/blob/main/include/TradeLogger.h): `include/TradeLogger.h`
- [CSV export](https://github.com/programmeradi-369/low-latency-order-matching-engine/blob/main/trades.csv): `trades.csv`
- [Performance analytics](https://github.com/programmeradi-369/low-latency-order-matching-engine/blob/main/src/PerformanceAnalyzer.cpp): `src/PerformanceAnalyzer.cpp`

### Other components

- **Operator**

## Connections

- Operator → Scenario runner: runs scenarios
- Scenario runner → Order validation: creates orders
- Order validation → Order model: constructs
- Scenario runner → Matching engine: submits orders
- Matching engine → Price-level book: reads and updates
- Matching engine → Trade logger: records trades
- Matching engine → Trade record: creates records
- Scenario runner → Matching engine: cancels orders
- Scenario runner → Price-level book: prints book
- Scenario runner → Trade logger: prints and exports
- Trade logger → CSV export: exports CSV
- Scenario runner → Performance analytics: records latency
