# lumina-lumi/openmanus-autoquant architecture

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

- Interactive diagram: https://gitdiagram.com/lumina-lumi/openmanus-autoquant
- Repository: https://github.com/lumina-lumi/openmanus-autoquant

## Overview

##### Project Type & Purpose
- Project Type: It is a full-scale financial quant system with modular components that use AI to generate and iterate trading strategies.
- Purpose: To automatically generate, test, and optimize trading strategies by integrating financial data pipelines (using sources like akshare), detailed analysis modules, strategy generators, and backtesting engines (integrating frameworks like backtrader).

##### File Structure Analysis
- Top-Level Organization:
- The “app” directory contains all core modules. Subdirectories include:
▸ agent – Contains several types of intelligent agents (e.g., browser, manus, mcp, react, swe, toolcall) which likely orchestrate different parts of the workflow.
▸ flow – Involved in planning and managing workflows for strategy generation and execution.
▸ mcp – Contains a server module; perhaps it handles communication or coordination between different agents.
▸ prompt – Holds different prompt templates corresponding to various tasks (e.g., browser, planning, toolcall) which align with an LLM-based chain-of-thought generation.
▸ sandbox – Provides a secure/test environment to execute and manage experimental code (modules for terminal operations, exception handling, etc).
▸ tool – Offers a library of helper routines (backtesting, strategy generation, browser usage, stock data fetching, file operations, etc). Notably, specific tool subdirectories (such as “search”) indicate modularity and specialization in tasks.
▸ resource – Contains markdown documentation for APIs and stock data integration; these act as API docs or specifications for data extraction.
- Other Files:
- Main scripts (e.g., main.py, run_flow.py, run_mcp*.py) signal different launch entry points for various parts of the system.
- Configuration files (Dockerfile, setup.py, requirements.txt, .pre-commit-config.yaml, and GitHub workflow files) ensure standardized build, dependency management, and deployment pipelines.

##### README Insights
- Describes the full automated workflow—from data pipeline (akshare integration) and analysis to strategy generation and refinement.
- Highlights the system’s iterative nature (self-generation, self-iteration, self-optimization), confirming that the module interactions are dynamic.
- Mentions integration with backtesting frameworks (backtrader) and outlines its value for private equity funds, individual investors, and academic research.

a. Main Components:
- Data Pipeline/Integration Module: Interfaces with financial data sources such as akshare.
- Analysis Engine: Handles data processing and business-specific analysis.
- Strategy Generation Module: Uses intelligent agents (under app/agent and app/prompt) to create strategies.
- Backtesting Engine: Uses backtrader (and associated tools in app/tool/backtest.py) for simulation and evaluation.
- Optimization Loop: Dynamically refines strategies based on backtesting results.
- Workflow / Flow Manager: (app/flow) coordinates the overall process and iteration.
- Communication/Coordination Server: (app/mcp) oversees agent communications.
- Sandbox Environment: (app/sandbox) for controlled code execution and testing.
- Tools & Utility Modules: (app/tool and its submodules) support specialized tasks, including market data fetching, search, and code execution.

b. Relationships & Interactions:
- Directional flows from data ingestion, to analysis, through strategy generation, into backtesting, and finally into optimization feedback.
- That the agents in “app/agent” work in tandem with prompt templates in “app/prompt” to drive LLM interactions.
- Workflow orchestration in “app/flow” that schedules and manages these activities.
- Deployment interactions with external libraries (e.g., akshare, backtrader) and optional browser automation with Playwright.

c. Architectural Patterns & Design Principles:
- Modular Design: Each major functionality (data, analysis, strategy generation, backtesting) is encapsulated in its own module.
- Separation of Concerns: Clear boundary between components like agents, flow management, and tools.
- Iterative/Feedback Loop: The core workflow supports self-iteration (cycle between strategy optimization and backtesting).
- Extensibility: The existence of multiple agent implementations and a sandbox environment shows an emphasis on adding new functionality without major refactoring.

d. Relevant Technologies & Frameworks:
- Python (use of virtual environments via conda or uv).
- Backtrader for backtesting.
- akshare for data collection.
- Playwright, if browser automation is enabled.
- GitHub workflows, Docker, and pre-commit hooks for CI/CD and quality management.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Layer 1: External Services
    subgraph "Layer 1: External Services"
        FD["Financial Data (akshare API)"]:::external
    end

    %% Layer 2: Core Engines
    subgraph "Layer 2: Core Engines"
        DP["Data Pipeline"]:::core
        AE["Analysis Engine"]:::core
        SG["Strategy Generation"]:::core
        BT["Backtesting Engine"]:::core
        OP["Optimization Loop"]:::core
    end

    %% Layer 3: Orchestration & Utility
    subgraph "Layer 3: Orchestration & Utility"
        WM["Workflow Manager"]:::orchestration
        CS["Coordination Server"]:::orchestration
        SA["Sandbox Environment"]:::orchestration
        TU["Utility Modules"]:::orchestration
        IA["Intelligent Agents"]:::agent
        PT["Prompt Templates"]:::agent
    end

    %% Data Flow between Core Engines
    FD -->|"providesData"| DP
    DP -->|"processes"| AE
    AE -->|"analyzes"| SG
    SG -->|"generates"| BT
    BT -->|"backtests"| OP
    OP -->|"feedback"| SG

    %% Orchestration connections from Workflow Manager
    WM -->|"schedules"| DP
    WM -->|"schedules"| AE
    WM -->|"schedules"| SG
    WM -->|"schedules"| BT
    WM -->|"schedules"| OP
    WM -->|"coordinates"| SA
    WM -->|"communicates"| CS

    %% Utility Modules support Core Engines
    TU -->|"supports"| DP
    TU -->|"supports"| AE
    TU -->|"supports"| SG
    TU -->|"supports"| BT
    TU -->|"supports"| OP

    %% Strategy Generation uses Intelligent Agents and Prompt Templates
    SG -->|"uses"| IA
    SG -->|"uses"| PT

    %% Coordination Server and Intelligent Agents Communication
    IA -->|"communicates"| CS
    CS -->|"communicates"| IA

    %% Click Events
    click DP "https://github.com/lumina-lumi/openmanus-autoquant/blob/main/app/tool/stock_data_fetch.py"
    click AE "https://github.com/lumina-lumi/openmanus-autoquant/blob/main/app/tool/stock_analysis.py"
    click SG "https://github.com/lumina-lumi/openmanus-autoquant/blob/main/app/tool/strategy_generator.py"
    click BT "https://github.com/lumina-lumi/openmanus-autoquant/blob/main/app/tool/backtest.py"
    click OP "https://github.com/lumina-lumi/openmanus-autoquant/blob/main/app/tool/strategy_optimizer.py"
    click WM "https://github.com/lumina-lumi/openmanus-autoquant/tree/main/app/flow"
    click CS "https://github.com/lumina-lumi/openmanus-autoquant/blob/main/app/mcp/server.py"
    click SA "https://github.com/lumina-lumi/openmanus-autoquant/tree/main/app/sandbox"
    click TU "https://github.com/lumina-lumi/openmanus-autoquant/tree/main/app/tool"
    click IA "https://github.com/lumina-lumi/openmanus-autoquant/tree/main/app/agent"
    click PT "https://github.com/lumina-lumi/openmanus-autoquant/tree/main/app/prompt"

    %% Styles
    classDef external fill:#fff3cd,stroke:#856404,stroke-width:2px;
    classDef core fill:#cce5ff,stroke:#004085,stroke-width:2px;
    classDef orchestration fill:#d4edda,stroke:#155724,stroke-width:2px;
    classDef agent fill:#f8d7da,stroke:#721c24,stroke-width:2px;
```
