How sakthimaran-venom/curatrack-v2 works
1. System Purpose and Deployable Surfaces
CuraTrack is a healthcare platform spanning a Next.js web/doctor portal, a separate mobile client, and a FastAPI clinical-services API. Its core workflows are health-record ingestion, patient monitoring, care access, telemedicine, emergency sharing, and benefits/safety analysis. Main entry points are backend/main.py, frontend/app/page.tsx, and mobile/app/page.tsx.
2. Identity, Persistence, and Access Boundary
Supabase is the shared system of record for PostgreSQL data, authentication, RLS authorization, and realtime signaling. Web uses Supabase client/server integrations; backend has privileged service access configured through environment variables. Database schemas encode the platform contract, including telemedicine and SDOH extensions.
• frontend/lib/supabase/client.ts
• frontend/lib/supabase/server.ts
• frontend/supabase/complete_v3_schema.sql
• frontend/supabase/telemedicine_schema.sql
3. FastAPI Domain API and Service Layer
The Python API composes route modules for patient-facing and clinical functions, with services separating persistence, parsing, LLM access, audit logging, JWT handling, and eligibility logic. It is the boundary for secrets and server-side integrations, rather than exposing those directly from clients.
• backend/main.py
• backend/routes/ingest.py
• backend/routes/passport.py
• backend/services/patient_data.py
• backend/services/audit_logger.py
4. Medical Document Ingestion Pipeline
Uploaded records enter the ingestion/OCR routes, are processed through Tesseract and AI parsing, then become structured patient data suitable for records and insight views. The backend supports Gemini and likely local Ollama/Llama fallback through a dedicated LLM service; sample ingestion JSON is retained locally under backend/data/.
• backend/routes/ocr.py
• backend/routes/ingest.py
• backend/services/ocr_service.py
• backend/services/parser_service.py
• backend/services/llm_service.py
5. Clinical Intelligence, Safety, and Assistance
Backend route families calculate health risks and SDOH outcomes, generate insights, check medicines against openFDA, and match insurance/government-scheme eligibility. These features consume patient records/vitals and external APIs, then return actionable summaries to web and mobile screens.
• backend/routes/health_risks.py
• backend/routes/sdoh.py
• backend/routes/drug_checker.py
• backend/routes/insurance.py
• backend/services/insights_service.py
• backend/services/government_schemes.py
6. Web Care Portals and Telemedicine
The Next.js App Router supplies patient dashboard areas, doctor workflows, role onboarding, QR passport access, and dynamic WebRTC call rooms. WebRTC media is peer-to-peer; Supabase Realtime acts as signaling infrastructure. Google STUN is an external connectivity dependency. The frontend also has server routes for auth and Google Fit OAuth/data proxying.
• frontend/app/(dashboard)/dashboard/page.tsx
• frontend/app/doctor/page.tsx
• frontend/app/call/[roomId]/CallClient.tsx
• frontend/lib/webrtc.ts
• frontend/app/api/auth/google/route.ts
7. Mobile and Native Delivery
mobile/ is a distinct mobile-oriented Next/Expo-style client surface with health, records, alerts, appointment, scheme, and drug-checker flows, sharing Supabase and backend API patterns. frontend/ additionally contains a Capacitor Android wrapper for its web application, with native startup at MainActivity.
• mobile/app/dashboard/page.tsx
• mobile/lib/api.ts
• mobile/lib/supabaseClient.ts
• frontend/capacitor.config.ts
• frontend/android/app/src/main/java/com/curatrack/app/MainActivity.java
8. Emergency Passport Flow
A patient passport route generates expiring JWT-backed QR access; token verification retrieves a constrained emergency health summary and is expected to audit access. This is a high-sensitivity boundary: token signing, Supabase RLS/service access, client QR rendering, and public token routes must remain coordinated.
• backend/routes/qr.py
• backend/routes/passport.py
• backend/services/jwt_helper.py
• frontend/app/passport/[token]/page.tsx
• frontend/components/PassportQRModal.tsx
Components 18
Client surfaces
- Next.js care portals · Patient, doctor, onboarding, and dashboard experiences.
frontend/app/(dashboard)/dashboard/page.tsx - Telemedicine calls · Dynamic peer-to-peer call rooms.
frontend/app/call/[roomId]/CallClient.tsx - Emergency passport UI · Renders QR-based emergency access.
frontend/app/passport/[token]/page.tsx - Mobile client · Health, records, alerts, appointments, schemes, and drug checks.
mobile/app/dashboard/page.tsx - Android wrapper
frontend/android/app/src/main/java/com/curatrack/app/MainActivity.java
Clinical API
- FastAPI clinical API · Server-side boundary for clinical workflows, secrets, and integrations.
backend/main.py - Record ingestion · Accepts records and produces structured patient data.
backend/routes/ingest.py - OCR and AI parsing · Extracts and normalizes uploaded medical documents.
backend/services/parser_service.py - Clinical intelligence · Risk, SDOH, insights, drug safety, and eligibility summaries.
backend/routes/health_risks.py - Passport access API · Issues and verifies expiring QR emergency access.
backend/routes/passport.py - JWT access tokens
backend/services/jwt_helper.py - Access audit log · Records sensitive access events.
backend/services/audit_logger.py
Data and identity
- Supabase platform · Shared system of record, authorization boundary, and signaling channel.
frontend/supabase/complete_v3_schema.sql - Telemedicine schema
frontend/supabase/telemedicine_schema.sql
External services
- LLM providers · Gemini with local Ollama/Llama fallback.
backend/services/llm_service.py - openFDA
- Benefits sources · Government and insurance scheme matching.
backend/services/government_schemes.py - WebRTC signaling and STUN · Supabase Realtime signaling plus Google STUN traversal.
frontend/lib/webrtc.ts
Connections 22
- Next.js care portals → FastAPI clinical API: clinical API requests
- Mobile client → FastAPI clinical API: clinical API requests
- Android wrapper → Next.js care portals: hosts web application
- Next.js care portals → Supabase platform: auth, data, RLS
- Mobile client → Supabase platform: auth and data
- Telemedicine calls → WebRTC signaling and STUN: media setup and signaling
- WebRTC signaling and STUN → Supabase platform: Realtime signaling
- FastAPI clinical API → Record ingestion: routes uploads
- Record ingestion → OCR and AI parsing: extracts records
- OCR and AI parsing → LLM providers: AI normalization
- OCR and AI parsing → Supabase platform: stores structured data
- FastAPI clinical API → Clinical intelligence: routes analysis
- Clinical intelligence → Supabase platform: reads patient data
- Clinical intelligence → openFDA: medicine safety lookup
- Clinical intelligence → Benefits sources: eligibility matching
- FastAPI clinical API → Passport access API: routes emergency access
- Passport access API → JWT access tokens: issues and verifies tokens
- Emergency passport UI → Passport access API: redeems QR token
- Passport access API → Supabase platform: constrained health summary
- Passport access API → Access audit log: records access
- Access audit log → Supabase platform: persists audit events
- Telemedicine schema → Supabase platform: extends data contract