How rupeshsangoju/health_bot works
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