# 3xcaffeine/rag architecture

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

- Interactive diagram: https://gitdiagram.com/3xcaffeine/rag
- Repository: https://github.com/3xcaffeine/rag

## Overview

##### Project Type and Purpose
- InfoRAG is an AI-powered documentation assistant that uses Retrieval-Augmented Generation (RAG) to supply context-aware, professional query responses.
- It contains both a full-stack application aspect (frontend in NextJS/TypeScript and backend in FastAPI) and a dedicated ingestion pipeline — indicating a separation between user-facing components and data processing/indexing.

##### Analyzing the File Structure
- Top-Level Directories:
- “backend”: Contains the FastAPI application, organized with directories for routes, models, services, and utilities. This denotes a structured backend following a modular pattern (e.g., MVC-like separation for routes, business logic, and data models).
- “frontend”: Houses the NextJS application with TypeScript, various UI components, context providers, and configuration files—clearly delineating the client-side presentation layer.
- “ingestion-pipeline”: Includes scripts, notebooks, and configuration files (e.g., “category_indexer.py”, “data” subdirectory) that handle document ingestion, vector embedding, and indexing. These files are likely used to process data that feeds into the retrieval system.
- Other supportive files such as Docker configurations, CI workflows (.github), and deployment scripts indicate containerized deployments and continuous integration.

##### Insights from the README
- The README highlights key features such as “Knowledge-Based Ingestion Pipeline”, “Vector Embedding”, and “Chain-of-Thought Implementation” to reduce hallucinations.
- The inclusion of multimodal input processing (audio, image, PDF) suggests that the system accepts various data types, and these processing modules should be clearly depicted as separate components or services.

##### Main Components and Their Relationships
a. Frontend:
- Built with NextJS/TypeScript. Responsible for the user interface, including the submission of text/audio/PDF/image inputs.
- Communicates with the backend API (over HTTP/HTTPS) and utilizes context components (e.g., category selector, message bubble, prompt form UI).

b. Backend:
- Developed with FastAPI, including distinct submodules:
- Routes (for handling API endpoints such as completions).
- Models (defining database or internal data structures, e.g., for completion actions).
- Services (encapsulating core business logic, file processing, interaction with vector stores, and papers).
- Utilities (for authentication, logging, etc.).
- Acts as the intermediary between the frontend and the AI models, carrying out RAG processing, managing requests, and interfacing with external model services (Gemini, Deepseek, etc.).

c. Ingestion Pipeline:
- A separate component that processes raw data for indexing.
- Utilizes Python scripts and Jupyter notebooks (for experimentation and parallel processing) to create vector embeddings and update the knowledge base.
- This component likely feeds data into the backend’s vector store services.

d. External Services/Models:
- AI models like Gemini, Deepseek R1, and Nomic-Embed-Text.
- LlamaIndex and associated plugins (Tool Calling, Arxiv Plugin, PubMed API) suggest further integration points that enhance search and document retrieval.
- Other external integrations for web search and API calls (e.g., stock prices, weather, current news).

##### Architectural Patterns & Design Principles
- Separation of concerns: Different directories (frontend, backend, ingestion pipeline) encapsulate distinct roles.
- Modular design: Backend modules are partitioned by function (routes, models, services, utilities).
- Containerized deployment: Presence of Dockerfile(s) and docker-compose indicate that the application is designed for microservice or container-based deployment.
- CI/CD integration: The .github/workflows directory and CI configuration signal automated testing and deployment.

## Diagram (Mermaid)

```mermaid
graph TD
    %% Frontend Layer
    subgraph "Frontend Layer"
        FE["Frontend (NextJS Client)"]:::frontend
        UI["UI Components"]:::frontend
    end

    %% Backend Layer
    subgraph "Backend Layer"
        BA["Backend API Server"]:::backend
        RT["API Routes"]:::backend
        MD["Data Models"]:::backend
        SV["Business Logic & File Processing"]:::backend
        UT["Utilities (Auth, Logging)"]:::backend
    end

    %% Ingestion Pipeline
    subgraph "Ingestion Pipeline"
        IP["Data Processing & Indexing"]:::ingestion
    end

    %% External Services
    subgraph "External Services"
        GE["Gemini AI Model"]:::external
        DS["Deepseek R1"]:::external
        NE["Nomic-Embed-Text"]:::external
        LI["LlamaIndex & Plugins"]:::external
    end

    %% CI/CD & Containerization
    subgraph "CI/CD & Containerization"
        CI["CI/CD Pipeline & Containerization"]:::ci
    end

    %% Connections
    FE -->|"Calls_API"| BA
    UI -->|"Provides_Input"| FE

    BA -->|"Handles"| RT
    RT -->|"Uses"| MD
    RT -->|"Delegates_to"| SV
    SV -->|"Utilizes"| UT

    BA -->|"Updates_VectorStore"| IP

    BA -->|"Queries"| GE
    BA -->|"Queries"| DS
    BA -->|"Queries"| NE
    BA -->|"Queries"| LI

    CI -->|"Deploys_Frontend"| FE
    CI -->|"Deploys_Backend"| BA
    CI -->|"Deploys_Ingestion"| IP

    %% Click Events
    click FE "https://github.com/3xcaffeine/rag/tree/main/frontend/"
    click UI "https://github.com/3xcaffeine/rag/tree/main/frontend/src/components/"
    click BA "https://github.com/3xcaffeine/rag/blob/main/backend/app/app.py"
    click RT "https://github.com/3xcaffeine/rag/tree/main/backend/app/routes/"
    click MD "https://github.com/3xcaffeine/rag/tree/main/backend/app/models/"
    click SV "https://github.com/3xcaffeine/rag/tree/main/backend/app/services/"
    click UT "https://github.com/3xcaffeine/rag/tree/main/backend/app/utils/"
    click IP "https://github.com/3xcaffeine/rag/tree/main/ingestion-pipeline/"
    click CI "https://github.com/3xcaffeine/rag/tree/main/.github/workflows/"

    %% Styles
    classDef frontend fill:#f9e79f,stroke:#b9770e,stroke-width:2px;
    classDef backend fill:#aed6f1,stroke:#2471a3,stroke-width:2px;
    classDef ingestion fill:#d2b4de,stroke:#7d3c98,stroke-width:2px;
    classDef external fill:#a9dfbf,stroke:#1e8449,stroke-width:2px;
    classDef ci fill:#f5b7b1,stroke:#c0392b,stroke-width:2px;
```
