# jatin-mehra119/wasserstoff-aiinterntask architecture

> Architecture diagram of the GitHub repository jatin-mehra119/wasserstoff-aiinterntask, 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/jatin-mehra119/wasserstoff-aiinterntask
- Repository: https://github.com/jatin-mehra119/wasserstoff-aiinterntask

## Overview

##### Project Type and Purpose
- This is a full-stack Retrieval-Augmented Generation (RAG) chat application.
- Purpose: Ingest multi-format documents (PDF, text, images), build a FAISS vector store, perform semantic search + AI-powered chat with citations and theme analysis, and serve via a FastAPI backend + HTML/JS frontend (plus an MVP Streamlit UI).

##### File Structure
- Top-level
- rag_elements/ – Core RAG engine (`enhanced_vectordb.py`, `config.py`)
- backend/ – FastAPI service (entry point, Pydantic models, utils, route modules, runtime vector_store/)
- frontend/ – Static web assets (HTML, JS, CSS)
- streamlit_rag_app.py – MVP Streamlit UI
- requirements.txt, Dockerfile, CI workflows, tests/
- Patterns & Config
- Modular “routes” in backend indicating clear API layering
- `vector_store/` folder shows disk-backed FAISS index + metadata
- `enhanced_vectordb.py` implements ingestion → chunking → embedding → FAISS index → search → AI integration

##### Core Components & Interactions
a. Client Layer (Browser)
- index.html, script.js, style.css
- Interacts via REST API (XHR/fetch) to FastAPI
b. Backend Layer (FastAPI)
- main.py: app startup, CORS, mounting routes
- models.py / utils.py: data schemas + helpers
- routes/:
- main_routes.py – serve static frontend + health check
- upload_routes.py – file-upload & directory processing
- chat_routes.py – chat endpoint, calls RAG engine
- store_routes.py – save/load FAISS vector store
c. RAG Engine Layer (rag_elements)
- EnhancedDocumentProcessor: process_documents(), create_vector_store(), search_documents(), get_chat_response(), save/load store
- Connects to FAISS library, SentenceTransformers, LangChain, GROQ Vision API for OCR & chat
d. Data Persistence
- FAISS index files (`index.faiss`, `index.pkl`) + `enhanced_metadata.json` in backend/vector_store/
e. External Services
- GROQ Vision API (OCR + LLM chat)
- Sentence Transformer models (embeddings)
- FAISS (local similarity search)

##### Architectural Patterns & Design Principles
- Layered Separation: UI ↔ API ↔ Core Engine
- Modular Routes: clear REST API surface
- Async I/O: FastAPI async endpoints + aiofiles
- Pluggable Engine: rag_elements easily reusable/testable
- Persistence decoupled: disk-backed vector store with load/save endpoints
- Single-page App style: frontend fetches JSON, renders chat & stats

## Diagram (Mermaid)

```mermaid
flowchart TD
  %% Client Layer
  subgraph "Client Layer"
    direction TB
    WebClient["Web Client (HTML/JS/CSS)"]:::ui
    StreamlitUI["MVP Streamlit UI"]:::ui
  end

  %% Backend Layer
  subgraph "Backend Layer"
    direction TB
    FastAPI["FastAPI Backend"]:::api
    subgraph routes["Routes"]
      direction TB
      MainRoutes["main_routes.py"]:::api
      UploadRoutes["upload_routes.py"]:::api
      ChatRoutes["chat_routes.py"]:::api
      StoreRoutes["store_routes.py"]:::api
    end
    Models["models.py"]:::api
    Utils["utils.py"]:::api
  end

  %% RAG Engine Layer
  subgraph "RAG Engine Layer"
    direction TB
    Config["config.py"]:::core
    CoreEngine["enhanced_vectordb.py"]:::core
  end

  %% Persistence Layer
  VectorStore[(Vector Store<br/>FAISS Index + Metadata)]:::store

  %% External Services
  subgraph "External Services"
    direction TB
    GROQ["GROQ Vision API"]:::external
    SentenceModel["SentenceTransformer Model"]:::external
  end

  %% Tests
  subgraph "Automated Tests"
    direction TB
    Tests1["test_api_endpoints.py"]:::tests
    Tests2["test_endpoints_pytest.py"]:::tests
  end

  %% Connections
  WebClient -->|"/api/*" fetch| FastAPI
  MainRoutes -->|serve static| WebClient
  StreamlitUI -->|in-process calls| CoreEngine
  FastAPI -->|calls RAG Engine| CoreEngine
  CoreEngine -->|read/write| VectorStore
  CoreEngine -->|OCR & LLM requests| GROQ
  CoreEngine -->|embedding requests| SentenceModel
  StoreRoutes -->|disk read/write| VectorStore

  %% Click Events
  click WebClient "https://github.com/jatin-mehra119/wasserstoff-aiinterntask/blob/main/frontend/index.html"
  click WebClient "https://github.com/jatin-mehra119/wasserstoff-aiinterntask/blob/main/frontend/script.js"
  click WebClient "https://github.com/jatin-mehra119/wasserstoff-aiinterntask/blob/main/frontend/style.css"
  click StreamlitUI "https://github.com/jatin-mehra119/wasserstoff-aiinterntask/blob/main/streamlit_rag_app.py"
  click FastAPI "https://github.com/jatin-mehra119/wasserstoff-aiinterntask/blob/main/backend/main.py"
  click Models "https://github.com/jatin-mehra119/wasserstoff-aiinterntask/blob/main/backend/models.py"
  click Utils "https://github.com/jatin-mehra119/wasserstoff-aiinterntask/blob/main/backend/utils.py"
  click MainRoutes "https://github.com/jatin-mehra119/wasserstoff-aiinterntask/blob/main/backend/routes/main_routes.py"
  click UploadRoutes "https://github.com/jatin-mehra119/wasserstoff-aiinterntask/blob/main/backend/routes/upload_routes.py"
  click ChatRoutes "https://github.com/jatin-mehra119/wasserstoff-aiinterntask/blob/main/backend/routes/chat_routes.py"
  click StoreRoutes "https://github.com/jatin-mehra119/wasserstoff-aiinterntask/blob/main/backend/routes/store_routes.py"
  click Config "https://github.com/jatin-mehra119/wasserstoff-aiinterntask/blob/main/rag_elements/config.py"
  click CoreEngine "https://github.com/jatin-mehra119/wasserstoff-aiinterntask/blob/main/rag_elements/enhanced_vectordb.py"
  click Tests1 "https://github.com/jatin-mehra119/wasserstoff-aiinterntask/blob/main/test/test_api_endpoints.py"
  click Tests2 "https://github.com/jatin-mehra119/wasserstoff-aiinterntask/blob/main/test/test_endpoints_pytest.py"

  %% Styles
  classDef ui fill:#E3F2FD,stroke:#1976D2,color:#0D47A1;
  classDef api fill:#E8F5E9,stroke:#388E3C,color:#1B5E20;
  classDef core fill:#FFF3E0,stroke:#FB8C00,color:#E65100;
  classDef store fill:#FFF9C4,stroke:#FBC02D,color:#F57F17;
  classDef external fill:#ECEFF1,stroke:#607D8B,color:#37474F;
  classDef tests fill:#F3E5F5,stroke:#8E24AA,color:#4A148C;
```
