# rutu-0725/fitness_assistant architecture

> Architecture diagram of the GitHub repository rutu-0725/fitness_assistant, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-04-02). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/rutu-0725/fitness_assistant
- Repository: https://github.com/rutu-0725/fitness_assistant

## Overview

##### Project Overview
- The project is an AI-powered fitness coach that processes live video from an Android device to provide real-time feedback on exercise form.
- The application employs MediaPipe and OpenCV libraries for pose estimation and video processing, along with machine learning techniques using provided training (train_angle.csv) and testing (test_angle.csv and yoga_Dataset/angle.csv) datasets.
- The Android app uses Camera2 API for high-quality video capture, Firebase for user authentication, and WebSocket for real-time communication with the backend.

##### Main Components
a. Android Client (Frontend):
- Contains the mobile user interface.
- Integrates the Camera2 API for video capture.
- Uses Firebase for account management (signup, login, password recovery, email verification).
- Establishes a WebSocket connection for real-time data exchange with the backend.

b. WebSocket Communication Layer:
- Serves as the real-time communication bridge between the Android client and the backend server.

c. Backend Processing System (Server):
- Managed by various Python scripts (main.py, dumbell.py, give_angle_teacher.py, Demo.py, utils.py) that implement core functionality.
- Uses MediaPipe for detecting body landmarks and OpenCV for video/image processing.
- Incorporates machine learning models to analyze poses, count repetitions, and provide corrective feedback.

d. Data/Model Training:
- Uses CSV datasets (train_angle.csv, test_angle.csv, and yoga_Dataset/angle.csv) to train or validate angle-based pose detection models.
- Serves as a source of training data for machine learning routines integrated within the backend processing modules.

##### File Structure
- The presence of multiple Python scripts (e.g., main.py, dumbell.py, give_angle_teacher.py) suggests that the backend logic is modularized into separate components, possibly handling different exercise types or processing steps.
- The utility functions within utils.py likely support common functionality (data processing, model loading, etc.) across different modules.
- The CSV files and dataset directory indicate that data-driven machine learning or calibration of pose angles is an integral part of the solution.

##### Architectural Patterns & Design Principles
- Separation of concerns between the frontend (Android app) and backend (Python-based server).
- Modular design in the backend where specific scripts or modules handle exercises, pose detection, and feedback.
- Real-time data exchange is achieved via WebSocket, emphasizing asynchronous and event-driven communication.
- Emphasis on scalability and maintainability by separating machine learning model handling from video processing logic.

##### Final Elements
- Annotations or notes on key technologies (MediaPipe, OpenCV, Firebase, WebSocket, etc.) next to the corresponding components.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Android Client (Frontend)
    client["Android Client (Camera2, Firebase)"]:::frontend

    %% WebSocket Communication Layer
    ws["WebSocket Communication Layer"]:::websocket

    %% Data / Model Training
    subgraph "Data/Model Training"
        direction TB
        data_train["train_angle.csv"]:::data
        data_test["test_angle.csv"]:::data
        data_yoga["yoga_Dataset/angle.csv"]:::data
    end

    %% Backend Processing System
    subgraph "Backend Processing System"
        direction TB
        backend_main["main.py (Orchestration)"]:::backend
        backend_dumbell["dumbell.py (Dumbell Processing)"]:::backend
        backend_teacher["give_angle_teacher.py (Yoga/Teacher Angle Processing)"]:::backend
        backend_demo["Demo.py (Demo Execution)"]:::backend
        backend_utils["utils.py (Utility Functions)"]:::backend

        backend_main -->|"calls"| backend_dumbell
        backend_main -->|"calls"| backend_teacher
        backend_main -->|"calls"| backend_demo
        backend_main -->|"uses"| backend_utils
    end

    %% Communication Flow
    client -->|"video_stream"| ws
    ws -->|"sends_video"| backend_main
    backend_main -->|"feedback"| ws
    ws -->|"feedback"| client

    %% Data Flow to Backend
    data_train -->|"trains"| backend_main
    data_test -->|"tests"| backend_main
    data_yoga -->|"provides_data"| backend_main

    %% Click Events
    click backend_main "https://github.com/rutu-0725/fitness_assistant/blob/main/main.py"
    click backend_dumbell "https://github.com/rutu-0725/fitness_assistant/blob/main/dumbell.py"
    click backend_teacher "https://github.com/rutu-0725/fitness_assistant/blob/main/give_angle_teacher.py"
    click backend_demo "https://github.com/rutu-0725/fitness_assistant/blob/main/Demo.py"
    click backend_utils "https://github.com/rutu-0725/fitness_assistant/blob/main/utils.py"
    click data_train "https://github.com/rutu-0725/fitness_assistant/blob/main/train_angle.csv"
    click data_test "https://github.com/rutu-0725/fitness_assistant/blob/main/test_angle.csv"
    click data_yoga "https://github.com/rutu-0725/fitness_assistant/blob/main/yoga_Dataset/angle.csv"

    %% Styles
    classDef frontend fill:#FFCC66,stroke:#FF9900,stroke-width:2px
    classDef websocket fill:#66CCFF,stroke:#0099CC,stroke-width:2px
    classDef backend fill:#99CC99,stroke:#339933,stroke-width:2px
    classDef data fill:#CCCCFF,stroke:#6666FF,stroke-width:2px
```
