# elitedebuggers/swasth architecture

> Architecture diagram of the GitHub repository elitedebuggers/swasth, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-11-21). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/elitedebuggers/swasth
- Repository: https://github.com/elitedebuggers/swasth

## Overview

Swasth+ is a patient-and-clinician healthcare portal. Users enter through the routed React app, then manage appointments, records, medications, and clinical workflows; patients can also consult the AI assistant. The README documents Supabase-backed data, offline caching and queued writes, document-upload fallback, and local AI triage. The graph combines those documented capabilities with source-index references and excerpts; unsampled feature internals and some runtime wiring are represented only where the README supports them.

Main entry points: [`src/App.tsx`](https://github.com/elitedebuggers/swasth/blob/main/src/App.tsx) (Route dispatcher), [`src/modules/patient/PatientDashboard.tsx`](https://github.com/elitedebuggers/swasth/blob/main/src/modules/patient/PatientDashboard.tsx) (Patient dashboard), [`src/modules/patient/MedicalRecords.tsx`](https://github.com/elitedebuggers/swasth/blob/main/src/modules/patient/MedicalRecords.tsx) (Medical records), [`src/lib/resilience.ts`](https://github.com/elitedebuggers/swasth/blob/main/src/lib/resilience.ts) (Resilience engine)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_entry["App entry and shell"]
  node_app["Route dispatcher<br/>[App.tsx]"]
  node_login["Sign-in<br/>[Login.tsx]"]
  node_layout["Shared portal shell<br/>[SharedLayout.tsx]"]
  node_layoutstate["Chat layout state<br/>[LayoutContext.tsx]"]
end

subgraph group_patient["Patient care"]
  node_home["Public home<br/>[Home.tsx]"]
  node_patientdash["Patient dashboard"]
  node_assistant["AI assistant"]
  node_timeline["Health timeline<br/>[HealthTimeline.tsx]"]
  node_records["Medical records<br/>[MedicalRecords.tsx]"]
  node_approvals["Record approvals"]
  node_documentview["Document viewer<br/>[DocumentView.tsx]"]
  node_docdelete["Document deletion"]
  node_meds["Medication tracking<br/>[Medications.tsx]"]
  node_doctors["Doctor discovery<br/>[Doctors.tsx]"]
  node_booking["Appointment booking"]
  node_patientappts["Patient appointments<br/>[Appointments.tsx]"]
  node_messages["Patient messages<br/>[Messages.tsx]"]
  node_patientsettings["Patient settings<br/>[Settings.tsx]"]
end

subgraph group_doctor["Clinician workflows"]
  node_schedule["Shift scheduler<br/>[Schedule.tsx]"]
  node_doctorappts["Appointment approvals<br/>[Appointments.tsx]"]
  node_doctorpatients["Patient records workspace<br/>[Patients.tsx]"]
  node_doctordash["Doctor dashboard"]
  node_doctorsettings["Doctor settings<br/>[Settings.tsx]"]
end

subgraph group_services["Data and resilience"]
  node_medlib["Medication helpers<br/>[medications.ts]"]
  node_supabaseclient["Supabase client<br/>[supabase.ts]"]
  node_supabase[("Supabase services")]
  node_resilience["Resilience engine<br/>[resilience.ts]"]
  node_localdocs[("Local document store<br/>[documents.ts]")]
  node_offlinequeue["Offline sync queue<br/>[resilience.ts]"]
  node_hud["Resilience console<br/>[ResilienceHUD.tsx]"]
  node_localtriage["Local triage rules<br/>[resilience.ts]"]
end

node_user(("Patient or doctor"))
node_groq{{"Groq / Grok AI"}}

node_user -->|"opens portal"| node_app
node_app -->|"routes to"| node_home
node_app -->|"routes to"| node_login
node_app -->|"routes to"| node_patientdash
node_app -->|"routes to"| node_records
node_app -->|"routes to"| node_meds
node_app -->|"routes to"| node_doctors
node_app -->|"routes to"| node_patientappts
node_app -->|"routes to"| node_messages
node_app -->|"routes to"| node_patientsettings
node_app -->|"routes to"| node_schedule
node_app -->|"routes to"| node_doctorappts
node_app -->|"routes to"| node_doctorpatients
node_app -->|"routes to"| node_doctorsettings
node_app -->|"routes to"| node_documentview
node_patientdash -->|"renders"| node_assistant
node_patientdash -->|"renders"| node_timeline
node_patientdash -->|"uses shell"| node_layout
node_records -->|"uses modal"| node_approvals
node_records -->|"uses modal"| node_docdelete
node_records -->|"uses helpers"| node_medlib
node_records -->|"saves documents"| node_localdocs
node_patientdash -->|"saves documents"| node_localdocs
node_documentview -.->|"reads fallback"| node_localdocs
node_meds -->|"uses helpers"| node_medlib
node_doctors -.->|"starts booking"| node_booking
node_patientappts -->|"uses modal"| node_booking
node_doctorappts -.->|"uses clinician slots"| node_schedule
node_doctorpatients -->|"uses modal"| node_docdelete
node_doctorpatients -->|"uses helpers"| node_medlib
node_doctorpatients -->|"uses shell"| node_layout
node_doctordash -->|"uses modal"| node_docdelete
node_doctordash -->|"uses helpers"| node_medlib
node_supabaseclient -->|"configures fetch"| node_resilience
node_supabaseclient -->|"connects"| node_supabase
node_resilience -->|"fetches or syncs"| node_supabase
node_resilience -->|"queues writes"| node_offlinequeue
node_resilience -.->|"caches reads"| node_localdocs
node_assistant -.->|"requests AI"| node_groq
node_assistant -->|"falls back to"| node_localtriage
node_localtriage -->|"returns advice"| node_assistant
node_layout -->|"renders console"| node_hud
node_hud -->|"monitors controls"| node_resilience
node_layout -->|"reads context"| node_layoutstate

click node_app "https://github.com/elitedebuggers/swasth/blob/main/src/App.tsx"
click node_login "https://github.com/elitedebuggers/swasth/blob/main/src/modules/shared/Login.tsx"
click node_layout "https://github.com/elitedebuggers/swasth/blob/main/src/components/SharedLayout.tsx"
click node_layoutstate "https://github.com/elitedebuggers/swasth/blob/main/src/components/LayoutContext.tsx"
click node_home "https://github.com/elitedebuggers/swasth/blob/main/src/modules/patient/Home.tsx"
click node_patientdash "https://github.com/elitedebuggers/swasth/blob/main/src/modules/patient/PatientDashboard.tsx"
click node_assistant "https://github.com/elitedebuggers/swasth/blob/main/src/modules/patient/components/PatientAIAssistant.tsx"
click node_timeline "https://github.com/elitedebuggers/swasth/blob/main/src/modules/patient/components/HealthTimeline.tsx"
click node_records "https://github.com/elitedebuggers/swasth/blob/main/src/modules/patient/MedicalRecords.tsx"
click node_approvals "https://github.com/elitedebuggers/swasth/blob/main/src/modules/patient/components/PendingApprovalsModal.tsx"
click node_documentview "https://github.com/elitedebuggers/swasth/blob/main/src/modules/shared/DocumentView.tsx"
click node_docdelete "https://github.com/elitedebuggers/swasth/blob/main/src/modules/shared/DeleteDocumentModal.tsx"
click node_meds "https://github.com/elitedebuggers/swasth/blob/main/src/modules/patient/Medications.tsx"
click node_medlib "https://github.com/elitedebuggers/swasth/blob/main/src/lib/medications.ts"
click node_doctors "https://github.com/elitedebuggers/swasth/blob/main/src/modules/patient/Doctors.tsx"
click node_booking "https://github.com/elitedebuggers/swasth/blob/main/src/modules/patient/components/AppointmentBookingModal.tsx"
click node_patientappts "https://github.com/elitedebuggers/swasth/blob/main/src/modules/patient/Appointments.tsx"
click node_messages "https://github.com/elitedebuggers/swasth/blob/main/src/modules/patient/Messages.tsx"
click node_patientsettings "https://github.com/elitedebuggers/swasth/blob/main/src/modules/patient/Settings.tsx"
click node_schedule "https://github.com/elitedebuggers/swasth/blob/main/src/modules/doctor/Schedule.tsx"
click node_doctorappts "https://github.com/elitedebuggers/swasth/blob/main/src/modules/doctor/Appointments.tsx"
click node_doctorpatients "https://github.com/elitedebuggers/swasth/blob/main/src/modules/doctor/Patients.tsx"
click node_doctordash "https://github.com/elitedebuggers/swasth/blob/main/src/modules/doctor/DoctorDashboard.tsx"
click node_doctorsettings "https://github.com/elitedebuggers/swasth/blob/main/src/modules/doctor/Settings.tsx"
click node_supabaseclient "https://github.com/elitedebuggers/swasth/blob/main/src/lib/supabase.ts"
click node_resilience "https://github.com/elitedebuggers/swasth/blob/main/src/lib/resilience.ts"
click node_localdocs "https://github.com/elitedebuggers/swasth/blob/main/src/lib/documents.ts"
click node_offlinequeue "https://github.com/elitedebuggers/swasth/blob/main/src/lib/resilience.ts"
click node_hud "https://github.com/elitedebuggers/swasth/blob/main/src/modules/shared/ResilienceHUD.tsx"
click node_localtriage "https://github.com/elitedebuggers/swasth/blob/main/src/lib/resilience.ts"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_app,node_login,node_layout,node_layoutstate toneBlue
class node_home,node_patientdash,node_assistant,node_timeline,node_records,node_approvals,node_documentview,node_docdelete,node_meds,node_doctors,node_booking,node_patientappts,node_messages,node_patientsettings toneAmber
class node_schedule,node_doctorappts,node_doctorpatients,node_doctordash,node_doctorsettings toneMint
class node_medlib,node_supabaseclient,node_supabase,node_resilience,node_localdocs,node_offlinequeue,node_hud,node_localtriage toneRose
class node_user,node_groq toneIndigo
```

## Components

### App entry and shell

- [Route dispatcher](https://github.com/elitedebuggers/swasth/blob/main/src/App.tsx): `src/App.tsx`
- [Sign-in](https://github.com/elitedebuggers/swasth/blob/main/src/modules/shared/Login.tsx): `src/modules/shared/Login.tsx`
- [Shared portal shell](https://github.com/elitedebuggers/swasth/blob/main/src/components/SharedLayout.tsx): `src/components/SharedLayout.tsx`
- [Chat layout state](https://github.com/elitedebuggers/swasth/blob/main/src/components/LayoutContext.tsx): `src/components/LayoutContext.tsx`

### Patient care

- [Public home](https://github.com/elitedebuggers/swasth/blob/main/src/modules/patient/Home.tsx): `src/modules/patient/Home.tsx`
- [Patient dashboard](https://github.com/elitedebuggers/swasth/blob/main/src/modules/patient/PatientDashboard.tsx): `src/modules/patient/PatientDashboard.tsx`
- [AI assistant](https://github.com/elitedebuggers/swasth/blob/main/src/modules/patient/components/PatientAIAssistant.tsx): `src/modules/patient/components/PatientAIAssistant.tsx`
- [Health timeline](https://github.com/elitedebuggers/swasth/blob/main/src/modules/patient/components/HealthTimeline.tsx): `src/modules/patient/components/HealthTimeline.tsx`
- [Medical records](https://github.com/elitedebuggers/swasth/blob/main/src/modules/patient/MedicalRecords.tsx): `src/modules/patient/MedicalRecords.tsx`
- [Record approvals](https://github.com/elitedebuggers/swasth/blob/main/src/modules/patient/components/PendingApprovalsModal.tsx): `src/modules/patient/components/PendingApprovalsModal.tsx`
- [Document viewer](https://github.com/elitedebuggers/swasth/blob/main/src/modules/shared/DocumentView.tsx): `src/modules/shared/DocumentView.tsx`
- [Document deletion](https://github.com/elitedebuggers/swasth/blob/main/src/modules/shared/DeleteDocumentModal.tsx): `src/modules/shared/DeleteDocumentModal.tsx`
- [Medication tracking](https://github.com/elitedebuggers/swasth/blob/main/src/modules/patient/Medications.tsx): `src/modules/patient/Medications.tsx`
- [Doctor discovery](https://github.com/elitedebuggers/swasth/blob/main/src/modules/patient/Doctors.tsx): `src/modules/patient/Doctors.tsx`
- [Appointment booking](https://github.com/elitedebuggers/swasth/blob/main/src/modules/patient/components/AppointmentBookingModal.tsx): `src/modules/patient/components/AppointmentBookingModal.tsx`
- [Patient appointments](https://github.com/elitedebuggers/swasth/blob/main/src/modules/patient/Appointments.tsx): `src/modules/patient/Appointments.tsx`
- [Patient messages](https://github.com/elitedebuggers/swasth/blob/main/src/modules/patient/Messages.tsx): `src/modules/patient/Messages.tsx`
- [Patient settings](https://github.com/elitedebuggers/swasth/blob/main/src/modules/patient/Settings.tsx): `src/modules/patient/Settings.tsx`

### Clinician workflows

- [Shift scheduler](https://github.com/elitedebuggers/swasth/blob/main/src/modules/doctor/Schedule.tsx): `src/modules/doctor/Schedule.tsx`
- [Appointment approvals](https://github.com/elitedebuggers/swasth/blob/main/src/modules/doctor/Appointments.tsx): `src/modules/doctor/Appointments.tsx`
- [Patient records workspace](https://github.com/elitedebuggers/swasth/blob/main/src/modules/doctor/Patients.tsx): `src/modules/doctor/Patients.tsx`
- [Doctor dashboard](https://github.com/elitedebuggers/swasth/blob/main/src/modules/doctor/DoctorDashboard.tsx): `src/modules/doctor/DoctorDashboard.tsx`
- [Doctor settings](https://github.com/elitedebuggers/swasth/blob/main/src/modules/doctor/Settings.tsx): `src/modules/doctor/Settings.tsx`

### Data and resilience

- [Medication helpers](https://github.com/elitedebuggers/swasth/blob/main/src/lib/medications.ts): `src/lib/medications.ts`
- [Supabase client](https://github.com/elitedebuggers/swasth/blob/main/src/lib/supabase.ts): `src/lib/supabase.ts`
- **Supabase services**
- [Resilience engine](https://github.com/elitedebuggers/swasth/blob/main/src/lib/resilience.ts): `src/lib/resilience.ts`
- [Local document store](https://github.com/elitedebuggers/swasth/blob/main/src/lib/documents.ts): `src/lib/documents.ts`
- [Offline sync queue](https://github.com/elitedebuggers/swasth/blob/main/src/lib/resilience.ts): `src/lib/resilience.ts`
- [Resilience console](https://github.com/elitedebuggers/swasth/blob/main/src/modules/shared/ResilienceHUD.tsx): `src/modules/shared/ResilienceHUD.tsx`
- [Local triage rules](https://github.com/elitedebuggers/swasth/blob/main/src/lib/resilience.ts): `src/lib/resilience.ts`

### Other components

- **Patient or doctor**
- **Groq / Grok AI**

## Connections

- Patient or doctor → Route dispatcher: opens portal (evidence: `src/App.tsx`)
- Route dispatcher → Public home: routes to (evidence: `src/App.tsx`)
- Route dispatcher → Sign-in: routes to (evidence: `src/App.tsx`)
- Route dispatcher → Patient dashboard: routes to (evidence: `src/App.tsx`)
- Route dispatcher → Medical records: routes to (evidence: `src/App.tsx`)
- Route dispatcher → Medication tracking: routes to (evidence: `src/App.tsx`)
- Route dispatcher → Doctor discovery: routes to (evidence: `src/App.tsx`)
- Route dispatcher → Patient appointments: routes to (evidence: `src/App.tsx`)
- Route dispatcher → Patient messages: routes to (evidence: `src/App.tsx`)
- Route dispatcher → Patient settings: routes to (evidence: `src/App.tsx`)
- Route dispatcher → Shift scheduler: routes to (evidence: `src/App.tsx`)
- Route dispatcher → Appointment approvals: routes to (evidence: `src/App.tsx`)
- Route dispatcher → Patient records workspace: routes to (evidence: `src/App.tsx`)
- Route dispatcher → Doctor settings: routes to (evidence: `src/App.tsx`)
- Route dispatcher → Document viewer: routes to (evidence: `src/App.tsx`)
- Patient dashboard → AI assistant: renders (evidence: `src/modules/patient/PatientDashboard.tsx`)
- Patient dashboard → Health timeline: renders (evidence: `src/modules/patient/PatientDashboard.tsx`)
- Patient dashboard → Shared portal shell: uses shell (evidence: `src/modules/patient/PatientDashboard.tsx`)
- Medical records → Record approvals: uses modal (evidence: `src/modules/patient/MedicalRecords.tsx`)
- Medical records → Document deletion: uses modal (evidence: `src/modules/patient/MedicalRecords.tsx`)
- Medical records → Medication helpers: uses helpers (evidence: `src/modules/patient/MedicalRecords.tsx`)
- Medical records → Local document store: saves documents (evidence: `src/modules/patient/MedicalRecords.tsx`)
- Patient dashboard → Local document store: saves documents (evidence: `src/modules/patient/PatientDashboard.tsx`)
- Document viewer → Local document store: reads fallback (evidence: `README.md`)
- Medication tracking → Medication helpers: uses helpers (evidence: `src/modules/patient/Medications.tsx`)
- Doctor discovery → Appointment booking: starts booking (evidence: `README.md`)
- Patient appointments → Appointment booking: uses modal (evidence: `src/modules/patient/Appointments.tsx`)
- Appointment approvals → Shift scheduler: uses clinician slots (evidence: `README.md`)
- Patient records workspace → Document deletion: uses modal (evidence: `src/modules/doctor/Patients.tsx`)
- Patient records workspace → Medication helpers: uses helpers (evidence: `src/modules/doctor/Patients.tsx`)
- Patient records workspace → Shared portal shell: uses shell (evidence: `src/modules/doctor/Patients.tsx`)
- Doctor dashboard → Document deletion: uses modal (evidence: `src/modules/doctor/DoctorDashboard.tsx`)
- Doctor dashboard → Medication helpers: uses helpers (evidence: `src/modules/doctor/DoctorDashboard.tsx`)
- Supabase client → Resilience engine: configures fetch (evidence: `src/lib/supabase.ts`)
- Supabase client → Supabase services: connects (evidence: `README.md`)
- Resilience engine → Supabase services: fetches or syncs (evidence: `README.md`)
- Resilience engine → Offline sync queue: queues writes (evidence: `README.md`)
- Resilience engine → Local document store: caches reads (evidence: `README.md`)
- AI assistant → Groq / Grok AI: requests AI (evidence: `README.md`)
- AI assistant → Local triage rules: falls back to (evidence: `src/modules/patient/components/PatientAIAssistant.tsx`)
- Local triage rules → AI assistant: returns advice (evidence: `src/modules/patient/components/PatientAIAssistant.tsx`)
- Shared portal shell → Resilience console: renders console (evidence: `src/components/SharedLayout.tsx`)
- Resilience console → Resilience engine: monitors controls (evidence: `src/components/SharedLayout.tsx`)
- Shared portal shell → Chat layout state: reads context (evidence: `src/components/SharedLayout.tsx`)
