# rohitkrish46/posture-insights-vision architecture

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

- Interactive diagram: https://gitdiagram.com/rohitkrish46/posture-insights-vision
- Repository: https://github.com/rohitkrish46/posture-insights-vision

## Overview

##### Project Overview and Purpose
- The project is a web-based posture correction tool built using Flask. Its purpose is to guide users in rectifying exercise postures by leveraging YOLOv8’s pose estimation and a set of heuristics for analyzing key joint positions.
- It captures real-time video from a webcam, processes each frame using the YOLOv8 pose estimation model to yield 17 key joints, and applies exercise-specific heuristics (for plank, pushup, and bicep curl) to determine if the posture is correct.

##### Key Components
- Web Frontend (Flask Templates & Static Assets):
- HTML pages (index.html, feed.html, streaming_page.html, etc.) that serve as the user interface.
- Static directory with videos and other assets that enhance the UI.
- Flask Backend (app.py):
- Handles routing, serving the web pages, and communicating with the pose analysis module.
- Pose Estimation Module:
- The YOLOv8 model files in the models directory (yolov8l-pose.pt, yolov8m-pose.pt, yolov8s-pose.pt), used for performing pose detection.
- The pose_estimator.py script, which likely encapsulates code to run inference using the YOLO model.
- Exercise Heuristics and Analysis:
- Scripts in the scripts directory (calculate_angle.py, curls.py, planks.py, rules_curls.py, rules_plank.py, rules_pushup.py) that implement the logic for evaluating the user's posture based on joint angles.
- Results Processing:
- The results folder shows output videos which may represent processed/annotated videos indicating correct or incorrect postures.
- Media Content:
- The videos folder provides demonstration or sample exercise videos.
- Dependencies & Environment Setup:
- Files such as requirements.txt that handle package installations and setup instructions in the README.

##### Determining Relationships and Interactions
- Data Flow and Control Flow:
- The user accesses a web page to select an exercise, which triggers webcam capture.
- Real-time video frames are sent to the Flask backend, where they are passed to the YOLOv8 pose estimation module.
- The pose estimator returns keypoint data to heuristic scripts.
- Heuristic modules calculate joint angles from the detected keypoints and determine if the posture is correct.
- Feedback (visual cues or messages) is then sent back through the Flask app and displayed to the user.
- External Dependencies:
- YOLO model downloads and possibly libraries for video processing, computer vision, and Flask routing.

##### Architectural Patterns and Design Principles
- Separation of Concerns:
- The project separates the web server (Flask app), pose estimation logic, and exercise-specific heuristics. This suggests a modular, layered architecture.
- Reusability and Extensibility:
- By isolating heuristics for different exercises in separate scripts, the design permits the addition of new exercises or modifications without significant changes to the core system.
- Real-Time Processing:
- The integration of camera input with frame-by-frame analysis suggests an emphasis on low latency and efficient processing.

##### Final Recommendations
- The user’s webcam input → Flask app → Pose estimation → Heuristic analysis → UI feedback.

## Diagram (Mermaid)

```mermaid
flowchart TD
    User("User"):::user

    subgraph "UI Layer"
        FE1("Templates (HTML Pages)"):::frontend
        FE2("Static Assets"):::frontend
    end

    subgraph "Backend Layer"
        BS("Flask Web Server (app.py)"):::backend
        ML2("Pose Estimator (pose_estimator.py)"):::ml
        ML1("YOLOv8 Models"):::ml
        EH("Exercise Heuristics (scripts/)"):::analysis
    end

    subgraph "Media & Data"
        RP("Results Processing (results/)"):::store
        MC("Media Content (videos/)"):::media
        DEP("Dependencies & Env Setup (requirements.txt & README.md)"):::dependency
    end

    User -->|"accesses"| FE1
    FE1 -->|"submit_request"| BS
    BS -->|"process_frame"| ML2
    ML2 -->|"use_model"| ML1
    ML2 -->|"return_keypoints"| BS
    BS -->|"analyze_pose"| EH
    EH -->|"return_analysis"| BS
    BS -->|"display_feedback"| FE1
    BS -->|"save_output"| RP
    RP -->|"load_processed_video"| FE1
    FE1 -->|"access_sample_videos"| MC
    BS -->|"uses_dependency"| DEP

    click FE1 "https://github.com/rohitkrish46/posture-insights-vision/tree/main/templates/"
    click FE2 "https://github.com/rohitkrish46/posture-insights-vision/tree/main/static/"
    click BS "https://github.com/rohitkrish46/posture-insights-vision/blob/main/app.py"
    click ML1 "https://github.com/rohitkrish46/posture-insights-vision/tree/main/models/"
    click ML2 "https://github.com/rohitkrish46/posture-insights-vision/blob/main/pose_estimator.py"
    click EH "https://github.com/rohitkrish46/posture-insights-vision/tree/main/scripts/"
    click RP "https://github.com/rohitkrish46/posture-insights-vision/tree/main/results/"
    click MC "https://github.com/rohitkrish46/posture-insights-vision/tree/main/videos/"
    click DEP "https://github.com/rohitkrish46/posture-insights-vision/blob/main/requirements.txt"

    classDef frontend fill:#FFDDC1,stroke:#333,stroke-width:2px;
    classDef backend fill:#C1E1FF,stroke:#333,stroke-width:2px;
    classDef ml fill:#C1FFC1,stroke:#333,stroke-width:2px;
    classDef analysis fill:#FFC1C1,stroke:#333,stroke-width:2px;
    classDef store fill:#FFFACD,stroke:#333,stroke-width:2px;
    classDef media fill:#E6E6FA,stroke:#333,stroke-width:2px;
    classDef dependency fill:#D3D3D3,stroke:#333,stroke-width:2px;
    classDef user fill:#FAD6A5,stroke:#333,stroke-width:2px;
```
