# jaronlee-stack/switch_project architecture

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

- Interactive diagram: https://gitdiagram.com/jaronlee-stack/switch_project
- Repository: https://github.com/jaronlee-stack/switch_project

## Overview

This is a posture-monitoring and coaching web application. Users submit camera frames for pose analysis; the server classifies posture, applies rules, stores detections, and exposes live status, history, and analytics. Authentication and role-protected rule administration are separate capabilities. The graph follows the documented Express routes and sampled posture-controller calls. Frontend request wiring and the camera/pose-service implementation are not shown, so those links are omitted; the bundled Python virtual environment is excluded as third-party tooling.

Main entry points: [`src/app.js`](https://github.com/jaronlee-stack/switch_project/blob/main/src/app.js) (Express routes), [`src/controller/postureController.js`](https://github.com/jaronlee-stack/switch_project/blob/main/src/controller/postureController.js) (Frame ingestion), [`src/public/api.js`](https://github.com/jaronlee-stack/switch_project/blob/main/src/public/api.js) (Browser API), [`dbConfig.js`](https://github.com/jaronlee-stack/switch_project/blob/main/dbConfig.js) (PostgreSQL pool)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_web["Web application"]
  node_app["Express routes<br/>[app.js]"]
  node_dashboard["Dashboard<br/>[Dashboard.js]"]
  node_livecoach["Live coach<br/>[LiveCoach.js]"]
  node_historyui["History view<br/>[HIstory.js]"]
  node_analyticsui["Analytics view<br/>[Analytics.js]"]
  node_api["Browser API<br/>[api.js]"]
end

subgraph group_posture["Posture monitoring"]
  node_frame["Frame ingestion"]
  node_pose["Pose service<br/>[poseService.js]"]
  node_camera["Camera capture<br/>[camera.py]"]
  node_rules["Posture rules<br/>[rulesController.js]"]
  node_analytics["Analytics endpoints"]
  node_ollama["Coaching poller<br/>[ollamaService.js]"]
end

subgraph group_identity["Identity and access"]
  node_auth["Authentication<br/>[authController.js]"]
  node_middleware["JWT authorization<br/>[auth.js]"]
end

subgraph group_persistence["Persistence"]
  node_posturedata["Detection records<br/>[postureModel.js]"]
  node_ruledata["Rule records<br/>[rulesModel.js]"]
  node_authdata["User records<br/>[authModel.js]"]
  node_analyticsdata["Analytics data<br/>[analyticsModel.js]"]
  node_db[("PostgreSQL pool<br/>[dbConfig.js]")]
end

node_user(("User"))

node_user -.->|"uses"| node_dashboard
node_user -->|"requests"| node_app
node_app -->|"routes auth"| node_auth
node_app -->|"protects routes"| node_middleware
node_app -->|"routes frames"| node_frame
node_app -->|"routes rules"| node_rules
node_app -->|"routes analytics"| node_analytics
node_frame -->|"detects pose"| node_pose
node_frame -->|"stores and reads"| node_posturedata
node_frame -->|"finds rule"| node_ruledata
node_auth -->|"reads and writes"| node_authdata
node_rules -->|"reads and writes"| node_ruledata
node_analytics -->|"queries"| node_analyticsdata
node_posturedata -->|"queries"| node_db
node_ruledata -.->|"queries"| node_db
node_authdata -->|"queries"| node_db
node_analyticsdata -.->|"queries"| node_db
node_camera -.->|"submits frames"| node_app
node_pose -.->|"uses camera input"| node_camera
node_dashboard -.->|"uses requests"| node_api
node_livecoach -.->|"uses requests"| node_api
node_historyui -.->|"uses requests"| node_api
node_analyticsui -.->|"uses requests"| node_api
node_app -.->|"starts poller"| node_ollama

click node_app "https://github.com/jaronlee-stack/switch_project/blob/main/src/app.js"
click node_dashboard "https://github.com/jaronlee-stack/switch_project/blob/main/src/public/Dashboard.js"
click node_livecoach "https://github.com/jaronlee-stack/switch_project/blob/main/src/public/LiveCoach.js"
click node_historyui "https://github.com/jaronlee-stack/switch_project/blob/main/src/public/HIstory.js"
click node_analyticsui "https://github.com/jaronlee-stack/switch_project/blob/main/src/public/Analytics.js"
click node_api "https://github.com/jaronlee-stack/switch_project/blob/main/src/public/api.js"
click node_frame "https://github.com/jaronlee-stack/switch_project/blob/main/src/controller/postureController.js"
click node_pose "https://github.com/jaronlee-stack/switch_project/blob/main/src/services/poseService.js"
click node_camera "https://github.com/jaronlee-stack/switch_project/blob/main/src/camera/camera.py"
click node_rules "https://github.com/jaronlee-stack/switch_project/blob/main/src/controller/rulesController.js"
click node_analytics "https://github.com/jaronlee-stack/switch_project/blob/main/src/controller/analyticsController.js"
click node_ollama "https://github.com/jaronlee-stack/switch_project/blob/main/src/services/ollamaService.js"
click node_auth "https://github.com/jaronlee-stack/switch_project/blob/main/src/controller/authController.js"
click node_middleware "https://github.com/jaronlee-stack/switch_project/blob/main/src/middleware/auth.js"
click node_posturedata "https://github.com/jaronlee-stack/switch_project/blob/main/src/models/postureModel.js"
click node_ruledata "https://github.com/jaronlee-stack/switch_project/blob/main/src/models/rulesModel.js"
click node_authdata "https://github.com/jaronlee-stack/switch_project/blob/main/src/models/authModel.js"
click node_analyticsdata "https://github.com/jaronlee-stack/switch_project/blob/main/src/models/analyticsModel.js"
click node_db "https://github.com/jaronlee-stack/switch_project/blob/main/dbConfig.js"

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_dashboard,node_livecoach,node_historyui,node_analyticsui,node_api,node_user toneBlue
class node_frame,node_pose,node_camera,node_rules,node_analytics,node_ollama toneAmber
class node_auth,node_middleware toneMint
class node_posturedata,node_ruledata,node_authdata,node_analyticsdata,node_db toneRose
```

## Components

### Web application

- [Express routes](https://github.com/jaronlee-stack/switch_project/blob/main/src/app.js): `src/app.js`
- [Dashboard](https://github.com/jaronlee-stack/switch_project/blob/main/src/public/Dashboard.js): `src/public/Dashboard.js`
- [Live coach](https://github.com/jaronlee-stack/switch_project/blob/main/src/public/LiveCoach.js): `src/public/LiveCoach.js`
- [History view](https://github.com/jaronlee-stack/switch_project/blob/main/src/public/HIstory.js): `src/public/HIstory.js`
- [Analytics view](https://github.com/jaronlee-stack/switch_project/blob/main/src/public/Analytics.js): `src/public/Analytics.js`
- [Browser API](https://github.com/jaronlee-stack/switch_project/blob/main/src/public/api.js): `src/public/api.js`

### Posture monitoring

- [Frame ingestion](https://github.com/jaronlee-stack/switch_project/blob/main/src/controller/postureController.js): `src/controller/postureController.js`
- [Pose service](https://github.com/jaronlee-stack/switch_project/blob/main/src/services/poseService.js): `src/services/poseService.js`
- [Camera capture](https://github.com/jaronlee-stack/switch_project/blob/main/src/camera/camera.py): `src/camera/camera.py`
- [Posture rules](https://github.com/jaronlee-stack/switch_project/blob/main/src/controller/rulesController.js): `src/controller/rulesController.js`
- [Analytics endpoints](https://github.com/jaronlee-stack/switch_project/blob/main/src/controller/analyticsController.js): `src/controller/analyticsController.js`
- [Coaching poller](https://github.com/jaronlee-stack/switch_project/blob/main/src/services/ollamaService.js): `src/services/ollamaService.js`

### Identity and access

- [Authentication](https://github.com/jaronlee-stack/switch_project/blob/main/src/controller/authController.js): `src/controller/authController.js`
- [JWT authorization](https://github.com/jaronlee-stack/switch_project/blob/main/src/middleware/auth.js): `src/middleware/auth.js`

### Persistence

- [Detection records](https://github.com/jaronlee-stack/switch_project/blob/main/src/models/postureModel.js): `src/models/postureModel.js`
- [Rule records](https://github.com/jaronlee-stack/switch_project/blob/main/src/models/rulesModel.js): `src/models/rulesModel.js`
- [User records](https://github.com/jaronlee-stack/switch_project/blob/main/src/models/authModel.js): `src/models/authModel.js`
- [Analytics data](https://github.com/jaronlee-stack/switch_project/blob/main/src/models/analyticsModel.js): `src/models/analyticsModel.js`
- [PostgreSQL pool](https://github.com/jaronlee-stack/switch_project/blob/main/dbConfig.js): `dbConfig.js`

### Other components

- **User**

## Connections

- User → Dashboard: uses
- User → Express routes: requests (evidence: `src/app.js`)
- Express routes → Authentication: routes auth (evidence: `src/app.js`)
- Express routes → JWT authorization: protects routes (evidence: `src/app.js`)
- Express routes → Frame ingestion: routes frames (evidence: `src/app.js`)
- Express routes → Posture rules: routes rules (evidence: `src/app.js`)
- Express routes → Analytics endpoints: routes analytics (evidence: `src/app.js`)
- Frame ingestion → Pose service: detects pose (evidence: `src/controller/postureController.js`)
- Frame ingestion → Detection records: stores and reads (evidence: `src/controller/postureController.js`)
- Frame ingestion → Rule records: finds rule (evidence: `src/controller/postureController.js`)
- Authentication → User records: reads and writes (evidence: `src/controller/authController.js`)
- Posture rules → Rule records: reads and writes (evidence: `src/controller/rulesController.js`)
- Analytics endpoints → Analytics data: queries (evidence: `src/controller/analyticsController.js`)
- Detection records → PostgreSQL pool: queries (evidence: `src/models/postureModel.js`)
- Rule records → PostgreSQL pool: queries (evidence: `src/models/rulesModel.js`)
- User records → PostgreSQL pool: queries (evidence: `src/models/authModel.js`)
- Analytics data → PostgreSQL pool: queries
- Camera capture → Express routes: submits frames
- Pose service → Camera capture: uses camera input
- Dashboard → Browser API: uses requests
- Live coach → Browser API: uses requests
- History view → Browser API: uses requests
- Analytics view → Browser API: uses requests
- Express routes → Coaching poller: starts poller (evidence: `src/app.js`)
