# yemount/pose-animator architecture

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

- Interactive diagram: https://gitdiagram.com/yemount/pose-animator
- Repository: https://github.com/yemount/pose-animator

## Overview

##### Project type and purpose
- This is a browser-based, front-end application (“Pose Animator”) that takes a 2D SVG illustration and animates it in real time using ML pose-estimation models (PoseNet and FaceMesh) via TensorFlow.js.
- Its primary use cases are two demos: a live camera feed demo (camera.html + camera.js) and a static-image demo (static_image.html + static_image.js).

##### File structure
- Top level:
- HTML entry points: camera.html, static_image.html, index.html
- JS entry scripts: camera.js, static_image.js
- Build/config: package.json, package-lock.json, firebase.json
- Third-party library: third_party/paper (Paper.js)
- Core modules: illustrationGen/, utils/
- Static assets: resources/ (gifs, illustrations, samples)
- Patterns:
- Pipeline stages: load model → read keypoints → update skeleton → redraw SVG paths

##### README for insights
- Describes two primary functional modules:
a) Skeleton rig parsing (from SVG skeleton group and predefined bone hierarchy)
b) Real-time bone updating (driven by PoseNet/FaceMesh keypoints)
c) Illustration surface rendering (vector path manipulation)
- Mentions TensorFlow.js and Paper.js as core frameworks.

##### Main components
A. Client Browser
– HTML pages (camera.html, static_image.html)
– JS bootstrap
B. Input Sources
– Webcam stream (MediaDevices API)
– Static image file drop
C. ML Inference Layer
– TensorFlow.js Loader
– PoseNet model
– FaceMesh model
D. Skeleton Module
– SVG parser (reads “skeleton” group from SVG)
– Bone hierarchy data structure
E. Illustration Module
– illustrationGen (generates/control point mapping)
– SVG path utilities (utils/svgUtils.js)
F. Rendering Engine
– Paper.js (third_party/paper) or direct SVG DOM updates
– Canvas/SVG output
G. Utilities
H. Hosting/Deployment
– Firebase Hosting (firebase.json)

Interactions
1. User opens camera.html or static_image.html
2. JS entry script initializes ML models (TensorFlow.js)
3. On each animation tick or static load:
- Frame/image → PoseNet/FaceMesh → keypoints
- Keypoints → Skeleton Module → bone transformations
- Transformations + SVG “illustration” paths → Illustration Module
- Updated paths rendered via Paper.js or direct SVG updates
5. All assets and scripts served from Firebase Hosting

##### Architectural patterns and design principles
- Modular separation: ML inference layer, skeletal logic, rendering logic, util libraries
- Pipeline flow: Input → Compute → Transform → Render
- Single-page-style demos with dynamic JS modules loaded at runtime

##### Detail
- Every module folder as its own subsystem if needed (e.g., utils/, illustrationGen/)
- Call out third_party dependencies (Paper.js)
- Two demo flows (camera vs. static) either as parallel lanes or combined with conditional annotations
- Where SVG files are parsed vs. where vector updates occur

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Client Browser Layer
    subgraph "Client Browser" 
        direction TB
        CAM_HTML["camera.html"]:::frontend
        STATIC_HTML["static_image.html"]:::frontend
        INDEX_HTML["index.html"]:::frontend
        CAM_JS["camera.js"]:::frontend
        STATIC_JS["static_image.js"]:::frontend
    end

    %% Input Sources
    subgraph "Input Sources"
        direction TB
        WEBCAM["Webcam Stream"]:::frontend
        STATIC_IMG["Static Image Drop"]:::frontend
    end

    %% ML Inference Layer
    subgraph "ML Inference Layer"
        direction TB
        TF_LOADER["TensorFlow.js Loader"]:::ml
        POSENET["PoseNet Model"]:::ml
        FACEMESH["FaceMesh Model"]:::ml
    end

    %% Skeleton Module
    subgraph "Skeleton Module"
        direction TB
        SVG_PARSER["SVG Skeleton Parser"]:::core
        BONE_DS["Bone Hierarchy Data"]:::core
    end

    %% Illustration Module
    subgraph "Illustration Module"
        direction TB
        ILLUSTRATION_GEN["Control Point Mapping"]:::core
        SVG_UTILS["SVG Path Utilities"]:::utils
    end

    %% Rendering Engine
    subgraph "Rendering Engine"
        direction TB
        PAPER_JS["Paper.js Integration"]:::render
        SVG_OUTPUT["SVG/Canvas Output"]:::render
    end

    %% Utilities
    subgraph "Utilities"
        direction TB
        COLOR_UTILS["Color Utils"]:::utils
        MATH_UTILS["Math Utils"]:::utils
        DEMO_UTILS["Demo Helpers"]:::utils
        FILE_UTILS["File Utils"]:::utils
    end

    %% Static Assets
    subgraph "Static Assets"
        direction TB
        GIFS["resources/gifs/"]:::assets
        ILLUSRES["resources/illustration/"]:::assets
        IMAGES["resources/images/"]:::assets
        SAMPLES["resources/samples/"]:::assets
    end

    %% Hosting
    FIREBASE["Firebase Hosting"]:::hosting

    %% Connections
    CAM_HTML --> CAM_JS
    STATIC_HTML --> STATIC_JS
    CAM_JS --> TF_LOADER
    STATIC_JS --> TF_LOADER

    WEBCAM --> CAM_JS
    STATIC_IMG --> STATIC_JS

    TF_LOADER --> POSENET
    TF_LOADER --> FACEMESH
    POSENET --> SVG_PARSER
    FACEMESH --> SVG_PARSER

    SVG_PARSER --> BONE_DS
    BONE_DS --> ILLUSTRATION_GEN
    ILLUSTRATION_GEN --> SVG_UTILS
    SVG_UTILS --> SVG_OUTPUT
    PAPER_JS --> SVG_OUTPUT

    COLOR_UTILS --> SVG_UTILS
    MATH_UTILS --> SVG_PARSER
    DEMO_UTILS --> CAM_JS
    DEMO_UTILS --> STATIC_JS
    FILE_UTILS --> STATIC_JS

    CAM_HTML --> FIREBASE
    STATIC_HTML --> FIREBASE
    INDEX_HTML --> FIREBASE

    %% Click Events
    click CAM_HTML "https://github.com/yemount/pose-animator/blob/master/camera.html"
    click STATIC_HTML "https://github.com/yemount/pose-animator/blob/master/static_image.html"
    click INDEX_HTML "https://github.com/yemount/pose-animator/blob/master/index.html"
    click CAM_JS "https://github.com/yemount/pose-animator/blob/master/camera.js"
    click STATIC_JS "https://github.com/yemount/pose-animator/blob/master/static_image.js"
    click SVG_PARSER "https://github.com/yemount/pose-animator/blob/master/illustrationGen/skeleton.js"
    click ILLUSTRATION_GEN "https://github.com/yemount/pose-animator/blob/master/illustrationGen/illustration.js"
    click SVG_UTILS "https://github.com/yemount/pose-animator/blob/master/utils/svgUtils.js"
    click PAPER_JS "https://github.com/yemount/pose-animator/tree/master/third_party/paper/"
    click COLOR_UTILS "https://github.com/yemount/pose-animator/blob/master/utils/colorUtils.js"
    click MATH_UTILS "https://github.com/yemount/pose-animator/blob/master/utils/mathUtils.js"
    click DEMO_UTILS "https://github.com/yemount/pose-animator/blob/master/utils/demoUtils.js"
    click FILE_UTILS "https://github.com/yemount/pose-animator/blob/master/utils/fileUtils.js"
    click GIFS "https://github.com/yemount/pose-animator/tree/master/resources/gifs/"
    click ILLUSRES "https://github.com/yemount/pose-animator/tree/master/resources/illustration/"
    click IMAGES "https://github.com/yemount/pose-animator/tree/master/resources/images/"
    click SAMPLES "https://github.com/yemount/pose-animator/tree/master/resources/samples/"
    click FIREBASE "https://github.com/yemount/pose-animator/blob/master/firebase.json"

    %% Styles
    classDef frontend fill:#D0E6FF,stroke:#0366d6,color:#0366d6;
    classDef ml fill:#DFFFE0,stroke:#28A745,color:#155724;
    classDef core fill:#FFF4E0,stroke:#EE7600,color:#663C00;
    classDef render fill:#FFE8D6,stroke:#E75A11,color:#722B05;
    classDef utils fill:#F0F0F0,stroke:#6a737d,color:#24292e;
    classDef assets fill:#F5E6FF,stroke:#6f42c1,color:#381175;
    classDef hosting fill:#F0E1FF,stroke:#8250df,color:#4b0082;
```
