# freecnsz/trading-bot architecture

> Architecture diagram of the GitHub repository freecnsz/trading-bot, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2024-12-28). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/freecnsz/trading-bot
- Repository: https://github.com/freecnsz/trading-bot

## Overview

##### Main Components

A. Frontend Layer (React Application):
- User Interface Components
- Real-time Data Visualization (CandlestickChart)
- Strategy Configuration Interface
- WebSocket Client for Real-time Updates

B. Backend Layer (Python FastAPI):
- Trading Engine Core
- Strategy Manager
- Binance Client Integration
- WebSocket Server
- Technical Indicators Calculator

C. External Services:
- Binance API
- Market Data Feeds

**[Client Layer]**
- ↕
**[Application Layer]**
- ↕
**[External Services Layer]**

##### Detailed Component Breakdown

A. Client Layer (Top):
- Sub-components:
- Strategy Editor
- Chart Visualization
- Trading Interface
- WebSocket Client

B. Application Layer (Middle):
- Core components:
- Trading Engine
- Strategy Manager
- Technical Indicators
- API Endpoints
- WebSocket Server

C. External Services (Bottom):
- Market Data Services

##### Important Elements to Highlight

A. Core Processing Flow:
- Market Data Ingestion → Trading Engine → Strategy Execution → Order Placement

B. Real-time Components:
- WebSocket connections for live data
- Candlestick chart updates
- Strategy execution feedback

##### Technical Details

Frontend:
- React Components Structure
- State Management Flow
- Real-time Data Handling

Backend:
- FastAPI Endpoints
- Strategy Processing Pipeline
- Technical Analysis Module
- Trading Engine Logic

##### Optimization Points

Potential scaling points:
- Strategy Manager (for multiple strategies)
- Trading Engine (for parallel execution)
- Data Processing Pipeline

## Diagram (Mermaid)

```mermaid
graph TB
    %% Title
    title[Trading Bot System Architecture]
    style title fill:#f9f9f9,stroke:#333,stroke-width:2px
    
    %% Frontend Layer
    subgraph Frontend
        UI["User Interface"]
        SC["Strategy Configuration"]
        CV["Candlestick Visualization"]
        WSC["WebSocket Client"]
        
        UI --> SC
        UI --> CV
        UI --> WSC
    end
    
    %% Backend Layer
    subgraph Backend
        TE["Trading Engine"]
        SM["Strategy Manager"]
        BC["Binance Client"]
        WSS["WebSocket Server"]
        TI["Technical Indicators"]
        API["API Endpoints"]
        
        TE --> SM
        SM --> TI
        TE --> BC
        WSS --> TE
        API --> TE
    end
    
    %% External Services Layer
    subgraph External
        BAPI["Binance API"]
        MDF["Market Data Feeds"]
    end
    
    %% Connections between layers
    WSC -. WebSocket Connection .- WSS
    UI -- REST API --> API
    BC -- Market Data --> BAPI
    MDF -- Price Feeds --> BC
    
    %% Component Styles
    classDef frontend fill:#d4e6f1,stroke:#2874a6
    classDef backend fill:#d4efdf,stroke:#196f3d
    classDef external fill:#f2f4f4,stroke:#566573
    
    %% Apply styles
    class UI,SC,CV,WSC frontend
    class TE,SM,BC,WSS,TI,API backend
    class BAPI,MDF external
    
    %% Click events for component mapping
    click TE "https://github.com/freecnsz/trading-bot/blob/master/backend/app/core/trading_engine.py"
    click SM "https://github.com/freecnsz/trading-bot/blob/master/backend/app/core/strategy_manager.py"
    click BC "https://github.com/freecnsz/trading-bot/blob/master/backend/app/core/binance_client.py"
    click WSS "https://github.com/freecnsz/trading-bot/blob/master/backend/app/endpoints/websocket.py"
    click TI "https://github.com/freecnsz/trading-bot/blob/master/backend/app/utils/indicators_calculations.py"
    click API "https://github.com/freecnsz/trading-bot/tree/master/backend/app/endpoints/"
    click CV "https://github.com/freecnsz/trading-bot/blob/master/frontend/src/components/CandlestickChart.js"
    click SC "https://github.com/freecnsz/trading-bot/blob/master/frontend/src/components/IndicatorEditor.js"
    click UI "https://github.com/freecnsz/trading-bot/blob/master/frontend/src/App.js"
    
    %% Legend
    subgraph Legend
        L1[Frontend Component]:::frontend
        L2[Backend Component]:::backend
        L3[External Service]:::external
        L4[" "]
        L4 -. WebSocket .-> L4
        L4 -- REST API --> L4
    end
```
