# givoxxs/baby_posture_analysis architecture

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

- Interactive diagram: https://gitdiagram.com/givoxxs/baby_posture_analysis
- Repository: https://github.com/givoxxs/baby_posture_analysis

## Overview

##### Project Identification
- The project is a full-stack application with a FastAPI-based backend and a lightweight web client. Its purpose is to analyze baby posture through image processing, pose detection (via MediaPipe), posture feature extraction, and risk assessment.
- Key modules include image preprocessing, pose keypoint extraction, posture feature analysis, and risk scoring.

##### Analyzing the File Structure
- The “app” directory is the heart of the project and contains:
- API endpoints in the “app/api” folder (image.py, pipeline.py, pose.py) that define routes and accept REST API requests.
- A “main.py” that initializes and runs the FastAPI server.
- Service classes in “app/services” (image_service.py, pose_service.py) that encapsulate business logic processing.
- Utility functions and helper modules in “app/utils” that provide image preprocessing, keypoint extraction, and posture feature extraction.
- Static assets (JavaScript and CSS) and HTML templates provide the client interface.
- A configuration file (config.py), logs folder, and requirements.txt support settings, debugging, and dependency management.

##### Architectural Highlights from the README
- The system is designed as a modular pipeline:
- Image Preprocessing Module (resizing, noise reduction, enhancements)
- Keypoint Extraction Module (MediaPipe usage, 3D landmark detection)
- Posture Feature Construction Module (computing angles, limb positions, etc.)
- Risk Analysis Module (interpretation of posture concerning safety)
- Dependencies include FastAPI for API routing and MediaPipe for pose detection.
- Clear API endpoints (e.g., /api/images/process, /api/pose/detect, /api/pipeline/analyze) indicate how the client interacts with backend processing.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Client Layer
    subgraph "Client Layer"
        HTML["HTML Page (Client)"]:::frontend
        Static["Static Assets (JS/CSS)"]:::frontend
    end

    %% API Layer
    subgraph "API Layer"
        AP1["Image Processing Endpoint (/api/images/process)"]:::api
        AP2["Pose Detection Endpoint (/api/pose/detect)"]:::api
        AP3["Pipeline Analysis Endpoint (/api/pipeline/analyze)"]:::api
    end

    %% Service Layer
    subgraph "Service Layer"
        S1["Image Service"]:::service
        S2["Pose Service"]:::service
    end

    %% Utility Modules
    subgraph "Utility Modules"
        U1a["Image Preprocessing (image_preprocessing.py)"]:::utility
        U1b["Image Helper (image_helper.py)"]:::utility
        U2["Keypoint Extraction (keypoint_extraction.py)"]:::utility
        U3a["Posture Features (posture_features.py)"]:::utility
        U3b["Posture Features V2 (posture_features_v2.py)"]:::utility
        U3c["Posture Features Copy (posture_features copy.py)"]:::utility
    end

    %% Connections from Client Layer to API Layer
    HTML -->|"sends_request"| AP1
    HTML -->|"sends_request"| AP2
    HTML -->|"sends_request"| AP3

    %% Connections from API Layer to Service Layer
    AP1 -->|"calls"| S1
    AP2 -->|"calls"| S2
    AP3 -->|"calls"| S1
    AP3 -->|"calls"| S2

    %% Connections from Service Layer to Utility Modules
    S1 -->|"uses"| U1a
    S1 -->|"uses"| U1b
    S1 -->|"uses"| U3a
    S1 -->|"uses"| U3b
    S1 -->|"uses"| U3c

    S2 -->|"uses"| U2
    S2 -->|"uses"| U3a
    S2 -->|"uses"| U3b
    S2 -->|"uses"| U3c

    %% Click Events
    click HTML "https://github.com/givoxxs/baby_posture_analysis/blob/main/app/templates/index.html"
    click Static "https://github.com/givoxxs/baby_posture_analysis/blob/main/app/static/script.js"
    click AP1 "https://github.com/givoxxs/baby_posture_analysis/blob/main/app/api/image.py"
    click AP2 "https://github.com/givoxxs/baby_posture_analysis/blob/main/app/api/pose.py"
    click AP3 "https://github.com/givoxxs/baby_posture_analysis/blob/main/app/api/pipeline.py"
    click S1 "https://github.com/givoxxs/baby_posture_analysis/blob/main/app/services/image_service.py"
    click S2 "https://github.com/givoxxs/baby_posture_analysis/blob/main/app/services/pose_service.py"
    click U1a "https://github.com/givoxxs/baby_posture_analysis/blob/main/app/utils/image_preprocessing.py"
    click U1b "https://github.com/givoxxs/baby_posture_analysis/blob/main/app/utils/image_helper.py"
    click U2 "https://github.com/givoxxs/baby_posture_analysis/blob/main/app/utils/keypoint_extraction.py"
    click U3a "https://github.com/givoxxs/baby_posture_analysis/blob/main/app/utils/posture_features.py"
    click U3b "https://github.com/givoxxs/baby_posture_analysis/blob/main/app/utils/posture_features_v2.py"
    click U3c "https://github.com/givoxxs/baby_posture_analysis/blob/main/app/utils/posture_features copy.py"

    %% Styling Classes
    classDef frontend fill:#DDEBF7,stroke:#6C8EBF,stroke-width:2px;
    classDef api fill:#FCE4D6,stroke:#D9892D,stroke-width:2px;
    classDef service fill:#E2EFDA,stroke:#8CBF26,stroke-width:2px;
    classDef utility fill:#FFF2CC,stroke:#C6A700,stroke-width:2px;
```
