# srujanrana07/rag-based-policy-agent architecture

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

- Interactive diagram: https://gitdiagram.com/srujanrana07/rag-based-policy-agent
- Repository: https://github.com/srujanrana07/rag-based-policy-agent

## Overview

##### Project Type and Purpose
- This is a focused, enterprise-grade Retrieval-Augmented Generation (RAG) system, exposed as a Flask REST API.
- Purpose: ingest and preprocess policy PDFs, build a searchable FAISS vector index of embeddings, and answer policy questions via Google Gemini LLM, all with strict context grounding.

##### File Structure Analysis
- Flat root directory with key modules (app.py/main.py as entrypoints).
- document_loader.py & deploy.sh: ingestion & deployment glue.
- vectorizer.py & retriever.py: embedding and search logic.
- gpt_client.py & submitter.py: LLM orchestration and query submission.
- Temporary/state files (answers_output.json, temp.json, log.txt) show runtime data flow.
- requirements.txt, .gitignore, Docker-ready deploy.sh signal containerized, Python-based micro-services.

##### README Insights
- Layers: PDF rendering (GhostScript) → Table extraction (Camelot-py) → Semantic embedding (Sentence Transformers) → Vector search (FAISS) → Reasoning (Gemini).
- Emphasis on modular Flask endpoints: /upload, /extract, /query.

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% External Client
    Client["Client UI"]:::external

    %% API Layer
    subgraph "API Layer"
        direction TB
        App["Flask API Server\n(app.py)"]:::internal
        Main["Alternative Entrypoint\n(main.py)"]:::internal
    end

    Client -->|"POST/GET JSON"| App
    Main --> App

    %% Preprocessing Layer
    subgraph "Preprocessing Layer"
        direction TB
        DocumentLoader["Document Loader\n(document_loader.py)"]:::internal
        GhostScript["GhostScript"]:::external
        Camelot["Camelot-py"]:::external
    end

    App -->|"upload PDF"| DocumentLoader
    DocumentLoader -->|"render pages"| GhostScript
    DocumentLoader -->|"extract tables/text"| Camelot
    DocumentLoader -->|"intermediate JSON"| DataStore

    %% Embedding Layer
    subgraph "Embedding Layer"
        direction TB
        Embedding["Embedding\n(vectorizer.py)"]:::internal
    end

    DocumentLoader -->|"JSON pages"| Embedding
    Embedding -->|"embedding vectors"| Retrieval

    %% Retrieval Layer
    subgraph "Retrieval Layer"
        direction TB
        Retrieval["FAISS Index\n(retriever.py)"]:::internal
    end

    Retrieval -->|"store index"| DataStore

    %% Query Flow
    App -->|"JSON query"| Retrieval
    Retrieval -->|"top-k contexts"| LLMClient

    %% LLM Service Layer
    subgraph "LLM Service"
        direction TB
        LLMClient["LLM Client\n(gpt_client.py)"]:::internal
        Submitter["Submitter\n(submitter.py)"]:::internal
        Gemini["Google Gemini"]:::external
    end

    LLMClient -->|"prepare prompt"| Submitter
    Submitter -->|"LLM API call"| Gemini
    Gemini -->|"LLM response"| Submitter
    Submitter -->|"response JSON"| LLMClient
    LLMClient -->|"final answer"| App
    App -->|"JSON response"| Client

    %% Data Store
    DataStore["File System\nanswers_output.json, temp.json, questions.json"]:::datastore

    %% Deployment & Metadata
    subgraph "Project Scripts & Metadata"
        direction TB
        Deploy["Deployment Script\n(deploy.sh)"]:::script
        Req["Dependencies\n(requirements.txt)"]:::script
        Log["Logging\n(log.txt)"]:::script
        Readme["README.md"]:::metadata
        Gitignore[".gitignore"]:::metadata
        License["LICENSE"]:::metadata
    end

    %% Click Events
    click App "https://github.com/srujanrana07/rag-based-policy-agent/blob/main/app.py"
    click Main "https://github.com/srujanrana07/rag-based-policy-agent/blob/main/main.py"
    click DocumentLoader "https://github.com/srujanrana07/rag-based-policy-agent/blob/main/document_loader.py"
    click Embedding "https://github.com/srujanrana07/rag-based-policy-agent/blob/main/vectorizer.py"
    click Retrieval "https://github.com/srujanrana07/rag-based-policy-agent/blob/main/retriever.py"
    click LLMClient "https://github.com/srujanrana07/rag-based-policy-agent/blob/main/gpt_client.py"
    click Submitter "https://github.com/srujanrana07/rag-based-policy-agent/blob/main/submitter.py"
    click Deploy "https://github.com/srujanrana07/rag-based-policy-agent/blob/main/deploy.sh"
    click DataStore "https://github.com/srujanrana07/rag-based-policy-agent/blob/main/answers_output.json"
    click DataStore "https://github.com/srujanrana07/rag-based-policy-agent/blob/main/temp.json"
    click DataStore "https://github.com/srujanrana07/rag-based-policy-agent/blob/main/questions.json"
    click Req "https://github.com/srujanrana07/rag-based-policy-agent/blob/main/requirements.txt"
    click Log "https://github.com/srujanrana07/rag-based-policy-agent/blob/main/log.txt"
    click Readme "https://github.com/srujanrana07/rag-based-policy-agent/blob/main/README.md"
    click Gitignore "https://github.com/srujanrana07/rag-based-policy-agent/blob/main/.gitignore"
    click License "https://github.com/srujanrana07/rag-based-policy-agent/tree/main/LICENSE"

    %% Styles
    classDef external fill:#f9f,stroke:#333,stroke-width:1px
    classDef internal fill:#bbf,stroke:#333,stroke-width:1px
    classDef datastore fill:#bfb,stroke:#333,stroke-width:1px
    classDef script fill:#ffb,stroke:#333,stroke-width:1px
    classDef metadata fill:#ddd,stroke:#333,stroke-width:1px
```
