# amritanshu2005/realtime-voice-video-ai-gym-trainer architecture

> Architecture diagram of the GitHub repository amritanshu2005/realtime-voice-video-ai-gym-trainer, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-07-22). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/amritanshu2005/realtime-voice-video-ai-gym-trainer
- Repository: https://github.com/amritanshu2005/realtime-voice-video-ai-gym-trainer

## Overview

#### Purpose and runtime
A Python/Streamlit realtime gym trainer: webcam frames are pose-estimated, exercise-specific logic counts reps and detects form issues, and coaching is delivered through UI and voice. Run with `streamlit run main.py`; the primary entry point is `main.py`.

#### Application shell and session lifecycle
`main.py` owns the Streamlit application flow, likely composing login, exercise selection, live video, metrics, and coaching. Streamlit session state is initialized and maintained through `services/state/session_defaults.py`; shared exercise abstractions belong in `core/base_exercise.py`.

#### Vision and pose-model boundary
The video-processing boundary is `services/vision/exercise_video_processor.py`: it should receive webcam/video frames, invoke pose estimation, and return annotated frames plus structured exercise observations. The packaged MediaPipe model is `ml_models/pose_landmarker_full.task`. This isolates camera/OpenCV/MediaPipe concerns from workout rules and UI.

#### Exercise analysis and repetition state machines
Exercise-specific posture analysis is split by movement: `detectors/biceps_curl.py`, `detectors/squat.py`, `detectors/pushup.py`, `detectors/lunges.py`, and `detectors/shoulder_press.py`. These modules are the core domain layer for landmark interpretation, rep transitions, and corrective signals; `core/base_exercise.py` is the likely common contract for interchangeable detector implementations.

#### Coaching pipeline
Detected form events, completed repetitions, and session context feed coaching services. `services/coaching/voice_pipeline.py` coordinates coaching delivery; `services/coaching/llm.py` is the external/AI language-generation boundary, while `services/coaching/tts.py` converts coaching text to audio. Internet connectivity is relevant when the LLM or cloud voice capabilities are used.

#### Metrics, configuration, and persistence
Workout configuration is centralized in `services/config/workout_config.py`. Live counters and workout summaries are handled by `services/tracking/metrics.py`. Durable exercise/session history is abstracted behind `services/persistence/exercise_repository.py`, keeping storage decisions separate from detector and Streamlit code.

#### Access and presentation boundaries
Authentication gating is isolated in `services/auth/login_wall.py`. UI styling is loaded via `services/ui/style_loader.py` and static assets such as `static/style.css`. The browser-facing layer should consume processed frames, metrics, and coaching outputs rather than directly depend on vision or detector internals.

Main entry points: [`main.py`](https://github.com/amritanshu2005/realtime-voice-video-ai-gym-trainer/blob/main/main.py) (App shell), [`core/base_exercise.py`](https://github.com/amritanshu2005/realtime-voice-video-ai-gym-trainer/blob/main/core/base_exercise.py) (Exercise contract), [`services/vision/exercise_video_processor.py`](https://github.com/amritanshu2005/realtime-voice-video-ai-gym-trainer/blob/main/services/vision/exercise_video_processor.py) (Video processor), [`services/coaching/voice_pipeline.py`](https://github.com/amritanshu2005/realtime-voice-video-ai-gym-trainer/blob/main/services/coaching/voice_pipeline.py) (Voice pipeline)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_ui["Streamlit UI"]
  node_main["App shell<br/>Streamlit entry point<br/>[main.py]"]
  node_login["Login gate<br/>authentication<br/>[login_wall.py]"]
  node_styles["Style loader<br/>presentation<br/>[style_loader.py]"]
end

subgraph group_vision["Vision &amp; Analysis"]
  node_base_exercise["Exercise contract<br/>domain abstraction<br/>[base_exercise.py]"]
  node_video_processor["Video processor<br/>vision boundary"]
  node_pose_model{{"Pose landmarker<br/>MediaPipe model"}}
  node_curl_detector["Biceps curl<br/>exercise detector<br/>[biceps_curl.py]"]
  node_squat_detector["Squat<br/>exercise detector<br/>[squat.py]"]
  node_pushup_detector["Push-up<br/>exercise detector<br/>[pushup.py]"]
  node_lunge_detector["Lunges<br/>exercise detector<br/>[lunges.py]"]
  node_press_detector["Shoulder press<br/>exercise detector<br/>[shoulder_press.py]"]
end

subgraph group_coaching["Coaching"]
  node_voice_pipeline["Voice pipeline<br/>coaching orchestration<br/>[voice_pipeline.py]"]
  node_llm["Coaching LLM<br/>external AI boundary<br/>[llm.py]"]
  node_tts["Text to speech<br/>audio delivery<br/>[tts.py]"]
end

subgraph group_workout["Workout State &amp; Data"]
  node_session_defaults["Session defaults<br/>session state"]
  node_workout_config["Workout config<br/>configuration<br/>[workout_config.py]"]
  node_metrics["Live metrics<br/>tracking<br/>[metrics.py]"]
  node_repository[("Exercise history<br/>persistence boundary")]
end

node_main -->|"gates access"| node_login
node_main -->|"loads styling"| node_styles
node_main -->|"initializes"| node_session_defaults
node_main -->|"selects workout"| node_workout_config
node_main -->|"webcam frames"| node_video_processor
node_main -->|"renders metrics"| node_metrics
node_main -->|"renders coaching"| node_voice_pipeline
node_video_processor -->|"estimates pose"| node_pose_model
node_video_processor -->|"routes observations"| node_base_exercise
node_base_exercise -.->|"implemented by"| node_curl_detector
node_base_exercise -.->|"implemented by"| node_squat_detector
node_base_exercise -.->|"implemented by"| node_pushup_detector
node_base_exercise -.->|"implemented by"| node_lunge_detector
node_base_exercise -.->|"implemented by"| node_press_detector
node_video_processor -->|"reps and form events"| node_metrics
node_metrics -->|"persists summaries"| node_repository
node_metrics -->|"session context"| node_voice_pipeline
node_voice_pipeline -->|"coaching prompt"| node_llm
node_llm -->|"coaching text"| node_tts
node_voice_pipeline -->|"audio and guidance"| node_main

click node_main "https://github.com/amritanshu2005/realtime-voice-video-ai-gym-trainer/blob/main/main.py"
click node_login "https://github.com/amritanshu2005/realtime-voice-video-ai-gym-trainer/blob/main/services/auth/login_wall.py"
click node_styles "https://github.com/amritanshu2005/realtime-voice-video-ai-gym-trainer/blob/main/services/ui/style_loader.py"
click node_session_defaults "https://github.com/amritanshu2005/realtime-voice-video-ai-gym-trainer/blob/main/services/state/session_defaults.py"
click node_workout_config "https://github.com/amritanshu2005/realtime-voice-video-ai-gym-trainer/blob/main/services/config/workout_config.py"
click node_base_exercise "https://github.com/amritanshu2005/realtime-voice-video-ai-gym-trainer/blob/main/core/base_exercise.py"
click node_video_processor "https://github.com/amritanshu2005/realtime-voice-video-ai-gym-trainer/blob/main/services/vision/exercise_video_processor.py"
click node_pose_model "https://github.com/amritanshu2005/realtime-voice-video-ai-gym-trainer/blob/main/ml_models/pose_landmarker_full.task"
click node_curl_detector "https://github.com/amritanshu2005/realtime-voice-video-ai-gym-trainer/blob/main/detectors/biceps_curl.py"
click node_squat_detector "https://github.com/amritanshu2005/realtime-voice-video-ai-gym-trainer/blob/main/detectors/squat.py"
click node_pushup_detector "https://github.com/amritanshu2005/realtime-voice-video-ai-gym-trainer/blob/main/detectors/pushup.py"
click node_lunge_detector "https://github.com/amritanshu2005/realtime-voice-video-ai-gym-trainer/blob/main/detectors/lunges.py"
click node_press_detector "https://github.com/amritanshu2005/realtime-voice-video-ai-gym-trainer/blob/main/detectors/shoulder_press.py"
click node_metrics "https://github.com/amritanshu2005/realtime-voice-video-ai-gym-trainer/blob/main/services/tracking/metrics.py"
click node_repository "https://github.com/amritanshu2005/realtime-voice-video-ai-gym-trainer/blob/main/services/persistence/exercise_repository.py"
click node_voice_pipeline "https://github.com/amritanshu2005/realtime-voice-video-ai-gym-trainer/blob/main/services/coaching/voice_pipeline.py"
click node_llm "https://github.com/amritanshu2005/realtime-voice-video-ai-gym-trainer/blob/main/services/coaching/llm.py"
click node_tts "https://github.com/amritanshu2005/realtime-voice-video-ai-gym-trainer/blob/main/services/coaching/tts.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_main,node_login,node_styles toneBlue
class node_base_exercise,node_video_processor,node_pose_model,node_curl_detector,node_squat_detector,node_pushup_detector,node_lunge_detector,node_press_detector toneAmber
class node_voice_pipeline,node_llm,node_tts toneMint
class node_session_defaults,node_workout_config,node_metrics,node_repository toneRose
```

## Components

### Streamlit UI

- [App shell](https://github.com/amritanshu2005/realtime-voice-video-ai-gym-trainer/blob/main/main.py): Streamlit entry point · Composes the live workout experience. · `main.py`
- [Login gate](https://github.com/amritanshu2005/realtime-voice-video-ai-gym-trainer/blob/main/services/auth/login_wall.py): authentication · `services/auth/login_wall.py`
- [Style loader](https://github.com/amritanshu2005/realtime-voice-video-ai-gym-trainer/blob/main/services/ui/style_loader.py): presentation · Loads browser styling assets. · `services/ui/style_loader.py`

### Vision & Analysis

- [Exercise contract](https://github.com/amritanshu2005/realtime-voice-video-ai-gym-trainer/blob/main/core/base_exercise.py): domain abstraction · Common interface for exercise detectors. · `core/base_exercise.py`
- [Video processor](https://github.com/amritanshu2005/realtime-voice-video-ai-gym-trainer/blob/main/services/vision/exercise_video_processor.py): vision boundary · Converts frames into annotations and exercise observations. · `services/vision/exercise_video_processor.py`
- [Pose landmarker](https://github.com/amritanshu2005/realtime-voice-video-ai-gym-trainer/blob/main/ml_models/pose_landmarker_full.task): MediaPipe model · `ml_models/pose_landmarker_full.task`
- [Biceps curl](https://github.com/amritanshu2005/realtime-voice-video-ai-gym-trainer/blob/main/detectors/biceps_curl.py): exercise detector · `detectors/biceps_curl.py`
- [Squat](https://github.com/amritanshu2005/realtime-voice-video-ai-gym-trainer/blob/main/detectors/squat.py): exercise detector · `detectors/squat.py`
- [Push-up](https://github.com/amritanshu2005/realtime-voice-video-ai-gym-trainer/blob/main/detectors/pushup.py): exercise detector · `detectors/pushup.py`
- [Lunges](https://github.com/amritanshu2005/realtime-voice-video-ai-gym-trainer/blob/main/detectors/lunges.py): exercise detector · `detectors/lunges.py`
- [Shoulder press](https://github.com/amritanshu2005/realtime-voice-video-ai-gym-trainer/blob/main/detectors/shoulder_press.py): exercise detector · `detectors/shoulder_press.py`

### Coaching

- [Voice pipeline](https://github.com/amritanshu2005/realtime-voice-video-ai-gym-trainer/blob/main/services/coaching/voice_pipeline.py): coaching orchestration · Delivers coaching from workout events and context. · `services/coaching/voice_pipeline.py`
- [Coaching LLM](https://github.com/amritanshu2005/realtime-voice-video-ai-gym-trainer/blob/main/services/coaching/llm.py): external AI boundary · Generates coaching language. · `services/coaching/llm.py`
- [Text to speech](https://github.com/amritanshu2005/realtime-voice-video-ai-gym-trainer/blob/main/services/coaching/tts.py): audio delivery · Converts coaching text to audio. · `services/coaching/tts.py`

### Workout State & Data

- [Session defaults](https://github.com/amritanshu2005/realtime-voice-video-ai-gym-trainer/blob/main/services/state/session_defaults.py): session state · Initializes Streamlit workout state. · `services/state/session_defaults.py`
- [Workout config](https://github.com/amritanshu2005/realtime-voice-video-ai-gym-trainer/blob/main/services/config/workout_config.py): configuration · `services/config/workout_config.py`
- [Live metrics](https://github.com/amritanshu2005/realtime-voice-video-ai-gym-trainer/blob/main/services/tracking/metrics.py): tracking · Maintains counters and workout summaries. · `services/tracking/metrics.py`
- [Exercise history](https://github.com/amritanshu2005/realtime-voice-video-ai-gym-trainer/blob/main/services/persistence/exercise_repository.py): persistence boundary · Stores durable exercise and session history. · `services/persistence/exercise_repository.py`

## Connections

- App shell → Login gate: gates access
- App shell → Style loader: loads styling
- App shell → Session defaults: initializes
- App shell → Workout config: selects workout
- App shell → Video processor: webcam frames
- App shell → Live metrics: renders metrics
- App shell → Voice pipeline: renders coaching
- Video processor → Pose landmarker: estimates pose
- Video processor → Exercise contract: routes observations
- Exercise contract → Biceps curl: implemented by
- Exercise contract → Squat: implemented by
- Exercise contract → Push-up: implemented by
- Exercise contract → Lunges: implemented by
- Exercise contract → Shoulder press: implemented by
- Video processor → Live metrics: reps and form events
- Live metrics → Exercise history: persists summaries
- Live metrics → Voice pipeline: session context
- Voice pipeline → Coaching LLM: coaching prompt
- Coaching LLM → Text to speech: coaching text
- Voice pipeline → App shell: audio and guidance
