# abhinavyadav11/ai-dataanalyst-agent architecture

> Architecture diagram of the GitHub repository abhinavyadav11/ai-dataanalyst-agent, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-05-12). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/abhinavyadav11/ai-dataanalyst-agent
- Repository: https://github.com/abhinavyadav11/ai-dataanalyst-agent

## Overview

##### Project Type and Purpose
- This is a monolithic, full-stack Streamlit application (“AI File Analyst”) written in Python.
- Purpose: Allow end users to upload various file types (.csv, .pdf, .docx, images, etc.), extract text, and perform LLM-based operations (summaries, Q&A, keyword/entities) via external APIs (OpenAI, Together AI).

##### File Structure
- Top-level files:
- .devcontainer/devcontainer.json – VS Code dev container configuration
- app1.py – main Streamlit application entrypoint
- requirements.txt – Python dependencies
- README.md, LICENSE
- No separate “frontend” vs “backend” directories – it’s a single Streamlit app.
- Dependencies include: PyMuPDF/pdfplumber (PDF parsing), python-docx, pandas, Pillow (image handling), plus LLM clients.

##### Key Insights from README
- Interactive UI built with Streamlit
- Supports file‐upload widget → local extraction pipeline → LLM calls → display results
- Secret management via .streamlit/secrets.toml for API keys
- Deployment target: Streamlit Cloud (or local devcontainer)

##### Main Components
a. Streamlit UI Layer (app1.py):
- File Upload Widget
- User controls (buttons for summary, Q&A)
- Results display panels
b. File Parsing Module(s):
- CSV/Excel parser (pandas)
- PDF extractor (PyMuPDF/pdfplumber)
- DOCX parser (python-docx)
- OCR pipeline (Pillow + pytesseract or similar)
c. Text Processing & Orchestration:
- Cleans/extracts consolidated text
- Routes request to appropriate LLM operation (summarize, keywords, Q&A)
d. External LLM Service Clients:
- OpenAI API client
- Together AI API client
- Handled via Python HTTP calls using API keys from Secrets Manager
e. Secrets/Config Management:
- .streamlit/secrets.toml or environment variables
- Accessed at runtime by Streamlit’s st.secrets
f. Dev/Deployment Infra:
- Devcontainer (.devcontainer/) for local environment
- Streamlit Cloud or containerized hosting

##### Relationships and Data Flows
- User → (1) Streamlit UI → (2) File Parsing Module → (3) Text Aggregator
- (3) Text → (4) LLM Client → External API (OpenAI/Together AI)
- External API → (5) Response → (6) UI Display
- Secrets Manager feeds API keys into LLM Client
- Devcontainer encapsulates entire stack for local dev

##### Architectural Patterns & Design Principles
- Single-page, event-driven UI (Streamlit callbacks)
- Modular pipeline for file-type handling (strategy pattern for parsers)
- Separation of concerns: UI vs parsing vs external API integration
- Configuration-as-code (.devcontainer, secrets.toml)
- Stateless: no persistent database; all state lives in session memory

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% User
    User["End User"]:::external

    %% Streamlit UI Layer
    subgraph "Streamlit UI Layer"
        direction TB
        MainApp["Main App Controller"]:::ui
        FileUpload["File Upload Widget"]:::ui
        Controls["User Controls (Summary, Q&A)"]:::ui
        Display["Results Display Panels"]:::ui
    end

    %% File Parsing Modules
    subgraph "File Parsing Modules"
        direction TB
        CSVParser["CSV/Excel Parser"]:::logic
        PDFExtractor["PDF Extractor"]:::logic
        DOCXParser["DOCX Parser"]:::logic
        OCRPipeline["OCR Pipeline"]:::logic
    end

    %% Orchestrator & Storage
    Orchestrator["Text Processing & Orchestration"]:::logic
    Session["In-Memory Session"]:::storage

    %% External LLM Clients
    subgraph "LLM Service Clients"
        direction TB
        LLMOpenAI["OpenAI API Client"]:::client
        LLMTogether["Together AI API Client"]:::client
    end

    %% External Services
    subgraph "External AI Services"
        direction TB
        ExternalOpenAI["OpenAI Service"]:::external
        ExternalTogether["Together AI Service"]:::external
    end

    %% Config & Infra
    Secrets["Secrets Manager (.streamlit/secrets.toml)"]:::config
    Devcontainer["Dev/Local Env Config"]:::infra
    StreamlitCloud["Streamlit Cloud Hosting"]:::infra

    %% Documentation & Config Files
    subgraph "Project Files"
        direction TB
        Requirements["requirements.txt"]:::doc
        README["README.md"]:::doc
        LICENSE["LICENSE"]:::doc
    end

    %% Connections
    User --> MainApp
    MainApp --> FileUpload
    MainApp --> Controls
    MainApp --> Display

    FileUpload --> CSVParser
    FileUpload --> PDFExtractor
    FileUpload --> DOCXParser
    FileUpload --> OCRPipeline

    CSVParser --> Orchestrator
    PDFExtractor --> Orchestrator
    DOCXParser --> Orchestrator
    OCRPipeline --> Orchestrator

    Orchestrator --> LLMOpenAI
    Orchestrator --> LLMTogether

    Secrets --> LLMOpenAI
    Secrets --> LLMTogether

    LLMOpenAI --> ExternalOpenAI
    LLMTogether --> ExternalTogether

    ExternalOpenAI --> Orchestrator
    ExternalTogether --> Orchestrator

    Orchestrator --> Display

    Devcontainer --> MainApp
    StreamlitCloud --> MainApp

    Requirements --> MainApp
    README --> MainApp
    LICENSE --> MainApp

    %% Click Events
    click MainApp "https://github.com/abhinavyadav11/ai-dataanalyst-agent/blob/main/app1.py"
    click Devcontainer "https://github.com/abhinavyadav11/ai-dataanalyst-agent/blob/main/.devcontainer/devcontainer.json"
    click Requirements "https://github.com/abhinavyadav11/ai-dataanalyst-agent/blob/main/requirements.txt"
    click README "https://github.com/abhinavyadav11/ai-dataanalyst-agent/blob/main/README.md"
    click LICENSE "https://github.com/abhinavyadav11/ai-dataanalyst-agent/tree/main/LICENSE"

    %% Styles
    classDef ui fill:#ADD8E6,stroke:#333,stroke-width:1px
    classDef logic fill:#90EE90,stroke:#333,stroke-width:1px
    classDef config fill:#FFD580,stroke:#333,stroke-width:1px
    classDef client fill:#D8BFD8,stroke:#333,stroke-width:1px
    classDef external fill:#BA55D3,stroke:#333,stroke-width:1px
    classDef storage fill:#D3D3D3,stroke:#333,stroke-width:1px
    classDef infra fill:#FFE4B5,stroke:#333,stroke-width:1px
    classDef doc fill:#F0E68C,stroke:#333,stroke-width:1px
```
