# ad-tech1009/sia-chatbot architecture

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

- Interactive diagram: https://gitdiagram.com/ad-tech1009/sia-chatbot
- Repository: https://github.com/ad-tech1009/sia-chatbot

## Overview

##### Project type and purpose
- From the file tree and README, Sia is a full-stack web application:
- Frontend: React (Vite + Tailwind) for an emotion-aware chat UI
- Backend: Python FastAPI serving an LLM-powered chatbot with RAG
- Vector Database: ChromaDB for retrieval-augmented generation
- LLM Engine: Ollama running Mistral

##### File structure
- Top level:
- LLM_backend/ – Python FastAPI service
– app.py & server.py (entry points)
– config/ (app settings, model parameters)
– routes/ (FastAPI route handlers: mood, sia_t1, test)
– prompts/ (LLM prompt templates)
– data/ (static text files like chapter_2.txt)
– requirements.txt
- Sia_frontend/ – React UI built with Vite
– src/ (App.jsx, components/, pages/)
– public/, index.html, package.json, vite.config.js
- Patterns:
- Clear frontend/backend separation
- Modular routing on backend
- RAG pattern with prompts + vector DB

##### README for additional insights
- Features highlight: emotion-aware visuals, context retrieval from sacred texts, LLM offline via Ollama
- Tech stack calls out React, Tailwind, FastAPI, LangChain, ChromaDB, Ollama

##### Main components & their interactions
a. User’s Browser (React UI)
– ChatInput, ChatWindow, MoodWave components
– Sends user messages to Backend via HTTP (e.g., POST /chat)
– Receives response + emotion metadata
– Renders text + updates animated wave thread
b. Backend (FastAPI)
– API Layer (routes/*.py)
– Prompt Engine (prompts/*.py + LangChain wrappers)
– Vector Retrieval (ChromaDB interface)
– LLM Inference (Ollama Mistral via Python client)
– Configuration (config/app.py, config/models.py)
c. Data Store
– ChromaDB vector store loaded with Bhagavad Gita corpus (data/chapter_2.txt, etc.)
d. External Services
– Ollama daemon running Mistral model
e. (Optionally) Notebook for experimentation (simpletrag.ipynb)

##### Architectural patterns & design principles
- Layered architecture: Presentation (React), API (FastAPI), Domain (prompt + retrieval), Infrastructure (ChromaDB, Ollama)
- RAG pattern: combine vector retrieval with generative LLM
- Separation of concerns: config, routes, prompts, data modularization

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Frontend Layer
    subgraph "Frontend (React/Vite/Tailwind)"
        direction TB
        ChatAppPage["ChatApp.jsx"]:::frontend
        ChatInput["ChatInput.jsx"]:::frontend
        ChatWindow["ChatWindow.jsx"]:::frontend
        MoodWave["MoodWave.jsx"]:::frontend
        Orb["Orb.jsx"]:::frontend
        Sidebar["Sidebar.jsx"]:::frontend
        Threads["Threads.jsx"]:::frontend
        AboutPage["About.jsx"]:::frontend
        LandingPage["Landing.jsx"]:::frontend
        AppJS["App.jsx"]:::frontend
        MainJS["main.jsx"]:::frontend
        IndexHTML["index.html"]:::frontend
        ViteConfig["vite.config.js"]:::frontend
    end

    %% Backend Layer
    subgraph "Backend (FastAPI/Python)"
        direction TB
        subgraph "API Layer (routes/)"
            direction TB
            MoodRoute["mood.py"]:::backend
            SiaRoute["sia_t1.py"]:::backend
            TestRoute["test.py"]:::backend
        end
        subgraph "Configuration (config/)"
            direction TB
            AppConfig["app.py"]:::backend
            ModelsConfig["models.py"]:::backend
        end
        subgraph "Prompt Engine (prompts/)"
            direction TB
            Test1Prompt["sia_test1.py"]:::backend
            TestPrompt["test.py"]:::backend
        end
        DataStore["Data (chapter_2.txt)"]:::backend
        Requirements["requirements.txt"]:::backend
        InferenceEngine["LLM Inference (Ollama)"]:::backend
    end

    %% External Services
    ChromaDB["ChromaDB Vector Store"]:::external
    Ollama["Ollama Mistral Model"]:::external

    %% Data Flows
    ChatAppPage -->|"POST /chat"| SiaRoute
    ChatAppPage -->|"GET /mood"| MoodRoute
    SiaRoute -->|"vector search"| ChromaDB
    SiaRoute -->|"inference call"| Ollama
    ChromaDB -->|context| SiaRoute
    Ollama -->|response| SiaRoute
    SiaRoute -->|"response + emotion"| ChatAppPage

    %% Click Events for Frontend
    click ChatAppPage "https://github.com/ad-tech1009/sia-chatbot/blob/main/Sia_frontend/src/pages/ChatApp.jsx"
    click ChatInput "https://github.com/ad-tech1009/sia-chatbot/blob/main/Sia_frontend/src/components/ChatInput.jsx"
    click ChatWindow "https://github.com/ad-tech1009/sia-chatbot/blob/main/Sia_frontend/src/components/ChatWindow.jsx"
    click MoodWave "https://github.com/ad-tech1009/sia-chatbot/blob/main/Sia_frontend/src/components/MoodWave.jsx"
    click Orb "https://github.com/ad-tech1009/sia-chatbot/blob/main/Sia_frontend/src/components/Orb.jsx"
    click Sidebar "https://github.com/ad-tech1009/sia-chatbot/blob/main/Sia_frontend/src/components/Sidebar.jsx"
    click Threads "https://github.com/ad-tech1009/sia-chatbot/blob/main/Sia_frontend/src/components/Threads.jsx"
    click AboutPage "https://github.com/ad-tech1009/sia-chatbot/blob/main/Sia_frontend/src/pages/About.jsx"
    click LandingPage "https://github.com/ad-tech1009/sia-chatbot/blob/main/Sia_frontend/src/pages/Landing.jsx"
    click AppJS "https://github.com/ad-tech1009/sia-chatbot/blob/main/Sia_frontend/src/App.jsx"
    click MainJS "https://github.com/ad-tech1009/sia-chatbot/blob/main/Sia_frontend/src/main.jsx"
    click IndexHTML "https://github.com/ad-tech1009/sia-chatbot/blob/main/Sia_frontend/index.html"
    click ViteConfig "https://github.com/ad-tech1009/sia-chatbot/blob/main/Sia_frontend/vite.config.js"

    %% Click Events for Backend
    click MoodRoute "https://github.com/ad-tech1009/sia-chatbot/blob/main/LLM_backend/routes/mood.py"
    click SiaRoute "https://github.com/ad-tech1009/sia-chatbot/blob/main/LLM_backend/routes/sia_t1.py"
    click TestRoute "https://github.com/ad-tech1009/sia-chatbot/blob/main/LLM_backend/routes/test.py"
    click AppConfig "https://github.com/ad-tech1009/sia-chatbot/blob/main/LLM_backend/config/app.py"
    click ModelsConfig "https://github.com/ad-tech1009/sia-chatbot/blob/main/LLM_backend/config/models.py"
    click Test1Prompt "https://github.com/ad-tech1009/sia-chatbot/blob/main/LLM_backend/prompts/sia_test1.py"
    click TestPrompt "https://github.com/ad-tech1009/sia-chatbot/blob/main/LLM_backend/prompts/test.py"
    click DataStore "https://github.com/ad-tech1009/sia-chatbot/blob/main/LLM_backend/data/chapter_2.txt"
    click InferenceEngine "https://github.com/ad-tech1009/sia-chatbot/blob/main/LLM_backend/app.py"
    click Requirements "https://github.com/ad-tech1009/sia-chatbot/blob/main/LLM_backend/requirements.txt"

    %% Click External Notebook & Docs
    click simpletrag "https://github.com/ad-tech1009/sia-chatbot/blob/main/LLM_backend/simpletrag.ipynb"
    click README "https://github.com/ad-tech1009/sia-chatbot/blob/main/README.md"

    %% Styles
    classDef frontend fill:#E0F7FA,stroke:#006064,color:#006064
    classDef backend fill:#E8F5E9,stroke:#1B5E20,color:#1B5E20
    classDef external fill:#FFF3E0,stroke:#E65100,color:#E65100
```
