# rauhanahmed/financialanalystaiagent architecture

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

- Interactive diagram: https://gitdiagram.com/rauhanahmed/financialanalystaiagent
- Repository: https://github.com/rauhanahmed/financialanalystaiagent

## Overview

##### Project Type & Purpose
- This is a Python-based, full-stack analytical dashboard combining market data retrieval, interactive visualizations, and AI-driven insights.
- The “backend” is a monolithic Streamlit application (`main.py`) that orchestrates data acquisition, visualization, and AI analysis.

##### File Structure Analysis
- Top-level scripts
- `main.py`: Entry point that renders the Streamlit UI and wires up all components.
- `financeAnalystAgent.py`: Encapsulates the AI agent logic (Google Gemini via Phidata).
- `utils.py`: Data-fetching (yfinance), chart generation (Plotly), helper functions.
- Configuration
- `params.yaml`: Model parameters, ticker list URL, agent instructions.
- Environment variables loaded via python-dotenv (`.env` expected).
- Support files
- `requirements.txt`, `.devcontainer/` for IDE/container setup, demo assets.

##### README Insights on Architecture
The README already breaks down the data flow:
1. Data Acquisition (Yahoo Finance, CSV ticker list)
2. Data Visualization (Plotly charts)
3. AI-Powered Analysis (Financial Analyst Agent → Google Gemini 2.0 Flash via Phidata)
4. User Interaction (Streamlit dashboard)
5. Configuration (YAML + dotenv)

a. Main Components
- Streamlit UI Layer (frontend)
- Data Layer
- YFinance API
- CSV Ticker List URL
- Visualization Layer (Plotly)
- AI Agent Layer
- FinanceAnalystAgent (Phidata wrapper)
- Google Gemini 2.0 Flash model
- Configuration Layer (params.yaml, .env)
- External Services (Yahoo Finance, Google Gemini endpoint)
b. Relationships & Data Flow
1. Streamlit UI sends ticker request → Utils.fetch_data → Yahoo Finance (yfinance)
2. Retrieved data → Utils.generate_chart → Plotly → Streamlit UI
3. User query in UI → FinanceAnalystAgent → Phidata → Google Gemini → Agent response → UI
4. At startup: main.py loads params.yaml + environment variables → passes config to agent and utils
c. Architectural Patterns & Principles
- Layered approach (UI, business logic, external services)
- Single process “full-stack” app but logically separated into modules
- Configuration-as-code (YAML + dotenv)
- Modular design for easy extension (adding new data sources or analytics tools)
d. Key Technologies & Frameworks
- Streamlit (UI)
- yfinance (data fetching)
- Plotly (visualization)
- Google Gemini 2.0 Flash + Phidata (AI analysis)
- PyYAML + python-dotenv (configuration)

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% UI Layer
    subgraph "Streamlit UI Layer"
        UI["Streamlit UI\n(Streamlit)"]:::ui
    end

    %% Data Layer
    subgraph "Data Layer"
        Utils["utils\n(yfinance & Plotly)"]:::data
    end

    %% Visualization Layer
    subgraph "Visualization Layer"
        Plotly["Plotly Charts"]:::data
    end

    %% AI Agent Layer
    subgraph "AI Agent Layer"
        Agent["FinanceAnalystAgent\n(Phidata wrapper)"]:::ai
    end

    %% Configuration Layer
    subgraph "Configuration"
        Params["params.yaml"]:::config
        DevContainer[".devcontainer/devcontainer.json"]:::config
        Requirements["requirements.txt"]:::config
        DemoAssets["demo/"]:::config
    end

    %% External Services
    subgraph "External Services"
        Yahoo["Yahoo Finance API"]:::external
        CSV["CSV Ticker List URL"]:::external
        Gemini["Google Gemini 2.0 Flash\n(Phidata endpoint)"]:::external
    end

    %% Data Flow
    UI -->|"fetch_data()"| Utils
    Utils -->|"API call"| Yahoo
    Utils -->|"download list"| CSV
    Utils -->|"generate_candlestick()"| Plotly
    Plotly -->|"render_chart()"| UI

    UI -->|"analyze_query()"| Agent
    Agent -->|"request_analysis()"| Gemini
    Gemini -->|"analysis_response()"| Agent
    Agent -->|"display_response()"| UI

    %% Configuration Flow
    Params -->|"load_config()"| UI
    Params -->|"load_config()"| Utils
    Params -->|"load_config()"| Agent
    DevContainer -->|"env_setup()"| UI
    Requirements -->|"dependencies()"| UI
    DemoAssets -->|"assets()"| UI

    %% Click Events
    click UI "https://github.com/rauhanahmed/financialanalystaiagent/blob/main/main.py"
    click Utils "https://github.com/rauhanahmed/financialanalystaiagent/blob/main/utils.py"
    click Agent "https://github.com/rauhanahmed/financialanalystaiagent/blob/main/financeAnalystAgent.py"
    click Params "https://github.com/rauhanahmed/financialanalystaiagent/blob/main/params.yaml"
    click DevContainer "https://github.com/rauhanahmed/financialanalystaiagent/blob/main/.devcontainer/devcontainer.json"
    click Requirements "https://github.com/rauhanahmed/financialanalystaiagent/blob/main/requirements.txt"
    click DemoAssets "https://github.com/rauhanahmed/financialanalystaiagent/tree/main/demo/"

    %% Styles
    classDef ui fill:#D6EAF8,stroke:#21618C
    classDef data fill:#D5F5E3,stroke:#1D8348
    classDef ai fill:#FDEBD0,stroke:#B9770E
    classDef config fill:#E5E8E8,stroke:#566573
    classDef external fill:#F5B7B1,stroke:#C0392B
```
