# imanoop7/financial-analysis--multi-agent-open-source-llm architecture

> Architecture diagram of the GitHub repository imanoop7/financial-analysis--multi-agent-open-source-llm, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-05-20). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/imanoop7/financial-analysis--multi-agent-open-source-llm
- Repository: https://github.com/imanoop7/financial-analysis--multi-agent-open-source-llm

## Overview

##### Project type and purpose
- This is an open-source, multi-agent financial analysis tool built as a single-page Streamlit application.
- It orchestrates several analysis “agents” (technical, fundamental, sentiment, risk, competitor) using crewai and LangChain, pulls market data via yfinance, and runs local LLMs via Ollama.

##### File structure
- Top-level:
- app.py – Streamlit front-end and entry point
- crew.py – agent orchestration setup using crewai
- requirements.txt – Python dependencies
- tools/ – one module per analysis agent:
- yf_tech_analysis_tool.py
- yf_fundamental_analysis_tool.py
- sentiment_analysis_tool.py
- risk_assessment_tool.py
- competitor_analysis_tool.py

##### Additional README insights
- Dependencies: crewai, langchain, ollama, yfinance, streamlit, plotly
- Features: real-time data, chart pattern recognition, financial analysis, sentiment, risk, competitor analysis, strategy recommendations, interactive charts

##### Main components
a. Streamlit UI (app.py) – user input, dashboard
b. Orchestrator (crew.py + crewai) – spawns and coordinates agents
c. Analysis Agents (tools/*.py) – modular analyzers
- Technical analysis agent
- Fundamental analysis agent
- Sentiment analysis agent
- Risk assessment agent
- Competitor analysis agent
d. Data Sources
- yfinance (external API)
- (Possibly local cache or in-memory)
e. LLM Engine
- Ollama local server
- LangChain wrappers
f. Visualizations
- plotly for charts
g. Dependencies & Config
- requirements.txt
- environment variables for API keys (if any)

##### Relationships and interactions
- User enters stock symbol → Streamlit UI
- UI calls the Orchestrator API in crew.py
- Orchestrator spins up each Analysis Agent in parallel
- Technical & Fundamental agents fetch data from yfinance
- Sentiment agent may pull social sentiment or news (via LLM)
- Risk & Competitor agents optionally use data + LLM
- Each agent uses LangChain to wrap prompts and send requests to Ollama
- Agents return structured results (JSON/dicts) to Orchestrator
- Orchestrator aggregates all agent outputs into a unified report
- UI receives aggregated report → renders charts (plotly) & text

##### Architectural patterns and design principles
- Agent-based, modular plugin architecture: each tool file is an interchangeable component
- Separation of concerns: UI / orchestration / data-fetching / LLM communication / visualization
- Concurrency: parallel analysis pipelines for responsiveness
- Extensibility: new tools = new .py module in tools/ + registration in crew.py

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Frontend
    subgraph "Frontend"
        UI["Streamlit UI\n(app.py)\n(Streamlit)"]:::ui
    end

    %% Backend Orchestrator
    subgraph "Backend"
        ORC["Orchestrator\n(crew.py)\n(crewai)"]:::backend
        subgraph "Analysis Agents"
            TA["Technical Analysis Agent\ntools/yf_tech_analysis_tool.py\n(yfinance, LangChain)"]:::agent
            FA["Fundamental Analysis Agent\ntools/yf_fundamental_analysis_tool.py\n(yfinance, LangChain)"]:::agent
            SA["Sentiment Analysis Agent\ntools/sentiment_analysis_tool.py\n(LLM)"]:::agent
            RA["Risk Assessment Agent\ntools/risk_assessment_tool.py\n(LLM)"]:::agent
            CA["Competitor Analysis Agent\ntools/competitor_analysis_tool.py\n(LLM)"]:::agent
        end
    end

    %% External Services
    subgraph "External Services"
        YF[(yfinance API)]:::external
        OL[(Ollama LLM)]:::external
    end

    %% Visualization
    subgraph "Visualization"
        PL["Plotly Visualizer\n(plotly)"]:::visual
    end

    %% Configuration
    CFG["Dependencies & Config\n(requirements.txt)"]:::config

    %% Data Flows
    UI -->|"user input\n(stock symbol)"| ORC
    ORC -->|"spawn agents"| TA
    ORC -->|"spawn agents"| FA
    ORC -->|"spawn agents"| SA
    ORC -->|"spawn agents"| RA
    ORC -->|"spawn agents"| CA

    TA -->|"fetch quotes"| YF
    FA -->|"fetch financials"| YF
    SA -->|"prompt sentiment"| OL
    RA -->|"prompt risk assessment"| OL
    CA -->|"prompt competitor analysis"| OL

    TA -->|"return JSON"| ORC
    FA -->|"return JSON"| ORC
    SA -->|"return JSON"| ORC
    RA -->|"return JSON"| ORC
    CA -->|"return JSON"| ORC

    ORC -->|"aggregate results"| UI
    UI -->|"render charts & text"| PL

    %% Click Events
    click UI "https://github.com/imanoop7/financial-analysis--multi-agent-open-source-llm/blob/main/app.py"
    click ORC "https://github.com/imanoop7/financial-analysis--multi-agent-open-source-llm/blob/main/crew.py"
    click TA "https://github.com/imanoop7/financial-analysis--multi-agent-open-source-llm/blob/main/tools/yf_tech_analysis_tool.py"
    click FA "https://github.com/imanoop7/financial-analysis--multi-agent-open-source-llm/blob/main/tools/yf_fundamental_analysis_tool.py"
    click SA "https://github.com/imanoop7/financial-analysis--multi-agent-open-source-llm/blob/main/tools/sentiment_analysis_tool.py"
    click RA "https://github.com/imanoop7/financial-analysis--multi-agent-open-source-llm/blob/main/tools/risk_assessment_tool.py"
    click CA "https://github.com/imanoop7/financial-analysis--multi-agent-open-source-llm/blob/main/tools/competitor_analysis_tool.py"
    click CFG "https://github.com/imanoop7/financial-analysis--multi-agent-open-source-llm/blob/main/requirements.txt"

    %% Styles
    classDef ui fill:#D6EAF8,stroke:#2980B9,stroke-width:2px
    classDef backend fill:#D5F5E3,stroke:#27AE60,stroke-width:2px
    classDef agent fill:#FCF3CF,stroke:#F1C40F,stroke-width:2px
    classDef external fill:#F2F3F4,stroke:#ABB2B9,stroke-width:2px
    classDef visual fill:#E8DAEF,stroke:#8E44AD,stroke-width:2px
    classDef config fill:#FDEDEC,stroke:#C0392B,stroke-width:2px
```
