# shreashi-saha/posture_ai architecture

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

- Interactive diagram: https://gitdiagram.com/shreashi-saha/posture_ai
- Repository: https://github.com/shreashi-saha/posture_ai

## Overview

PostureAI is a posture-screening and care-coordination application. A patient uses the web app to submit an image and symptoms; the backend runs posture analysis, produces explanations and a report, then supports history, exercise programs, provider discovery, and appointments. The graph follows documented and indexed backend calls. Frontend-to-API wiring and several unsampled route internals are not evidenced in the excerpts, so those links are omitted or marked unverified.

Main entry points: [`backend/app/services/analysis_service.py`](https://github.com/shreashi-saha/posture_ai/blob/main/backend/app/services/analysis_service.py) (Analysis Orchestrator), [`backend/app/repositories/repository.py`](https://github.com/shreashi-saha/posture_ai/blob/main/backend/app/repositories/repository.py) (Data Repository), [`backend/app/main.py`](https://github.com/shreashi-saha/posture_ai/blob/main/backend/app/main.py) (FastAPI Application), [`backend/app/posture/pipeline.py`](https://github.com/shreashi-saha/posture_ai/blob/main/backend/app/posture/pipeline.py) (Image Analysis Pipeline)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_web["Patient Web App"]
  node_web_home["Screening Entry<br/>[page.tsx]"]
  node_web_dashboard["Dashboard<br/>[page.tsx]"]
  node_web_history["Assessment History<br/>[page.tsx]"]
  node_web_doctors["Doctor Search<br/>[page.tsx]"]
  node_web_api["API Client<br/>[api.ts]"]
end

subgraph group_api["API Workflows"]
  node_app["FastAPI Application<br/>[main.py]"]
  node_auth["Authentication<br/>[auth.py]"]
  node_analysis_route["Analysis API<br/>[analysis.py]"]
  node_analysis_service["Analysis Orchestrator"]
end

subgraph group_vision["Posture Assessment"]
  node_cv_engine["CV Engine<br/>[cv_engine.py]"]
  node_pipeline["Image Analysis Pipeline<br/>[pipeline.py]"]
  node_pose_detection["Pose Detection<br/>[detector.py]"]
  node_landmarks["Landmark Model<br/>[landmarks.py]"]
  node_posture_metrics["Geometry and Metrics<br/>[metrics.py]"]
  node_posture_quality["Quality and Thresholds<br/>[quality.py]"]
  node_classifier["Finding Classification<br/>[classifier.py]"]
end

subgraph group_care["Care Coordination"]
  node_doctors_route["Provider Search API<br/>[doctors.py]"]
  node_discovery["Provider Discovery<br/>[discovery_agent.py]"]
  node_appointments["Appointment API<br/>[appointments.py]"]
  node_programs["Exercise Programs<br/>[programs.py]"]
  node_recommendations["Care Recommendations<br/>[recommendations.py]"]
  node_reports["PDF Reports<br/>[pdf_generator.py]"]
end

subgraph group_data["Persistence and Services"]
  node_repository["Data Repository<br/>[repository.py]"]
  node_models[("Clinical Records<br/>[models.py]")]
  node_db_session["Database Session<br/>[session.py]"]
  node_storage["Private File Storage<br/>[storage.py]"]
  node_audit["Audit Logging<br/>[audit.py]"]
end

node_patient(("Patient"))
node_ollama{{"Local Ollama"}}
node_osm{{"OpenStreetMap Services"}}

node_patient -->|"starts screening"| node_web_home
node_patient -->|"views progress"| node_web_dashboard
node_patient -->|"reviews assessments"| node_web_history
node_patient -->|"finds care"| node_web_doctors
node_web_home -.->|"submits request"| node_web_api
node_web_dashboard -.->|"loads results"| node_web_api
node_web_history -.->|"loads history"| node_web_api
node_web_doctors -.->|"searches providers"| node_web_api
node_web_api -.->|"calls API"| node_app
node_app -->|"registers router"| node_auth
node_app -->|"registers router"| node_analysis_route
node_app -->|"registers router"| node_doctors_route
node_app -->|"registers router"| node_appointments
node_app -->|"registers router"| node_programs
node_analysis_route -->|"delegates analysis"| node_analysis_service
node_analysis_route -->|"accesses records"| node_repository
node_analysis_route -->|"validates and stores files"| node_storage
node_analysis_service -->|"analyzes image"| node_cv_engine
node_cv_engine -->|"runs pipeline"| node_pipeline
node_pipeline -->|"detects pose"| node_pose_detection
node_pipeline -->|"measures alignment"| node_posture_metrics
node_pipeline -->|"assesses quality"| node_posture_quality
node_pipeline -->|"classifies findings"| node_classifier
node_pose_detection -->|"uses landmarks"| node_landmarks
node_posture_metrics -->|"reads pose points"| node_landmarks
node_posture_metrics -->|"checks visibility"| node_posture_quality
node_analysis_service -->|"requests care plan"| node_recommendations
node_analysis_service -.->|"requests reasoning"| node_ollama
node_analysis_service -->|"creates report"| node_reports
node_analysis_service -->|"stores image and report"| node_storage
node_analysis_service -->|"uses data access"| node_repository
node_analysis_service -->|"records events"| node_audit
node_repository -->|"queries records"| node_models
node_repository -.->|"uses database session"| node_db_session
node_auth -->|"looks up users"| node_repository
node_auth -->|"records auth events"| node_audit
node_programs -->|"uses care plans"| node_recommendations
node_doctors_route -.->|"refreshes provider data"| node_discovery
node_discovery -->|"discovers clinics"| node_osm
node_doctors_route -.->|"searches nearby providers"| node_repository
node_appointments -.->|"manages bookings"| node_repository
node_discovery -->|"stores providers"| node_models

click node_web_home "https://github.com/shreashi-saha/posture_ai/blob/main/frontend/app/page.tsx"
click node_web_dashboard "https://github.com/shreashi-saha/posture_ai/blob/main/frontend/app/dashboard/page.tsx"
click node_web_history "https://github.com/shreashi-saha/posture_ai/blob/main/frontend/app/history/page.tsx"
click node_web_doctors "https://github.com/shreashi-saha/posture_ai/blob/main/frontend/app/doctors/page.tsx"
click node_web_api "https://github.com/shreashi-saha/posture_ai/blob/main/frontend/lib/api.ts"
click node_app "https://github.com/shreashi-saha/posture_ai/blob/main/backend/app/main.py"
click node_auth "https://github.com/shreashi-saha/posture_ai/blob/main/backend/app/routers/auth.py"
click node_analysis_route "https://github.com/shreashi-saha/posture_ai/blob/main/backend/app/routers/analysis.py"
click node_analysis_service "https://github.com/shreashi-saha/posture_ai/blob/main/backend/app/services/analysis_service.py"
click node_cv_engine "https://github.com/shreashi-saha/posture_ai/blob/main/backend/app/services/cv_engine.py"
click node_pipeline "https://github.com/shreashi-saha/posture_ai/blob/main/backend/app/posture/pipeline.py"
click node_pose_detection "https://github.com/shreashi-saha/posture_ai/blob/main/backend/app/posture/detector.py"
click node_landmarks "https://github.com/shreashi-saha/posture_ai/blob/main/backend/app/posture/landmarks.py"
click node_posture_metrics "https://github.com/shreashi-saha/posture_ai/blob/main/backend/app/posture/metrics.py"
click node_posture_quality "https://github.com/shreashi-saha/posture_ai/blob/main/backend/app/posture/quality.py"
click node_classifier "https://github.com/shreashi-saha/posture_ai/blob/main/backend/app/posture/classifier.py"
click node_doctors_route "https://github.com/shreashi-saha/posture_ai/blob/main/backend/app/routers/doctors.py"
click node_discovery "https://github.com/shreashi-saha/posture_ai/blob/main/backend/app/services/discovery_agent.py"
click node_appointments "https://github.com/shreashi-saha/posture_ai/blob/main/backend/app/routers/appointments.py"
click node_programs "https://github.com/shreashi-saha/posture_ai/blob/main/backend/app/routers/programs.py"
click node_recommendations "https://github.com/shreashi-saha/posture_ai/blob/main/backend/app/services/recommendations.py"
click node_reports "https://github.com/shreashi-saha/posture_ai/blob/main/backend/app/services/pdf_generator.py"
click node_repository "https://github.com/shreashi-saha/posture_ai/blob/main/backend/app/repositories/repository.py"
click node_models "https://github.com/shreashi-saha/posture_ai/blob/main/backend/app/models/models.py"
click node_db_session "https://github.com/shreashi-saha/posture_ai/blob/main/backend/app/db/session.py"
click node_storage "https://github.com/shreashi-saha/posture_ai/blob/main/backend/app/services/storage.py"
click node_audit "https://github.com/shreashi-saha/posture_ai/blob/main/backend/app/services/audit.py"

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_home,node_web_dashboard,node_web_history,node_web_doctors,node_web_api toneBlue
class node_app,node_auth,node_analysis_route,node_analysis_service toneAmber
class node_cv_engine,node_pipeline,node_pose_detection,node_landmarks,node_posture_metrics,node_posture_quality,node_classifier toneMint
class node_doctors_route,node_discovery,node_appointments,node_programs,node_recommendations,node_reports toneRose
class node_repository,node_models,node_db_session,node_storage,node_audit,node_patient,node_ollama,node_osm toneIndigo
```

## Components

### Patient Web App

- [Screening Entry](https://github.com/shreashi-saha/posture_ai/blob/main/frontend/app/page.tsx): `frontend/app/page.tsx`
- [Dashboard](https://github.com/shreashi-saha/posture_ai/blob/main/frontend/app/dashboard/page.tsx): `frontend/app/dashboard/page.tsx`
- [Assessment History](https://github.com/shreashi-saha/posture_ai/blob/main/frontend/app/history/page.tsx): `frontend/app/history/page.tsx`
- [Doctor Search](https://github.com/shreashi-saha/posture_ai/blob/main/frontend/app/doctors/page.tsx): `frontend/app/doctors/page.tsx`
- [API Client](https://github.com/shreashi-saha/posture_ai/blob/main/frontend/lib/api.ts): `frontend/lib/api.ts`

### API Workflows

- [FastAPI Application](https://github.com/shreashi-saha/posture_ai/blob/main/backend/app/main.py): `backend/app/main.py`
- [Authentication](https://github.com/shreashi-saha/posture_ai/blob/main/backend/app/routers/auth.py): `backend/app/routers/auth.py`
- [Analysis API](https://github.com/shreashi-saha/posture_ai/blob/main/backend/app/routers/analysis.py): `backend/app/routers/analysis.py`
- [Analysis Orchestrator](https://github.com/shreashi-saha/posture_ai/blob/main/backend/app/services/analysis_service.py): `backend/app/services/analysis_service.py`

### Posture Assessment

- [CV Engine](https://github.com/shreashi-saha/posture_ai/blob/main/backend/app/services/cv_engine.py): `backend/app/services/cv_engine.py`
- [Image Analysis Pipeline](https://github.com/shreashi-saha/posture_ai/blob/main/backend/app/posture/pipeline.py): `backend/app/posture/pipeline.py`
- [Pose Detection](https://github.com/shreashi-saha/posture_ai/blob/main/backend/app/posture/detector.py): `backend/app/posture/detector.py`
- [Landmark Model](https://github.com/shreashi-saha/posture_ai/blob/main/backend/app/posture/landmarks.py): `backend/app/posture/landmarks.py`
- [Geometry and Metrics](https://github.com/shreashi-saha/posture_ai/blob/main/backend/app/posture/metrics.py): `backend/app/posture/metrics.py`
- [Quality and Thresholds](https://github.com/shreashi-saha/posture_ai/blob/main/backend/app/posture/quality.py): `backend/app/posture/quality.py`
- [Finding Classification](https://github.com/shreashi-saha/posture_ai/blob/main/backend/app/posture/classifier.py): `backend/app/posture/classifier.py`

### Care Coordination

- [Provider Search API](https://github.com/shreashi-saha/posture_ai/blob/main/backend/app/routers/doctors.py): `backend/app/routers/doctors.py`
- [Provider Discovery](https://github.com/shreashi-saha/posture_ai/blob/main/backend/app/services/discovery_agent.py): `backend/app/services/discovery_agent.py`
- [Appointment API](https://github.com/shreashi-saha/posture_ai/blob/main/backend/app/routers/appointments.py): `backend/app/routers/appointments.py`
- [Exercise Programs](https://github.com/shreashi-saha/posture_ai/blob/main/backend/app/routers/programs.py): `backend/app/routers/programs.py`
- [Care Recommendations](https://github.com/shreashi-saha/posture_ai/blob/main/backend/app/services/recommendations.py): `backend/app/services/recommendations.py`
- [PDF Reports](https://github.com/shreashi-saha/posture_ai/blob/main/backend/app/services/pdf_generator.py): `backend/app/services/pdf_generator.py`

### Persistence and Services

- [Data Repository](https://github.com/shreashi-saha/posture_ai/blob/main/backend/app/repositories/repository.py): `backend/app/repositories/repository.py`
- [Clinical Records](https://github.com/shreashi-saha/posture_ai/blob/main/backend/app/models/models.py): `backend/app/models/models.py`
- [Database Session](https://github.com/shreashi-saha/posture_ai/blob/main/backend/app/db/session.py): `backend/app/db/session.py`
- [Private File Storage](https://github.com/shreashi-saha/posture_ai/blob/main/backend/app/services/storage.py): `backend/app/services/storage.py`
- [Audit Logging](https://github.com/shreashi-saha/posture_ai/blob/main/backend/app/services/audit.py): `backend/app/services/audit.py`

### Other components

- **Patient**
- **Local Ollama**
- **OpenStreetMap Services**

## Connections

- Patient → Screening Entry: starts screening (evidence: `README.md`)
- Patient → Dashboard: views progress (evidence: `README.md`)
- Patient → Assessment History: reviews assessments (evidence: `README.md`)
- Patient → Doctor Search: finds care (evidence: `README.md`)
- Screening Entry → API Client: submits request
- Dashboard → API Client: loads results
- Assessment History → API Client: loads history
- Doctor Search → API Client: searches providers
- API Client → FastAPI Application: calls API
- FastAPI Application → Authentication: registers router (evidence: `backend/app/main.py`)
- FastAPI Application → Analysis API: registers router (evidence: `backend/app/main.py`)
- FastAPI Application → Provider Search API: registers router (evidence: `backend/app/main.py`)
- FastAPI Application → Appointment API: registers router (evidence: `backend/app/main.py`)
- FastAPI Application → Exercise Programs: registers router (evidence: `backend/app/main.py`)
- Analysis API → Analysis Orchestrator: delegates analysis (evidence: `backend/app/routers/analysis.py`)
- Analysis API → Data Repository: accesses records (evidence: `backend/app/routers/analysis.py`)
- Analysis API → Private File Storage: validates and stores files (evidence: `backend/app/routers/analysis.py`)
- Analysis Orchestrator → CV Engine: analyzes image (evidence: `backend/app/services/analysis_service.py`)
- CV Engine → Image Analysis Pipeline: runs pipeline (evidence: `backend/app/services/cv_engine.py`)
- Image Analysis Pipeline → Pose Detection: detects pose (evidence: `backend/app/posture/pipeline.py`)
- Image Analysis Pipeline → Geometry and Metrics: measures alignment (evidence: `backend/app/posture/pipeline.py`)
- Image Analysis Pipeline → Quality and Thresholds: assesses quality (evidence: `backend/app/posture/pipeline.py`)
- Image Analysis Pipeline → Finding Classification: classifies findings (evidence: `backend/app/posture/pipeline.py`)
- Pose Detection → Landmark Model: uses landmarks (evidence: `backend/app/posture/detector.py`)
- Geometry and Metrics → Landmark Model: reads pose points (evidence: `backend/app/posture/metrics.py`)
- Geometry and Metrics → Quality and Thresholds: checks visibility (evidence: `backend/app/posture/metrics.py`)
- Analysis Orchestrator → Care Recommendations: requests care plan (evidence: `backend/app/services/analysis_service.py`)
- Analysis Orchestrator → Local Ollama: requests reasoning (evidence: `README.md`)
- Analysis Orchestrator → PDF Reports: creates report (evidence: `backend/app/services/analysis_service.py`)
- Analysis Orchestrator → Private File Storage: stores image and report (evidence: `backend/app/services/analysis_service.py`)
- Analysis Orchestrator → Data Repository: uses data access (evidence: `backend/app/services/analysis_service.py`)
- Analysis Orchestrator → Audit Logging: records events (evidence: `backend/app/services/analysis_service.py`)
- Data Repository → Clinical Records: queries records (evidence: `backend/app/repositories/repository.py`)
- Data Repository → Database Session: uses database session
- Authentication → Data Repository: looks up users (evidence: `backend/app/routers/auth.py`)
- Authentication → Audit Logging: records auth events (evidence: `backend/app/routers/auth.py`)
- Exercise Programs → Care Recommendations: uses care plans (evidence: `backend/app/routers/programs.py`)
- Provider Search API → Provider Discovery: refreshes provider data
- Provider Discovery → OpenStreetMap Services: discovers clinics (evidence: `README.md`)
- Provider Search API → Data Repository: searches nearby providers
- Appointment API → Data Repository: manages bookings
- Provider Discovery → Clinical Records: stores providers (evidence: `README.md`)
