# pandaai-tech/panda_quantflow architecture

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

- Interactive diagram: https://gitdiagram.com/pandaai-tech/panda_quantflow
- Repository: https://github.com/pandaai-tech/panda_quantflow

## Overview

##### Project Type & Purpose
After reviewing the file tree and README, this is a full-stack, modular microservices platform (“PandaAI QuantFlow”) for end-to-end quantitative research, backtesting, live trading and ML workflows. It provides:
– A browser-based UI for visual workflow design (“panda_web”)
– A FastAPI-based backend API (“panda_server”)
– Dedicated backtest engine (“panda_backtest”)
– Live trading engine (“panda_trading”)
– Plugin framework for custom processing nodes (“panda_plugins”)
– ML orchestration support (“panda_ml”)
– Scheduling/cron service (“panda_schedule”)
– Shared common utilities (connectors, logging, config under “common”)

##### Key Directories & Architectural Patterns
- src/common: shared connectors (MongoDB, MySQL, Redis), config, logging, cron helpers
- panda_server: HTTP routes → business logic → data models → connectors → persistence
- panda_backtest & panda_trading: standalone engines with event-driven cores and exchange/quotation adapters
- panda_plugins: base classes & discovery of @work_node plugins for extending the workflow graph
- panda_ml: data/compute nodes for ML pipelines
- panda_schedule: cron/periodic task runner
- panda_web: static assets (JS/CSS), Monaco editor, React-style pages for charts & workflow design

Architectural patterns:
– Microservices / modular Python packages
– Event-driven engine in backtest & trading
– Plugin/extension registry via decorators
– REST API + WebSocket for real-time monitoring & chat (LLM agents)
– Asynchronous messaging (RabbitMQ) for workflow tasks

##### Detailing Essentials
– Show each microservice’s entry points (HTTP routes, message consumers)
– Capture the event-driven core_context & engine in backtest/trading
– Highlight connectors (mongodb_handler, redis_client, mysql_client)
– Include the plugin discovery & execution path (BaseWorkNode → custom nodes)
– Annotate scheduling flows from crontab_manager → cron_run

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph "Frontend" 
        Frontend["Browser SPA (panda_web)"]:::frontend
    end

    subgraph "Backend Services"
        APIGateway["API Gateway & Workflow Manager\n(panda_server)"]:::service
        WorkflowMgr["Workflow Manager"]:::service
        Backtest["Backtest Engine\n(panda_backtest)"]:::service
        Trading["Trading Engine\n(panda_trading)"]:::service
        PluginEngine["Plugin Framework\n(panda_plugins)"]:::service
        MLEngine["ML Orchestration Engine\n(panda_ml)"]:::service
        Scheduler["Scheduler / Cron Service\n(panda_schedule)"]:::service
    end

    subgraph "Data Stores"
        Mongo["MongoDB"]:::db
        MySQL["MySQL"]:::db
        Redis["Redis"]:::cache
        RabbitMQ["RabbitMQ"]:::mq
    end

    subgraph "Common Utilities"
        Shared["Shared Utilities\n(src/common)"]:::service
    end

    subgraph "External Services"
        PandaFactor["PandaFactor Service"]:::ext
        WeChat["WeChat API"]:::ext
        CTP["CTP Trading API"]:::ext
        LLM["LLM Providers"]:::ext
    end

    %% User interaction
    User["User"]:::ext -->|uses| Frontend
    Frontend -->|HTTP| APIGateway

    %% API routing
    APIGateway -->|routes to| WorkflowMgr
    APIGateway -->|routes to| Backtest
    APIGateway -->|routes to| Trading
    APIGateway -.->|WebSocket/chat| LLM
    APIGateway -->|fetch context| Mongo
    APIGateway -->|send notifications| WeChat

    %% Workflow and messaging
    WorkflowMgr -.->|enqueue tasks| RabbitMQ
    RabbitMQ -.->|consume| PluginEngine
    PluginEngine -.->|execute plugins| MLEngine
    RabbitMQ -.->|dispatch| Backtest
    RabbitMQ -.->|dispatch| Trading

    %% Engines emit events
    Backtest -->|write events| Mongo
    Trading -->|write events| Mongo
    Backtest -->|cache/pubsub| Redis
    Trading -->|cache/pubsub| Redis
    Backtest -->|trade via| CTP
    Trading -->|trade via| CTP

    %% Scheduling
    Scheduler -->|trigger jobs| WorkflowMgr
    Scheduler -->|trigger backtests| Backtest

    %% External service calls
    WorkflowMgr -->|fetch factors| PandaFactor

    %% Shared utilities usage
    APIGateway --> Shared
    WorkflowMgr --> Shared
    Backtest --> Shared
    Trading --> Shared
    PluginEngine --> Shared
    MLEngine --> Shared
    Scheduler --> Shared

    %% Click Events
    click Shared "https://github.com/pandaai-tech/panda_quantflow/tree/main/src/common"
    click APIGateway "https://github.com/pandaai-tech/panda_quantflow/tree/main/src/panda_server"
    click Backtest "https://github.com/pandaai-tech/panda_quantflow/tree/main/src/panda_backtest"
    click Trading "https://github.com/pandaai-tech/panda_quantflow/tree/main/src/panda_trading"
    click PluginEngine "https://github.com/pandaai-tech/panda_quantflow/tree/main/src/panda_plugins"
    click MLEngine "https://github.com/pandaai-tech/panda_quantflow/tree/main/src/panda_ml"
    click Scheduler "https://github.com/pandaai-tech/panda_quantflow/tree/main/src/panda_schedule"
    click Frontend "https://github.com/pandaai-tech/panda_quantflow/tree/main/src/panda_web"

    %% Styles
    classDef frontend fill:#cce5ff,stroke:#0366d6;
    classDef service fill:#d4edda,stroke:#28a745;
    classDef db fill:#fff3cd,stroke:#ffc107;
    classDef cache fill:#fff3cd,stroke:#ffc107;
    classDef mq fill:#e2e3e5,stroke:#6f42c1;
    classDef ext fill:#f8f9fa,stroke:#6c757d;
```
