# techn-0/my_avatar_trainer architecture

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

- Interactive diagram: https://gitdiagram.com/techn-0/my_avatar_trainer
- Repository: https://github.com/techn-0/my_avatar_trainer

## Overview

##### Project Type and Purpose
- This project is a full-stack web application that tracks and measures the user’s workout movements. The recorded data is replayed by an animated avatar (“아바타”) and the system also supports multiplayer scenarios (chat and competitive recordings). This indicates both real-time and asynchronous components, with separate frontend and backend implementations.

##### File Structure
- Two main directories exist:
- The “pose” directory: Contains the frontend. It includes:
▪ A public folder holding HTML pages, 3D model assets (e.g., .glb, .gltf, animations), sounds, and other media needed for the workout/animation experience.
▪ An “src” directory with React components (pages for login, my-page, multiplay, ranking, scene, and UI components) and various utility scripts (e.g., for the camera, WebGL initialization, etc.). You also see files related to “workoutCam” and real-time motion processing.
- The “server” directory: Represents the backend built using NestJS.
▪ It is modularized with folders for authentication (traditional and social via Google, Kakao, Naver), multiplayer (with WebSocket gateways for chat and friend status), my-page (friend management, comments, room management), workout tracking, and the tier system.
▪ Multiple modules are defined – each with controllers, services, DTOs, and schemas – ensuring a well-separated modular architecture.

##### Points from the README
- The README specifies the project as a web service that recognizes user movements to track workouts. It highlights key features like avatar replaying the movements, competitive aspects, and a multiplayer environment.
- This indicates that both synchronous (real-time multiplayer interactions, video chat or WebRTC integration) and asynchronous interactions (storing workout records, leaderboard updates) are part of the design.

a. Main Components:
- Frontend (Client-Side – “pose”):
▪ User Interface: Includes pages for login, my-page, ranking, exercises, and real-time scene rendering.
▪ Animation & 3D Rendering: Handles avatars and models using WebGL, 3D assets (.glb, .gltf, etc.).
▪ Client-Side Logic: Workout timers, camera views (push-up, squat, etc.), and integration with WebRTC or socket handling for multiplay scenarios.
- Backend (Server – “server”):
▪ REST API Endpoints: For authentication, workout data submission, friend and comment management, tier calculation, and my-page functions.
▪ WebSocket Gateways: Modules in “multiplay” for chat and real-time friend status / multiplayer game rooms.
▪ Social Authentication: Modules handling external login strategies (Google, Kakao, Naver).
▪ Database: Implied by the use of schemas for users, comments, workouts, tiers, etc.
- External Services:
▪ Social Login Providers: External authentication via Google, Kakao, and Naver.
▪ (Optional) Third-Party Media Services: For serving or streaming the asset files and audio/video resources.

b. Relationships and Interactions:
- The Frontend communicates with the Backend via RESTful API calls (for login, fetching/sending workout data, profile updates, etc.).
- For real-time multiplayer features, establish a WebSocket connection between the client and the backend (managed by dedicated gateway modules) that enable chat, video streaming activities, and live update of game rooms.
- The social login modules interact with external OAuth providers to authenticate users.
- Data flows from user input (via UI and sensors/camera inputs) through the React components to backend endpoints that validate, store, or broadcast this data.

c. Architectural Patterns & Design Principles:
- Separation of Concerns: Clear division between client-side presentation and server-side business logic.
- Modular Architecture: Both frontend and backend have separated modules (for example, “auth”, “multiplay”, “my-page”, “workout”, etc.), which makes the system more maintainable and scalable.
- Real-Time Communication: Use of WebSocket gateways for multiplayer interactions.
- Use of standard REST and WebSocket protocols ensures scalable, decoupled communication between components.

d. Technologies, Frameworks, or Libraries Highlighted:
- Frontend: Likely React (evidenced by “src/App.js”, “src/pages”), WebGL/Three.js (for rendering 3D scenes), Tailwind CSS (tailwind.config.js), and additional libraries for handling animations and webcam input.
- Backend: Node.js with NestJS (look for nest-cli.json, module structure), integration with databases (schemas for users, workouts, etc.) and social authentication libraries.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Client Layer
    subgraph "Client Layer"
        FUI("Frontend UI"):::frontend
        Assets("3D Assets"):::frontend
        LoadChar("Load Character"):::frontend
        Cam("Workout Camera Module"):::frontend
    end

    %% Backend Layer
    subgraph "Backend Layer"
        Auth("Auth Module"):::backend
        SocAuth("Social Auth"):::backend
        Multi("Multiplay Module"):::backend
        MyPage("MyPage Module"):::backend
        Workout("Workout Module"):::backend
        Tier("Tier Module"):::backend
    end

    %% External and Database layers
    OAuth("OAuth Providers"):::external
    DB("Database"):::db

    %% Client interactions with Frontend components
    FUI -->|"renders"| Assets
    FUI -->|"loads"| LoadChar
    FUI -->|"API"| Auth
    FUI -->|"API"| MyPage
    FUI -->|"realTime"| Multi
    Cam -->|"data"| Workout

    %% Social Auth interaction with external OAuth providers
    SocAuth -->|"OAuth"| OAuth

    %% Backend modules storing data
    Auth -->|"stores"| DB
    MyPage -->|"stores"| DB
    Workout -->|"stores"| DB
    Tier -->|"stores"| DB
    Multi -->|"stores"| DB

    %% Styling Definitions
    classDef frontend fill:#ADD8E6,stroke:#333,stroke-width:2px;
    classDef backend fill:#F4A460,stroke:#333,stroke-width:2px;
    classDef db fill:#90EE90,stroke:#333,stroke-width:2px;
    classDef external fill:#FFB6C1,stroke:#333,stroke-width:2px;

    %% Click Events for Client Layer
    click FUI "https://github.com/techn-0/my_avatar_trainer/tree/main/pose/src/pages"
    click Assets "https://github.com/techn-0/my_avatar_trainer/tree/main/pose/public"
    click LoadChar "https://github.com/techn-0/my_avatar_trainer/blob/main/pose/src/shared/loadCharacter.js"
    click Cam "https://github.com/techn-0/my_avatar_trainer/tree/main/pose/src/app/workoutCam"

    %% Click Events for Backend Layer
    click Auth "https://github.com/techn-0/my_avatar_trainer/tree/main/server/src/auth"
    click SocAuth "https://github.com/techn-0/my_avatar_trainer/tree/main/server/src/socauth"
    click Multi "https://github.com/techn-0/my_avatar_trainer/tree/main/server/src/multiplay"
    click MyPage "https://github.com/techn-0/my_avatar_trainer/tree/main/server/src/my-page"
    click Workout "https://github.com/techn-0/my_avatar_trainer/tree/main/server/src/workout"
    click Tier "https://github.com/techn-0/my_avatar_trainer/tree/main/server/src/tier"
```
