# xueguoliang/xt architecture

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

- Interactive diagram: https://gitdiagram.com/xueguoliang/xt
- Repository: https://github.com/xueguoliang/xt

## Overview

XT is a small C++ market-data prototype: its entry point subscribes to an instrument through a singleton core, which starts a CTP market-data adapter and runs an epoll loop. The repository also contains timer, thread, heap, locking, and logging support. The README gives no further product detail, and vendor API headers were not inspected; their role is evident only through the adapter declarations and includes.

Main entry points: [`XTCore.cpp`](https://github.com/xueguoliang/xt/blob/master/XTCore.cpp) (Core Event Loop), [`ctp/XTCtpMd.cpp`](https://github.com/xueguoliang/xt/blob/master/ctp/XTCtpMd.cpp) (CTP Adapter), [`main.cpp`](https://github.com/xueguoliang/xt/blob/master/main.cpp) (Program Entry), [`XTDef.h`](https://github.com/xueguoliang/xt/blob/master/XTDef.h) (Shared Definitions)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_app["Application"]
  node_entry["Program Entry<br/>[main.cpp]"]
  node_core["Core Event Loop<br/>[XTCore.cpp]"]
end

subgraph group_market["Market Data"]
  node_ctp_adapter["CTP Adapter<br/>[XTCtpMd.cpp]"]
  node_ctp_api["CTP API Headers"]
  node_ctp_definitions["CTP Definitions<br/>[XTCTPDef.h]"]
end

subgraph group_runtime["Runtime Support"]
  node_thread["Thread Coordination<br/>[XTThread.cpp]"]
  node_timer["Timer Handling<br/>[XTTimer.cpp]"]
  node_heap["Timer Heap<br/>[XTHeap.h]"]
  node_lock["Mutex Utilities<br/>[XTLock.cpp]"]
  node_log["Logging<br/>[XTLog.cpp]"]
  node_definitions["Shared Definitions<br/>[XTDef.h]"]
end

node_user(("Caller"))
node_ctp_service(("CTP Front"))

node_user -->|"starts"| node_entry
node_entry -->|"subscribes, runs"| node_core
node_core -->|"creates, subscribes"| node_ctp_adapter
node_ctp_adapter -->|"uses"| node_ctp_api
node_ctp_adapter -->|"connects"| node_ctp_service
node_ctp_adapter -->|"extends"| node_thread
node_core -->|"stores timers"| node_heap
node_core -->|"locks timer state"| node_lock
node_definitions -->|"includes"| node_log
node_core -->|"checks timers"| node_timer
node_ctp_adapter -->|"logs events"| node_log
node_ctp_definitions -->|"includes"| node_definitions

click node_entry "https://github.com/xueguoliang/xt/blob/master/main.cpp"
click node_core "https://github.com/xueguoliang/xt/blob/master/XTCore.cpp"
click node_ctp_adapter "https://github.com/xueguoliang/xt/blob/master/ctp/XTCtpMd.cpp"
click node_ctp_api "https://github.com/xueguoliang/xt/tree/master/ctp/v6.3.6_20160606_api_tradeapi_linux64"
click node_thread "https://github.com/xueguoliang/xt/blob/master/XTThread.cpp"
click node_timer "https://github.com/xueguoliang/xt/blob/master/XTTimer.cpp"
click node_heap "https://github.com/xueguoliang/xt/blob/master/util/XTHeap.h"
click node_lock "https://github.com/xueguoliang/xt/blob/master/util/XTLock.cpp"
click node_log "https://github.com/xueguoliang/xt/blob/master/util/XTLog.cpp"
click node_definitions "https://github.com/xueguoliang/xt/blob/master/XTDef.h"
click node_ctp_definitions "https://github.com/xueguoliang/xt/blob/master/ctp/XTCTPDef.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_entry,node_core toneBlue
class node_ctp_adapter,node_ctp_api,node_ctp_definitions toneAmber
class node_thread,node_timer,node_heap,node_lock,node_log,node_definitions toneMint
class node_user,node_ctp_service toneIndigo
```

## Components

### Application

- [Program Entry](https://github.com/xueguoliang/xt/blob/master/main.cpp): `main.cpp`
- [Core Event Loop](https://github.com/xueguoliang/xt/blob/master/XTCore.cpp): `XTCore.cpp`

### Market Data

- [CTP Adapter](https://github.com/xueguoliang/xt/blob/master/ctp/XTCtpMd.cpp): `ctp/XTCtpMd.cpp`
- [CTP API Headers](https://github.com/xueguoliang/xt/tree/master/ctp/v6.3.6_20160606_api_tradeapi_linux64): `ctp/v6.3.6_20160606_api_tradeapi_linux64`
- [CTP Definitions](https://github.com/xueguoliang/xt/blob/master/ctp/XTCTPDef.h): `ctp/XTCTPDef.h`

### Runtime Support

- [Thread Coordination](https://github.com/xueguoliang/xt/blob/master/XTThread.cpp): `XTThread.cpp`
- [Timer Handling](https://github.com/xueguoliang/xt/blob/master/XTTimer.cpp): `XTTimer.cpp`
- [Timer Heap](https://github.com/xueguoliang/xt/blob/master/util/XTHeap.h): `util/XTHeap.h`
- [Mutex Utilities](https://github.com/xueguoliang/xt/blob/master/util/XTLock.cpp): `util/XTLock.cpp`
- [Logging](https://github.com/xueguoliang/xt/blob/master/util/XTLog.cpp): `util/XTLog.cpp`
- [Shared Definitions](https://github.com/xueguoliang/xt/blob/master/XTDef.h): `XTDef.h`

### Other components

- **Caller**
- **CTP Front**

## Connections

- Caller → Program Entry: starts (evidence: `main.cpp`)
- Program Entry → Core Event Loop: subscribes, runs (evidence: `main.cpp`)
- Core Event Loop → CTP Adapter: creates, subscribes (evidence: `XTCore.cpp`)
- CTP Adapter → CTP API Headers: uses
- CTP Adapter → CTP Front: connects (evidence: `ctp/XTCtpMd.cpp`)
- CTP Adapter → Thread Coordination: extends
- Core Event Loop → Timer Heap: stores timers
- Core Event Loop → Mutex Utilities: locks timer state (evidence: `XTCore.cpp`)
- Shared Definitions → Logging: includes (evidence: `XTDef.h`)
- Core Event Loop → Timer Handling: checks timers (evidence: `XTCore.cpp`)
- CTP Adapter → Logging: logs events (evidence: `ctp/XTCtpMd.cpp`)
- CTP Definitions → Shared Definitions: includes (evidence: `ctp/XTCTPDef.h`)
