# mnmxmx/three-dom-alignment architecture

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

- Interactive diagram: https://gitdiagram.com/mnmxmx/three-dom-alignment
- Repository: https://github.com/mnmxmx/three-dom-alignment

## Overview

##### Project type and purpose
- This is a frontend JavaScript “demo library” project (“three‑dom‑alignment”) that uses WebGL (Three.js), custom shaders (GLSL), SCSS, and Webpack to build two standalone demos (demo1 & demo2).
- It produces static HTML/CSS/JS bundles (in dist/) that illustrate how 3D objects stay aligned with the DOM.

##### File structure
- Top‐level:
- package.json, webpack.config.js → build & dependency config
- dist/ → compiled demo artifacts (HTML+CSS for demo1 and demo2, plus main.css)
- js/ → source code subdivided by demo
- js/demo1 & js/demo2 each contain:
- A “root” entry (demo1.js / demo2.js)
- modules/Artwork.js, Controls.js, Object.js → core logic for 3D+DOM alignment
- scss/styles.scss → demo‑specific styles
- js/glsl/ → shared shader code (plane.vert, plane.frag, utils/snoise3D.glsl)
- webpack.config.js → orchestrates module bundling (JS + SCSS + GLSL) into dist/

##### README for additional insights
- Minimal README: indicates Node.js v16, Yarn install & dev scripts. No further architectural notes; everything must be inferred from file layout and webpack config.

a. Main components
1. Development Environment (Node.js + Yarn)
2. Source Artifacts
– JS Entry Points (js/demo1.js, js/demo2.js)
– JS Modules (Artwork, Controls, Object)
– SCSS (styles.scss for each demo)
– GLSL Shaders (plane.vert, plane.frag, utils/snoise3D.glsl)
3. Build Pipeline (Webpack)
4. Output Bundles (dist/demo1.html, .css; dist/demo2.html, .css; main.css)
5. Runtime Environment (Browser)
– DOM
– Canvas & WebGL Context (Three.js)
– CSS styling
b. Relationships & interactions
– Source Artifacts flow into Webpack
– Webpack processes:
- JS modules → bundle.js
- SCSS → CSS files
- GLSL → inlined shader strings or separate assets
– Bundled outputs deployed to dist/
– Browser loads demoN.html → pulls in CSS & JS bundles
– JS bundle initializes Three.js scene, loads shaders, instantiates Artwork/Controls/Object, and manipulates DOM for alignment
c. Architectural patterns & design principles
– Module‑based design (ES modules per logical unit)
– Build‑time asset transformation (SCSS → CSS; GLSL → JS imports)
– Separation of concerns: rendering logic (Artwork/Object), input & UI controls, style definitions
d. Key technologies & libraries
– Node.js, Yarn (package management)
– Webpack (bundler + loaders for SCSS & GLSL)
– Three.js (WebGL abstraction)
– SCSS (preprocessed CSS)
– GLSL (shader language)

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Development Environment & Config
    subgraph "Dev Environment & Config"
        PKG["package.json"]:::source
        WEBP_CFG["webpack.config.js"]:::source
        README["README.md"]:::source
    end

    %% Source Code
    subgraph "Source Code"
        subgraph "JS Entry Points"
            Demo1Entry["js/demo1.js"]:::source
            Demo2Entry["js/demo2.js"]:::source
        end
        subgraph "JS Modules (demo1)"
            D1Artwork["Artwork.js"]:::source
            D1Controls["Controls.js"]:::source
            D1Object["Object.js"]:::source
        end
        subgraph "JS Modules (demo2)"
            D2Artwork["Artwork.js"]:::source
            D2Controls["Controls.js"]:::source
            D2Object["Object.js"]:::source
        end
        subgraph "SCSS Styles"
            SCSS1["styles.scss (demo1)"]:::source
            SCSS2["styles.scss (demo2)"]:::source
        end
        subgraph "GLSL Shaders"
            VERT["plane.vert"]:::source
            FRAG["plane.frag"]:::source
            SNOISE["snoise3D.glsl"]:::source
        end
    end

    %% Build Pipeline
    subgraph "Build Pipeline"
        WEBPACK["Webpack"]:::build
        subgraph "Loaders"
            JSLoader["JS Loader (transpile)"]:::build
            SCSSLoader["SCSS Loader (compile)"]:::build
            GLSLLoader["GLSL Loader (import)"]:::build
        end
    end

    %% Output Bundles
    subgraph "dist/ Output"
        D1HTML["demo1.html"]:::output
        D1CSS["demo1.css"]:::output
        D2HTML["demo2.html"]:::output
        D2CSS["demo2.css"]:::output
        MAINCSS["main.css"]:::output
        JSBundle["bundle.js"]:::output
    end

    %% Browser Runtime
    subgraph "Browser Runtime"
        DOM["DOM"]:::runtime
        Canvas["Canvas & WebGL Context"]:::runtime
        ThreeJS["Three.js Scene"]:::runtime
    end

    %% Connections: Config to Build
    PKG -->|provides deps| WEBPACK
    WEBP_CFG -->|configures| WEBPACK

    %% Source to Loaders
    Demo1Entry --> JSLoader
    Demo2Entry --> JSLoader
    D1Artwork --> JSLoader
    D1Controls --> JSLoader
    D1Object --> JSLoader
    D2Artwork --> JSLoader
    D2Controls --> JSLoader
    D2Object --> JSLoader
    SCSS1 --> SCSSLoader
    SCSS2 --> SCSSLoader
    VERT --> GLSLLoader
    FRAG --> GLSLLoader
    SNOISE --> GLSLLoader

    %% Loaders to Webpack
    JSLoader --> WEBPACK
    SCSSLoader --> WEBPACK
    GLSLLoader --> WEBPACK

    %% Webpack to Outputs
    WEBPACK --> JSBundle
    WEBPACK --> D1HTML
    WEBPACK --> D1CSS
    WEBPACK --> D2HTML
    WEBPACK --> D2CSS
    WEBPACK --> MAINCSS

    %% Browser loads outputs
    D1HTML --> DOM
    D1CSS --> DOM
    D2HTML --> DOM
    D2CSS --> DOM
    MAINCSS --> DOM
    JSBundle --> ThreeJS
    ThreeJS --> Canvas
    Canvas --> DOM

    %% Click Events
    click PKG "https://github.com/mnmxmx/three-dom-alignment/blob/master/package.json"
    click WEBP_CFG "https://github.com/mnmxmx/three-dom-alignment/blob/master/webpack.config.js"
    click README "https://github.com/mnmxmx/three-dom-alignment/blob/master/README.md"
    click Demo1Entry "https://github.com/mnmxmx/three-dom-alignment/blob/master/js/demo1.js"
    click Demo2Entry "https://github.com/mnmxmx/three-dom-alignment/blob/master/js/demo2.js"
    click D1Artwork "https://github.com/mnmxmx/three-dom-alignment/blob/master/js/demo1/modules/Artwork.js"
    click D1Controls "https://github.com/mnmxmx/three-dom-alignment/blob/master/js/demo1/modules/Controls.js"
    click D1Object "https://github.com/mnmxmx/three-dom-alignment/blob/master/js/demo1/modules/Object.js"
    click D2Artwork "https://github.com/mnmxmx/three-dom-alignment/blob/master/js/demo2/modules/Artwork.js"
    click D2Controls "https://github.com/mnmxmx/three-dom-alignment/blob/master/js/demo2/modules/Controls.js"
    click D2Object "https://github.com/mnmxmx/three-dom-alignment/blob/master/js/demo2/modules/Object.js"
    click SCSS1 "https://github.com/mnmxmx/three-dom-alignment/blob/master/js/demo1/scss/styles.scss"
    click SCSS2 "https://github.com/mnmxmx/three-dom-alignment/blob/master/js/demo2/scss/styles.scss"
    click VERT "https://github.com/mnmxmx/three-dom-alignment/blob/master/js/glsl/plane.vert"
    click FRAG "https://github.com/mnmxmx/three-dom-alignment/blob/master/js/glsl/plane.frag"
    click SNOISE "https://github.com/mnmxmx/three-dom-alignment/blob/master/js/glsl/utils/snoise3D.glsl"
    click D1HTML "https://github.com/mnmxmx/three-dom-alignment/blob/master/dist/demo1.html"
    click D1CSS "https://github.com/mnmxmx/three-dom-alignment/blob/master/dist/demo1.css"
    click D2HTML "https://github.com/mnmxmx/three-dom-alignment/blob/master/dist/demo2.html"
    click D2CSS "https://github.com/mnmxmx/three-dom-alignment/blob/master/dist/demo2.css"
    click MAINCSS "https://github.com/mnmxmx/three-dom-alignment/blob/master/dist/main.css"

    %% Styles
    classDef source fill:#D0E6FF,stroke:#036,stroke-width:1px
    classDef build fill:#FFDDA0,stroke:#E68A00,stroke-width:1px
    classDef output fill:#DFFFD0,stroke:#6A0,stroke-width:1px
    classDef runtime fill:#D0FFD6,stroke:#0A5,stroke-width:1px
```
