# radityawsgtg/pulihgo architecture

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

- Interactive diagram: https://gitdiagram.com/radityawsgtg/pulihgo
- Repository: https://github.com/radityawsgtg/pulihgo

## Overview

PulihGo is a gyroscope-based home stroke-rehabilitation product: therapists prescribe exercise targets, patients practise on a phone that measures movement and records sessions, and therapists review synced results. The phone app and dashboard communicate through Supabase, not directly. The sampled source confirms app navigation, calibrated sensor input, local session storage, and dashboard database calls; README documents the wider reporting and offline-first loop. Some screen and sync implementations were not sampled, so uncertain internal wiring is omitted.

Main entry points: [`pulihgo-app/src/screens/ExerciseScreen.tsx`](https://github.com/radityawsgtg/pulihgo/blob/main/pulihgo-app/src/screens/ExerciseScreen.tsx) (Exercise session), [`pulihgo-app/App.tsx`](https://github.com/radityawsgtg/pulihgo/blob/main/pulihgo-app/App.tsx) (App navigation), [`pulihgo-app/src/storage/sessionStore.ts`](https://github.com/radityawsgtg/pulihgo/blob/main/pulihgo-app/src/storage/sessionStore.ts) (Session history), [`pulihgo-app/src/sync/supabaseClient.ts`](https://github.com/radityawsgtg/pulihgo/blob/main/pulihgo-app/src/sync/supabaseClient.ts) (Phone Supabase client)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_patient_app["Patient app"]
  node_app["App navigation<br/>[App.tsx]"]
  node_onboarding["Onboarding"]
  node_exercise_list["Exercise selection"]
  node_exercise["Exercise session<br/>[ExerciseScreen.tsx]"]
  node_progress["Progress view<br/>[ProgressScreen.tsx]"]
  node_summary["Session summary<br/>[SummaryScreen.tsx]"]
end

subgraph group_measurement["Exercise measurement"]
  node_calibrated_angle["Angle calibration"]
  node_device_angle["Device motion input<br/>[useDeviceAngle.ts]"]
  node_rep_detector["Rep detection<br/>[repDetector.ts]"]
  node_rom["ROM metrics<br/>[rom.ts]"]
  node_smoothness["Movement smoothness<br/>[smoothness.ts]"]
  node_safety["Safety checks<br/>[safety.ts]"]
end

subgraph group_sync["Sync and storage"]
  node_prescription_hook["Prescription loading<br/>[usePrescription.ts]"]
  node_prescription_fetch["Prescription resolver"]
  node_session_store[("Session history<br/>[sessionStore.ts]")]
  node_async_storage[("Device storage")]
  node_upload["Session upload<br/>[uploadSession.ts]"]
  node_mobile_client["Phone Supabase client<br/>[supabaseClient.ts]"]
end

subgraph group_therapist["Therapist dashboard"]
  node_dashboard["Therapist dashboard<br/>[App.tsx]"]
  node_dashboard_client["Dashboard data access<br/>[supabase.ts]"]
end

node_patient(("Patient"))
node_supabase[("Supabase")]
node_therapist_actor(("Therapist"))

node_patient -->|"uses"| node_app
node_app -->|"shows first-run"| node_onboarding
node_app -->|"opens exercise"| node_exercise_list
node_app -->|"opens progress"| node_progress
node_app -->|"opens summary"| node_summary
node_exercise_list -->|"selects exercise"| node_exercise
node_exercise -->|"loads plan"| node_prescription_hook
node_prescription_hook -->|"resolves plan"| node_prescription_fetch
node_prescription_fetch -.->|"queries"| node_mobile_client
node_mobile_client -.->|"reads plan"| node_supabase
node_exercise -->|"reads angle"| node_calibrated_angle
node_calibrated_angle -->|"calibrates"| node_device_angle
node_device_angle -->|"supplies samples"| node_exercise
node_exercise -->|"counts reps"| node_rep_detector
node_exercise -->|"checks range"| node_safety
node_exercise -->|"measures ROM"| node_rom
node_exercise -->|"scores movement"| node_smoothness
node_exercise -->|"saves session"| node_session_store
node_app -->|"hydrates history"| node_session_store
node_session_store -->|"persists locally"| node_async_storage
node_session_store -.->|"uploads best-effort"| node_upload
node_upload -.->|"sends session"| node_mobile_client
node_mobile_client -.->|"writes session"| node_supabase
node_therapist_actor -->|"uses"| node_dashboard
node_dashboard -->|"loads and saves data"| node_dashboard_client
node_dashboard_client -->|"reads sessions; writes plan"| node_supabase
node_supabase -->|"returns records"| node_dashboard_client
node_session_store -->|"provides history"| node_progress
node_session_store -->|"provides sessions"| node_summary

click node_app "https://github.com/radityawsgtg/pulihgo/blob/main/pulihgo-app/App.tsx"
click node_onboarding "https://github.com/radityawsgtg/pulihgo/blob/main/pulihgo-app/src/screens/OnboardingScreen.tsx"
click node_exercise_list "https://github.com/radityawsgtg/pulihgo/blob/main/pulihgo-app/src/screens/ExerciseListScreen.tsx"
click node_exercise "https://github.com/radityawsgtg/pulihgo/blob/main/pulihgo-app/src/screens/ExerciseScreen.tsx"
click node_progress "https://github.com/radityawsgtg/pulihgo/blob/main/pulihgo-app/src/screens/ProgressScreen.tsx"
click node_summary "https://github.com/radityawsgtg/pulihgo/blob/main/pulihgo-app/src/screens/SummaryScreen.tsx"
click node_prescription_hook "https://github.com/radityawsgtg/pulihgo/blob/main/pulihgo-app/src/sync/usePrescription.ts"
click node_prescription_fetch "https://github.com/radityawsgtg/pulihgo/blob/main/pulihgo-app/src/sync/fetchPrescription.ts"
click node_calibrated_angle "https://github.com/radityawsgtg/pulihgo/blob/main/pulihgo-app/src/sensors/useCalibratedAngle.ts"
click node_device_angle "https://github.com/radityawsgtg/pulihgo/blob/main/pulihgo-app/src/sensors/useDeviceAngle.ts"
click node_rep_detector "https://github.com/radityawsgtg/pulihgo/blob/main/pulihgo-app/src/metrics/repDetector.ts"
click node_rom "https://github.com/radityawsgtg/pulihgo/blob/main/pulihgo-app/src/metrics/rom.ts"
click node_smoothness "https://github.com/radityawsgtg/pulihgo/blob/main/pulihgo-app/src/metrics/smoothness.ts"
click node_safety "https://github.com/radityawsgtg/pulihgo/blob/main/pulihgo-app/src/safety/safety.ts"
click node_session_store "https://github.com/radityawsgtg/pulihgo/blob/main/pulihgo-app/src/storage/sessionStore.ts"
click node_upload "https://github.com/radityawsgtg/pulihgo/blob/main/pulihgo-app/src/sync/uploadSession.ts"
click node_mobile_client "https://github.com/radityawsgtg/pulihgo/blob/main/pulihgo-app/src/sync/supabaseClient.ts"
click node_dashboard "https://github.com/radityawsgtg/pulihgo/blob/main/therapist-dashboard/src/App.tsx"
click node_dashboard_client "https://github.com/radityawsgtg/pulihgo/blob/main/therapist-dashboard/src/lib/supabase.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_onboarding,node_exercise_list,node_exercise,node_progress,node_summary toneBlue
class node_calibrated_angle,node_device_angle,node_rep_detector,node_rom,node_smoothness,node_safety,node_supabase toneAmber
class node_prescription_hook,node_prescription_fetch,node_session_store,node_async_storage,node_upload,node_mobile_client,node_therapist_actor toneMint
class node_dashboard,node_dashboard_client toneRose
class node_patient toneIndigo
```

## Components

### Patient app

- [App navigation](https://github.com/radityawsgtg/pulihgo/blob/main/pulihgo-app/App.tsx): `pulihgo-app/App.tsx`
- [Onboarding](https://github.com/radityawsgtg/pulihgo/blob/main/pulihgo-app/src/screens/OnboardingScreen.tsx): `pulihgo-app/src/screens/OnboardingScreen.tsx`
- [Exercise selection](https://github.com/radityawsgtg/pulihgo/blob/main/pulihgo-app/src/screens/ExerciseListScreen.tsx): `pulihgo-app/src/screens/ExerciseListScreen.tsx`
- [Exercise session](https://github.com/radityawsgtg/pulihgo/blob/main/pulihgo-app/src/screens/ExerciseScreen.tsx): `pulihgo-app/src/screens/ExerciseScreen.tsx`
- [Progress view](https://github.com/radityawsgtg/pulihgo/blob/main/pulihgo-app/src/screens/ProgressScreen.tsx): `pulihgo-app/src/screens/ProgressScreen.tsx`
- [Session summary](https://github.com/radityawsgtg/pulihgo/blob/main/pulihgo-app/src/screens/SummaryScreen.tsx): `pulihgo-app/src/screens/SummaryScreen.tsx`

### Exercise measurement

- [Angle calibration](https://github.com/radityawsgtg/pulihgo/blob/main/pulihgo-app/src/sensors/useCalibratedAngle.ts): `pulihgo-app/src/sensors/useCalibratedAngle.ts`
- [Device motion input](https://github.com/radityawsgtg/pulihgo/blob/main/pulihgo-app/src/sensors/useDeviceAngle.ts): `pulihgo-app/src/sensors/useDeviceAngle.ts`
- [Rep detection](https://github.com/radityawsgtg/pulihgo/blob/main/pulihgo-app/src/metrics/repDetector.ts): `pulihgo-app/src/metrics/repDetector.ts`
- [ROM metrics](https://github.com/radityawsgtg/pulihgo/blob/main/pulihgo-app/src/metrics/rom.ts): `pulihgo-app/src/metrics/rom.ts`
- [Movement smoothness](https://github.com/radityawsgtg/pulihgo/blob/main/pulihgo-app/src/metrics/smoothness.ts): `pulihgo-app/src/metrics/smoothness.ts`
- [Safety checks](https://github.com/radityawsgtg/pulihgo/blob/main/pulihgo-app/src/safety/safety.ts): `pulihgo-app/src/safety/safety.ts`

### Sync and storage

- [Prescription loading](https://github.com/radityawsgtg/pulihgo/blob/main/pulihgo-app/src/sync/usePrescription.ts): `pulihgo-app/src/sync/usePrescription.ts`
- [Prescription resolver](https://github.com/radityawsgtg/pulihgo/blob/main/pulihgo-app/src/sync/fetchPrescription.ts): `pulihgo-app/src/sync/fetchPrescription.ts`
- [Session history](https://github.com/radityawsgtg/pulihgo/blob/main/pulihgo-app/src/storage/sessionStore.ts): `pulihgo-app/src/storage/sessionStore.ts`
- **Device storage**
- [Session upload](https://github.com/radityawsgtg/pulihgo/blob/main/pulihgo-app/src/sync/uploadSession.ts): `pulihgo-app/src/sync/uploadSession.ts`
- [Phone Supabase client](https://github.com/radityawsgtg/pulihgo/blob/main/pulihgo-app/src/sync/supabaseClient.ts): `pulihgo-app/src/sync/supabaseClient.ts`

### Therapist dashboard

- [Therapist dashboard](https://github.com/radityawsgtg/pulihgo/blob/main/therapist-dashboard/src/App.tsx): `therapist-dashboard/src/App.tsx`
- [Dashboard data access](https://github.com/radityawsgtg/pulihgo/blob/main/therapist-dashboard/src/lib/supabase.ts): `therapist-dashboard/src/lib/supabase.ts`

### Other components

- **Patient**
- **Supabase**
- **Therapist**

## Connections

- Patient → App navigation: uses
- App navigation → Onboarding: shows first-run
- App navigation → Exercise selection: opens exercise
- App navigation → Progress view: opens progress
- App navigation → Session summary: opens summary
- Exercise selection → Exercise session: selects exercise
- Exercise session → Prescription loading: loads plan
- Prescription loading → Prescription resolver: resolves plan
- Prescription resolver → Phone Supabase client: queries
- Phone Supabase client → Supabase: reads plan
- Exercise session → Angle calibration: reads angle
- Angle calibration → Device motion input: calibrates
- Device motion input → Exercise session: supplies samples
- Exercise session → Rep detection: counts reps
- Exercise session → Safety checks: checks range
- Exercise session → ROM metrics: measures ROM
- Exercise session → Movement smoothness: scores movement
- Exercise session → Session history: saves session
- App navigation → Session history: hydrates history
- Session history → Device storage: persists locally
- Session history → Session upload: uploads best-effort
- Session upload → Phone Supabase client: sends session
- Phone Supabase client → Supabase: writes session
- Therapist → Therapist dashboard: uses
- Therapist dashboard → Dashboard data access: loads and saves data
- Dashboard data access → Supabase: reads sessions; writes plan
- Supabase → Dashboard data access: returns records
- Session history → Progress view: provides history
- Session history → Session summary: provides sessions
