# 1ajinkya2/ayurvedaai architecture

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

- Interactive diagram: https://gitdiagram.com/1ajinkya2/ayurvedaai
- Repository: https://github.com/1ajinkya2/ayurvedaai

## Overview

##### Project type and purpose
- This is a full-stack AI-driven web application (“AyurVedaAI”) that provides personalized Ayurvedic recommendations.
- Key features: Prakriti assessment (quiz), scripture analysis (LLM+vector search), personalized remedy suggestions, educational resources, chatbot interface.

##### File structure
- Top-level:
- backend/ – Python-based API & chatbot logic (Chainlit + LangChain + FAISS)
- frontend/ – React + TypeScript + Vite + Tailwind UI
- testing/ – Jupyter notebooks and datasets for evaluating model outputs
- backend details:
- app.py – main web server (Flask or FastAPI style) integrating Chainlit
- ingest.py – data ingestion pipeline: PDF → embeddings → FAISS vectorstore
- data/ – raw Ayurvedic PDFs
- vectorstore/db_faiss/ – serialized FAISS index
- frontend details:
- src/pages/PrakrutiAnalyzerPage.tsx – quiz UI
- src/pages/Chatbot.tsx – chat interface calling backend
- Tailwind & postCSS configs for styling
- Configs: requirements.txt, package.json files, .gitignore, tsconfig, pnpm/yarn locks.

##### README
- Confirms use of LLMs (e.g., GPT-3), Node.js/Express.js (but code shows Python), MongoDB (user profiles), and a web frontend.
- Mentions account creation & quiz → personalized recommendations → AI-chatbot interactions.

##### Main components
a. Frontend (Client):
- Browser UI (React/Vite/Tailwind)
- Prakriti Quiz Module
- Chatbot Module
- Static Educational Content (HTML/CSS/js)
b. Backend API Server:
- HTTP/WebSocket endpoints (app.py + Chainlit)
- Prakriti assessment logic (score computation)
- Chat request handler (LangChain chains + FAISS retrieval)
- Ingestion pipeline service (ingest.py, run offline or as job)
c. Data Layer:
- PDF Data Store (backend/data/)
- Vector Store (FAISS index on disk)
- User Profile DB (MongoDB – user credentials, quiz results, preferences)
d. External Services:
- OpenAI (or other LLM provider) for embeddings & completions
- Email/SMS service (optional, for notifications)

##### Relationships and interactions
1. User → Frontend UI
2. Frontend Quiz submission → Backend /assess endpoint → MongoDB save → response
3. Frontend Chat message → Backend /chat endpoint →
a. retrieve relevant docs via FAISS
b. call OpenAI for completion
c. return answer stream to UI
4. Ingestion pipeline (offline or scheduled):
- Read PDFs → chunk → embed via OpenAI → index into FAISS

##### Architectural patterns & design principles
- Client-Server separation
- Modular services: ingestion vs. runtime API
- Retrieval-augmented generation (RAG) pattern: vector store + LLM
- Single-Page Application (SPA) on frontend
- Stateless API servers with persistent data in DBs

##### Essential elements
- Don’t overcrowd: group related UI elements under a single “Frontend” container
- Both runtime path (user interactions) and offline path (data ingestion)
- Every persistent store and external dependency

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% User
    User["User"]:::user

    %% Frontend Layer
    subgraph "Frontend Layer"
        direction TB
        UI["Browser UI\n(React/Vite/Tailwind)"]:::frontend
        Quiz["Prakriti Quiz Module"]:::frontend
        Chat["Chatbot Module"]:::frontend
        Edu["Static Educational Content"]:::frontend
        UIComp["Shared UI Components"]:::frontend
        Utils["Utility Functions"]:::frontend
        UI --> Quiz
        UI --> Chat
        UI --> Edu
        UI --> UIComp
        UI --> Utils
    end

    %% Backend Services
    subgraph "Backend Services"
        direction TB
        API["API Server & Chatbot Integration"]:::backend
        Ingest["Ingestion Pipeline Service"]:::backend
        Config["Chainlit Configuration"]:::backend
        API -->|"POST /assess"| Mongo
        API -->|"GET /chat"| FAISS
        Config -.-> API
        PDF -.-> Ingest
        Ingest --> FAISS
    end

    %% Data Layer
    subgraph "Data Layer"
        direction TB
        Mongo["MongoDB\n(User Profiles)"]:::db
        PDF["PDF Data Store"]:::db
        FAISS["FAISS Vector Store"]:::db
    end

    %% External Services
    subgraph "External Services"
        direction TB
        LLM["OpenAI LLM API"]:::external
        Notify["Email/SMS Service"]:::external
        API -->|"calls embeddings/completions"| LLM
        API -->|"notifications"| Notify
    end

    %% User Interaction Flow
    User --> UI
    User --> Quiz
    User --> Chat

    %% Click Events
    click UI "https://github.com/1ajinkya2/ayurvedaai/blob/main/frontend/src/main.tsx"
    click Quiz "https://github.com/1ajinkya2/ayurvedaai/blob/main/frontend/src/components/pages/PrakrutiAnalyzerPage.tsx"
    click Chat "https://github.com/1ajinkya2/ayurvedaai/blob/main/frontend/src/components/pages/Chatbot.tsx"
    click Edu "https://github.com/1ajinkya2/ayurvedaai/blob/main/frontend/src/components/pages/LandingPage.tsx"
    click UIComp "https://github.com/1ajinkya2/ayurvedaai/blob/main/frontend/src/components/ui/button.tsx"
    click Utils "https://github.com/1ajinkya2/ayurvedaai/blob/main/frontend/src/lib/utils.ts"
    click API "https://github.com/1ajinkya2/ayurvedaai/blob/main/backend/app.py"
    click Ingest "https://github.com/1ajinkya2/ayurvedaai/blob/main/backend/ingest.py"
    click Config "https://github.com/1ajinkya2/ayurvedaai/blob/main/backend/.chainlit/config.toml"
    click PDF "https://github.com/1ajinkya2/ayurvedaai/blob/main/backend/data/*.pdf"
    click FAISS "https://github.com/1ajinkya2/ayurvedaai/blob/main/backend/vectorstore/db_faiss/index.faiss"

    %% Styles
    classDef frontend fill:#E0F7FA,stroke:#0288D1,stroke-width:1px
    classDef backend fill:#E8F5E9,stroke:#2E7D32,stroke-width:1px
    classDef db fill:#FFF3E0,stroke:#EF6C00,stroke-width:1px
    classDef external fill:#F3E5F5,stroke:#6A1B9A,stroke-width:1px
    classDef user fill:#FFEBEE,stroke:#C62828,stroke-width:1px
```
