# gurpreetkaurjethra/multi-pdfs_chatapp_ai-agent architecture

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

- Interactive diagram: https://gitdiagram.com/gurpreetkaurjethra/multi-pdfs_chatapp_ai-agent
- Repository: https://github.com/gurpreetkaurjethra/multi-pdfs_chatapp_ai-agent

## Overview

##### Project type and purpose
- This is a full-stack, single‐page Streamlit web application (“chatapp.py”) that empowers users to upload multiple PDF documents, convert them into embeddings via LangChain + Google Gemini Pro (and other LLMs), store them in a FAISS vector store, and interact with a conversational QA chatbot in real time.

##### File structure
- Top-level files:
- chatapp.py – main Streamlit entry point (backend + frontend glue)
- requirements.txt – Python dependencies (Streamlit, langchain, google-generativeai, faiss-cpu, PyPDF2, etc.)
- docs/ – sample PDF corpus
- img/ – architecture & demo screenshots
- README.md, .gitignore, LICENSE
- No separate “frontend” vs “backend” folders—Streamlit serves both UI and backend code from one script.
- External config: expects a `.env` with GOOGLE_API_KEY.

##### Extract architecture details from README
- Pipeline:
1. PDF Loading (PyPDF2)
2. Text Chunking (LangChain Sliding Window)
3. Embedding Generation (Google Gemini Pro via langchain_google_genai or other LLMs)
4. Vector Storage & Similarity Search (FAISS)
5. Chat Interface & Response Generation (LLM + chunk retrieval)
- External dependencies: Google Generative AI API (embeddings + chat), optionally OpenAI, Anthropic, Llama2.
- UI: Streamlit front end in the same Python process.

##### Main components
a. **Users (Browser)** – end users interact via web browser
b. **Streamlit Application Server** (chatapp.py)
- UI Layer (Streamlit widgets: file uploader, chat interface)
- Controller/Orchestration layer that invokes processing modules
c. **PDF Loader Module** (PyPDF2)
d. **Text Chunker Module** (LangChain text-splitter, Sliding Window)
e. **Embedding Service** (LangChain abstraction calling Google Generative AI API or alternative LLM endpoints)
f. **Vector Store** (FAISS in-memory or on-disk)
g. **Retriever Module** (calls FAISS similarity search)
h. **Response Generator** (passes selected chunks + user query to LLM API, returns answer)
i. **External Services**
- Google Generative AI API (embeddings + chat completions)
- Optional: OpenAI / Anthropic / Llama2 endpoints
j. **Storage/Config**
- Local .env for API keys
- docs/ folder for sample inputs (not in production)

##### Relationships and data flows
1. Browser → Streamlit UI: user uploads PDFs / sends chat queries
2. Streamlit UI → PDF Loader → extracted text
3. Extracted text → Text Chunker → text chunks
4. Chunks → Embedding Service → vector embeddings
5. Embeddings → FAISS Vector Store → stored vectors
6. On user question:
a. Streamlit UI → Retriever → queries FAISS → top-k chunks
b. Selected chunks + user question → Response Generator → LLM API → formatted answer
7. Answer → Streamlit UI → Browser

##### Architectural patterns and principles
- Pipeline/RAG pattern: ingestion → vectorization → retrieval → generation
- Separation of concerns within the monolithic script: loader, chunker, embedding, storage, retrieval, UI
- Externalize secrets/config via `.env`
- Pluggable LLM backends via LangChain abstractions

##### Relevant technologies/frameworks
- Streamlit (UI + server)
- PyPDF2 (PDF parsing)
- LangChain (text splitting, embeddings, LLM chaining)
- langchain_google_genai (Google API adapter)
- faiss‐cpu (vector database)
- python‐dotenv (config)
- Python 3.x

##### Summary
- Capturing the essential pipeline stages and their interconnections is key.
- Be exhaustive but logical: group related steps under “Ingestion”, “Vector DB & Retrieval”, “LLM Interaction”, and “UI”.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% User Interaction
    Users["Users (Browser)"]:::external
    Users -->|"upload PDFs / send queries"| UI

    %% UI Layer
    subgraph "UI Layer"
        UI["Streamlit UI"]:::internal
    end

    UI -->|"invoke PDF loader"| PDFLoader
    UI -->|"submit chat query"| Retriever

    %% Ingestion
    subgraph "Ingestion"
        PDFLoader["PDF Loader<br/>(PyPDF2)"]:::internal
        TextChunker["Text Chunker<br/>(LangChain Sliding Window)"]:::internal
        EmbeddingService["Embedding Service<br/>(LangChain → Google GenAI / LLM)"]:::internal
    end

    PDFLoader -->|"extracted text"| TextChunker
    TextChunker -->|"text chunks"| EmbeddingService
    EmbeddingService -->|"generate embeddings"| FAISS

    %% Vector DB & Retrieval
    subgraph "Vector DB & Retrieval"
        FAISS["FAISS Vector Store"]:::storage
        Retriever["Retriever Module<br/>(FAISS similarity search)"]:::internal
    end

    FAISS -->|"store vectors"| FAISS
    Retriever -->|"top-k chunks"| ResponseGen

    %% LLM Interaction
    subgraph "LLM Interaction"
        ResponseGen["Response Generator<br/>(LLM chat completion)"]:::internal
    end

    ResponseGen -->|"chat completion request"| Google
    ResponseGen -->|"chat completion request"| OpenAI
    ResponseGen -->|"chat completion request"| Anthropic
    ResponseGen -->|"chat completion request"| Llama2
    ResponseGen -->|"formatted answer"| UI

    %% External Services
    subgraph "External Services"
        Google["Google Generative AI API"]:::external
        OpenAI["OpenAI API (optional)"]:::external
        Anthropic["Anthropic API (optional)"]:::external
        Llama2["Llama2 Endpoint (optional)"]:::external
    end

    %% Storage & Config
    subgraph "Storage / Config"
        docs["docs/ folder"]:::storage
        env[".env (API Keys)"]:::storage
        requirements["requirements.txt"]:::storage
        README["README.md"]:::storage
        LICENSE["LICENSE"]:::storage
        gitignore[".gitignore"]:::storage
        img["img/ folder"]:::storage
    end

    %% Legend (for clarity, can be omitted if not needed)
    classDef internal fill:#9f6,stroke:#333,stroke-width:1px;
    classDef external fill:#6cf,stroke:#333,stroke-width:1px;
    classDef storage fill:#f96,stroke:#333,stroke-width:1px;

    %% Click Events
    click UI "https://github.com/gurpreetkaurjethra/multi-pdfs_chatapp_ai-agent/blob/main/chatapp.py"
    click PDFLoader "https://github.com/gurpreetkaurjethra/multi-pdfs_chatapp_ai-agent/blob/main/chatapp.py"
    click TextChunker "https://github.com/gurpreetkaurjethra/multi-pdfs_chatapp_ai-agent/blob/main/chatapp.py"
    click EmbeddingService "https://github.com/gurpreetkaurjethra/multi-pdfs_chatapp_ai-agent/blob/main/chatapp.py"
    click FAISS "https://github.com/gurpreetkaurjethra/multi-pdfs_chatapp_ai-agent/blob/main/chatapp.py"
    click Retriever "https://github.com/gurpreetkaurjethra/multi-pdfs_chatapp_ai-agent/blob/main/chatapp.py"
    click ResponseGen "https://github.com/gurpreetkaurjethra/multi-pdfs_chatapp_ai-agent/blob/main/chatapp.py"
    click docs "https://github.com/gurpreetkaurjethra/multi-pdfs_chatapp_ai-agent/tree/main/docs/"
    click img "https://github.com/gurpreetkaurjethra/multi-pdfs_chatapp_ai-agent/tree/main/img/"
    click requirements "https://github.com/gurpreetkaurjethra/multi-pdfs_chatapp_ai-agent/blob/main/requirements.txt"
    click README "https://github.com/gurpreetkaurjethra/multi-pdfs_chatapp_ai-agent/blob/main/README.md"
    click LICENSE "https://github.com/gurpreetkaurjethra/multi-pdfs_chatapp_ai-agent/tree/main/LICENSE"
    click gitignore "https://github.com/gurpreetkaurjethra/multi-pdfs_chatapp_ai-agent/blob/main/.gitignore"
    click env "https://github.com/gurpreetkaurjethra/multi-pdfs_chatapp_ai-agent/blob/main/.env"
```
