# muhammadzainrehmani/document-gpt architecture

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

- Interactive diagram: https://gitdiagram.com/muhammadzainrehmani/document-gpt
- Repository: https://github.com/muhammadzainrehmani/document-gpt

## Overview

##### Project type and purpose
- DocumentGPT is a full-stack, single-page Streamlit application for conversational document Q&A.
- It accepts user‐uploaded PDFs/DOCXs, chunks and embeds text, stores vectors in Qdrant, and routes queries through Gemini 1.5 Flash via LangChain.

##### File structure
- Top level:
- app.py – main Streamlit entrypoint and orchestration
- requirements.txt – Python dependencies
- PDF/ – sample document storage
- images/ – UI assets (if any)
- .streamlit/secrets.toml (described in README) – contains API keys for Gemini and Qdrant
- No separate “frontend” or “backend” folders; the app.py script houses both UI and server logic.

##### README for additional insights
- Embedding model: HuggingFace all-mpnet-base-v2
- Vector store: Qdrant (external service)
- LLM: Google Gemini 1.5 Flash via Generative AI API
- Pipeline steps: upload → chunk & metadata tag → embeddings → Qdrant upsert → chat interface → query embeddings → LLM call

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Client
    UserBrowser["User's Browser"]:::frontend
    %% UI Layer
    StreamlitUI["Streamlit UI\n(app.py)"]:::ui
    %% Preprocessing
    DocumentLoader["Document Loader & Chunker"]:::process
    EmbeddingGenerator["Embedding Generator\n(all-mpnet-base-v2)"]:::process
    %% Storage & Config
    QdrantDB["Vector Database\n(Qdrant)"]:::storage
    Secrets["Config & Secrets\n(.streamlit/secrets.toml)"]:::config
    PDFStorage["Sample Documents\n(PDF/)"]:::storage
    UIAssets["UI Assets\n(images/)"]:::storage
    Dependencies["Project Dependencies\n(requirements.txt)"]:::config
    README["Project Overview\n(README.md)"]:::config
    %% Agent & External Services
    LangChainAgent["Conversational Agent\n(LangChain)"]:::external
    GeminiAPI["Gemini 1.5 Flash API"]:::external

    %% Ingestion Flow
    UserBrowser -->|"upload document"| StreamlitUI
    StreamlitUI -->|"upload"| DocumentLoader
    DocumentLoader -->|"text chunks"| EmbeddingGenerator
    EmbeddingGenerator -->|"vectors"| QdrantDB
    QdrantDB -->|"upsert confirmation"| StreamlitUI

    %% Query Flow
    UserBrowser -->|"ask query"| StreamlitUI
    StreamlitUI -->|"query text"| LangChainAgent
    LangChainAgent -->|"similarity search"| QdrantDB
    QdrantDB -->|"retrieved chunks"| LangChainAgent
    LangChainAgent -->|"API call"| GeminiAPI
    GeminiAPI -->|"response text"| LangChainAgent
    LangChainAgent -->|"answer"| StreamlitUI
    StreamlitUI -->|"display answer"| UserBrowser

    %% Dependencies & Assets
    StreamlitUI --- Secrets
    StreamlitUI --- Dependencies
    StreamlitUI --- README
    StreamlitUI --- UIAssets
    StreamlitUI --- PDFStorage

    %% Click events
    click StreamlitUI "https://github.com/muhammadzainrehmani/document-gpt/blob/main/app.py"
    click DocumentLoader "https://github.com/muhammadzainrehmani/document-gpt/blob/main/app.py"
    click EmbeddingGenerator "https://github.com/muhammadzainrehmani/document-gpt/blob/main/app.py"
    click QdrantDB "https://github.com/muhammadzainrehmani/document-gpt/blob/main/app.py"
    click LangChainAgent "https://github.com/muhammadzainrehmani/document-gpt/blob/main/app.py"
    click Dependencies "https://github.com/muhammadzainrehmani/document-gpt/blob/main/requirements.txt"
    click PDFStorage "https://github.com/muhammadzainrehmani/document-gpt/tree/main/PDF/"
    click UIAssets "https://github.com/muhammadzainrehmani/document-gpt/tree/main/images/"
    click README "https://github.com/muhammadzainrehmani/document-gpt/blob/main/README.md"

    %% Styles
    classDef frontend fill:#d0e6fa,stroke:#0366d6,color:#0366d6;
    classDef ui fill:#cfe8fc,stroke:#0366d6,color:#0366d6;
    classDef process fill:#e2f7e1,stroke:#2c662d,color:#2c662d;
    classDef storage fill:#f0e1ff,stroke:#5c2e7e,color:#5c2e7e;
    classDef config fill:#f2f2f2,stroke:#808080,color:#333333,stroke-dasharray: 2 2;
    classDef external fill:#ffe5cc,stroke:#d97706,color:#d97706;
```
