# dphillipov/project-lion architecture

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

- Interactive diagram: https://gitdiagram.com/dphillipov/project-lion
- Repository: https://github.com/dphillipov/project-lion

## Overview

##### Project type and purpose
- This is a Python-based automated trading system composed of several cooperating microservices.
- Its goal is to collect market data, calculate indicators, generate trading signals/strategies, execute orders on an exchange, and track wallet balances.

##### File structure
- Top-level directories:
- config – central configuration for DB tables, exchanges, message queues
- data_producer – market data ingestion and historical data logging
- indicators – transforms raw data into trading signals
- services – four microservices (data producer, strategy generator, trader, wallet)
- modules – pluggable strategy implementations (f22, mig29) and exchange clients
- strategy – spearhead strategy entrypoint and logging
- wallet – balance calculation and consumption
- Dockerfiles and docker-compose.yml define containerization of each service.
- requirements.txt lists Python dependencies; .gitlab-ci.yml orchestrates CI/CD.

##### Key insights from README

- Clear labels for each service, data store, and external exchange

##### Detail
- Config module consumption by each service.
- Docker-compose layer to indicate how containers are networked.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Container Orchestration
    subgraph "Container Orchestration"
        DC["docker-compose.yml"]:::docker
        CI[".gitlab-ci.yml"]:::docker
        REQ["requirements.txt"]:::docker
    end

    %% Configuration Store
    subgraph "Global Configuration" 
        CFG_INIT["config/__init__.py"]:::config
        QUEUE_CFG["queue_config.py"]:::config
        DB_CFG["db_tables.py"]:::config
        EXCH_CFG["exchange_config.py"]:::config
    end

    %% Message Broker
    MB["Message Broker"]:::broker

    %% Database
    DB["Database"]:::database

    %% Data Producer Service
    subgraph "DataProducerService" 
        DPS["DataProducer Service"]:::compute
        CL["candles_logger.py"]:::compute
        DH["data_historical.py"]:::compute
        DS["data_subscriber.py"]:::compute
    end

    %% Indicators Module
    subgraph "Indicators Module" 
        IB["indicators_base.py"]:::compute
        SG["signals_generator.py"]:::compute
    end

    %% Strategy Generator Service
    subgraph "StrategyGeneratorService"
        SGS["StrategyGenerator Service"]:::compute
        subgraph "f22 Strategy"
            F22L["f22_long_market.py"]:::compute
            F22S["f22_short_market.py"]:::compute
            F22O["f22_order_manager.py"]:::compute
            F22SE["f22_session.py"]:::compute
        end
        subgraph "mig29 Strategy"
            MIGL["mig29_long_market.py"]:::compute
            MIGS["mig29_short_market.py"]:::compute
            MIGO["mig29_order_manager.py"]:::compute
        end
    end

    %% Trader Service
    subgraph "TraderService"
        TS["Trader Service"]:::compute
        BFC["binance_futures_client.py"]:::compute
        GOP["get_open_orders.py"]:::compute
        GPP["get_open_positions.py"]:::compute
        CO["close_orders.py"]:::compute
        CP["close_position.py"]:::compute
        CA["close_all.py"]:::compute
    end

    %% Wallet Service
    subgraph "WalletService"
        WS["Wallet Service"]:::compute
        BAL["balance.py"]:::compute
        BC["balance_consumer.py"]:::compute
    end

    %% Strategy Entrypoint
    subgraph "Strategy Entrypoint"
        SP["spearhead.py"]:::compute
        SL["strategy_logger.py"]:::compute
    end

    %% External Exchange
    EX["External Exchange API"]:::external

    %% Docker Compose connections
    DC -->|orchestrates| DPS
    DC -->|orchestrates| SGS
    DC -->|orchestrates| TS
    DC -->|orchestrates| WS

    %% Config consumption
    CFG_INIT -->|loads| DPS
    CFG_INIT -->|loads| SGS
    CFG_INIT -->|loads| TS
    CFG_INIT -->|loads| WS

    QUEUE_CFG -->|defines queues| DPS
    QUEUE_CFG -->|defines queues| SGS
    QUEUE_CFG -->|defines queues| TS
    QUEUE_CFG -->|defines queues| WS

    EXCH_CFG -->|exchange settings| TS

    DB_CFG -->|schema definitions| TS
    DB_CFG -->|schema definitions| WS

    %% Data flows
    DPS -->|market_data| MB
    MB -->|subscribes market_data| IB
    IB -->|signals| MB
    MB -->|subscribes signals| SGS
    SGS -->|orders| MB
    MB -->|subscribes orders| TS
    TS -->|executes via API| EX
    TS -->|write/read| DB
    WS -->|write/read| DB
    MB -->|execution_reports| WS

    %% Strategy Entrypoint usage
    SP -->|runs| SGS
    SP -->|logs| SL

    %% Click Events
    click QUEUE_CFG "https://github.com/dphillipov/project-lion/blob/main/config/queue_config.py"
    click DB_CFG "https://github.com/dphillipov/project-lion/blob/main/config/db_tables.py"
    click EXCH_CFG "https://github.com/dphillipov/project-lion/blob/main/config/exchange_config.py"
    click CFG_INIT "https://github.com/dphillipov/project-lion/blob/main/config/__init__.py"
    click DC "https://github.com/dphillipov/project-lion/blob/main/docker-compose.yml"
    click CI "https://github.com/dphillipov/project-lion/blob/main/.gitlab-ci.yml"
    click REQ "https://github.com/dphillipov/project-lion/blob/main/requirements.txt"

    click DPS "https://github.com/dphillipov/project-lion/blob/main/services/data_producer_service.py"
    click CL "https://github.com/dphillipov/project-lion/blob/main/data_producer/candles_logger.py"
    click DH "https://github.com/dphillipov/project-lion/blob/main/data_producer/data_historical.py"
    click DS "https://github.com/dphillipov/project-lion/blob/main/data_producer/data_subscriber.py"

    click IB "https://github.com/dphillipov/project-lion/blob/main/indicators/indicators_base.py"
    click SG "https://github.com/dphillipov/project-lion/blob/main/indicators/signals_generator.py"

    click SGS "https://github.com/dphillipov/project-lion/blob/main/services/strategy_generator_service.py"
    click F22L "https://github.com/dphillipov/project-lion/blob/main/modules/f22/f22_long_market.py"
    click F22S "https://github.com/dphillipov/project-lion/blob/main/modules/f22/f22_short_market.py"
    click F22O "https://github.com/dphillipov/project-lion/blob/main/modules/f22/f22_order_manager.py"
    click F22SE "https://github.com/dphillipov/project-lion/blob/main/modules/f22/f22_session.py"
    click MIGL "https://github.com/dphillipov/project-lion/blob/main/modules/mig29/mig29_long_market.py"
    click MIGS "https://github.com/dphillipov/project-lion/blob/main/modules/mig29/mig29_short_market.py"
    click MIGO "https://github.com/dphillipov/project-lion/blob/main/modules/mig29/mig29_order_manager.py"

    click TS "https://github.com/dphillipov/project-lion/blob/main/services/trader_service.py"
    click BFC "https://github.com/dphillipov/project-lion/blob/main/modules/binance_futures_client.py"
    click GOP "https://github.com/dphillipov/project-lion/blob/main/modules/get_open_orders.py"
    click GPP "https://github.com/dphillipov/project-lion/blob/main/modules/get_open_positions.py"
    click CO "https://github.com/dphillipov/project-lion/blob/main/modules/close_orders.py"
    click CP "https://github.com/dphillipov/project-lion/blob/main/modules/close_position.py"
    click CA "https://github.com/dphillipov/project-lion/blob/main/modules/close_all.py"

    click WS "https://github.com/dphillipov/project-lion/blob/main/services/wallet_service.py"
    click BAL "https://github.com/dphillipov/project-lion/blob/main/wallet/balance.py"
    click BC "https://github.com/dphillipov/project-lion/blob/main/wallet/balance_consumer.py"

    click SP "https://github.com/dphillipov/project-lion/blob/main/strategy/spearhead.py"
    click SL "https://github.com/dphillipov/project-lion/blob/main/strategy/strategy_logger.py"

    %% Styles
    classDef compute fill:#D0E8FF,stroke:#0366D6,color:#0366D6;
    classDef config fill:#FFF4D6,stroke:#C08F00,color:#C08F00;
    classDef broker fill:#FFEFD5,stroke:#E69500,color:#E69500,shape:hexagon;
    classDef database fill:#E0FFE0,stroke:#00A000,color:#008000,shape:cylinder;
    classDef external fill:#F0F0F0,stroke:#666666,color:#666666,stroke-dasharray: 5 5;
    classDef docker fill:#F2F2F2,stroke:#888888,color:#888888;
```
