# rupeshsangoju/health_bot architecture

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

- Interactive diagram: https://gitdiagram.com/rupeshsangoju/health_bot
- Repository: https://github.com/rupeshsangoju/health_bot

## Overview

##### Project type and purpose
- HealthBot is a full-stack AI-powered healthcare assistant web application.
- Frontend: React + Tailwind (deployed on Netlify)
- Backend services:
- Flask monolith on Render serving ML inference endpoints
- Serverless “chat” microservice (Netlify Functions) for Grok chatbot & TTS
- Database: Firebase Firestore
- External APIs: Grok (AI chatbot), OpenStreetMap (hospital finder)

##### File structure
- Top-level:
- package.json, src/ & public/ → React single-page app
- functions/chat.js → Netlify Functions project for chatbot
- backend/server.py & backend/models/ → Flask inference service + ML model artifacts
- netlify.toml → frontend & serverless deploy config
- tailwind.config.js, postcss.config.js → frontend styling
- Patterns:
- Presentation tier (React)
- Application tier split into:
– Serverless functions (chatbot)
– Stateful Flask service (ML inference)
- Data tier: Firestore + external APIs
- Deployment artifacts:
- Render: render.yaml / gunicorn in README
- Netlify: netlify.toml
- Git LFS for large .h5/.pkl models

##### Key insights from README
- Flask backend lazily loads heavy models (.h5, .pkl)
- Two distinct backends: Netlify Functions (Grok, gTTS via @xenova/transformers) and Flask on Render
- Firebase used both for authentication and Firestore storage

##### Main components & relationships
A. Client (Browser)
- Loads React app from Netlify CDN
- Presents UI components (Dashboard, Diagnostics, ChatWindow, HistorySidebar, etc.)
B. Frontend (React SPA)
- Calls backend inference API (/predict, /image, /health) on Render
- Calls serverless chat API (/.netlify/functions/chat)
- Reads/writes user data (journal, mood) to Firestore via Firebase SDK
C. Serverless Chatbot (Netlify Function)
- chat.js handles incoming chat requests
- Forwards to Grok API (GROQ_API_KEY)
- Optionally uses gTTS or @xenova/transformers for TTS
- Returns JSON chat responses to React
D. Flask Inference Service (Render)
- server.py exposes endpoints:
- /predict/disease (XGBoost)
- /predict/diabetes, /predict/heart, /predict/mental (Keras)
- /predict/image/chest_xray, /predict/image/skin_lesion (CNN/InceptionV3)
- /hospital-finder (OpenStreetMap)
- /health (health check)
- Loads ML models lazily from backend/models/
- Uses CORS and Firebase JWT for auth
E. Database (Firebase Firestore)
- Stores user profiles, mood entries, journals
- Authentication via Firebase Auth
F. External Services
- Grok API (chatbot)
- OpenStreetMap API (hospital finder)

##### Architectural patterns & design principles
- Separation of concerns:
- UI layer (React)
- Business logic split: serverless vs monolithic
- Data layer (Firestore)
- Lazy loading & model compression (tflite, joblib)
- Secure communication with environment variables and CORS
- Micro-frontends-ish: React app + serverless functions

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Client
    subgraph "Client"
        Browser["Browser"]:::frontend
    end

    %% Presentation Tier
    subgraph "Presentation Tier (React SPA)"
        React["React SPA\n(Netlify CDN)"]:::frontend
        ChatWindow["ChatWindow.js"]:::frontend
        Dashboard["Dashboard.js"]:::frontend
        Diagnostics["Diagnostics.js"]:::frontend
        HistorySidebar["HistorySidebar.js"]:::frontend
        InputSection["InputSection.js"]:::frontend
        JournalSection["JournalSection.js"]:::frontend
        LoginPage["LoginPage.js"]:::frontend
        RegisterPage["RegisterPage.js"]:::frontend
        ProfilePanel["ProfilePanel.js"]:::frontend
        SettingsPanel["SettingsPanel.js"]:::frontend
    end

    %% Application Tier
    subgraph "Application Tier"
        subgraph "Serverless Chatbot (Netlify Functions)"
            chat["functions/chat.js\n(Chat Function)\n[gTTS & @xenova]"]:::serverless
        end
        subgraph "Flask Inference Service (Render)"
            server["server.py\n(Flask Service)"]:::flask
            models["models/\n(.h5 & .pkl)"]:::flask
        end
    end

    %% Data Tier
    subgraph "Data Tier"
        Firestore["Firebase Firestore"]:::db
    end

    %% External Services
    subgraph "External Services"
        Grok["Grok API"]:::external
        OSM["OpenStreetMap API"]:::external
    end

    %% Connections
    Browser-->React
    React-->server
    React-->chat
    React-->Firestore
    server-->models
    server-->OSM
    chat-->Grok

    %% Click Events
    click React "https://github.com/rupeshsangoju/health_bot/blob/main/package.json"
    click React "https://github.com/rupeshsangoju/health_bot/blob/main/netlify.toml"
    click React "https://github.com/rupeshsangoju/health_bot/blob/main/tailwind.config.js"
    click React "https://github.com/rupeshsangoju/health_bot/blob/main/postcss.config.js"
    click React "https://github.com/rupeshsangoju/health_bot/tree/main/public/"
    click React "https://github.com/rupeshsangoju/health_bot/tree/main/src/"
    click chat "https://github.com/rupeshsangoju/health_bot/blob/main/functions/chat.js"
    click server "https://github.com/rupeshsangoju/health_bot/blob/main/backend/server.py"
    click models "https://github.com/rupeshsangoju/health_bot/tree/main/backend/models/"
    click Firestore "https://github.com/rupeshsangoju/health_bot/blob/main/src/firebase.js"
    click ChatWindow "https://github.com/rupeshsangoju/health_bot/blob/main/src/components/ChatWindow.js"
    click Dashboard "https://github.com/rupeshsangoju/health_bot/blob/main/src/components/Dashboard.js"
    click Diagnostics "https://github.com/rupeshsangoju/health_bot/blob/main/src/components/Diagnostics.js"
    click HistorySidebar "https://github.com/rupeshsangoju/health_bot/blob/main/src/components/HistorySidebar.js"
    click InputSection "https://github.com/rupeshsangoju/health_bot/blob/main/src/components/InputSection.js"
    click JournalSection "https://github.com/rupeshsangoju/health_bot/blob/main/src/components/JournalSection.js"
    click LoginPage "https://github.com/rupeshsangoju/health_bot/blob/main/src/components/LoginPage.js"
    click RegisterPage "https://github.com/rupeshsangoju/health_bot/blob/main/src/components/RegisterPage.js"
    click ProfilePanel "https://github.com/rupeshsangoju/health_bot/blob/main/src/components/ProfilePanel.js"
    click SettingsPanel "https://github.com/rupeshsangoju/health_bot/blob/main/src/components/SettingsPanel.js"

    %% Styles
    classDef frontend fill:#D0E8FF,stroke:#0366d6,color:#0366d6;
    classDef flask fill:#DFFFD6,stroke:#28a745,color:#28a745;
    classDef serverless fill:#FFE0B2,stroke:#ff8c00,color:#e65100;
    classDef db fill:#E1BEE7,stroke:#6a1b9a,color:#4a148c;
    classDef external fill:#FFCDD2,stroke:#b71c1c,color:#b71c1c;
```
