How hetmehta0/physalign2 works
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: ios-ci.yml Surface-specific CI · ProgramFlowViewModel.swift Program flow · ProgramViewModel.kt Program state · ConsentGate.tsx Patient web flow
Components 18
iOS patient app
- SwiftUI app
Physalign/Physalign/PhysalignApp.swift - Program flow · Advances prescribed exercise sessions and persists outcomes.
Physalign/Physalign/Views/ProgramFlowViewModel.swift - Pose validation · Detection, joint angles, and exercise validation run locally.
Physalign/Physalign/Services/PoseDetectionService.swift - Camera recording · Coordinates camera setup, recording, and upload.
Physalign/Physalign/Views/CameraViewModel.swift - Patient repository
Physalign/Physalign/Services/PhysalignRepository.swift
Android patient app
- Compose app
android/app/src/main/java/com/physalign/android/MainActivity.kt - Program state
android/app/src/main/java/com/physalign/android/ui/ProgramViewModel.kt - Pose analyzer · Analyzes landmarks and records tracking data locally.
android/app/src/main/java/com/physalign/android/pose/PoseAnalyzer.kt - Camera recording
android/app/src/main/java/com/physalign/android/ui/recording/CameraViewModel.kt - Patient repository
android/app/src/main/java/com/physalign/android/data/remote/PhysalignRepository.kt
Web applications
- Patient web flow · Browser-based consent, exercise, and feedback experience.
components/patient/ConsentGate.tsx - Browser pose tracker
components/patient/PoseTracker.tsx - Clinician dashboard · Clinic management, patients, programs, trends, and settings.
physalign-dashboard/app/page.tsx - Dashboard data boundary · Encapsulates clinician dashboard platform access.
physalign-dashboard/lib/supabase.ts
Backend platform
- FastAPI service · Separate containerized integration runtime.
api/main.py - Get program function · Serves program progression data.
supabase/functions/get-program/index.ts - Supabase platform · PostgreSQL, object storage, and realtime subscriptions.
Delivery
- Surface-specific CI · Independent workflows validate iOS, dashboard, API, and web deployments.
.github/workflows/ios-ci.yml
Connections 24
- 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