# mocco329/htwm architecture

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

- Interactive diagram: https://gitdiagram.com/mocco329/htwm
- Repository: https://github.com/mocco329/htwm

## Overview

##### Main Components
- App Front End: Built with React Native and TypeScript (see the “front_app” directory). This mobile application handles user interactions, routine management, PT calls, workout logs, and photo management.
- Device Front End: Located under “front_device”, this component is built with Electron, React, and Redux. It runs on the smart mirror device (Raspberry Pi, Jetson NANO) and is responsible for interacting with hardware (vibration sensors, cameras) as well as presenting reference/exercise videos.
- Back End: Found under “back/htwm”, this Spring Boot Java application uses controllers, services, repositories, and DTOs to implement APIs. It integrates features such as WebSocket communication (see WebSocketConfig, CustomHandshakeHandler), S3-based file storage, and various REST endpoints for managing data (users, routines, notices, pictures, records, etc.).
- Embedded Modules for Sensor/AI Functions: The “emb” directory contains Python modules for pose estimation (with OpenCV) and speech processing. These scripts integrate sensor triggers (knocking or voice commands) with device functions.
- Infrastructure: The README specifies that infrastructure is managed with Jenkins, AWS EC2, S3, and NginX, and there’s also a Dockerfile for containerization (in back/htwm). A MySQL database (ERD and SQL dump in “exec/dumpHTWM.sql”) serves as the primary datastore.

##### Detail the Relationships and Interactions
- Mobile App and Device Front End as Clients:
- The mobile app communicates directly with the backend via API endpoints (notice the organized API calls in “front_app/api”).
- The device front end is used to interact with the smart mirror hardware and integrates sensor inputs from connected devices.
- Backend Server:
- Handles business logic and API requests, serves as the central hub for users, exercises, routines, and media management.
- It further manages WebSocket connections (for real-time PT sessions and streaming) and integrates with external services like AWS S3 for file storage.
- Embedded Sensor/AI Modules:
- The pose and speech modules (in the “emb” directory) provide additional functionality (e.g., posture-based exercise tracking and voice command recognition) that better integrate with the device front end.
- Infrastructure:
- Deployment and CI/CD processes (Jenkins) manage build and deployment.
- Docker and AWS setup ensure scalability and availability.

##### Architectural Patterns and Technologies
- Modular & Layered Architecture: The separation into distinct modules – mobile app, device application, backend, and embedded services – points to a micro-modular design.
- Client-Server Interaction / RESTful API: The backend exposes REST endpoints and WebSocket channels for real-time notifications and video PT sessions.
- Hardware-Software Integration: The device side is customized to interact with physical sensors (vibration, camera) and leverages speech & pose modules for improved exercise monitoring.
- Technology Stack:
- Frontend: React Native (mobile) and Electron with React (device).
- Backend: Spring Boot with Gradle, Java, MySQL, WebSockets, and AWS integrations.
- Embedded: Python scripts for pose and speech (utilizing OpenCV for computer vision).

##### Instructing the Principal Software Engineer
- Annotations or labels that identify key frameworks (React Native, Electron, Spring Boot) as well as technologies (Docker, AWS EC2/S3, Jenkins).
- Integration points, like the S3 uploader in the backend configuration and the sensor triggers in the device front end.

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Client Layer"
        MA["Mobile App (React Native, TypeScript)"]:::frontend
        DA["Device App (Electron, React, Redux)"]:::frontend
    end

    subgraph "Embedded Modules"
        PE["Pose Estimation Module (Python, OpenCV)"]:::embedded
        SP["Speech Processing Module (Python)"]:::embedded
    end

    subgraph "Service Layer"
        BE["Backend API Server (Spring Boot, Java)"]:::backend
    end

    subgraph "Infrastructure"
        S3["AWS S3 Storage"]:::infrastructure
        MYSQL["MySQL Database"]:::infrastructure
        CI["CI/CD (Jenkins, AWS EC2, NGINX)"]:::infrastructure
        DOCK["Containerization (Dockerfile)"]:::infrastructure
        DUMP["MySQL Dump"]:::infrastructure
    end

    %% Client to Backend connections
    MA -->|"REST_API"| BE
    DA -->|"REST_API/WebSocket"| BE
    BE -->|"RealTime_Updates"| MA
    BE -->|"RealTime_Updates"| DA

    %% Backend to External Services
    BE -->|"File_Uploads"| S3
    BE -->|"Data_Storage"| MYSQL
    CI --- BE

    %% Embedded Modules to Device App connection
    PE -->|"Sensor_Triggers"| DA
    SP -->|"Voice_Commands"| DA

    %% Styles
    classDef frontend fill:#ADD8E6,stroke:#000,stroke-width:1px;
    classDef backend fill:#90EE90,stroke:#000,stroke-width:1px;
    classDef embedded fill:#FFD700,stroke:#000,stroke-width:1px;
    classDef infrastructure fill:#D3D3D3,stroke:#000,stroke-width:1px;

    %% Click Events
    click MA "https://github.com/mocco329/htwm/tree/master/front_app/"
    click DA "https://github.com/mocco329/htwm/tree/master/front_device/"
    click BE "https://github.com/mocco329/htwm/tree/master/back/htwm/"
    click PE "https://github.com/mocco329/htwm/tree/master/emb/pose/"
    click SP "https://github.com/mocco329/htwm/tree/master/emb/speech/"
    click DOCK "https://github.com/mocco329/htwm/tree/master/back/htwm/Dockerfile"
    click DUMP "https://github.com/mocco329/htwm/blob/master/exec/dumpHTWM.sql"
```
