# sakibuzzaman99/hridpindo architecture

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

- Interactive diagram: https://gitdiagram.com/sakibuzzaman99/hridpindo
- Repository: https://github.com/sakibuzzaman99/hridpindo

## Overview

#### Purpose and deployment shape
HridPindo is a bilingual remote cardiac-rehabilitation platform with patient and clinician workflows. It has three deployable surfaces: a React/Vite PWA, a native Android app, and Supabase backend/Edge Functions. Patients capture logs, guided tests, phone sensor data, and optional BLE strap streams; clinicians prescribe, review, and communicate. Core persistence and authorization are database-backed.
Paths: `src/main.jsx`, `android/app/src/main/java/com/hridpindo/app/MainActivity.kt`, `supabase/schema.sql`.

#### Web application entry and role workflows
The browser entry mounts `App.jsx`, whose routed pages separate public/auth, doctor, and patient experiences. Role-specific layouts organize dashboards, records, prescriptions, medications, chat, and consultations. Shared components provide clinical snapshots, alert queues, charts, record inspection, exercise plans, and video-call UI.
Paths: `src/main.jsx`, `src/App.jsx`, `src/pages/doctor/DoctorLayout.jsx`.

#### Android application and native sensing
`MainActivity` and Compose `AppRoot` host the Android patient experience. Native data adapters cover Health Connect, medication reminders, device IMU/step collection, CameraX PPG heart-rate capture, and MediaPipe pose analysis using the bundled landmarker model. WorkManager/services support passive capture and background continuity.
Paths: `android/app/src/main/java/com/hridpindo/app/MainActivity.kt`, `android/app/src/main/java/com/hridpindo/app/data/PpgCamera.kt`, `android/app/src/main/assets/pose_landmarker_lite.task`.

#### Shared clinical and signal-processing core
Kotlin Multiplatform centralizes models, patient repository access, sensing semantics, clinical calculations, movement/pose/PPG processing, records parsing, and study-session logic across Android and potential iOS consumers. It is the main boundary for portable science logic versus Android hardware integration; platform-specific locks, upload behavior, and platform APIs use expect/actual-style source sets.
Paths: `android/shared/src/commonMain/kotlin/com/hridpindo/app/data/Models.kt`, `android/shared/src/commonMain/kotlin/com/hridpindo/app/data/Clinical.kt`, `android/shared/src/commonMain/kotlin/com/hridpindo/app/data/PpgProcessor.kt`.

#### BLE capture, offline archive, and synchronization
The BLE subsystem connects standard HR GATT devices and Polar H10 PMD streams for HR, RR intervals, accelerometry, and raw ECG. Capture flows parse and analyze samples, retain raw chunks/archive data locally, and run foreground/background workers to synchronize idempotently when connectivity returns. Research-device protocols and upload throttling live in shared code; Android owns Bluetooth, stores, workers, and services.
Paths: `android/app/src/main/java/com/hridpindo/app/data/ble/PolarH10.kt`, `android/app/src/main/java/com/hridpindo/app/data/ble/HrSyncWorker.kt`, `android/shared/src/commonMain/kotlin/com/hridpindo/app/data/ble/PmdProtocol.kt`.

#### Rehabilitation insights and safety boundaries
The platform derives adherence, activity/exercise proposals, HR/HRV/session statistics, recovery metrics, and risk evidence from recorded data. Functional-test and adherence formulas retain missing measurements rather than treating them as zero. Detection is advisory: exercise sessions require patient confirmation; AI summaries require clinician review. ECG is captured/archived, not interpreted, and clinical thresholds are configurable rather than hard-coded.
Paths: `android/shared/src/commonMain/kotlin/com/hridpindo/app/data/cr/Adherence.kt`, `android/shared/src/commonMain/kotlin/com/hridpindo/app/data/ble/SegmentDetector.kt`, `src/lib/alerts.js`.

#### Backend, authorization, and external services
Supabase PostgreSQL is the system of record, with schema-defined Row-Level Security as the authorization boundary; Auth, Storage, and realtime backend capabilities are consumed by clients. Deno Edge Functions isolate privileged integrations: Gemini for chat, summaries, and OCR; Agora token issuance for video; plus push, speech-to-text, and text-to-speech services. Browser clients use only the anon key; server-side secrets remain in Supabase/function environments.
Paths: `supabase/schema.sql`, `src/lib/supabase.js`, `supabase/functions/gemini-chat/index.ts`.

#### Data flow
Authenticated patient/clinician clients read and mutate Supabase records under RLS. Android can first collect sensor/test data locally, process it through the shared science core, archive raw streams, then upload through workers. Web and Android render persisted measurements and derived results for patient confirmation or clinician action. Gemini and Agora calls cross only through Edge Functions/token boundaries rather than exposing provider credentials to clients.
Paths: `android/app/src/main/java/com/hridpindo/app/data/ble/RawUploadWorker.kt`, `src/components/DoctorDataExplorer.jsx`, `supabase/functions/agora-token/index.ts`.

Main entry points: [`src/App.jsx`](https://github.com/sakibuzzaman99/hridpindo/blob/main/src/App.jsx) (Role workflows), [`supabase/schema.sql`](https://github.com/sakibuzzaman99/hridpindo/blob/main/supabase/schema.sql) (Supabase system of record), [`android/app/src/main/java/com/hridpindo/app/data/PpgCamera.kt`](https://github.com/sakibuzzaman99/hridpindo/blob/main/android/app/src/main/java/com/hridpindo/app/data/PpgCamera.kt) (Native sensing), [`android/app/src/main/java/com/hridpindo/app/data/ble/PolarH10.kt`](https://github.com/sakibuzzaman99/hridpindo/blob/main/android/app/src/main/java/com/hridpindo/app/data/ble/PolarH10.kt) (BLE capture)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_web["Web PWA"]
  node_web_entry["React PWA entry<br/>Vite/React<br/>[main.jsx]"]
  node_web_routes["Role workflows<br/>React routes<br/>[App.jsx]"]
  node_doctor_ui["Clinician workspace<br/>doctor layout<br/>[DoctorLayout.jsx]"]
  node_web_supabase["Web Supabase client<br/>anon client<br/>[supabase.js]"]
end

subgraph group_android["Android app"]
  node_android_entry["Android patient app<br/>Compose host<br/>[MainActivity.kt]"]
  node_native_sensing["Native sensing<br/>Android adapters<br/>[PpgCamera.kt]"]
  node_pose_model["Pose landmarker model<br/>MediaPipe asset"]
  node_ble_capture["BLE capture<br/>Android BLE<br/>[PolarH10.kt]"]
  node_offline_sync["Offline archive &amp; sync<br/>Android workers<br/>[HrSyncWorker.kt]"]
end

subgraph group_shared["Shared clinical core"]
  node_shared_models["Clinical models &amp; repository<br/>KMP common core<br/>[Models.kt]"]
  node_signal_core["Signal &amp; clinical processing<br/>KMP science core<br/>[PpgProcessor.kt]"]
  node_ble_protocol["Research BLE protocol<br/>KMP PMD<br/>[PmdProtocol.kt]"]
  node_insights["Advisory rehab insights<br/>KMP analytics<br/>[Adherence.kt]"]
end

subgraph group_backend["Supabase backend"]
  node_supabase[("Supabase system of record<br/>PostgreSQL + RLS<br/>[schema.sql]")]
  node_edge_gemini{{"Gemini integration<br/>Deno Edge Function<br/>[index.ts]"}}
  node_edge_agora{{"Agora token boundary<br/>Deno Edge Function<br/>[index.ts]"}}
end

subgraph group_external["External services"]
  node_providers(("AI, video &amp; communications<br/>external providers"))
end

node_web_entry -->|"mounts"| node_web_routes
node_web_routes -->|"renders clinician routes"| node_doctor_ui
node_web_routes -->|"uses"| node_web_supabase
node_web_supabase -->|"authenticated reads/writes"| node_supabase
node_web_routes -->|"requests AI features"| node_edge_gemini
node_web_routes -->|"requests video token"| node_edge_agora
node_android_entry -->|"hosts"| node_native_sensing
node_native_sensing -->|"uses"| node_pose_model
node_native_sensing -->|"feeds measurements"| node_signal_core
node_android_entry -->|"starts capture"| node_ble_capture
node_ble_capture -->|"parses PMD streams"| node_ble_protocol
node_ble_capture -->|"archives raw chunks"| node_offline_sync
node_offline_sync -->|"syncs when online"| node_supabase
node_signal_core -->|"uses records"| node_shared_models
node_shared_models -->|"patient repository access"| node_supabase
node_signal_core -->|"derives metrics"| node_insights
node_insights -->|"persists derived results"| node_supabase
node_supabase -->|"clinical records and alerts"| node_doctor_ui
node_edge_gemini -->|"server-side AI calls"| node_providers
node_edge_agora -->|"server-side token calls"| node_providers

click node_web_entry "https://github.com/sakibuzzaman99/hridpindo/blob/main/src/main.jsx"
click node_web_routes "https://github.com/sakibuzzaman99/hridpindo/blob/main/src/App.jsx"
click node_doctor_ui "https://github.com/sakibuzzaman99/hridpindo/blob/main/src/pages/doctor/DoctorLayout.jsx"
click node_web_supabase "https://github.com/sakibuzzaman99/hridpindo/blob/main/src/lib/supabase.js"
click node_android_entry "https://github.com/sakibuzzaman99/hridpindo/blob/main/android/app/src/main/java/com/hridpindo/app/MainActivity.kt"
click node_native_sensing "https://github.com/sakibuzzaman99/hridpindo/blob/main/android/app/src/main/java/com/hridpindo/app/data/PpgCamera.kt"
click node_pose_model "https://github.com/sakibuzzaman99/hridpindo/blob/main/android/app/src/main/assets/pose_landmarker_lite.task"
click node_ble_capture "https://github.com/sakibuzzaman99/hridpindo/blob/main/android/app/src/main/java/com/hridpindo/app/data/ble/PolarH10.kt"
click node_offline_sync "https://github.com/sakibuzzaman99/hridpindo/blob/main/android/app/src/main/java/com/hridpindo/app/data/ble/HrSyncWorker.kt"
click node_shared_models "https://github.com/sakibuzzaman99/hridpindo/blob/main/android/shared/src/commonMain/kotlin/com/hridpindo/app/data/Models.kt"
click node_signal_core "https://github.com/sakibuzzaman99/hridpindo/blob/main/android/shared/src/commonMain/kotlin/com/hridpindo/app/data/PpgProcessor.kt"
click node_ble_protocol "https://github.com/sakibuzzaman99/hridpindo/blob/main/android/shared/src/commonMain/kotlin/com/hridpindo/app/data/ble/PmdProtocol.kt"
click node_insights "https://github.com/sakibuzzaman99/hridpindo/blob/main/android/shared/src/commonMain/kotlin/com/hridpindo/app/data/cr/Adherence.kt"
click node_supabase "https://github.com/sakibuzzaman99/hridpindo/blob/main/supabase/schema.sql"
click node_edge_gemini "https://github.com/sakibuzzaman99/hridpindo/blob/main/supabase/functions/gemini-chat/index.ts"
click node_edge_agora "https://github.com/sakibuzzaman99/hridpindo/blob/main/supabase/functions/agora-token/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_web_entry,node_web_routes,node_doctor_ui,node_web_supabase toneBlue
class node_android_entry,node_native_sensing,node_pose_model,node_ble_capture,node_offline_sync toneAmber
class node_shared_models,node_signal_core,node_ble_protocol,node_insights toneMint
class node_supabase,node_edge_gemini,node_edge_agora toneRose
class node_providers toneIndigo
```

## Components

### Web PWA

- [React PWA entry](https://github.com/sakibuzzaman99/hridpindo/blob/main/src/main.jsx): Vite/React · Mounts the browser application. · `src/main.jsx`
- [Role workflows](https://github.com/sakibuzzaman99/hridpindo/blob/main/src/App.jsx): React routes · Public, patient, and clinician experiences. · `src/App.jsx`
- [Clinician workspace](https://github.com/sakibuzzaman99/hridpindo/blob/main/src/pages/doctor/DoctorLayout.jsx): doctor layout · Records, prescriptions, alerts, chat, and consultations. · `src/pages/doctor/DoctorLayout.jsx`
- [Web Supabase client](https://github.com/sakibuzzaman99/hridpindo/blob/main/src/lib/supabase.js): anon client · Accesses backend capabilities without service secrets. · `src/lib/supabase.js`

### Android app

- [Android patient app](https://github.com/sakibuzzaman99/hridpindo/blob/main/android/app/src/main/java/com/hridpindo/app/MainActivity.kt): Compose host · Hosts the native patient experience. · `android/app/src/main/java/com/hridpindo/app/MainActivity.kt`
- [Native sensing](https://github.com/sakibuzzaman99/hridpindo/blob/main/android/app/src/main/java/com/hridpindo/app/data/PpgCamera.kt): Android adapters · Health Connect, IMU, CameraX PPG, pose, reminders, and background services. · `android/app/src/main/java/com/hridpindo/app/data/PpgCamera.kt`
- [Pose landmarker model](https://github.com/sakibuzzaman99/hridpindo/blob/main/android/app/src/main/assets/pose_landmarker_lite.task): MediaPipe asset · `android/app/src/main/assets/pose_landmarker_lite.task`
- [BLE capture](https://github.com/sakibuzzaman99/hridpindo/blob/main/android/app/src/main/java/com/hridpindo/app/data/ble/PolarH10.kt): Android BLE · Connects HR GATT and Polar H10 PMD streams. · `android/app/src/main/java/com/hridpindo/app/data/ble/PolarH10.kt`
- [Offline archive & sync](https://github.com/sakibuzzaman99/hridpindo/blob/main/android/app/src/main/java/com/hridpindo/app/data/ble/HrSyncWorker.kt): Android workers · Archives raw data and performs idempotent uploads. · `android/app/src/main/java/com/hridpindo/app/data/ble/HrSyncWorker.kt`

### Shared clinical core

- [Clinical models & repository](https://github.com/sakibuzzaman99/hridpindo/blob/main/android/shared/src/commonMain/kotlin/com/hridpindo/app/data/Models.kt): KMP common core · Portable patient data and sensing semantics. · `android/shared/src/commonMain/kotlin/com/hridpindo/app/data/Models.kt`
- [Signal & clinical processing](https://github.com/sakibuzzaman99/hridpindo/blob/main/android/shared/src/commonMain/kotlin/com/hridpindo/app/data/PpgProcessor.kt): KMP science core · Clinical calculations, PPG, movement, pose, and study sessions. · `android/shared/src/commonMain/kotlin/com/hridpindo/app/data/PpgProcessor.kt`
- [Research BLE protocol](https://github.com/sakibuzzaman99/hridpindo/blob/main/android/shared/src/commonMain/kotlin/com/hridpindo/app/data/ble/PmdProtocol.kt): KMP PMD · Shared Polar PMD parsing and upload semantics. · `android/shared/src/commonMain/kotlin/com/hridpindo/app/data/ble/PmdProtocol.kt`
- [Advisory rehab insights](https://github.com/sakibuzzaman99/hridpindo/blob/main/android/shared/src/commonMain/kotlin/com/hridpindo/app/data/cr/Adherence.kt): KMP analytics · Derives adherence and recovery evidence; confirmation and review remain required. · `android/shared/src/commonMain/kotlin/com/hridpindo/app/data/cr/Adherence.kt`

### Supabase backend

- [Supabase system of record](https://github.com/sakibuzzaman99/hridpindo/blob/main/supabase/schema.sql): PostgreSQL + RLS · Database-backed persistence and authorization boundary. · `supabase/schema.sql`
- [Gemini integration](https://github.com/sakibuzzaman99/hridpindo/blob/main/supabase/functions/gemini-chat/index.ts): Deno Edge Function · Privileged chat, summaries, and OCR boundary. · `supabase/functions/gemini-chat/index.ts`
- [Agora token boundary](https://github.com/sakibuzzaman99/hridpindo/blob/main/supabase/functions/agora-token/index.ts): Deno Edge Function · Issues video tokens without exposing provider credentials. · `supabase/functions/agora-token/index.ts`

### External services

- **AI, video & communications**: external providers · Gemini, Agora, push, speech-to-text, and text-to-speech services.

## Connections

- React PWA entry → Role workflows: mounts
- Role workflows → Clinician workspace: renders clinician routes
- Role workflows → Web Supabase client: uses
- Web Supabase client → Supabase system of record: authenticated reads/writes · RLS enforces record access.
- Role workflows → Gemini integration: requests AI features
- Role workflows → Agora token boundary: requests video token
- Android patient app → Native sensing: hosts
- Native sensing → Pose landmarker model: uses
- Native sensing → Signal & clinical processing: feeds measurements
- Android patient app → BLE capture: starts capture
- BLE capture → Research BLE protocol: parses PMD streams
- BLE capture → Offline archive & sync: archives raw chunks
- Offline archive & sync → Supabase system of record: syncs when online
- Signal & clinical processing → Clinical models & repository: uses records
- Clinical models & repository → Supabase system of record: patient repository access
- Signal & clinical processing → Advisory rehab insights: derives metrics
- Advisory rehab insights → Supabase system of record: persists derived results
- Supabase system of record → Clinician workspace: clinical records and alerts
- Gemini integration → AI, video & communications: server-side AI calls
- Agora token boundary → AI, video & communications: server-side token calls
