# vikrantvikaasa27/ai-document-assistant architecture

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

- Interactive diagram: https://gitdiagram.com/vikrantvikaasa27/ai-document-assistant
- Repository: https://github.com/vikrantvikaasa27/ai-document-assistant

## Overview

##### Project Type and Purpose
- This is a single-page, full-stack document-QA web application built with Streamlit and LangChain.
- Purpose: Allow users to upload research PDFs, extract and chunk text, index embeddings in memory, and answer user questions via NVIDIA’s Llama-3.3-70B model.

##### File Structure
- Top-level files:
- app.py – entry point combining UI and backend logic
- requirements.txt – Python dependencies
- README.md – describes features, workflows, and tech stack
- No separate “frontend” or “backend” folders – both UI and processing logic live in app.py.

##### Key Components (to represent
a. Streamlit Frontend
- File upload widget
- Query input field & response display
b. Document Processing Pipeline
- LangChain’s PDFPlumberLoader
- RecursiveCharacterTextSplitter (text chunking)
c. In-Memory Vector Store
- Storage for document embeddings
- Similarity search layer
d. LLM Service (External)
- Requires NVIDIA_API_KEY environment variable
e. Orchestration & Glue Code
- Sequence of calls in app.py tying UI, processing, vector store, and LLM

##### Relationships & Data Flows
1) User uploads PDF via Streamlit UI
2) PDFPlumberLoader extracts raw text
3) TextSplitter divides text into chunks
4) Each chunk is embedded (vectorized) and stored in In-Memory Vector Store
5) User enters a question; similarity search finds top chunks
6) Selected chunks plus question are sent to NVIDIA LLM endpoint
7) Response returns to app.py, then displayed in the UI

##### Architectural Patterns & Principles
- Monolithic service with well-defined stages (loader → splitter → index → query → LLM)
- “Pipelines” pattern: sequential transformation of data
- Separation of concerns at the code level (embeddings vs. storage vs. UI), though in one file

##### Technologies & Frameworks to Call Out
- Streamlit (UI) – Python-based interactive web front end
- LangChain modules (Loader, TextSplitter, InMemoryVectorStore)
- NVIDIA AI Endpoint (external LLM API)
- PDFPlumber (PDF parsing)
- Environment Variables (.env for API key)

##### Final Checklist
- All main components present: UI, loader, splitter, index, LLM API
- Call out important libraries (Streamlit, LangChain, PDFPlumber)

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Streamlit UI Layer
    subgraph "Streamlit Frontend"
        direction TB
        SF["Streamlit Frontend"]:::ui
        FU["File Upload Widget"]:::ui
        QI["Query Input Field"]:::ui
        RDSP["Response Display"]:::ui
    end

    %% Document Processing Pipeline
    subgraph "Document Processing Pipeline"
        direction TB
        DP["Document Processing Pipeline"]:::processing
        PL["PDFPlumberLoader"]:::processing
        TS["RecursiveCharacterTextSplitter"]:::processing
    end

    %% In-Memory Vector Store
    subgraph "In-Memory Vector Store"
        direction TB
        VS["In-Memory Vector Store"]:::store
        SS["Similarity Search"]:::store
    end

    %% External LLM Service
    subgraph "LLM Service (External)"
        direction TB
        LLM["NVIDIA Llama-3.3-70B Endpoint"]:::external
        ENV[".env (NVIDIA_API_KEY)"]:::config
    end

    %% Orchestration & Entry Point
    ORCH["Application Orchestration (app.py)"]:::orchestration

    %% Documentation & Manifest
    REQ["requirements.txt"]:::docs
    RDM["README.md"]:::docs

    %% Data Flows
    FU -->|"upload PDF"| PL
    PL -->|"extract text"| TS
    TS -->|"embed chunk"| VS
    QI -->|"question"| SS
    VS -->|"store vectors"| SS
    SS -->|"top chunks + question"| LLM
    ENV --> LLM
    LLM -->|"response"| RDSP
    ORCH --> SF
    ORCH --> DP
    ORCH --> VS
    ORCH --> LLM

    %% Click Events
    click SF "https://github.com/vikrantvikaasa27/ai-document-assistant/blob/main/app.py"
    click DP "https://github.com/vikrantvikaasa27/ai-document-assistant/blob/main/app.py"
    click VS "https://github.com/vikrantvikaasa27/ai-document-assistant/blob/main/app.py"
    click LLM "https://github.com/vikrantvikaasa27/ai-document-assistant/blob/main/app.py"
    click ORCH "https://github.com/vikrantvikaasa27/ai-document-assistant/blob/main/app.py"
    click REQ "https://github.com/vikrantvikaasa27/ai-document-assistant/blob/main/requirements.txt"
    click RDM "https://github.com/vikrantvikaasa27/ai-document-assistant/blob/main/README.md"

    %% Styles
    classDef ui fill:#cce5ff,stroke:#004085,color:#004085
    classDef processing fill:#d4edda,stroke:#155724,color:#155724
    classDef store fill:#d1ecf1,stroke:#0c5460,color:#0c5460
    classDef external fill:#fff3cd,stroke:#856404,color:#856404
    classDef config fill:#e2e3e5,stroke:#6c757d,color:#6c757d
    classDef orchestration fill:#f8d7da,stroke:#721c24,color:#721c24
    classDef docs fill:#f5f5f5,stroke:#333333,color:#333333
```
