Version: 1.0
Platform: Progressive Web App (Mobile-First)
Stack: React + TypeScript + Vite + Tailwind CSS + Lovable Cloud
- Overview
- Problem Statement
- Architecture
- User Roles & Dashboards
- Core Features
- Technology Stack
- Data Flow
- Offline Capabilities
- AI Integration
- Database Schema
- File Structure
- Security
- Future Roadmap
NeuroTriage is a mobile-first health application designed to bring AI-powered medical triage, consultation, and emergency assistance to underserved rural communities. It works both online (AI-enhanced) and offline (rule-based fallback), ensuring critical health features remain accessible regardless of network connectivity.
- ๐ง AI-Powered Diagnosis โ Gemini AI analyzes symptoms and provides specific medicine recommendations with dosages
- ๐ฃ๏ธ Voice-First Interface โ Speech-to-text symptom intake in 4 languages (English, Hindi, Tamil, Telugu)
- ๐ด Offline Resilient โ Core triage and medical knowledge base work without internet
- ๐ Battery Aware โ Automatically switches to lighter AI models on low battery
- ๐จ Emergency SOS โ One-tap emergency calls with GPS-based hospital finder
- ๐ Appointment Booking โ In-chat appointment scheduling through MedBot AI
In rural India, patients face:
- Limited access to doctors โ Often 1 doctor per 10,000+ people
- Language barriers โ Many patients speak only regional languages
- Poor connectivity โ Intermittent or no internet in remote areas
- Low digital literacy โ Need for voice-first, simple interfaces
- Delayed emergency response โ No structured triage before hospital visits
NeuroTriage addresses all five by providing an AI medical assistant that speaks local languages, works offline, and triages symptoms to appropriate urgency levels.
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ FRONTEND (React) โ
โ โ
โ Landing โ Role Selection โ Role Dashboard โ
โ โ
โ โโโโโโโโโโโโ โโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโโ โ
โ โ Voice โ โ MedBot โ โ Appointment โ โ
โ โ Triage โ โ AI Chat โ โ Booking โ โ
โ โโโโโโฌโโโโโโ โโโโโโฌโโโโโโ โโโโโโโโโโฌโโโโโโโโโโ โ
โ โ โ โ โ
โ โโโโโโผโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโผโโโโโโโโโโ โ
โ โ Zustand State Management โ โ
โ โ (roles, profiles, triage history) โ โ
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
โโโโโโโโโโโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ
โโโโโโโโโโโโผโโโโโโโโโโโ
โ Lovable Cloud โ
โ (Supabase) โ
โ โ
โ โโโโโโโโโโโโโโโโโ โ
โ โ Edge Functions โ โ
โ โ โ โ
โ โ medical-chat โ โ
โ โ (Gemini AI) โ โ
โ โโโโโโโโโโโโโโโโโ โ
โ โ
โ โโโโโโโโโโโโโโโโโ โ
โ โ Database โ โ
โ โ โ โ
โ โ appointments โ โ
โ โโโโโโโโโโโโโโโโโ โ
โโโโโโโโโโโโโโโโโโโโโโโ
The primary user. Features include:
| Feature | Description |
|---|---|
| Quick Triage | One-tap access to AI voice triage |
| MedBot Chat | AI medical assistant with streaming responses |
| Health Records | View triage history and past consultations |
| Emergency SOS | One-tap emergency call with GPS hospital finder |
| Profile | Patient demographics, blood group, allergies |
For healthcare professionals reviewing cases:
| Feature | Description |
|---|---|
| Patient Queue | View triaged cases by urgency |
| Appointments | Real-time incoming appointment list with Accept/Confirm |
| Case Stats | Total cases, pending appointments, emergencies |
| Referrals | Cases referred from health workers |
| Video Consult | Telemedicine consultation link |
For community health workers doing field triage:
| Feature | Description |
|---|---|
| Community Stats | Triage summary for the community |
| Field Triage | Quick symptom assessment tools |
| Emergency Alerts | Critical cases needing escalation |
| Patient Registry | Community patient tracking |
How it works:
- Patient taps the microphone button and speaks symptoms in any supported language
- Web Speech API converts voice to text
- Online: Gemini AI analyzes symptoms โ returns structured JSON with urgency level, possible conditions, and specific medicine recommendations
- Offline: Expanded rule-based engine with 20+ condition patterns matches symptoms against known patterns
- Results displayed with color-coded urgency (๐ข Safe / ๐ก Consult / ๐ด Emergency)
Urgency Classification:
| Level | Color | Action |
|---|---|---|
| Safe | ๐ข Green | Home care with OTC medicines |
| Consult | ๐ก Yellow | Book doctor appointment within 24-48hrs |
| Emergency | ๐ด Red | Go to hospital NOW, call 112/108 |
An intelligent medical chatbot that:
- Asks 2-3 follow-up questions before diagnosing
- Provides specific medicine names with dosages (e.g., "Paracetamol 500mg, twice daily after food")
- Supports 4 languages: English, Hindi (เคนเคฟเคจเฅเคฆเฅ), Tamil (เฎคเฎฎเฎฟเฎดเฏ), Telugu (เฐคเฑเฐฒเฑเฐเฑ)
- Works in text mode and voice-to-voice mode (Web Speech API)
- Detects appointment booking intent and shows inline booking form
- Streams responses in real-time via Server-Sent Events (SSE)
Battery-Aware AI:
- Normal battery โ
google/gemini-3-flash-preview(full capability) - Low battery (<20%) โ
google/gemini-2.5-flash-lite(faster, lighter)
Triggered when patient types "book appointment" or related keywords in MedBot:
- Patient name, age, gender (pre-filled from profile)
- Doctor specialty selection (General, Pediatrics, Gynecology, etc.)
- Date picker and time slot grid
- Symptoms auto-attached from chat context
- Saved to database โ appears in Doctor Dashboard in real-time
- Call Emergency (112) โ National emergency number
- Call Ambulance (108) โ Ambulance service
- Find Nearest Hospital โ GPS-based Google Maps hospital search
- Pulsing red animation for urgency
- Accessible from every screen via Emergency Button
Full conversational loop using browser-native APIs:
๐๏ธ Listen (SpeechRecognition)
โ ๐ง Process (Gemini AI via Edge Function)
โ ๐ Speak (SpeechSynthesis)
โ ๐๏ธ Listen again (continuous loop)
Supports language-specific voices for Hindi, Tamil, and Telugu.
| Layer | Technology | Purpose |
|---|---|---|
| Frontend | React 18 + TypeScript | UI framework |
| Bundler | Vite | Fast development & builds |
| Styling | Tailwind CSS + shadcn/ui | Design system |
| State | Zustand | Global state management |
| Animation | Framer Motion | Smooth transitions |
| Routing | React Router v6 | Client-side navigation |
| Backend | Lovable Cloud (Supabase) | Database + Edge Functions |
| AI | Google Gemini (via Lovable AI Gateway) | Medical reasoning |
| Voice Input | Web Speech API (SpeechRecognition) | Browser-native STT |
| Voice Output | Web Speech API (SpeechSynthesis) | Browser-native TTS |
| Markdown | react-markdown | Render AI chat responses |
Patient speaks symptoms
โ
โผ
SpeechRecognition API
โ
โผ
Text extracted
โ
โโโ Online? โโโบ Edge Function (medical-chat)
โ โ
โ โผ
โ Gemini AI analyzes
โ โ
โ โผ
โ Structured JSON result
โ โ
โโโ Offline? โโโบ Local triage-engine.ts
โ
โผ
Pattern matching (20+ conditions)
โ
โผ
TriageResult displayed
โ
โผ
Saved to Zustand store
Patient says "book appointment" in MedBot
โ
โผ
Keyword detection triggers booking form
โ
โผ
Patient fills: name, date, time, doctor type
โ
โผ
Saved to Supabase `appointments` table
โ
โผ
Real-time update โ Doctor Dashboard
โ
โผ
Doctor clicks "Accept" โ status: confirmed
| Feature | Online | Offline |
|---|---|---|
| Voice Triage | AI-powered (Gemini) | Rule-based (20+ patterns) |
| MedBot Chat | Streaming AI responses | Offline medical knowledge base |
| Emergency SOS | Full functionality | GPS + direct phone calls |
| Appointment Booking | โ Saves to database | โ Requires internet |
| Voice Input | โ SpeechRecognition | โ SpeechRecognition |
| Voice Output | โ SpeechSynthesis | โ SpeechSynthesis |
The offline medical knowledge base (src/lib/offline-medical-kb.ts) contains pre-written responses for common symptoms including fever, headache, stomach issues, skin problems, and more โ with home remedies and OTC medicine suggestions.
Endpoint: POST /functions/v1/medical-chat
Request:
{
"messages": [{"role": "user", "content": "I have fever"}],
"language": "en",
"lightweight": false
}Behavior:
- System prompt instructs the AI to act as "MedBot" โ a rural medical assistant
- Asks 2-3 follow-up questions before suggesting medicine
- No disclaimers โ direct, practical advice
- Responds in the selected language regardless of input language
- Streams response via SSE (Server-Sent Events)
Models Used:
| Condition | Model |
|---|---|
| Normal battery | google/gemini-3-flash-preview |
| Low battery (<20%) | google/gemini-2.5-flash-lite |
| Triage classification | google/gemini-2.5-flash-lite |
| Column | Type | Description |
|---|---|---|
| id | UUID (PK) | Auto-generated |
| patient_name | TEXT | Required |
| patient_age | TEXT | Optional |
| patient_gender | TEXT | Optional |
| symptoms | TEXT | Auto-filled from chat |
| preferred_date | DATE | Required |
| preferred_time | TEXT | Required |
| doctor_type | TEXT | Default: "General" |
| status | TEXT | "pending" or "confirmed" |
| created_at | TIMESTAMPTZ | Auto-set |
Real-time: Enabled via supabase_realtime publication for live updates to Doctor Dashboard.
src/
โโโ components/
โ โโโ AppointmentBooking.tsx # In-chat booking form
โ โโโ BottomNav.tsx # Tab navigation
โ โโโ EmergencyButton.tsx # SOS button component
โ โโโ LanguageSelector.tsx # EN/HI/TA/TE picker
โ โโโ MobileLayout.tsx # Mobile viewport wrapper
โ โโโ VoiceMode.tsx # Voice-to-voice conversation
โ โโโ ui/ # shadcn/ui components
โ
โโโ hooks/
โ โโโ use-battery.ts # Battery level detection
โ โโโ use-mobile.tsx # Mobile viewport detection
โ
โโโ lib/
โ โโโ offline-medical-kb.ts # Offline symptom responses
โ โโโ store.ts # Zustand global state
โ โโโ triage-engine.ts # Hybrid AI + rule-based triage
โ โโโ utils.ts # Utility functions
โ
โโโ pages/
โ โโโ Landing.tsx # Role selection screen
โ โโโ Dashboard.tsx # Patient dashboard
โ โโโ DoctorDashboard.tsx # Doctor dashboard + appointments
โ โโโ HealthWorkerDashboard.tsx # CHW dashboard
โ โโโ MedBot.tsx # AI chat interface
โ โโโ Triage.tsx # Voice triage screen
โ โโโ Emergency.tsx # Emergency SOS screen
โ โโโ Records.tsx # Health records
โ โโโ Profile.tsx # User profile
โ โโโ Consultation.tsx # Telemedicine placeholder
โ
โโโ integrations/supabase/
โ โโโ client.ts # Supabase client (auto-generated)
โ โโโ types.ts # Database types (auto-generated)
โ
โโโ App.tsx # Routes + role-based dashboard logic
supabase/functions/
โโโ medical-chat/index.ts # AI chat edge function (Gemini)
โโโ elevenlabs-conversation-token/index.ts # Voice agent token
| Measure | Implementation |
|---|---|
| API Keys | Stored as server-side secrets (never in client code) |
| AI Gateway | Requests proxied through Lovable AI Gateway with auth |
| Database RLS | Row-level security enabled on all tables |
| CORS | Configured on edge functions |
| Input Sanitization | User input processed server-side before AI |
- User Authentication โ Email/phone login for persistent profiles
- Patient-Doctor Video Calls โ WebRTC telemedicine consultations
- Prescription Generation โ Doctors can issue digital prescriptions
- Health Worker GPS Tracking โ Field worker route optimization
- SMS Alerts โ Appointment confirmations via SMS for non-smartphone users
- PWA Installation โ Full offline-first PWA with service worker caching
- Multi-language Voice Triage โ Language selector on triage page
- Community Health Analytics โ Dashboard with disease trend charts
- Bluetooth Relay โ Mesh networking for areas with zero connectivity
- Open the app โ Select your role (Patient / Doctor / Health Worker)
- Patient: Tap "Voice Triage" โ Speak symptoms โ Get AI diagnosis
- Patient: Open "MedBot" โ Chat about symptoms โ Book appointment
- Doctor: View incoming appointments โ Accept/Confirm
- Emergency: Tap the red SOS button from any screen โ Call 112/108
Built with โค๏ธ for rural healthcare accessibility