# kingofknights/excalibur architecture

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

- Interactive diagram: https://gitdiagram.com/kingofknights/excalibur
- Repository: https://github.com/kingofknights/excalibur

## Overview

##### Main Components
- Excalibur Core: The central orchestration component (as suggested by Excalibur.cpp and Excalibur.hpp) which likely ties together the various modules.
- I/O/Networking Module: Represented by the EpollSocket component (EpollSocket.cpp/hpp) which is designed to handle I/O events efficiently (using epoll) for processing numerous tick data connections.
- Data Aggregation/Building: LadderBuilder (LadderBuilder.cpp/hpp) seems to build or organize order book structures (ladders) from the incoming tick data.
- Stream Management: The StreamManager (StreamManager.cpp/hpp) module probably oversees and routes streaming data through the system.
- Recovery Mechanism: Recovery (Recovery.cpp/hpp) likely handles fault tolerance, error correction, or recovery operations during data processing.

##### Interactions and Data Flow
- Once data is captured, it is handed off to the StreamManager, which routes or processes the data further.
- Depending on the data processing needs, StreamManager can then interface with the LadderBuilder to construct an aggregated order book or market ladder, as well as pass data to the Recovery module when errors or discrepancies are detected.
- The Excalibur core module acts as the orchestrator, connecting and managing the above components, ensuring that data flows correctly and in a coordinated manner.

##### Architectural Patterns and Principles
- Modularity: Clearly separate each component into its own module (as indicated by the distinct source and header files).
- Event-driven design: Emphasize the use of an epoll-based architecture for handling high-velocity data streams.
- Fault Tolerance: The Recovery module underlines the system’s design for resiliency and error handling.
- Single Executable Structure: With main.cpp as the entry point and CMakeLists configuration, it suggests a unified application rather than microservices.

##### Relevant Technologies, Frameworks, and Tools
- C++ with CMake: The system builds using CMake (CMakeLists.txt) and adheres to coding standards (as seen by the presence of a .clang-format file).
- Linux networking APIs: Likely using epoll and related I/O event handling on Linux systems.
- (If applicable) Any external libraries or custom JSON configurations (e.g., Excalibur.json) that might hint at further configuration or runtime parameters.

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Market Data Input"
        A("External Tick Data Feed"):::external
        E("EpollSocket"):::io
        A -->|"feeds"| E
    end

    subgraph "Processing Modules"
        S("StreamManager"):::stream
        L("LadderBuilder"):::ladder
        R("Recovery"):::recovery
        S -->|"builds"| L
        S -->|"detects"| R
        L -->|"feedback"| S
    end

    C("Excalibur Core"):::core

    %% Orchestration connections from Excalibur Core to modules
    C -->|"orchestrates"| E
    C -->|"orchestrates"| S
    C -->|"orchestrates"| L
    C -->|"orchestrates"| R

    %% Main data routing
    E -->|"routes"| S

    %% Click Events for Component Mapping
    click C "https://github.com/kingofknights/excalibur/blob/master/include/Excalibur.hpp"
    click C "https://github.com/kingofknights/excalibur/blob/master/src/Excalibur.cpp"
    click E "https://github.com/kingofknights/excalibur/blob/master/include/EpollSocket.hpp"
    click E "https://github.com/kingofknights/excalibur/blob/master/src/EpollSocket.cpp"
    click L "https://github.com/kingofknights/excalibur/blob/master/include/LadderBuilder.hpp"
    click L "https://github.com/kingofknights/excalibur/blob/master/src/LadderBuilder.cpp"
    click S "https://github.com/kingofknights/excalibur/blob/master/include/StreamManager.hpp"
    click S "https://github.com/kingofknights/excalibur/blob/master/src/StreamManager.cpp"
    click R "https://github.com/kingofknights/excalibur/blob/master/include/Recovery.hpp"
    click R "https://github.com/kingofknights/excalibur/blob/master/src/Recovery.cpp"

    %% Styles
    classDef core fill:#d1e7dd,stroke:#0f5132,stroke-width:2px;
    classDef io fill:#cfe2ff,stroke:#084298,stroke-width:2px;
    classDef stream fill:#e7d3ff,stroke:#6f42c1,stroke-width:2px;
    classDef ladder fill:#fff3cd,stroke:#856404,stroke-width:2px;
    classDef recovery fill:#f8d7da,stroke:#842029,stroke-width:2px;
    classDef external fill:#f0f0f0,stroke:#6c757d,stroke-width:2px;
```
