# runrun9/webgl_works architecture

> Architecture diagram of the GitHub repository runrun9/webgl_works, 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/runrun9/webgl_works
- Repository: https://github.com/runrun9/webgl_works

## Overview

##### Main Components
- Server Component: Represented by app.js and its associated configurations (Procfile, package.json). This layer is responsible for serving the static assets and possibly handling any API or server-side logic.
- HTML & Entry Point: public/index.html which initializes the application.
- CSS Assets: All styles in public/css (mmd.css, normalize.css, pushy.css) that determine the visual layout and responsive behavior.
- JavaScript Modules: Located in public/js and its subdirectories that contain the code for rendering models, handling WebGL dynamics, VR controls (via DeviceOrientationControls), animations, and other behaviors.
- 3D Models & Assets: In public/models, segmented by type (pmd for MMD models, vox for voxel models), which are loaded and rendered by the JavaScript modules.

##### Relationships and Data Flow
- Within the JavaScript layer, show modules like MMDLoader, MMDPhysics, and various control modules as interconnected libraries that work together to load and animate 3D models.
- How the 3D models stored under public/models are fetched by the client’s code and passed through the loading and rendering pipelines.

##### Architectural Patterns
- Separation of Concerns: The design clearly separates the server (Node.js) from the client (WebGL demo).
- Modular Client Architecture: The use of independent JavaScript modules (each in its own file within public/js/modules) stresses modularity and potential reusability.
- Static Asset Delivery: The server’s primary function is to deliver static files; this could be emphasized as a “static content” architecture pattern.

##### Relevant Technologies and Frameworks
- Node.js as the server environment.
- Likely Three.js (or a similar WebGL library) as the basis for the WebGL modules.
- Client-side libraries or frameworks for VR and device orientation (e.g., DeviceOrientationControls).
- The modular folder structure indicates usage of standard ES modules or a bundling approach via Node (even if not explicitly a bundler tool, the organization is still modular).

- Component (server, client-side HTML, CSS, JS modules, and assets) is clearly labeled.

- A Node.js server layer that primarily serves static files.
- A client-side structure that is divided into HTML/CSS for layout and styling, a rich set of JavaScript modules for WebGL and VR rendering, and a repository of 3D models.
- Clear depiction of data/service flows: how the application is initialized, assets loaded, and 3D visuals rendered.
- Special emphasis on controlling VR interactions on smartphones via device orientation controls.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Server Layer
    subgraph "Server Layer"
        appjs("app.js"):::serverNode
        pkg("package.json"):::serverNode
        proc("Procfile"):::serverNode
    end

    %% Client Side
    subgraph "Client Side (public)"
        index("public/index.html"):::htmlNode
        
        subgraph "CSS Assets"
            css1("mmd.css"):::cssNode
            css2("normalize.css"):::cssNode
            css3("pushy.css"):::cssNode
        end
        
        subgraph "JavaScript"
            view("view.js"):::jsNode
            char("char.js"):::jsNode
            subgraph "JS Modules"
                dor("DeviceOrientationControls.js"):::jsModule
                orbit("OrbitControls.js"):::jsModule
                mmdLoader("MMDLoader.js"):::jsModule
                mmdPhysics("MMDPhysics.js"):::jsModule
                ccdik("CCDIKSolver.js"):::jsModule
                detector("Detector.js"):::jsModule
                stereo("StereoEffect.js"):::jsModule
                tgal("TGALoader.js"):::jsModule
                jquery("jquery.textFx.js"):::jsModule
            end
        end
        
        subgraph "3D Models & Assets"
            subgraph "MMD Models"
                miku("miku_v2.pmd"):::modelNode
                serval("サーバル Model"):::modelNode
            end
            subgraph "Voxel Models"
                fox("chr_fox.vox"):::modelNode
                rain("chr_rain.vox"):::modelNode
            end
        end
    end

    %% Data Flow
    appjs -->|"serves"| index
    index -->|"loads"| css1
    index -->|"loads"| css2
    index -->|"loads"| css3
    index -->|"loads"| view
    index -->|"loads"| char
    view -->|"utilizes"| dor
    view -->|"utilizes"| orbit
    view -->|"utilizes"| mmdLoader
    view -->|"utilizes"| mmdPhysics
    view -->|"utilizes"| ccdik
    view -->|"utilizes"| detector
    view -->|"utilizes"| stereo
    view -->|"utilizes"| tgal
    view -->|"utilizes"| jquery
    mmdLoader -->|"fetches"| miku
    mmdLoader -->|"fetches"| serval
    mmdLoader -->|"fetches"| fox
    mmdLoader -->|"fetches"| rain
    dor -->|"triggers VR"| view

    %% Click Events
    click appjs "https://github.com/runrun9/webgl_works/blob/master/app.js"
    click pkg "https://github.com/runrun9/webgl_works/blob/master/package.json"
    click proc "https://github.com/runrun9/webgl_works/tree/master/Procfile"
    click index "https://github.com/runrun9/webgl_works/blob/master/public/index.html"
    click css1 "https://github.com/runrun9/webgl_works/blob/master/public/css/mmd.css"
    click css2 "https://github.com/runrun9/webgl_works/blob/master/public/css/normalize.css"
    click css3 "https://github.com/runrun9/webgl_works/blob/master/public/css/pushy.css"
    click view "https://github.com/runrun9/webgl_works/blob/master/public/js/view.js"
    click char "https://github.com/runrun9/webgl_works/blob/master/public/js/char.js"
    click dor "https://github.com/runrun9/webgl_works/blob/master/public/js/modules/DeviceOrientationControls.js"
    click orbit "https://github.com/runrun9/webgl_works/blob/master/public/js/modules/OrbitControls.js"
    click mmdLoader "https://github.com/runrun9/webgl_works/blob/master/public/js/modules/MMDLoader.js"
    click mmdPhysics "https://github.com/runrun9/webgl_works/blob/master/public/js/modules/MMDPhysics.js"
    click ccdik "https://github.com/runrun9/webgl_works/blob/master/public/js/modules/CCDIKSolver.js"
    click detector "https://github.com/runrun9/webgl_works/blob/master/public/js/modules/Detector.js"
    click stereo "https://github.com/runrun9/webgl_works/blob/master/public/js/modules/StereoEffect.js"
    click tgal "https://github.com/runrun9/webgl_works/blob/master/public/js/modules/TGALoader.js"
    click jquery "https://github.com/runrun9/webgl_works/blob/master/public/js/modules/jquery.textFx.js"
    click miku "https://github.com/runrun9/webgl_works/blob/master/public/models/pmd/miku/miku_v2.pmd"
    click serval "https://github.com/runrun9/webgl_works/tree/master/public/models/pmd/サーバル"
    click fox "https://github.com/runrun9/webgl_works/blob/master/public/models/vox/chr_fox.vox"
    click rain "https://github.com/runrun9/webgl_works/blob/master/public/models/vox/chr_rain.vox"

    %% Styles
    classDef serverNode fill:#ffcc00,stroke:#333,stroke-width:2px;
    classDef htmlNode fill:#b3e5fc,stroke:#333,stroke-width:2px;
    classDef cssNode fill:#c8e6c9,stroke:#333,stroke-width:2px;
    classDef jsNode fill:#ffe082,stroke:#333,stroke-width:2px;
    classDef jsModule fill:#f8bbd0,stroke:#333,stroke-width:2px;
    classDef modelNode fill:#dcedc8,stroke:#333,stroke-width:2px;
```
