# zhangks93/quanpass-rs architecture

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

- Interactive diagram: https://gitdiagram.com/zhangks93/quanpass-rs
- Repository: https://github.com/zhangks93/quanpass-rs

## Overview

##### Main Components
- Entry Point: The main.rs serves as the application’s entry point.
- Clients & External APIs: The src/client directory (binance_client.rs, binance_domain.rs, db_client.rs) indicates connections to exchange APIs and possibly a database interface.
- Crypto and Market Interfaces: Under src/crypto and src/market you have modules that handle communication with cryptocurrency and stock markets, as well as futures and RSS feeds.
- Notification System: The src/notify module provides different clients (mail_client, wechat_client) for alerting users.
- Trading Robot and Routing: The src/robot (which hosts the trading logic in robot.rs) and src/router modules, which likely manage internal routing of commands or requests between components.
- Trading Strategies: The src/strategy folder contains implementations for various trading strategies (like grid_strategy and future_grid_strategy) that dictate how market data is translated into trade actions.
- Utility Functions: The src/util directory covers common tasks (error handling, JSON operations, time and number utilities) that support the rest of the system.

##### Relationships and Interactions
- The main application (main.rs) should be illustrated as coordinating the initialization of all modules.
- From the Client layer to Market/Crypto modules (e.g., binance_client interacting with binance_domain).
- From Market and Crypto modules to the Strategy module, which processes incoming market data.
- From the Strategy module to the Robot module that executes trading decisions.
- From the Robot module to the Notify module to send alerts via email or WeChat.
- Lines from the Utility module to all other modules, indicating shared, low-level functionality.

##### Architectural Patterns and Principles
- Separation of Concerns: Each module (client, market, crypto, notify, robot, strategy, router) has a clear responsibility.
- Modularity: Distinct modules allow you to swap out, modify, or extend capabilities (for example, adding a new notification channel or market client).
- Dependency Injection: Although not explicitly stated, the structure indicates that primary modules are designed to be loosely coupled (e.g., the robot uses strategies and clients without hard-wired implementations).

##### Relevant Technologies
- Rust and Cargo: Indicated by the Cargo.toml and the Rust file structure.
- External APIs: Binance API, potential stock and cryptocurrency feeds.
- Notification Frameworks: Mail and WeChat integrations.
- Trading Algorithms: Implemented as grid-based strategies.
- Python Script: The existence of src/ticket.py suggests there might be some auxiliary tooling or integration scripts in Python.

## Diagram (Mermaid)

```mermaid
graph TD
    %% Main Application
    MA["Main Application (main.rs)"]:::main

    %% External Interfaces Subgraph
    subgraph "External Interfaces"
        CEA["Clients & External APIs"]:::client
        CI["Crypto Interfaces"]:::client
        MDI["Market Data Interfaces"]:::client
    end

    %% Core Trading Engine Subgraph
    subgraph "Core Trading Engine"
        TS["Trading Strategies"]:::core
        TR["Trading Robot"]:::core
        RT["Router"]:::core
    end

    %% Notification Services Subgraph
    subgraph "Notification Services"
        NS["Notification System"]:::notify
    end

    %% Support Services Subgraph
    subgraph "Support Services"
        UF["Utility Functions"]:::util
    end

    %% Connections from Main Application
    MA -->|"init_client"| CEA
    MA -->|"init_crypto"| CI
    MA -->|"init_market"| MDI
    MA -->|"init_strategy"| TS

    %% Data flow from External Interfaces to Trading Strategies
    CI -->|"market_data"| TS
    MDI -->|"market_data"| TS

    %% Core Trading Engine flow
    TS -->|"trigger_trade"| TR
    RT -->|"route_to_robot"| TR
    RT -->|"route_to_strategy"| TS

    %% Notification flow
    TR -->|"send_alert"| NS

    %% Utility Functions support dotted connections
    CEA -.-> UF
    CI -.-> UF
    MDI -.-> UF
    TS -.-> UF
    TR -.-> UF
    RT -.-> UF
    NS -.-> UF
    MA -.-> UF

    %% Click Events
    click MA "https://github.com/zhangks93/quanpass-rs/blob/master/src/main.rs"
    click CEA "https://github.com/zhangks93/quanpass-rs/tree/master/src/client"
    click CI "https://github.com/zhangks93/quanpass-rs/tree/master/src/crypto"
    click MDI "https://github.com/zhangks93/quanpass-rs/tree/master/src/market"
    click TS "https://github.com/zhangks93/quanpass-rs/tree/master/src/strategy"
    click TR "https://github.com/zhangks93/quanpass-rs/tree/master/src/robot"
    click RT "https://github.com/zhangks93/quanpass-rs/tree/master/src/router"
    click NS "https://github.com/zhangks93/quanpass-rs/tree/master/src/notify"
    click UF "https://github.com/zhangks93/quanpass-rs/tree/master/src/util"

    %% Styles
    classDef main fill:#fddde6,stroke:#cc3366,stroke-width:2px;
    classDef client fill:#cce5ff,stroke:#0066cc,stroke-width:2px;
    classDef core fill:#ccffcc,stroke:#009933,stroke-width:2px;
    classDef notify fill:#ffe6cc,stroke:#ff6600,stroke-width:2px;
    classDef util fill:#e6e6e6,stroke:#808080,stroke-width:2px;
```
