# ace-ify/swadhikaar architecture

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

- Interactive diagram: https://gitdiagram.com/ace-ify/swadhikaar
- Repository: https://github.com/ace-ify/swadhikaar

## Overview

Swadhikaar is a voice-first care operations platform spanning walk-in intake, prescription understanding, hospital access, emergency response, and longitudinal follow-up. The principal flow runs from patient or staff workflows through frontend and Supabase Edge Functions into durable clinical state; voice calls use a dedicated LiveKit worker. README statements establish the broad architecture and product capabilities; source excerpts support the shown intake, dispatch, risk, and recovery relationships. Unsampled subsystems are represented at their exact tree paths, without asserting unverified internal calls.

Main entry points: [`backend/voice_agent/agent.py`](https://github.com/ace-ify/swadhikaar/blob/main/backend/voice_agent/agent.py) (Voice agent), [`frontend/src/app/patient/pmjay/page.tsx`](https://github.com/ace-ify/swadhikaar/blob/main/frontend/src/app/patient/pmjay/page.tsx) (Patient portal), [`supabase/functions/case-session/index.ts`](https://github.com/ace-ify/swadhikaar/blob/main/supabase/functions/case-session/index.ts) (Walk-in case session), [`supabase/functions/incident-complete/index.ts`](https://github.com/ace-ify/swadhikaar/blob/main/supabase/functions/incident-complete/index.ts) (Recovery handoff)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_front["Care experiences"]
  node_kiosk["Walk-in kiosk<br/>[page.tsx]"]
  node_patient_portal["Patient portal<br/>[page.tsx]"]
  node_doctor_ops["Clinical dashboards<br/>[page.tsx]"]
  node_admin_ops["Operations dashboards<br/>[page.tsx]"]
end

subgraph group_access["Access and records"]
  node_ocr["Prescription OCR<br/>[route.ts]"]
  node_med_schedule["Medication schedule"]
  node_pmjay["PM-JAY guidance<br/>[ask-box.tsx]"]
  node_case_session["Walk-in case session<br/>[index.ts]"]
  node_case_summary["Clinical summary<br/>[summary_builder.ts]"]
  node_abdm["ABDM gateway<br/>[index.ts]"]
  node_abdm_export["FHIR export bundle<br/>[bundle.ts]"]
end

subgraph group_acute["Acute response"]
  node_sos["Emergency SOS<br/>[page.tsx]"]
  node_incident_intake["Incident intake<br/>[index.ts]"]
  node_triage["Risk assessment<br/>[index.ts]"]
  node_dispatch["Ambulance dispatch<br/>[page.tsx]"]
end

subgraph group_continuity["Voice and follow-up"]
  node_incident_complete["Recovery handoff<br/>[index.ts]"]
  node_voice_setup["Voice call setup<br/>[index.ts]"]
  node_voice_worker["Voice agent<br/>[agent.py]"]
  node_prompts["Care conversation prompts<br/>[system_prompts.py]"]
  node_heat_advisory["Weather outreach<br/>[index.ts]"]
end

subgraph group_platform["Supabase platform"]
  node_state[("Clinical and operational state")]
end

node_patient(("Patient"))
node_care_staff(("Care staff"))
node_livekit{{"LiveKit telephony"}}
node_hospital_data[("Empanelled hospitals")]

node_patient -->|"starts intake"| node_kiosk
node_care_staff -->|"reviews care"| node_doctor_ops
node_care_staff -->|"operates response"| node_admin_ops
node_patient -->|"seeks guidance"| node_patient_portal
node_kiosk -->|"opens session"| node_case_session
node_case_session -->|"creates room"| node_livekit
node_patient_portal -.->|"submits prescription"| node_ocr
node_ocr -.->|"enables schedule"| node_med_schedule
node_patient_portal -->|"requests guidance"| node_pmjay
node_pmjay -->|"finds hospitals"| node_hospital_data
node_doctor_ops -.->|"supports review"| node_case_summary
node_abdm -->|"builds bundle"| node_abdm_export
node_abdm -->|"reads care context"| node_state
node_patient -->|"requests help"| node_sos
node_sos -->|"submits incident"| node_incident_intake
node_incident_intake -->|"records incident"| node_state
node_admin_ops -.->|"coordinates response"| node_dispatch
node_dispatch -->|"completes incident"| node_incident_complete
node_incident_complete -->|"writes recovery record"| node_state
node_incident_complete -->|"schedules follow-up"| node_voice_worker
node_voice_setup -->|"creates call room"| node_livekit
node_livekit -->|"dispatches agent"| node_voice_worker
node_voice_worker -->|"loads prompts"| node_prompts
node_voice_worker -->|"updates care state"| node_state
node_heat_advisory -->|"queues outreach calls"| node_state
node_heat_advisory -.->|"places calls later"| node_livekit
node_case_session -->|"writes session data"| node_state
node_triage -.->|"assesses risk"| node_sos

click node_kiosk "https://github.com/ace-ify/swadhikaar/blob/main/frontend/src/app/kiosk/page.tsx"
click node_patient_portal "https://github.com/ace-ify/swadhikaar/blob/main/frontend/src/app/patient/pmjay/page.tsx"
click node_doctor_ops "https://github.com/ace-ify/swadhikaar/blob/main/frontend/src/app/doctor/dashboard/page.tsx"
click node_admin_ops "https://github.com/ace-ify/swadhikaar/blob/main/frontend/src/app/admin/dispatch/page.tsx"
click node_ocr "https://github.com/ace-ify/swadhikaar/blob/main/frontend/src/app/api/ocr/route.ts"
click node_med_schedule "https://github.com/ace-ify/swadhikaar/blob/main/frontend/src/components/kiosk/medication-schedule.tsx"
click node_pmjay "https://github.com/ace-ify/swadhikaar/blob/main/frontend/src/components/pmjay/ask-box.tsx"
click node_case_session "https://github.com/ace-ify/swadhikaar/blob/main/supabase/functions/case-session/index.ts"
click node_case_summary "https://github.com/ace-ify/swadhikaar/blob/main/supabase/functions/case-summary/summary_builder.ts"
click node_abdm "https://github.com/ace-ify/swadhikaar/blob/main/supabase/functions/abdm-gateway/index.ts"
click node_abdm_export "https://github.com/ace-ify/swadhikaar/blob/main/supabase/functions/export-abdm/bundle.ts"
click node_sos "https://github.com/ace-ify/swadhikaar/blob/main/frontend/src/app/patient/sos/page.tsx"
click node_incident_intake "https://github.com/ace-ify/swadhikaar/blob/main/supabase/functions/incident-intake/index.ts"
click node_triage "https://github.com/ace-ify/swadhikaar/blob/main/supabase/functions/risk-predict/index.ts"
click node_dispatch "https://github.com/ace-ify/swadhikaar/blob/main/frontend/src/app/admin/dispatch/page.tsx"
click node_incident_complete "https://github.com/ace-ify/swadhikaar/blob/main/supabase/functions/incident-complete/index.ts"
click node_voice_setup "https://github.com/ace-ify/swadhikaar/blob/main/supabase/functions/start-voice-call/index.ts"
click node_voice_worker "https://github.com/ace-ify/swadhikaar/blob/main/backend/voice_agent/agent.py"
click node_prompts "https://github.com/ace-ify/swadhikaar/blob/main/backend/voice_agent/prompts/system_prompts.py"
click node_heat_advisory "https://github.com/ace-ify/swadhikaar/blob/main/supabase/functions/heat-advisory/index.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_kiosk,node_patient_portal,node_doctor_ops,node_admin_ops toneBlue
class node_ocr,node_med_schedule,node_pmjay,node_case_session,node_case_summary,node_abdm,node_abdm_export,node_hospital_data toneAmber
class node_sos,node_incident_intake,node_triage,node_dispatch toneMint
class node_incident_complete,node_voice_setup,node_voice_worker,node_prompts,node_heat_advisory toneRose
class node_state,node_patient,node_care_staff,node_livekit toneIndigo
```

## Components

### Care experiences

- [Walk-in kiosk](https://github.com/ace-ify/swadhikaar/blob/main/frontend/src/app/kiosk/page.tsx): `frontend/src/app/kiosk/page.tsx`
- [Patient portal](https://github.com/ace-ify/swadhikaar/blob/main/frontend/src/app/patient/pmjay/page.tsx): `frontend/src/app/patient/pmjay/page.tsx`
- [Clinical dashboards](https://github.com/ace-ify/swadhikaar/blob/main/frontend/src/app/doctor/dashboard/page.tsx): `frontend/src/app/doctor/dashboard/page.tsx`
- [Operations dashboards](https://github.com/ace-ify/swadhikaar/blob/main/frontend/src/app/admin/dispatch/page.tsx): `frontend/src/app/admin/dispatch/page.tsx`

### Access and records

- [Prescription OCR](https://github.com/ace-ify/swadhikaar/blob/main/frontend/src/app/api/ocr/route.ts): `frontend/src/app/api/ocr/route.ts`
- [Medication schedule](https://github.com/ace-ify/swadhikaar/blob/main/frontend/src/components/kiosk/medication-schedule.tsx): `frontend/src/components/kiosk/medication-schedule.tsx`
- [PM-JAY guidance](https://github.com/ace-ify/swadhikaar/blob/main/frontend/src/components/pmjay/ask-box.tsx): `frontend/src/components/pmjay/ask-box.tsx`
- [Walk-in case session](https://github.com/ace-ify/swadhikaar/blob/main/supabase/functions/case-session/index.ts): `supabase/functions/case-session/index.ts`
- [Clinical summary](https://github.com/ace-ify/swadhikaar/blob/main/supabase/functions/case-summary/summary_builder.ts): `supabase/functions/case-summary/summary_builder.ts`
- [ABDM gateway](https://github.com/ace-ify/swadhikaar/blob/main/supabase/functions/abdm-gateway/index.ts): `supabase/functions/abdm-gateway/index.ts`
- [FHIR export bundle](https://github.com/ace-ify/swadhikaar/blob/main/supabase/functions/export-abdm/bundle.ts): `supabase/functions/export-abdm/bundle.ts`

### Acute response

- [Emergency SOS](https://github.com/ace-ify/swadhikaar/blob/main/frontend/src/app/patient/sos/page.tsx): `frontend/src/app/patient/sos/page.tsx`
- [Incident intake](https://github.com/ace-ify/swadhikaar/blob/main/supabase/functions/incident-intake/index.ts): `supabase/functions/incident-intake/index.ts`
- [Risk assessment](https://github.com/ace-ify/swadhikaar/blob/main/supabase/functions/risk-predict/index.ts): `supabase/functions/risk-predict/index.ts`
- [Ambulance dispatch](https://github.com/ace-ify/swadhikaar/blob/main/frontend/src/app/admin/dispatch/page.tsx): `frontend/src/app/admin/dispatch/page.tsx`

### Voice and follow-up

- [Recovery handoff](https://github.com/ace-ify/swadhikaar/blob/main/supabase/functions/incident-complete/index.ts): `supabase/functions/incident-complete/index.ts`
- [Voice call setup](https://github.com/ace-ify/swadhikaar/blob/main/supabase/functions/start-voice-call/index.ts): `supabase/functions/start-voice-call/index.ts`
- [Voice agent](https://github.com/ace-ify/swadhikaar/blob/main/backend/voice_agent/agent.py): `backend/voice_agent/agent.py`
- [Care conversation prompts](https://github.com/ace-ify/swadhikaar/blob/main/backend/voice_agent/prompts/system_prompts.py): `backend/voice_agent/prompts/system_prompts.py`
- [Weather outreach](https://github.com/ace-ify/swadhikaar/blob/main/supabase/functions/heat-advisory/index.ts): `supabase/functions/heat-advisory/index.ts`

### Supabase platform

- **Clinical and operational state**

### Other components

- **Patient**
- **Care staff**
- **LiveKit telephony**
- **Empanelled hospitals**

## Connections

- Patient → Walk-in kiosk: starts intake
- Care staff → Clinical dashboards: reviews care
- Care staff → Operations dashboards: operates response
- Patient → Patient portal: seeks guidance
- Walk-in kiosk → Walk-in case session: opens session (evidence: `supabase/functions/case-session/index.ts`)
- Walk-in case session → LiveKit telephony: creates room (evidence: `supabase/functions/case-session/index.ts`)
- Patient portal → Prescription OCR: submits prescription
- Prescription OCR → Medication schedule: enables schedule
- Patient portal → PM-JAY guidance: requests guidance
- PM-JAY guidance → Empanelled hospitals: finds hospitals
- Clinical dashboards → Clinical summary: supports review
- ABDM gateway → FHIR export bundle: builds bundle (evidence: `supabase/functions/abdm-gateway/index.ts`)
- ABDM gateway → Clinical and operational state: reads care context (evidence: `supabase/functions/abdm-gateway/index.ts`)
- Patient → Emergency SOS: requests help
- Emergency SOS → Incident intake: submits incident (evidence: `supabase/functions/incident-intake/index.ts`)
- Incident intake → Clinical and operational state: records incident (evidence: `supabase/functions/incident-intake/index.ts`)
- Operations dashboards → Ambulance dispatch: coordinates response (evidence: `frontend/src/app/admin/dispatch/page.tsx`)
- Ambulance dispatch → Recovery handoff: completes incident
- Recovery handoff → Clinical and operational state: writes recovery record (evidence: `supabase/functions/incident-complete/index.ts`)
- Recovery handoff → Voice agent: schedules follow-up (evidence: `supabase/functions/incident-complete/index.ts`)
- Voice call setup → LiveKit telephony: creates call room (evidence: `supabase/functions/start-voice-call/index.ts`)
- LiveKit telephony → Voice agent: dispatches agent
- Voice agent → Care conversation prompts: loads prompts (evidence: `backend/voice_agent/agent.py`)
- Voice agent → Clinical and operational state: updates care state
- Weather outreach → Clinical and operational state: queues outreach calls (evidence: `supabase/functions/heat-advisory/index.ts`)
- Weather outreach → LiveKit telephony: places calls later
- Walk-in case session → Clinical and operational state: writes session data (evidence: `supabase/functions/case-session/index.ts`)
- Risk assessment → Emergency SOS: assesses risk
