# saikumarbolishetty/nutrivibe-ai-rag-chatbot architecture

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

- Interactive diagram: https://gitdiagram.com/saikumarbolishetty/nutrivibe-ai-rag-chatbot
- Repository: https://github.com/saikumarbolishetty/nutrivibe-ai-rag-chatbot

## Overview

##### Project type and purpose
- NutriVibe is a full-stack web application with:
- A FastAPI backend exposing REST and file-upload endpoints
- A simple static frontend (single-page UI in `static/index.html`)
- AI-powered features: ChatGPT integration (via OpenAI API), Retrieval-Augmented Generation (RAG) with Milvus, and optional image analysis (OCR + vision)

##### File structure
- Top-level files:
- `main.py`: FastAPI app definition & endpoint wiring
- `rag_service.py`: Encapsulates vector DB (Milvus) access and retrieval logic
- `requirements.txt`, `.gitignore`, `.env` (for API keys & Milvus creds)
- Static assets:
- `static/index.html`: UI shell, JS code to call backend endpoints
- No separate “frontend” or “backend” folder—static UI is served by the same FastAPI server

##### README for additional insights
- Lists core features and endpoints (`/ask`, `/analyze-image`, `/documents`, `/documents/search`, `/documents/count`)
- Describes external dependencies: OpenAI API, managed Milvus cluster, Tesseract OCR (optional)
- Mentions how RAG works: semantic search → augment ChatGPT context

##### Detail
- Sequence:
1. User asks question →
2. FastAPI `/ask` →
3. rag_service queries Milvus →
4. retrieved docs + user prompt sent to OpenAI →
5. response back to FastAPI →
6. JSON to Browser
- Mirror similar flow for `/analyze-image`, `/documents`, etc.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Frontend Layer
    subgraph "Frontend Layer"
        direction TB
        UX["User’s Browser (UI)"]:::frontend
        Static["static/index.html"]:::frontend
        UX -->|"Loads UI (GET /)"| Static
        UX -->|"POST /ask, /analyze-image"| BackendAPI
        BackendAPI -->|"HTML/JSON Response"| UX
    end

    %% Backend Layer
    subgraph "Backend Layer"
        direction TB
        BackendAPI["FastAPI Server (API Layer & Static Handler)"]:::backend
        rag["Business Service (rag_service)"]:::backend
        BackendAPI -->|"delegates to rag_service"| rag
    end

    %% Configuration & Docs
    subgraph "Configuration & Docs"
        direction TB
        Req["requirements.txt"]:::backend
        Readme["README.md"]:::backend
        Gitignore[".gitignore"]:::backend
        Env[".env"]:::backend
        Req -->|"dependency list"| BackendAPI
        Env -->|"credentials"| BackendAPI
        Readme -->|"documentation"| BackendAPI
        Gitignore -->|"exclusions"| BackendAPI
    end

    %% External Services
    subgraph "External Integrations"
        direction TB
        DB[(Milvus Vector DB)]:::external
        OpenAI[(OpenAI API)]:::external
        OCR["OCR Engine (Tesseract)"]:::optional
        Vision["AI Vision Module"]:::optional
        rag -->|"vector search / insert"| DB
        BackendAPI -->|"chat completion"| OpenAI
        BackendAPI -->|"image to text"| OCR
        OCR -->|"classification"| Vision
    end

    %% Click Events
    click Static "https://github.com/saikumarbolishetty/nutrivibe-ai-rag-chatbot/blob/main/static/index.html"
    click BackendAPI "https://github.com/saikumarbolishetty/nutrivibe-ai-rag-chatbot/blob/main/main.py"
    click rag "https://github.com/saikumarbolishetty/nutrivibe-ai-rag-chatbot/blob/main/rag_service.py"
    click Req "https://github.com/saikumarbolishetty/nutrivibe-ai-rag-chatbot/blob/main/requirements.txt"
    click Readme "https://github.com/saikumarbolishetty/nutrivibe-ai-rag-chatbot/blob/main/README.md"
    click Gitignore "https://github.com/saikumarbolishetty/nutrivibe-ai-rag-chatbot/blob/main/.gitignore"

    %% Styles
    classDef frontend fill:#cce5ff,stroke:#004085,color:#004085;
    classDef backend fill:#d4edda,stroke:#155724,color:#155724;
    classDef external fill:#fff3cd,stroke:#856404,color:#856404;
    classDef optional fill:#e2e3e5,stroke:#6c757d,color:#6c757d;
```
