# bgstaal/multiplewindow3dscene architecture

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

- Interactive diagram: https://gitdiagram.com/bgstaal/multiplewindow3dscene
- Repository: https://github.com/bgstaal/multiplewindow3dscene

## Overview

##### Project type and purpose
- This is a front-end web application/demo that runs entirely in the browser. It creates and renders a Three.js-based 3D scene across multiple windows and synchronizes their state via localStorage. There is no backend or server component—everything lives in HTML, JavaScript, and the browser’s storage APIs.

##### File structure
- index.html: the single entry point, pulls in Three.js and your two scripts.
- three-LICENSE: Three.js license file.
- WindowManager.js: a class that opens new windows, manages their lifecycle, and synchronizes shared state through localStorage and storage events.
- main.js: bootstraps the 3D scene, hooks into WindowManager, handles render loop, resize events, and input.

##### README for insights
- Confirms the focus on “multiple browser windows,” “scene synchronization,” and “dynamic window management” via localStorage.
- No server, no database; purely in-browser.
- Technologies: HTML, Three.js (r124), ES6 modules or vanilla scripts, localStorage API, window.open and storage events for cross-window comms.

##### Main components
a. Browser Windows (multiple instances)
- Each window runs the same code: index.html → Three.js + main.js + WindowManager.js
b. Module/Script Layers inside each window
- Three.js library (three.r124.min.js)
- main.js (scene init, render loop)
- WindowManager.js (handles open/close, localStorage sync)
c. Shared State Layer
- Browser localStorage
- StorageEvent API for broadcasting changes
d. User interactions / DOM events
- UI calls WindowManager to open/close windows, or interacts with the 3D scene
e. Render Engine
- Three.js WebGLRenderer drawing to each window’s canvas element

##### Architectural patterns and principles
- Single-page application pattern across multiple windows
- Publish/subscribe via the browser’s storage event bus
- Modular separation: rendering layer (Three.js) vs. window orchestration (WindowManager) vs. state sync (localStorage)

##### Relevant technologies/frameworks
- Three.js r124
- ES6 or vanilla JavaScript modules
- HTML5 localStorage and StorageEvent
- Browser window.open() and window lifecycle events

##### Diagramming details
- Clear labels on every component (e.g., “Three.js Renderer,” “WindowManager,” “localStorage”)
- Arrowheads showing direction of data or event flow

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Browser Windows
    subgraph "Browser Window A" 
        direction TB
        A_index["index.html"]:::window
        A_three["Three.js Library"]:::library
        A_main["main.js"]:::script
        A_wm["WindowManager.js"]:::script
        A_renderer["WebGLRenderer"]:::renderer
    end

    subgraph "Browser Window B"
        direction TB
        B_index["index.html"]:::window
        B_three["Three.js Library"]:::library
        B_main["main.js"]:::script
        B_wm["WindowManager.js"]:::script
        B_renderer["WebGLRenderer"]:::renderer
    end

    %% Shared Storage
    storage["localStorage"]:::storage

    %% Relationships in Window A
    A_index -->|"loads"| A_three
    A_index -->|"loads"| A_main
    A_index -->|"loads"| A_wm
    A_main -->|"initializes scene & render loop"| A_renderer
    A_wm -->|"open()"| B_index
    A_main -->|"write state"| storage
    storage -->|"storage event"| A_wm

    %% Relationships in Window B
    B_index -->|"loads"| B_three
    B_index -->|"loads"| B_main
    B_index -->|"loads"| B_wm
    B_main -->|"initializes scene & render loop"| B_renderer
    B_main -->|"write state"| storage
    storage -->|"storage event"| B_wm

    %% Click Events
    click A_index "https://github.com/bgstaal/multiplewindow3dscene/blob/main/index.html"
    click B_index "https://github.com/bgstaal/multiplewindow3dscene/blob/main/index.html"
    click A_main "https://github.com/bgstaal/multiplewindow3dscene/blob/main/main.js"
    click B_main "https://github.com/bgstaal/multiplewindow3dscene/blob/main/main.js"
    click A_wm "https://github.com/bgstaal/multiplewindow3dscene/blob/main/WindowManager.js"
    click B_wm "https://github.com/bgstaal/multiplewindow3dscene/blob/main/WindowManager.js"
    click three_LIC "https://github.com/bgstaal/multiplewindow3dscene/tree/main/three-LICENSE"
    click README "https://github.com/bgstaal/multiplewindow3dscene/blob/main/README.md"

    %% Styles
    classDef window fill:#D6E9FF,stroke:#036,stroke-width:2px
    classDef library fill:#E0F7FA,stroke:#00796B,stroke-width:2px
    classDef script fill:#E8F5E9,stroke:#2E7D32,stroke-width:2px
    classDef renderer fill:#F1F8E9,stroke:#558B2F,stroke-width:2px
    classDef storage fill:#FFF3E0,stroke:#FB8C00,stroke-width:2px

    %% External license and docs
    subgraph "Project Files"
        direction TB
        three_LIC["three-LICENSE"]:::library
        README["README.md"]:::script
    end
```
