# yutiansut/qautlra-rs architecture

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

- Interactive diagram: https://gitdiagram.com/yutiansut/qautlra-rs
- Repository: https://github.com/yutiansut/qautlra-rs

## Overview

##### Project type and purpose
- This is a full-stack, modular, distributed trading and market-data processing platform implemented in Rust with a front-end component.
- Purpose: ingest market data from multiple sources (CTP, Sina, QQ), normalize it, distribute it in real time (WebSocket/REST), process/transform it into standard formats, run quantitative strategies, and provide a web UI for monitoring and trading.

##### File structure
- Top-level Cargo.toml defines the workspace.
- Sub-crates under root:
- qamdgateway, qamdgateway-ctp/qq/sina: market data gateways (Actor model via Actix)
- qamd-rs: market-data processing library (standard structures, converters)
- qars: quantitative engine core (backtest, factor compute, strategy execution, Python FFI)
- qifi-rs: standardized financial interfaces (account/order structs, serialization)
- ctp-md, ctp-md-qq/sina, ctp-trader, openctp-trader: bindings and wrappers around CTP/OpenCTP APIs
- qaoms/web: front-end (Vue.js) for data visualization and trading
- Common crates: ctp-common, ctp-common-tts generate Rust bindings for CTP.
- Configuration files: config.json, config_ctp.json, etc.
- Examples and tests in each crate illustrate usage and integration points.

##### README for additional insights
- Architecture uses an Actor model for distribution and concurrency.
- Main flows: market data ingestion → normalization → distribution → subscription via WebSocket/REST → consumption by strategies or front-end.
- Emphasizes modular components that can run independently or together.

##### Final advice
- Rust crate as a component.
- Feature flags or build-time config for gateway selection.
- Detail both real-time streaming path (WebSocket) and control path (REST).
- Layer 1: External Sources
- Layer 2: Gateways (Actors)
- Layer 3: Processing & Engine
- Layer 4: Distribution & Consumption
- This level of detail ensures the engineer can trace end-to-end data flow and deployment boundaries.

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Layer 1: External Sources"
        CTP["CTP Exchange"]:::external
        QQEX["QQ Source"]:::external
        SINA["Sina Source"]:::external
        XTP["XTP Exchange"]:::external
    end

    subgraph "Layer 2: Market Data Gateways"
        GDG["Market Data Gateway Core"]:::service
        CTPG["CTP Gateway"]:::service
        QQG["QQ Gateway"]:::service
        SINAG["Sina Gateway"]:::service
    end

    subgraph "Layer 3: Processing & Engine"
        QAMD["qamd-rs Library"]:::library
        QIFI["qifi-rs Library"]:::library
        QARS["qars Engine"]:::service
        subgraph "CTP Bindings"
            CTPMD["ctp-md"]:::service
            CTPMDQQ["ctp-md-qq"]:::service
            CTPMDSINA["ctp-md-sina"]:::service
        end
        subgraph "Trader Bindings"
            CTPT["ctp-trader"]:::service
            OPENCTP["openctp-trader"]:::service
        end
        COMMON["ctp-common"]:::service
        TTS["ctp-common-tts"]:::service
    end

    subgraph "Layer 4: Distribution & Consumption"
        QSR["qautlra-rs Runtime & WebServer"]:::service
        WS["WebSocket API"]:::service
        REST["REST API"]:::service
        UI["QAOMS Front-End"]:::frontend
        STRAT["Quant Strategies"]:::service
    end

    CTP-->CTPG
    QQEX-->QQG
    SINA-->SINAG
    XTP-->GDG

    CTPG-->GDG
    QQG-->GDG
    SINAG-->GDG

    GDG-->QAMD
    QAMD-->QSR

    COMMON-->CTPG
    COMMON-->QQG
    COMMON-->SINAG
    TTS-->CTPG
    TTS-->QQG
    TTS-->SINAG

    COMMON-->CTPMD
    COMMON-->CTPMDQQ
    COMMON-->CTPMDSINA
    TTS-->CTPMD
    TTS-->CTPMDQQ
    TTS-->CTPMDSINA

    QAMD-->QARS
    QIFI-->QARS

    QARS-->CTPT
    QARS-->OPENCTP

    CTPT-->CTP
    OPENCTP-->CTP

    QSR-->WS
    QSR-->REST

    WS-->UI
    REST-->UI
    WS-->STRAT

    click CTPG "https://github.com/yutiansut/qautlra-rs/tree/master/qamdgateway-ctp/src"
    click QQG "https://github.com/yutiansut/qautlra-rs/tree/master/qamdgateway-qq/src"
    click SINAG "https://github.com/yutiansut/qautlra-rs/tree/master/qamdgateway-sina/src"
    click GDG "https://github.com/yutiansut/qautlra-rs/tree/master/qamdgateway/src"
    click QAMD "https://github.com/yutiansut/qautlra-rs/tree/master/qamd-rs/src"
    click QARS "https://github.com/yutiansut/qautlra-rs/tree/master/qars/src"
    click QIFI "https://github.com/yutiansut/qautlra-rs/tree/master/qifi-rs/src"
    click CTPMD "https://github.com/yutiansut/qautlra-rs/tree/master/ctp-md/src"
    click CTPMDQQ "https://github.com/yutiansut/qautlra-rs/tree/master/ctp-md-qq/src"
    click CTPMDSINA "https://github.com/yutiansut/qautlra-rs/tree/master/ctp-md-sina/src"
    click CTPT "https://github.com/yutiansut/qautlra-rs/tree/master/ctp-trader/src"
    click OPENCTP "https://github.com/yutiansut/qautlra-rs/tree/master/openctp-trader/src"
    click COMMON "https://github.com/yutiansut/qautlra-rs/tree/master/ctp-common/src"
    click TTS "https://github.com/yutiansut/qautlra-rs/tree/master/ctp-common-tts/src"

    classDef external fill:#9f6,stroke:#333,stroke-width:1px;
    classDef service fill:#6cf,stroke:#333,stroke-width:1px;
    classDef library fill:#fc6,stroke:#333,stroke-width:1px;
    classDef frontend fill:#f96,stroke:#333,stroke-width:1px;
```
