# pandaai-tech/panda_factor architecture

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

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

## Overview

##### Project Type & Purpose
- This is a **full-stack, microservices-style Python platform** for quantitative finance (“PandaAI量化因子库”), providing:
- Data ingestion & cleaning (panda_data_hub)
- Core data readers & utilities (panda_data)
- Factor‐construction library & workflows (panda_factor)
- REST API server to serve factors (panda_factor_server + “server” folder)
- LLM-driven chat service (panda_llm)
- Web frontend (panda_web)
- Shared common modules (panda_common)
- Persistent storage (MongoDB)
- External data sources (Tushare, RiceQuant, XTquant, etc.)

##### File Structure
- Top-level packages correspond to separate Python services or libraries:
- panda_common: config, DB handler, logging, shared models/utilities
- panda_data: low-level readers and quick-run scripts
- panda_data_hub: HTTP routes + scheduled tasks for nightly data cleaning/ingestion
- panda_factor: factor generation workflows & CLI entrypoint
- panda_factor_server (& server/): REST API layer exposing factor services
- panda_llm: chat endpoints, LLM service adapters, MongoDB integration
- panda_web: static UI assets + web server entrypoint
- Deployment artifacts: Dockerfile(.server), setup.py in each module, requirements.txt

##### README Insights
- Describes:
- Quant factor library + visualization
- Two factor‐writing modes (Python & formula)
- Data pipelines update nightly via schedulers
- MongoDB back-end
- Frontend + API for users to query factors or chat with LLM

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Frontend Layer
    subgraph "Frontend Layer"
        FW["panda_web (Frontend)"]:::frontend
    end

    %% API Layer
    subgraph "API Layer"
        FAPI["panda_factor_server"]:::service
        DHAPI["panda_data_hub\n(cron)"]:::service
        LLAPI["panda_llm"]:::service
    end

    %% Libraries
    subgraph "Libraries"
        PC["panda_common"]:::library
        PD["panda_data"]:::library
        PF["panda_factor"]:::library
    end

    %% Persistence
    DB[(MongoDB)]:::database

    %% External Services
    subgraph "External Services"
        EXD["Tushare / RiceQuant / XTquant"]:::external
        EXL["OpenAI LLM"]:::external
    end

    %% Connections
    FW -->|"requests factors"| FAPI
    FW -->|"sends chat"| LLAPI

    FAPI -->|"uses"| PF
    FAPI -->|"reads raw data"| PD
    FAPI -->|"shared config"| PC
    FAPI -->|"read/write factors"| DB

    DHAPI -->|"uses"| PD
    DHAPI -->|"shared config"| PC
    DHAPI -->|"ETL load"| DB
    EXD -->|"pull data"| DHAPI

    LLAPI -->|"shared config"| PC
    LLAPI -->|"store chat"| DB
    LLAPI -->|"call LLM"| EXL

    PF -->|"shared config"| PC

    %% Click Events
    click FW "https://github.com/pandaai-tech/panda_factor/tree/main/panda_web/panda_web"
    click FAPI "https://github.com/pandaai-tech/panda_factor/blob/main/panda_factor_server/panda_factor_server/server.py"
    click DHAPI "https://github.com/pandaai-tech/panda_factor/tree/main/panda_data_hub/panda_data_hub"
    click LLAPI "https://github.com/pandaai-tech/panda_factor/blob/main/panda_llm/panda_llm/server.py"
    click PF "https://github.com/pandaai-tech/panda_factor/tree/main/panda_factor/panda_factor"
    click PD "https://github.com/pandaai-tech/panda_factor/tree/main/panda_data/panda_data"
    click PC "https://github.com/pandaai-tech/panda_factor/tree/main/panda_common/panda_common"

    %% Styles
    classDef frontend fill:#ADD8E6,stroke:#333,stroke-width:1px
    classDef service fill:#87CEFA,stroke:#333,stroke-width:1px
    classDef library fill:#FFFF66,stroke:#333,stroke-width:1px
    classDef database fill:#90EE90,stroke:#333,stroke-width:1px
    classDef external fill:#D3D3D3,stroke:#333,stroke-width:1px
```
