# waditu/czsc architecture

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

- Interactive diagram: https://gitdiagram.com/waditu/czsc
- Repository: https://github.com/waditu/czsc

## Overview

##### Project Type and Core Components

a) Core Analysis Layer
- "Analysis Engine" at the center (czsc/analyze.py)
- "Objects System" (czsc/objects.py) connected to it
- "Technical Indicators" module (czsc/utils/ta.py)

b) Data Layer (Bottom)
- Different data connectors (czsc/connectors/*)
- Data caching system (czsc/utils/cache.py)
- Data sources integration (Tushare, JoinQuant, etc.)

c) Feature & Signal Layer (Middle)
- Signal processors (czsc/signals/*)
- Feature extractors (czsc/features/*)
- Sensor systems (czsc/sensors/*)

d) Trading Layer (Top)
- Trading strategies (czsc/traders/*)
- Optimization components (czsc/traders/optimize.py)
- Performance analysis (czsc/traders/performance.py)

##### Component Relationships

- Blue: Core analysis components
- Green: Data handling
- Yellow: Signal processing
- Red: Trading components
- Gray: Utility functions

##### Specific Implementation Details

**[Trading Strategies Layer]**
- ↑
**[Signal & Feature Processing]**
- ↑
**[Core Analysis Engine]**
- ↑
**[Data Connectors Layer]**

Critical elements:
- FSA (Finite State Automata) components
- Event processing system
- Backtesting framework
- Visualization utilities

##### Integration Points

External integration points:
- API interfaces
- Data source connections
- Visualization outputs (Plotly, Echarts)
- Command-line interface

##### Key Architectural Patterns

Patterns:
- Signal-Factor-Event-Trade pipeline
- Multi-level analysis system
- Modular connector system
- Caching mechanisms

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Style definitions
    classDef core fill:#2196F3,stroke:#1565C0,color:white
    classDef data fill:#4CAF50,stroke:#2E7D32,color:white
    classDef signal fill:#FFC107,stroke:#FFA000,color:black
    classDef trading fill:#F44336,stroke:#D32F2F,color:white
    classDef utils fill:#9E9E9E,stroke:#616161,color:white

    %% Data Layer
    subgraph DataLayer
        DC["Data Connectors"]
        DCache["Data Caching System"]
        DSources["Data Sources Integration"]
        DC --> DCache
        DSources --> DCache
    end

    %% Core Analysis Layer
    subgraph CoreLayer
        AE["Analysis Engine"]
        OS["Objects System"]
        TI["Technical Indicators"]
        AE <--> OS
        TI --> AE
    end

    %% Feature & Signal Layer
    subgraph ProcessingLayer
        SP["Signal Processors"]
        FE["Feature Extractors"]
        SS["Sensor Systems"]
        FSA["FSA Components"]
        EP["Event Processing"]
        
        SP <--> FE
        FE <--> SS
        FSA --> SP
        EP --> SP
    end

    %% Trading Layer
    subgraph TradingLayer
        TS["Trading Strategies"]
        OC["Optimization Components"]
        PA["Performance Analysis"]
        BT["Backtesting Framework"]
        
        TS --> OC
        TS --> PA
        BT --> PA
    end

    %% Visualization
    subgraph VisualizationLayer
        VU["Visualization Utilities"]
    end

    %% Inter-layer connections
    DataLayer --> CoreLayer
    CoreLayer --> ProcessingLayer
    ProcessingLayer --> TradingLayer
    CoreLayer --> VU
    TradingLayer --> VU

    %% Click events
    click DC "https://github.com/waditu/czsc/tree/master/czsc/connectors/"
    click DCache "https://github.com/waditu/czsc/blob/master/czsc/utils/cache.py"
    click DSources "https://github.com/waditu/czsc/tree/master/czsc/data/"
    click AE "https://github.com/waditu/czsc/blob/master/czsc/analyze.py"
    click OS "https://github.com/waditu/czsc/blob/master/czsc/objects.py"
    click TI "https://github.com/waditu/czsc/blob/master/czsc/utils/ta.py"
    click SP "https://github.com/waditu/czsc/tree/master/czsc/signals/"
    click FE "https://github.com/waditu/czsc/tree/master/czsc/features/"
    click SS "https://github.com/waditu/czsc/tree/master/czsc/sensors/"
    click FSA "https://github.com/waditu/czsc/tree/master/czsc/fsa/"
    click EP "https://github.com/waditu/czsc/blob/master/czsc/utils/events.py"
    click TS "https://github.com/waditu/czsc/tree/master/czsc/traders/"
    click OC "https://github.com/waditu/czsc/blob/master/czsc/traders/optimize.py"
    click PA "https://github.com/waditu/czsc/blob/master/czsc/traders/performance.py"
    click BT "https://github.com/waditu/czsc/blob/master/czsc/traders/weight_backtest.py"
    click VU "https://github.com/waditu/czsc/blob/master/czsc/utils/echarts_plot.py"

    %% Style applications
    class AE,OS,TI core
    class DC,DCache,DSources data
    class SP,FE,SS,FSA,EP signal
    class TS,OC,PA,BT trading
    class VU utils

    %% Legend
    subgraph Legend
        L1["Core Components"]:::core
        L2["Data Components"]:::data
        L3["Signal Processing"]:::signal
        L4["Trading Components"]:::trading
        L5["Utilities"]:::utils
    end
```
