# ivebotunac/primoagent architecture

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

- Interactive diagram: https://gitdiagram.com/ivebotunac/primoagent
- Repository: https://github.com/ivebotunac/primoagent

## Overview

##### Project type and purpose
- This is a domain-specific, multi-agent data processing and backtesting system for stock market analysis.
- It implements a linear “LangGraph” workflow where four specialized agents sequentially enrich a shared state with data, technical indicators, NLP-derived metrics, and trading signals, then supports backtesting.

##### File structure
Top-level files:
- main.py – runs the full data-collection and analysis pipeline
- backtest.py – runs the backtesting suite against historical data
- requirements.txt / .env.example – dependency management and API key configuration
src/agents/
- Four agent modules (data_collection_agent, technical_analysis_agent, news_intelligence_agent, portfolio_manager_agent)
src/tools/
- API wrappers and utility functions (yfinance, Finnhub, etc.)
src/backtesting/
- Engine, data loader, strategies, reporting, and plotting submodules
src/workflows/
- Stateful orchestration (LangGraph workflow implementation)
src/config/
- Config loader, JSON templates, model factory for LLMs
src/prompts/
- LLM prompts for each agent’s NLP tasks
output/
- CSV folder for daily per‐symbol analysis
- backtests folder for result charts and markdown reports

##### README for additional insights
- Sequential pipeline: Data → Technical Indicators → News NLP → Portfolio signals
- External integrations: yFinance, Finnhub, Firecrawl, Perplexity
- Backtesting component for performance evaluation

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Configuration & Initialization
    subgraph "Configuration & Initialization"
        CI_ENV[".env.example"]:::config
        CI_JSON["config.json"]:::config
        CI_PY["config.py"]:::config
        CI_MF["model_factory.py"]:::config
    end

    %% LLM Prompts
    subgraph "LLM Prompts"
        PP_SHARED["shared.py"]:::prompts
        PP_NEWS["news_intelligence.py"]:::prompts
        PP_PM["portfolio_manager.py"]:::prompts
    end

    %% Main Runner
    MAIN["main.py"]:::orchestrator

    %% Workflow Orchestrator
    subgraph "Workflow Orchestrator"
        WF_STATE["state.py"]:::orchestrator
        WF_FLOW["workflow.py"]:::orchestrator
    end

    %% Agent Layer
    subgraph "Agent Layer"
        A1["Data Collection Agent"]:::agent
        A2["Technical Analysis Agent"]:::agent
        A3["News Intelligence Agent"]:::agent
        A4["Portfolio Manager Agent"]:::agent
    end

    %% Tools Layer
    subgraph "Tools Layer"
        T1["yfinance_tool.py"]:::tool
        T2["finnhub_tool.py"]:::tool
        T3["firecrawl_tool.py"]:::tool
        T4["perplexity_tool.py"]:::tool
        T5["technical_indicators_tool.py"]:::tool
        T6["daily_csv_tool.py"]:::tool
        T7["utils.py"]:::tool
    end

    %% Outputs
    subgraph "Data Sinks & Outputs"
        OUT_CSV[("CSV Outputs")]:::storage
        OUT_BT[("Backtest Reports & Charts")]:::storage
    end

    %% Backtesting Pipeline
    BT_ENTRY["backtest.py"]:::backtesting
    subgraph "Backtesting Pipeline"
        BT1["data.py"]:::backtesting
        BT2["engine.py"]:::backtesting
        BT3["strategies.py"]:::backtesting
        BT4["reporting.py"]:::backtesting
        BT5["plotting.py"]:::backtesting
    end

    %% Connections
    CI_ENV --> MAIN
    CI_JSON --> MAIN
    CI_PY --> MAIN
    CI_MF --> MAIN

    PP_SHARED --> MAIN
    PP_NEWS --> MAIN
    PP_PM --> MAIN

    MAIN --> WF_STATE
    MAIN --> WF_FLOW
    WF_FLOW --> A1

    A1 --> A2
    A2 --> A3
    A3 --> A4
    A4 --> OUT_CSV

    A1 --> T1
    A1 --> T2
    A1 --> T7

    A2 --> T5
    A2 --> T7

    A3 --> T3
    A3 --> T4
    A3 --> T7

    A4 --> T6
    A4 --> T7

    OUT_CSV --> BT_ENTRY
    BT_ENTRY --> BT1
    BT1 --> BT2
    BT2 --> BT3
    BT3 --> BT4
    BT4 --> BT5
    BT5 --> OUT_BT

    %% Click Events
    click CI_ENV "https://github.com/ivebotunac/primoagent/blob/main/.env.example"
    click CI_JSON "https://github.com/ivebotunac/primoagent/blob/main/src/config/config.json"
    click CI_PY "https://github.com/ivebotunac/primoagent/blob/main/src/config/config.py"
    click CI_MF "https://github.com/ivebotunac/primoagent/blob/main/src/config/model_factory.py"
    click T1 "https://github.com/ivebotunac/primoagent/blob/main/src/tools/yfinance_tool.py"
    click T2 "https://github.com/ivebotunac/primoagent/blob/main/src/tools/finnhub_tool.py"
    click T3 "https://github.com/ivebotunac/primoagent/blob/main/src/tools/firecrawl_tool.py"
    click T4 "https://github.com/ivebotunac/primoagent/blob/main/src/tools/perplexity_tool.py"
    click T5 "https://github.com/ivebotunac/primoagent/blob/main/src/tools/technical_indicators_tool.py"
    click T6 "https://github.com/ivebotunac/primoagent/blob/main/src/tools/daily_csv_tool.py"
    click T7 "https://github.com/ivebotunac/primoagent/blob/main/src/tools/utils.py"
    click A1 "https://github.com/ivebotunac/primoagent/blob/main/src/agents/data_collection_agent.py"
    click A2 "https://github.com/ivebotunac/primoagent/blob/main/src/agents/technical_analysis_agent.py"
    click A3 "https://github.com/ivebotunac/primoagent/blob/main/src/agents/news_intelligence_agent.py"
    click A4 "https://github.com/ivebotunac/primoagent/blob/main/src/agents/portfolio_manager_agent.py"
    click WF_STATE "https://github.com/ivebotunac/primoagent/blob/main/src/workflows/state.py"
    click WF_FLOW "https://github.com/ivebotunac/primoagent/blob/main/src/workflows/workflow.py"
    click BT_ENTRY "https://github.com/ivebotunac/primoagent/blob/main/backtest.py"
    click BT1 "https://github.com/ivebotunac/primoagent/blob/main/src/backtesting/data.py"
    click BT2 "https://github.com/ivebotunac/primoagent/blob/main/src/backtesting/engine.py"
    click BT3 "https://github.com/ivebotunac/primoagent/blob/main/src/backtesting/strategies.py"
    click BT4 "https://github.com/ivebotunac/primoagent/blob/main/src/backtesting/reporting.py"
    click BT5 "https://github.com/ivebotunac/primoagent/blob/main/src/backtesting/plotting.py"
    click MAIN "https://github.com/ivebotunac/primoagent/blob/main/main.py"
    click PP_SHARED "https://github.com/ivebotunac/primoagent/blob/main/src/prompts/shared.py"
    click PP_NEWS "https://github.com/ivebotunac/primoagent/blob/main/src/prompts/news_intelligence.py"
    click PP_PM "https://github.com/ivebotunac/primoagent/blob/main/src/prompts/portfolio_manager.py"

    %% Styles
    classDef config fill:#f9f,stroke:#333,stroke-width:1px;
    classDef prompts fill:#fbb,stroke:#333,stroke-width:1px;
    classDef orchestrator fill:#fa8,stroke:#333,stroke-width:1px;
    classDef agent fill:#8cf,stroke:#333,stroke-width:1px;
    classDef tool fill:#9f9,stroke:#333,stroke-width:1px;
    classDef backtesting fill:#ccf,stroke:#333,stroke-width:1px;
    classDef storage fill:#fcf,stroke:#333,stroke-width:1px;
```
