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