# saheba-freeji/simran-r-wasserstoff-aiinterntask architecture

> Architecture diagram of the GitHub repository saheba-freeji/simran-r-wasserstoff-aiinterntask, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-05-22). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/saheba-freeji/simran-r-wasserstoff-aiinterntask
- Repository: https://github.com/saheba-freeji/simran-r-wasserstoff-aiinterntask

## Overview

##### Project Type and Purpose
- This is a full-stack “Document Theme Identifier Chatbot.”
- Frontend: Streamlit UI for uploading documents and chatting.
- Backend: FastAPI service that ingests documents, runs OCR, builds a vector store, queries an LLM, and identifies themes.
- Data: FAISS vector store for embeddings; local file store for original docs.
- External Services: Tesseract OCR and OpenAI GPT API.

##### File Structure
- Top‐level folders:
- backend/ – FastAPI code, models (api.py, document.py), service modules (document_parser.py, theme_identifier.py, vector_store.py, etc.), Dockerfile, data/vectorstore, files/
- frontend/ – Streamlit app (app.py), Dockerfile
- docker-compose.yml, start.sh – orchestrates frontend, backend, and any side‐cars
- Key patterns:
- Modular “services” in backend – single FastAPI process coordinating parsing, vector store, theme logic
- Separate concerns: config, models, services, data, files

##### README for Additional Insights
- Confirms architecture: FastAPI + Streamlit, FAISS, Tesseract, OpenAI
- Lists API endpoints (/upload, /chat, /documents) and UI flow tabs
- Describes containerized deployment via Docker Compose

##### Main Components & Their Relationships
a. Frontend (Streamlit)
- UI for file upload, query input, and displaying citations/themes
- Communicates via HTTP to Backend API endpoints
b. Backend (FastAPI)
- /upload → DocumentParser service:
- Reads DOCX, PDF, images
- Runs Tesseract OCR on scans
- Normalizes text, calls VectorStore service to index embeddings in FAISS
- /chat → ThemeIdentifier service:
- Receives user query
- Queries FAISS for relevant document chunks
- Calls OpenAI GPT API to extract themes and generate citations
- /documents → Lists available files and metadata
c. Data Storage
- FAISS vectorstore (faiss.index + metadata.pkl) for nearest‐neighbor embedding retrieval
- Local “files/” folder to hold original docs
d. External Services
- Tesseract OCR engine (local container or binary)
- OpenAI GPT (REST API)

##### Architectural Patterns & Design Principles
- Layered architecture:
- Presentation (Streamlit)
- API (FastAPI controllers)
- Business logic (document_parser, theme_identifier, vector_store services)
- Infrastructure (Vector store, file storage, external OCR/LLM)
- Separation of concerns: parsing vs. indexing vs. theme extraction
- Containerized micro‐deploy units orchestrated by Docker Compose

##### Elements to Include for Maximum Clarity
- Component labels with filenames or modules (e.g., DocumentParser service, ThemeIdentifier service)

## Diagram (Mermaid)

```mermaid
graph TD
    subgraph "Frontend Container"
        UI["Streamlit UI<br>(app.py)"]:::ui
        FDOCKER["Dockerfile"]:::infra
    end

    subgraph "Backend Container"
        subgraph "Controller Layer"
            API["FastAPI API<br>(main.py)"]:::backend
        end
        subgraph "Models"
            APIModel["API Models<br>(api.py)"]:::backend
            DocModel["Document Model<br>(document.py)"]:::backend
        end
        subgraph "Service Layer"
            Parser["DocumentParser Service"]:::backend
            Vector["VectorStore Service"]:::backend
            Theme["ThemeIdentifier Service"]:::backend
            TestP["Test Parser"]:::backend
        end
        BDOCKER["Dockerfile"]:::infra
    end

    subgraph "Data Stores"
        VS["FAISS Vector Store<br>(metadata.pkl)"]:::datastore
        FS["File Storage"]:::datastore
    end

    subgraph "External Services"
        OCR["Tesseract OCR"]:::external
        LLM["OpenAI GPT API"]:::external
    end

    subgraph "Orchestration"
        Compose["docker-compose.yml"]:::infra
        Start["start.sh"]:::infra
    end

    %% Data Flows
    UI -->|HTTP JSON /upload| API
    UI -->|HTTP JSON /chat| API
    UI -->|HTTP JSON /documents| API

    API -->|save docs| FS
    API -->|indexEmbeddings| Parser
    Parser -->|runs OCR| OCR
    Parser -->|FAISS SDK calls| Vector
    Vector -->|write index| VS

    API -->|queryEmbeddings| Vector
    Vector -->|return chunks| API
    API -->|generateThemes| LLM
    LLM -->|themes & citations| API
    API -->|HTTP JSON response| UI

    %% Click Events
    click UI "https://github.com/saheba-freeji/simran-r-wasserstoff-aiinterntask/blob/main/frontend/app.py"
    click FDOCKER "https://github.com/saheba-freeji/simran-r-wasserstoff-aiinterntask/tree/main/frontend/Dockerfile"
    click API "https://github.com/saheba-freeji/simran-r-wasserstoff-aiinterntask/blob/main/backend/app/main.py"
    click APIModel "https://github.com/saheba-freeji/simran-r-wasserstoff-aiinterntask/blob/main/backend/app/models/api.py"
    click DocModel "https://github.com/saheba-freeji/simran-r-wasserstoff-aiinterntask/blob/main/backend/app/models/document.py"
    click Parser "https://github.com/saheba-freeji/simran-r-wasserstoff-aiinterntask/blob/main/backend/app/services/document_parser.py"
    click Vector "https://github.com/saheba-freeji/simran-r-wasserstoff-aiinterntask/blob/main/backend/app/services/vector_store.py"
    click Theme "https://github.com/saheba-freeji/simran-r-wasserstoff-aiinterntask/blob/main/backend/app/services/theme_identifier.py"
    click TestP "https://github.com/saheba-freeji/simran-r-wasserstoff-aiinterntask/blob/main/backend/app/services/test_parser.py"
    click VS "https://github.com/saheba-freeji/simran-r-wasserstoff-aiinterntask/blob/main/backend/data/vectorstore/metadata.pkl"
    click FS "https://github.com/saheba-freeji/simran-r-wasserstoff-aiinterntask/tree/main/backend/files/"
    click BDOCKER "https://github.com/saheba-freeji/simran-r-wasserstoff-aiinterntask/tree/main/backend/Dockerfile"
    click Compose "https://github.com/saheba-freeji/simran-r-wasserstoff-aiinterntask/blob/main/docker-compose.yml"
    click Start "https://github.com/saheba-freeji/simran-r-wasserstoff-aiinterntask/blob/main/start.sh"

    %% Styles
    classDef ui fill:#cfe2f3,stroke:#6fa8dc,color:#000
    classDef backend fill:#d9e1f2,stroke:#6d9eeb,color:#000
    classDef datastore fill:#d9ead3,stroke:#82c91e,color:#000
    classDef external fill:#f4cccc,stroke:#e06666,color:#000
    classDef infra fill:#eeeeee,stroke:#999999,color:#000
```
