# hetmehta0/physalign2 architecture

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

- Interactive diagram: https://gitdiagram.com/hetmehta0/physalign2
- Repository: https://github.com/hetmehta0/physalign2

## Overview

#### Purpose and Deployable Surfaces
Physalign is a multi-client rehabilitation platform: patients receive prescribed exercise programs, perform camera-guided sessions with pose tracking, and upload recordings; clinicians manage programs and review outcomes. Deployable surfaces are a root Next.js patient/marketing app, FastAPI service, SwiftUI iOS app, Kotlin/Compose Android app, and clinician Next.js dashboard.

Entry points: `api/main.py`, `Physalign/Physalign/PhysalignApp.swift`, `android/app/src/main/java/com/physalign/android/MainActivity.kt`, `physalign-dashboard/app/page.tsx`.

#### Shared Backend and Data Boundary
Supabase is the primary external platform: PostgreSQL, object storage for exercise videos/skeleton JSON, and realtime subscriptions. Client repositories/providers isolate Supabase access from UI and local pose pipelines:
- iOS: `Physalign/Physalign/Supabase.swift`, `Physalign/Physalign/Services/PhysalignRepository.swift`
- Android: `android/app/src/main/java/com/physalign/android/data/remote/PhysalignRepository.kt`, `android/app/src/main/java/com/physalign/android/data/remote/SupabaseProvider.kt`
- Dashboard: `physalign-dashboard/lib/supabase.ts`
- Schema/API-adjacent artifacts: `api/supabase_migration.sql`, `supabase/functions/get-program/index.ts`

The FastAPI service is a separate Python runtime and integration boundary at `api/main.py`, containerized by `api/Dockerfile`.

#### Program and Session Domain
Exercise definitions, prescribed programs, sessions, and set summaries form the patient workflow’s core domain. iOS centralizes these types and exercise catalog:
`Physalign/Physalign/Models/Exercise.swift`, `Physalign/Physalign/Models/ExerciseProgram.swift`, `Physalign/Physalign/Models/ExerciseSession.swift`.

Program progression is orchestrated in presentation state, then persisted through repositories:
`Physalign/Physalign/Views/ProgramFlowViewModel.swift`,
`android/app/src/main/java/com/physalign/android/ui/ProgramViewModel.kt`,
`supabase/functions/get-program/index.ts`.

#### Patient Camera/Pose Pipeline
The mobile apps own device-camera capture and real-time pose processing rather than delegating it to the backend. On iOS, pose detection feeds smoothing, joint-angle calculation, exercise validation, and accessibility feedback:
`Physalign/Physalign/Services/PoseDetectionService.swift`,
`Physalign/Physalign/Services/ExercisePoseValidator.swift`,
`Physalign/Physalign/Services/JointAngleCalculator.swift`.

Android parallels this with analyzer/landmark/tracking layers:
`android/app/src/main/java/com/physalign/android/pose/PoseAnalyzer.kt`,
`android/app/src/main/java/com/physalign/android/pose/PoseLandmarks.kt`,
`android/app/src/main/java/com/physalign/android/pose/PoseTrackingRecorder.kt`.

#### Recording, Consent, and Upload Flow
Camera screens/view models coordinate permission/setup, framing, pose overlay, recording result, and upload. Recordings can be composited with skeleton output before persistence:
`Physalign/Physalign/Views/CameraViewModel.swift`,
`Physalign/Physalign/Services/SkeletonVideoCompositor.swift`,
`android/app/src/main/java/com/physalign/android/ui/recording/CameraViewModel.kt`,
`android/app/src/main/java/com/physalign/android/media/SkeletonVideoCompositor.kt`.

Consent is an explicit gate before patient tracking/recording in the web flow and a persisted concern on iOS:
`components/patient/ConsentGate.tsx`,
`Physalign/Physalign/Services/RecordingConsentStore.swift`.

#### Clinician Dashboard
The standalone dashboard is a Next.js application for clinic management, patients, program creation, trends, invitations, and settings. Its route-level entry points represent clinician workflows:
`physalign-dashboard/app/clinic/page.tsx`,
`physalign-dashboard/app/patients/page.tsx`,
`physalign-dashboard/app/createProgram/page.tsx`,
`physalign-dashboard/app/trends/page.tsx`.

It accesses Supabase through its own library boundary and contains clinic/deletion domain logic:
`physalign-dashboard/lib/supabase.ts`,
`physalign-dashboard/lib/clinic.ts`,
`physalign-dashboard/lib/deletion.ts`.

#### Web Patient Flow
The root Next.js app contains the browser-based patient-facing flow and shared UI. Pose tracking and pose math are local frontend components/utilities, while API URL selection and Supabase client access are separate boundaries:
`components/patient/PoseTracker.tsx`,
`components/patient/FatigueRating.tsx`,
`lib/patient/poseMath.ts`,
`lib/patient/supabase.ts`.

#### Runtime and Delivery Topology
Runtimes are Swift/SwiftUI on iOS, Kotlin/Jetpack Compose on Android, TypeScript/Next.js for both web applications, Python/FastAPI for the API, and Supabase-managed backend services. CI is partitioned by deployable surface:
`.github/workflows/ios-ci.yml`,
`.github/workflows/dashboard-ci.yml`,
`.github/workflows/api-ci.yml`,
`.github/workflows/web-ci.yml`.

Main entry points: [`.github/workflows/ios-ci.yml`](https://github.com/hetmehta0/physalign2/blob/main/.github/workflows/ios-ci.yml) (Surface-specific CI), [`Physalign/Physalign/Views/ProgramFlowViewModel.swift`](https://github.com/hetmehta0/physalign2/blob/main/Physalign/Physalign/Views/ProgramFlowViewModel.swift) (Program flow), [`android/app/src/main/java/com/physalign/android/ui/ProgramViewModel.kt`](https://github.com/hetmehta0/physalign2/blob/main/android/app/src/main/java/com/physalign/android/ui/ProgramViewModel.kt) (Program state), [`components/patient/ConsentGate.tsx`](https://github.com/hetmehta0/physalign2/blob/main/components/patient/ConsentGate.tsx) (Patient web flow)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_ios["iOS patient app"]
  node_ios_app["SwiftUI app<br/>iOS entry<br/>[PhysalignApp.swift]"]
  node_ios_program["Program flow<br/>presentation state"]
  node_ios_pose["Pose validation<br/>on-device pipeline"]
  node_ios_camera["Camera recording<br/>capture flow"]
  node_ios_repository["Patient repository<br/>data access"]
end

subgraph group_android["Android patient app"]
  node_android_app["Compose app<br/>Android entry<br/>[MainActivity.kt]"]
  node_android_program["Program state<br/>presentation state"]
  node_android_pose["Pose analyzer<br/>on-device pipeline<br/>[PoseAnalyzer.kt]"]
  node_android_camera["Camera recording<br/>capture flow<br/>[CameraViewModel.kt]"]
  node_android_repository["Patient repository<br/>data access"]
end

subgraph group_web["Web applications"]
  node_patient_web["Patient web flow<br/>Next.js UI<br/>[ConsentGate.tsx]"]
  node_web_pose["Browser pose tracker<br/>local pose pipeline<br/>[PoseTracker.tsx]"]
  node_dashboard["Clinician dashboard<br/>Next.js entry<br/>[page.tsx]"]
  node_dashboard_data["Dashboard data boundary<br/>Supabase client<br/>[supabase.ts]"]
end

subgraph group_backend["Backend platform"]
  node_api{{"FastAPI service<br/>Python API<br/>[main.py]"}}
  node_program_function["Get program function<br/>Supabase Edge Function<br/>[index.ts]"]
  node_supabase[("Supabase platform<br/>managed data platform")]
end

subgraph group_delivery["Delivery"]
  node_ci["Surface-specific CI<br/>GitHub Actions<br/>[ios-ci.yml]"]
end

node_ios_app -->|"hosts"| node_ios_program
node_ios_program -->|"guides session"| node_ios_pose
node_ios_pose -->|"feeds tracking"| node_ios_camera
node_ios_camera -->|"uploads through"| node_ios_repository
node_ios_program -->|"persists through"| node_ios_repository
node_ios_repository -->|"reads and writes"| node_supabase
node_android_app -->|"hosts"| node_android_program
node_android_program -->|"guides session"| node_android_pose
node_android_pose -->|"feeds tracking"| node_android_camera
node_android_camera -->|"uploads through"| node_android_repository
node_android_program -->|"persists through"| node_android_repository
node_android_repository -->|"reads and writes"| node_supabase
node_patient_web -->|"gates and hosts"| node_web_pose
node_patient_web -->|"stores patient data"| node_supabase
node_dashboard -->|"uses"| node_dashboard_data
node_dashboard_data -->|"manages clinic data"| node_supabase
node_program_function -->|"queries"| node_supabase
node_ios_program -.->|"retrieves program"| node_program_function
node_android_program -.->|"retrieves program"| node_program_function
node_api -->|"integrates with"| node_supabase
node_ci -.->|"validates"| node_ios_app
node_ci -.->|"validates"| node_dashboard
node_ci -.->|"validates"| node_api
node_ci -.->|"validates"| node_patient_web

click node_ios_app "https://github.com/hetmehta0/physalign2/blob/main/Physalign/Physalign/PhysalignApp.swift"
click node_ios_program "https://github.com/hetmehta0/physalign2/blob/main/Physalign/Physalign/Views/ProgramFlowViewModel.swift"
click node_ios_pose "https://github.com/hetmehta0/physalign2/blob/main/Physalign/Physalign/Services/PoseDetectionService.swift"
click node_ios_camera "https://github.com/hetmehta0/physalign2/blob/main/Physalign/Physalign/Views/CameraViewModel.swift"
click node_ios_repository "https://github.com/hetmehta0/physalign2/blob/main/Physalign/Physalign/Services/PhysalignRepository.swift"
click node_android_app "https://github.com/hetmehta0/physalign2/blob/main/android/app/src/main/java/com/physalign/android/MainActivity.kt"
click node_android_program "https://github.com/hetmehta0/physalign2/blob/main/android/app/src/main/java/com/physalign/android/ui/ProgramViewModel.kt"
click node_android_pose "https://github.com/hetmehta0/physalign2/blob/main/android/app/src/main/java/com/physalign/android/pose/PoseAnalyzer.kt"
click node_android_camera "https://github.com/hetmehta0/physalign2/blob/main/android/app/src/main/java/com/physalign/android/ui/recording/CameraViewModel.kt"
click node_android_repository "https://github.com/hetmehta0/physalign2/blob/main/android/app/src/main/java/com/physalign/android/data/remote/PhysalignRepository.kt"
click node_patient_web "https://github.com/hetmehta0/physalign2/blob/main/components/patient/ConsentGate.tsx"
click node_web_pose "https://github.com/hetmehta0/physalign2/blob/main/components/patient/PoseTracker.tsx"
click node_dashboard "https://github.com/hetmehta0/physalign2/blob/main/physalign-dashboard/app/page.tsx"
click node_dashboard_data "https://github.com/hetmehta0/physalign2/blob/main/physalign-dashboard/lib/supabase.ts"
click node_api "https://github.com/hetmehta0/physalign2/blob/main/api/main.py"
click node_program_function "https://github.com/hetmehta0/physalign2/blob/main/supabase/functions/get-program/index.ts"
click node_ci "https://github.com/hetmehta0/physalign2/blob/main/.github/workflows/ios-ci.yml"

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_ios_app,node_ios_program,node_ios_pose,node_ios_camera,node_ios_repository toneBlue
class node_android_app,node_android_program,node_android_pose,node_android_camera,node_android_repository toneAmber
class node_patient_web,node_web_pose,node_dashboard,node_dashboard_data toneMint
class node_api,node_program_function,node_supabase toneRose
class node_ci toneIndigo
```

## Components

### iOS patient app

- [SwiftUI app](https://github.com/hetmehta0/physalign2/blob/main/Physalign/Physalign/PhysalignApp.swift): iOS entry · `Physalign/Physalign/PhysalignApp.swift`
- [Program flow](https://github.com/hetmehta0/physalign2/blob/main/Physalign/Physalign/Views/ProgramFlowViewModel.swift): presentation state · Advances prescribed exercise sessions and persists outcomes. · `Physalign/Physalign/Views/ProgramFlowViewModel.swift`
- [Pose validation](https://github.com/hetmehta0/physalign2/blob/main/Physalign/Physalign/Services/PoseDetectionService.swift): on-device pipeline · Detection, joint angles, and exercise validation run locally. · `Physalign/Physalign/Services/PoseDetectionService.swift`
- [Camera recording](https://github.com/hetmehta0/physalign2/blob/main/Physalign/Physalign/Views/CameraViewModel.swift): capture flow · Coordinates camera setup, recording, and upload. · `Physalign/Physalign/Views/CameraViewModel.swift`
- [Patient repository](https://github.com/hetmehta0/physalign2/blob/main/Physalign/Physalign/Services/PhysalignRepository.swift): data access · `Physalign/Physalign/Services/PhysalignRepository.swift`

### Android patient app

- [Compose app](https://github.com/hetmehta0/physalign2/blob/main/android/app/src/main/java/com/physalign/android/MainActivity.kt): Android entry · `android/app/src/main/java/com/physalign/android/MainActivity.kt`
- [Program state](https://github.com/hetmehta0/physalign2/blob/main/android/app/src/main/java/com/physalign/android/ui/ProgramViewModel.kt): presentation state · `android/app/src/main/java/com/physalign/android/ui/ProgramViewModel.kt`
- [Pose analyzer](https://github.com/hetmehta0/physalign2/blob/main/android/app/src/main/java/com/physalign/android/pose/PoseAnalyzer.kt): on-device pipeline · Analyzes landmarks and records tracking data locally. · `android/app/src/main/java/com/physalign/android/pose/PoseAnalyzer.kt`
- [Camera recording](https://github.com/hetmehta0/physalign2/blob/main/android/app/src/main/java/com/physalign/android/ui/recording/CameraViewModel.kt): capture flow · `android/app/src/main/java/com/physalign/android/ui/recording/CameraViewModel.kt`
- [Patient repository](https://github.com/hetmehta0/physalign2/blob/main/android/app/src/main/java/com/physalign/android/data/remote/PhysalignRepository.kt): data access · `android/app/src/main/java/com/physalign/android/data/remote/PhysalignRepository.kt`

### Web applications

- [Patient web flow](https://github.com/hetmehta0/physalign2/blob/main/components/patient/ConsentGate.tsx): Next.js UI · Browser-based consent, exercise, and feedback experience. · `components/patient/ConsentGate.tsx`
- [Browser pose tracker](https://github.com/hetmehta0/physalign2/blob/main/components/patient/PoseTracker.tsx): local pose pipeline · `components/patient/PoseTracker.tsx`
- [Clinician dashboard](https://github.com/hetmehta0/physalign2/blob/main/physalign-dashboard/app/page.tsx): Next.js entry · Clinic management, patients, programs, trends, and settings. · `physalign-dashboard/app/page.tsx`
- [Dashboard data boundary](https://github.com/hetmehta0/physalign2/blob/main/physalign-dashboard/lib/supabase.ts): Supabase client · Encapsulates clinician dashboard platform access. · `physalign-dashboard/lib/supabase.ts`

### Backend platform

- [FastAPI service](https://github.com/hetmehta0/physalign2/blob/main/api/main.py): Python API · Separate containerized integration runtime. · `api/main.py`
- [Get program function](https://github.com/hetmehta0/physalign2/blob/main/supabase/functions/get-program/index.ts): Supabase Edge Function · Serves program progression data. · `supabase/functions/get-program/index.ts`
- **Supabase platform**: managed data platform · PostgreSQL, object storage, and realtime subscriptions.

### Delivery

- [Surface-specific CI](https://github.com/hetmehta0/physalign2/blob/main/.github/workflows/ios-ci.yml): GitHub Actions · Independent workflows validate iOS, dashboard, API, and web deployments. · `.github/workflows/ios-ci.yml`

## Connections

- SwiftUI app → Program flow: hosts
- Program flow → Pose validation: guides session
- Pose validation → Camera recording: feeds tracking
- Camera recording → Patient repository: uploads through
- Program flow → Patient repository: persists through
- Patient repository → Supabase platform: reads and writes
- Compose app → Program state: hosts
- Program state → Pose analyzer: guides session
- Pose analyzer → Camera recording: feeds tracking
- Camera recording → Patient repository: uploads through
- Program state → Patient repository: persists through
- Patient repository → Supabase platform: reads and writes
- Patient web flow → Browser pose tracker: gates and hosts
- Patient web flow → Supabase platform: stores patient data
- Clinician dashboard → Dashboard data boundary: uses
- Dashboard data boundary → Supabase platform: manages clinic data
- Get program function → Supabase platform: queries
- Program flow → Get program function: retrieves program
- Program state → Get program function: retrieves program
- FastAPI service → Supabase platform: integrates with
- Surface-specific CI → SwiftUI app: validates
- Surface-specific CI → Clinician dashboard: validates
- Surface-specific CI → FastAPI service: validates
- Surface-specific CI → Patient web flow: validates
