# karwap22/ragi architecture

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

- Interactive diagram: https://gitdiagram.com/karwap22/ragi
- Repository: https://github.com/karwap22/ragi

## Overview

##### Project type and purpose
- This is a full-stack browser extension (“AI Buddy”) that combines a frontend (the extension UI + background script + content scripts) with a Python/Flask backend.
- Purpose: extract page text → send it to a retrieval-augmented generation (RAG) pipeline → generate streaming summaries and Q&A responses → display and persist results per URL.

##### File structure
├─ backend/
│   ├─ main.py       # entry point – starts Flask server & SSE endpoints
│   ├─ server.py     # defines REST/SSE routes for summarization & Q&A
│   ├─ utils.py      # text splitting, embedding generation, FAISS setup
│   └─ requirements.txt
├─ frontend/
│   ├─ manifest.json & manifest_sidebar.json  # extension metadata, permissions, scripts
│   ├─ background.js  # service worker handling network calls & message routing
│   ├─ popup.html/css/js  # UI for “Extract Text”, display summary & Q&A form
│   ├─ question.js     # logic for sending questions & rendering streaming answers
│   └─ summary.js      # logic for initiating summarization and handling SSE stream
└─ README.md, Demo_compressed.mp4, .gitignore

##### Key README insights
- Tech stack: JavaScript/HTML/CSS (extension) + Python/Flask + Flask-CORS + LangChain + Ollama LLM + FAISS.
- Workflow summary: frontend → backend RAG (embeddings + vector search + LLM) → SSE streaming back.
- Persistent storage: local extension storage for summaries/Q&A per URL.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Browser Extension Layer
    subgraph "Browser Extension" 
        direction TB
        Manifest["manifest.json"]:::frontend
        SidebarManifest["manifest_sidebar.json"]:::frontend
        Background["background.js"]:::frontend
        PopupHTML["popup.html"]:::frontend
        PopupCSS["popup.css"]:::frontend
        PopupJS["popup.js"]:::frontend
        QuestionJS["question.js"]:::frontend
        SummaryJS["summary.js"]:::frontend
        LocalStorage[(Local Storage)]:::datastore
    end

    %% Backend RAG Server Layer
    subgraph "Backend RAG Server"
        direction TB
        MainPy["main.py"]:::backend
        ServerPy["server.py"]:::backend
        UtilsPy["utils.py"]:::backend
        Requirements["requirements.txt"]:::backend
        FAISS[(FAISS Index)]:::datastore
        Ollama((Ollama LLM)):::external
    end

    %% Interactions
    PopupHTML -->|loads CSS & JS| PopupCSS
    PopupHTML --> PopupJS
    PopupJS --> SummaryJS
    PopupJS --> QuestionJS
    SummaryJS -->|message| Background
    QuestionJS -->|message| Background
    Background -->|HTTP POST /summarize| MainPy
    Background -->|HTTP POST /ask| MainPy
    MainPy --> ServerPy
    ServerPy --> UtilsPy
    UtilsPy --> FAISS
    ServerPy --> Ollama
    ServerPy -->|SSE stream summary| SummaryJS
    ServerPy -->|SSE stream answer| QuestionJS
    SummaryJS -->|store summary| LocalStorage
    QuestionJS -->|store QA| LocalStorage

    %% Click Events
    click Manifest "https://github.com/karwap22/ragi/blob/main/frontend/manifest.json"
    click SidebarManifest "https://github.com/karwap22/ragi/blob/main/frontend/manifest_sidebar.json"
    click Background "https://github.com/karwap22/ragi/blob/main/frontend/background.js"
    click PopupHTML "https://github.com/karwap22/ragi/blob/main/frontend/popup.html"
    click PopupCSS "https://github.com/karwap22/ragi/blob/main/frontend/popup.css"
    click PopupJS "https://github.com/karwap22/ragi/blob/main/frontend/popup.js"
    click QuestionJS "https://github.com/karwap22/ragi/blob/main/frontend/question.js"
    click SummaryJS "https://github.com/karwap22/ragi/blob/main/frontend/summary.js"
    click MainPy "https://github.com/karwap22/ragi/blob/main/backend/main.py"
    click ServerPy "https://github.com/karwap22/ragi/blob/main/backend/server.py"
    click UtilsPy "https://github.com/karwap22/ragi/blob/main/backend/utils.py"
    click Requirements "https://github.com/karwap22/ragi/blob/main/backend/requirements.txt"

    %% Styles
    classDef frontend fill:#AEDFF7,stroke:#0366d6,stroke-width:1px;
    classDef backend fill:#D4F8C4,stroke:#2E7D32,stroke-width:1px;
    classDef external fill:#E0E0E0,stroke:#616161,stroke-width:1px,stroke-dasharray: 5 5;
    classDef datastore fill:#FFF3CD,stroke:#FFB300,stroke-width:1px,stroke-dasharray: 2 2;
```
