# isurulkh/rag-application-gemini architecture

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

- Interactive diagram: https://gitdiagram.com/isurulkh/rag-application-gemini
- Repository: https://github.com/isurulkh/rag-application-gemini

## Overview

##### Project Type and Purpose
- Type: Full-stack web application (single-page UI + backend logic bundled in app.py).
- Purpose: Let users upload PDFs, index them via embeddings, then ask context-aware questions answered by Google Gemini.

##### Main Components
a. User Interface (Streamlit)
- Rendered in the browser.
- Handles file upload, question input, and displays answers.
b. Application Logic (app.py)
- Orchestrates ingestion, embedding, retrieval, and inference.
- Uses LangChain to build the RAG pipeline.
c. Document Store
- Temporary storage of uploaded PDFs (in memory or disk).
d. Vector Store (ChromaDB)
- Stores and indexes document embeddings.
e. Embedding & LLM Service (Google Generative AI / Gemini)
- Generates embeddings for document chunks.
- Performs question answering over retrieved context.
f. Configuration / Environment
- Manages GOOGLE_API_KEY via .env.

##### Relationships & Data Flow
1) User uploads PDF via Streamlit UI.
2) app.py extracts text → chunks → calls Gemini embeddings API.
3) Embeddings stored in ChromaDB.
4) User submits a question → app.py sends retrieval request to ChromaDB → retrieves top-k relevant chunks.
5) Retrieved chunks + question forwarded to Gemini LLM for answer.
6) Answer returned to Streamlit for display.

##### Architectural Patterns & Design Principles
- Single Entry Point: app.py orchestrates end-to-end flow.
- Modular Pipeline: clear separation of ingestion, indexing, retrieval, and inference stages.
- External Service Integration: Google Gemini API for both embeddings and generation.
- State Management: ephemeral document storage and persistent vector store.

4. Within Application Logic, show two sub-blocks:
- Ingestion & Embeddings
- Retrieval & Generation
7. Vector Store → back to Retrieval sub-block.
9. Answer → back to Streamlit UI → Browser → User.
10. Off to the side, list environment config component (.env / GOOGLE_API_KEY).

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% User and Browser
    User(["User"]):::external
    Browser(["Browser"]):::external
    User -->|interacts with| Browser
    Browser -->|access UI| UI
    
    %% UI Layer
    UI["Streamlit UI"]:::ui
    click UI "https://github.com/isurulkh/rag-application-gemini/blob/main/app.py"
    
    %% Application Logic
    subgraph "Application Logic"
        AppLogic["app.py / LangChain Pipeline"]:::logic
        Ingest["Ingestion & Embeddings"]:::storage
        DocumentStore["Document Store"]:::storage
        Retrieve["Retrieval & Generation"]:::retrieval
    end
    click AppLogic "https://github.com/isurulkh/rag-application-gemini/blob/main/app.py"
    click Ingest "https://github.com/isurulkh/rag-application-gemini/blob/main/app.py"
    click DocumentStore "https://github.com/isurulkh/rag-application-gemini/blob/main/app.py"
    click Retrieve "https://github.com/isurulkh/rag-application-gemini/blob/main/app.py"
    
    UI -->|upload PDF / submit question| AppLogic
    AppLogic --> Ingest
    Ingest -->|store PDF| DocumentStore
    Ingest -->|get embeddings| GeminiAPI
    
    %% Vector Store
    VectorStore[(ChromaDB)]:::storage
    click VectorStore "https://github.com/isurulkh/rag-application-gemini/blob/main/app.py"
    Ingest -->|store embeddings| VectorStore
    
    VectorStore -->|retrieve chunks| Retrieve
    Retrieve -->|prepare context| Retrieve
    Retrieve -->|send context| GeminiAPI
    
    %% External AI Service
    GeminiAPI["Google Gemini API"]:::external
    click GeminiAPI "https://github.com/isurulkh/rag-application-gemini/blob/main/app.py"
    
    GeminiAPI -->|return answer| Retrieve
    Retrieve -->|answer| UI
    UI -->|display answer| Browser
    Browser -->|view| User
    
    %% Configuration and Docs
    Env[".env (GOOGLE_API_KEY)"]:::config
    click Env "https://github.com/isurulkh/rag-application-gemini/blob/main/.env"
    Req["requirements.txt"]:::config
    click Req "https://github.com/isurulkh/rag-application-gemini/blob/main/requirements.txt"
    Readme["README.md"]:::config
    click Readme "https://github.com/isurulkh/rag-application-gemini/blob/main/README.md"
    License["LICENSE"]:::config
    click License "https://github.com/isurulkh/rag-application-gemini/tree/main/LICENSE"
    
    %% Legend / Side cluster
    subgraph "Configuration & Docs"
        Env
        Req
        Readme
        License
    end

    %% Styles
    classDef ui fill:#cce5ff,stroke:#003366,color:#003366;
    classDef storage fill:#d4edda,stroke:#155724,color:#155724;
    classDef logic fill:#e2e3e5,stroke:#6c757d,color:#6c757d;
    classDef retrieval fill:#fff3cd,stroke:#856404,color:#856404;
    classDef external fill:#f5c6cb,stroke:#721c24,color:#721c24;
    classDef config fill:#e2e3e5,stroke:#6c757d,color:#6c757d;
```
