# cavargas10/pagethreejs architecture

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

- Interactive diagram: https://gitdiagram.com/cavargas10/pagethreejs
- Repository: https://github.com/cavargas10/pagethreejs

## Overview

##### Project type and purpose
- This is a front-end single-page application (SPA) built with React and Vite.
- It loads 3D models (GLTF + BIN + textures) and custom GLSL shaders to render interactive graphics in the browser.
- There is no separate backend; static assets are served by Vite’s dev server or a static‐site host in production.

##### File structure
- Top level:
– index.html: application entry point
– package.json / vite.config.js: build/dev configuration
– public/: static folder with 3D models and textures
– src/: React source code, components, shaders, styling
- Key components:
– App.jsx: root component
– Header.jsx: UI header
– ParticleModel.jsx: 3D‐model & shader loader + renderer
– shaders/: fragment.glsl & vertex.glsl — GPU programs
- Config: .eslintrc.cjs, vite.config.js → define plugins (@vitejs/plugin-react), dev server, build output.

##### README
- Confirms: minimal React + Vite template with HMR and ESLint
- Mentions the use of official Vite plugins for fast refresh.

a. Main components
1. Developer Machine
– Node.js & npm/Yarn
– Source files (src/, public/)
– Configuration (vite.config.js, .eslintrc)
2. Vite Dev Server / Build Pipeline
– @vitejs/plugin-react (Babel or SWC)
– Asset handling (serves public/, inlines shaders)
– Hot Module Replacement (HMR)
3. Browser Runtime
– index.html loads built bundle
– React application (App → Header, ParticleModel)
– WebGL context via Three.js or raw WebGL, shaders loaded from .glsl
– Fetches 3D model files (scene.gltf, scene.bin, textures)
4. Static Hosting (Production)
– Dist/ directory output (not shown in file tree, implied)
– Served by any static file host (Netlify, Vercel, S3)
b. Relationships & interactions
- Developer edits src/ → Vite watches & recompiles → updates browser via HMR
- Browser requests index.html from Vite → loads JS bundle → executes React app
- ParticleModel component uses fetch/GLTFLoader to retrieve 3D assets from public/
- Shaders are imported as text modules, compiled by WebGL at runtime
- On build, Vite bundles React code, inlines small assets, copies public/ to dist/
c. Architectural patterns & design principles
- SPA architecture: single entry point, client-side routing (if added later)
- Component-based UI (React): separation of concerns (App vs. Header vs. ParticleModel)
- Asset pipeline: build-time (Vite) vs. runtime (GLTFLoader, WebGL)
- Dev/prod parity: same code paths, Vite abstracts dev server and production bundler
d. Key technologies & libraries
- React (JSX components)
- Vite (ESM dev server, Rollup‐powered build)
- @vitejs/plugin-react (fast refresh via Babel or SWC)
- GLSL shaders (vertex & fragment)
- GLTF model format (public/3d-models)
- CSS modules or global CSS (App.css, index.css)

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Developer Machine"
        NodeJS["Node.js & npm"]:::dev
        package_json["package.json"]:::config
        vite_config["vite.config.js"]:::config
        eslint_config[".eslintrc.cjs"]:::config
        index_html["index.html"]:::config
        subgraph src["src/"]
            main["src/main.jsx"]:::dev
            App["src/App.jsx"]:::frontend
            Header["src/Header.jsx"]:::frontend
            Particle["src/ParticleModel.jsx"]:::frontend
            index_css["src/index.css"]:::assets
            App_css["src/App.css"]:::assets
            subgraph shaders["src/shaders/"]
                vert["vertex.glsl"]:::assets
                frag["fragment.glsl"]:::assets
            end
        end
        subgraph public["public/3d-models/"]
            monkey["Monkey-Head Assets"]:::assets
            rabbit["Rabbit Assets"]:::assets
        end
    end

    NodeJS -->|"start dev"| ViteDevServer["Vite Dev Server\n(@vitejs/plugin-react, HMR)"]:::build
    vite_config --> ViteDevServer
    eslint_config -.-> ViteDevServer

    ViteDevServer -->|"serves index.html\nand assets"| BrowserRT["Browser Runtime"]:::frontend

    NodeJS -->|"vite build"| ViteBuild["Vite Build"]:::build
    ViteBuild --> dist["Dist/ (Production bundle)"]:::config
    dist --> StaticHost["Static Host\n(Netlify/Vercel/S3)"]:::build
    StaticHost -->|"serves bundle"| BrowserRT

    subgraph BrowserRT["Browser Runtime"]
        index_html2["index.html"]:::config
        subgraph ReactApp["React Application"]
            App2["App Component"]:::frontend
            Header2["Header Component"]:::frontend
            Particle2["ParticleModel Component"]:::frontend
        end
        WebGL["WebGL Context\n(Three.js/Raw)"]:::frontend
    end

    BrowserRT --> index_html2
    index_html2 -->|"loads bundle"| App2
    App2 --> Header2
    App2 --> Particle2
    App2 -->|"uses global CSS"| index_css
    App2 -->|"uses component CSS"| App_css

    Particle2 -->|"fetches model"| monkey
    Particle2 -->|"fetches model"| rabbit
    Particle2 -->|"compiles shaders"| WebGL
    vert -->|"bundled shader"| Particle2
    frag -->|"bundled shader"| Particle2

    click index_html "https://github.com/cavargas10/pagethreejs/blob/main/index.html"
    click vite_config "https://github.com/cavargas10/pagethreejs/blob/main/vite.config.js"
    click eslint_config "https://github.com/cavargas10/pagethreejs/blob/main/.eslintrc.cjs"
    click main "https://github.com/cavargas10/pagethreejs/blob/main/src/main.jsx"
    click App "https://github.com/cavargas10/pagethreejs/blob/main/src/App.jsx"
    click Header "https://github.com/cavargas10/pagethreejs/blob/main/src/Header.jsx"
    click Particle "https://github.com/cavargas10/pagethreejs/blob/main/src/ParticleModel.jsx"
    click vert "https://github.com/cavargas10/pagethreejs/blob/main/src/shaders/vertex.glsl"
    click frag "https://github.com/cavargas10/pagethreejs/blob/main/src/shaders/fragment.glsl"
    click index_css "https://github.com/cavargas10/pagethreejs/blob/main/src/index.css"
    click App_css "https://github.com/cavargas10/pagethreejs/blob/main/src/App.css"
    click monkey "https://github.com/cavargas10/pagethreejs/blob/main/public/3d-models/monkey-head/scene.gltf"
    click rabbit "https://github.com/cavargas10/pagethreejs/blob/main/public/3d-models/rabbit/scene.gltf"
    click package_json "https://github.com/cavargas10/pagethreejs/blob/main/package.json"

    classDef dev fill:#e0f7e9,stroke:#2ca02c,color:#2ca02c
    classDef frontend fill:#e7f1ff,stroke:#1f77b4,color:#1f77b4
    classDef assets fill:#fff5e6,stroke:#ff7f0e,color:#ff7f0e
    classDef config fill:#f0f0f0,stroke:#7f7f7f,color:#7f7f7f
    classDef build fill:#f5f5f5,stroke:#17becf,color:#17becf
```
