# kungfu-origin/kungfu architecture

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

- Interactive diagram: https://gitdiagram.com/kungfu-origin/kungfu
- Repository: https://github.com/kungfu-origin/kungfu

## Overview

##### Overall Project Type and Purpose
- This is a complete trading execution system that targets extremely low latency (down to microseconds or even nanoseconds) while supporting flexible strategy development (in both C++ and Python).
- The system is built as a modular, layered architecture with clearly separated concerns: the backend “core” (data structures, time-series storage, and strategy execution), the strategy interface layer (providing APIs for different languages and reactive programming), and a frontend UI supporting both graphical interfaces and command-line tools.

##### Key Components
- Backend Core (C++):
– Longfist module: Handles financial data structures and serialization (found in framework/core/src/bindings and related directories).
– Yijinjing module: Provides the ultra-low latency time-series memory database with nanosecond precision (its code is spread across the core library directories).
– Wingchun module: The strategy execution engine that maintains real-time bookkeeping and trading positions.
- Strategy Interfaces:
– The SDK and developer tools (under developer/sdk and developer/toolchain) also provide command modules to build, package, and manage strategies.
- Frontend/UI:
– Built on Electron (Node.js-based desktop app) paired with Vue.js for the UI, which is visible in the “framework/app” directory (with separate main/renderer processes, webpack configurations, and public assets).
– API layer (under framework/api), where Node.js based services use similar config files and build scripts.
– CLI tools (in framework/cli) that offer command-based interactions.
- Extensions/Connectors:
– “extensions” directory contains samples for market connectors (e.g., XTP) and simulation modules that integrate externally.

##### Relationships and Data Flow
- Connectors to external market data providers or trading counters (e.g., the XTP connector as referenced in the README and built as an extension).

##### Architectural Patterns & Design Principles
- Modularity and separation of concerns: Backend core components, strategy APIs, and user interfaces are developed and compiled independently.
- Use of modern C++ (with C++20 features) and a multi-language interfacing approach (leveraging pybind11 for Python and Node’s binding interfaces).
- The layered approach also demonstrates a plug-in/extensible architecture (SDKs and connectors).

## Diagram (Mermaid)

```mermaid
graph TD
    subgraph "Strategy Interfaces"
        A1["C++ Bindings"]:::strategy
        A2["Python Bindings"]:::strategy
    end

    subgraph "SDK/Developer Tools"
        D1["SDK"]:::dev
        D2["Developer Toolchain"]:::dev
    end

    subgraph "Backend Core"
        B1["Wingchun"]:::backend
        B2["Longfist"]:::backend
        B3["Yijinjing"]:::backend
        B1 --> B2
        B1 --> B3
    end

    subgraph "Frontend/UI"
        F1["UI Application"]:::frontend
        F2["API Services"]:::frontend
        F3["CLI Tools"]:::frontend
    end

    subgraph "Extensions/Connectors"
        E1["Market Connector (XTP)"]:::extensions
        E2["Simulation Modules"]:::extensions
    end

    subgraph "Build & Deployment"
        L1["yarn,cmake,conan,pipenv"]:::build
    end

    %% Connections between layers
    A1 <-->|"bidirectional"| B1
    A2 <-->|"bidirectional"| B1

    D1 -->|"supports"| A1
    D2 -->|"supports"| A2

    B1 -->|"exposes state to"| F1
    B1 -->|"exposes state to"| F2
    B1 -->|"exposes state to"| F3

    E1 -->|"feeds data"| B1
    E2 -->|"feeds data"| B1

    L1 -->|"builds"| A1
    L1 -->|"builds"| B1
    L1 -->|"builds"| F1

    %% Styles
    classDef strategy fill:#C5FAD5,stroke:#333,stroke-width:2px;
    classDef backend fill:#ADD8E6,stroke:#333,stroke-width:2px;
    classDef frontend fill:#FFDAB9,stroke:#333,stroke-width:2px;
    classDef dev fill:#E6E6FA,stroke:#333,stroke-width:2px;
    classDef extensions fill:#F0E68C,stroke:#333,stroke-width:2px;
    classDef build fill:#D8BFD8,stroke:#333,stroke-width:2px;

    %% Click Events
    click A1 "https://github.com/kungfu-origin/kungfu/tree/main/framework/core/src/bindings/node"
    click A2 "https://github.com/kungfu-origin/kungfu/tree/main/framework/core/src/python"
    click D1 "https://github.com/kungfu-origin/kungfu/tree/main/developer/sdk"
    click D2 "https://github.com/kungfu-origin/kungfu/tree/main/developer/toolchain"
    click B2 "https://github.com/kungfu-origin/kungfu/blob/main/framework/core/src/bindings/node/binding/longfist.cpp"
    click B1 "https://github.com/kungfu-origin/kungfu/tree/main/framework/core/src/include/kungfu/wingchun"
    click B3 "https://github.com/kungfu-origin/kungfu/tree/main/framework/core/src/include/kungfu/yijinjing"
    click F1 "https://github.com/kungfu-origin/kungfu/tree/main/framework/app"
    click F2 "https://github.com/kungfu-origin/kungfu/tree/main/framework/api"
    click F3 "https://github.com/kungfu-origin/kungfu/tree/main/framework/cli"
    click E1 "https://github.com/kungfu-origin/kungfu/tree/main/extensions/xtp"
    click E2 "https://github.com/kungfu-origin/kungfu/tree/main/extensions/sim"
```
