# wowserhq/client architecture

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

- Interactive diagram: https://gitdiagram.com/wowserhq/client
- Repository: https://github.com/wowserhq/client

## Overview

Key Components to Include:

##### Core Application Layer
- Entry point (Client.ts)
- Main application lifecycle management
- Connection between major subsystems

##### Graphics Engine (src/gfx/)
- Multiple Graphics APIs Support
- WebGL2 Implementation
- WebGPU Implementation
- Device Management
- Shader System
- Texture Management
- Screen/Layer Management

##### UI System (src/ui/)
- Component Hierarchy
- Template System
- Rendering Pipeline
- Event System
- Scripting Engine

##### Resource Management
- Asset Loading
- Shader Management
- Texture Registry
- Template Registry

##### Use a layered architecture approach
- Top Layer: Client Interface
- Middle Layer: Core Systems
- Bottom Layer: Graphics APIs

##### Component Relationships
- Clear hierarchical relationships between UI components
- Data flow between graphics pipeline stages
- Demonstrate resource loading paths

Specific Elements to Include:

##### Graphics Pipeline
**WebGL2/WebGPU API → Device → Shader Registry → Texture Registry → Screen Renderer**

##### UI Component System
**UIRoot → Layout Frames → Simple Components**
- ↓
**Script Engine → Event System**

##### Resource Loading Flow
**Asset Loader → Template Registry → Component Factory → Live UI**

Important Considerations:

##### Separation between
- Graphics rendering system (WebGL2/WebGPU)
- UI component system
- Scripting/event system

##### Clear boundaries between
- Core engine code
- WoW-specific implementations
- Browser APIs

##### Special attention to
- Shader management (public/Shaders/)
- UI template system (XML-based)
- Lua scripting integration

##### Performance-Critical Paths
- Render batch processing
- Event handling
- Resource loading

##### Notes for important implementation details

Key Technical Details to Highlight:

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Core["Core Application Layer"]
        Client["Client"]:::core
        Bootstrap["Bootstrap"]:::core
        Client --> Bootstrap
    end

    subgraph Graphics["Graphics Engine"]
        Device["Device Manager"]:::graphics
        WebGL2["WebGL2 Device"]:::graphics
        WebGPU["WebGPU Device"]:::graphics
        ShaderSys["Shader System"]:::graphics
        ShaderReg["Shader Registry"]:::graphics
        TextureMgr["Texture Manager"]:::graphics
        TextureReg["Texture Registry"]:::graphics
        Screen["Screen Manager"]:::graphics
        ScreenLayer["Screen Layer"]:::graphics

        Device --> WebGL2
        Device --> WebGPU
        Device --> ShaderSys
        ShaderSys --> ShaderReg
        Device --> TextureMgr
        TextureMgr --> TextureReg
        Device --> Screen
        Screen --> ScreenLayer
    end

    subgraph UI["UI System"]
        UIRoot["UI Root"]:::ui
        TemplateSystem["Template System"]:::ui
        RenderPipeline["Render Pipeline"]:::ui
        EventSystem["Event System"]:::ui
        ComponentFactory["Component Factory"]:::ui

        UIRoot --> TemplateSystem
        UIRoot --> RenderPipeline
        UIRoot --> EventSystem
        TemplateSystem --> ComponentFactory
    end

    subgraph Resources["Resource Management"]
        ShaderRes["Shader Resources"]:::resource
        TemplateReg["Template Registry"]:::resource
        TextureRegistry["Texture Registry"]:::resource
        AssetLoader["Asset Loader"]:::resource

        AssetLoader --> ShaderRes
        AssetLoader --> TemplateReg
        AssetLoader --> TextureRegistry
    end

    subgraph Scripting["Scripting System"]
        ScriptEngine["Script Engine"]:::script
        ScriptReg["Script Registry"]:::script
        ScriptCtx["Scripting Context"]:::script
        GlobalScripts["Global Scripts"]:::script

        ScriptEngine --> ScriptReg
        ScriptEngine --> ScriptCtx
        ScriptCtx --> GlobalScripts
    end

    subgraph Rendering["Rendering System"]
        RenderBatch["Render Batch"]:::render
        RenderMesh["Render Mesh"]:::render
        Renderer["Main Renderer"]:::render

        Renderer --> RenderBatch
        RenderBatch --> RenderMesh
    end

    %% Core relationships
    Client --> Device
    Client --> UIRoot
    Client --> ScriptEngine

    %% Cross-system relationships
    UIRoot --> Renderer
    ScriptEngine --> EventSystem
    RenderPipeline --> Device
    ComponentFactory --> RenderMesh

    %% Resource relationships
    ShaderRes --> ShaderReg
    TemplateReg --> ComponentFactory
    TextureRegistry --> TextureMgr

    %% Click events
    click Client "https://github.com/wowserhq/client/blob/main/src/Client.ts"
    click Bootstrap "https://github.com/wowserhq/client/blob/main/src/index.ts"
    click WebGL2 "https://github.com/wowserhq/client/blob/main/src/gfx/apis/webgl2/WebGL2Device.ts"
    click WebGPU "https://github.com/wowserhq/client/blob/main/src/gfx/apis/webgpu/WebGPUDevice.ts"
    click Device "https://github.com/wowserhq/client/blob/main/src/gfx/Device.ts"
    click ShaderSys "https://github.com/wowserhq/client/blob/main/src/gfx/Shader.ts"
    click ShaderReg "https://github.com/wowserhq/client/blob/main/src/gfx/ShaderRegistry.ts"
    click TextureMgr "https://github.com/wowserhq/client/blob/main/src/gfx/Texture.ts"
    click TextureReg "https://github.com/wowserhq/client/blob/main/src/gfx/TextureRegistry.ts"
    click Screen "https://github.com/wowserhq/client/blob/main/src/gfx/Screen.ts"
    click ScreenLayer "https://github.com/wowserhq/client/blob/main/src/gfx/ScreenLayer.ts"
    click UIRoot "https://github.com/wowserhq/client/blob/main/src/ui/components/UIRoot.ts"
    click TemplateSystem "https://github.com/wowserhq/client/blob/main/src/ui/TemplateRegistry.ts"
    click RenderPipeline "https://github.com/wowserhq/client/blob/main/src/ui/rendering/Renderer.ts"
    click EventSystem "https://github.com/wowserhq/client/blob/main/src/ui/scripting/EventEmitter.ts"
    click ComponentFactory "https://github.com/wowserhq/client/blob/main/src/ui/components/FactoryRegistry.ts"
    click ShaderRes "https://github.com/wowserhq/client/tree/main/public/Shaders/"
    click ScriptEngine "https://github.com/wowserhq/client/blob/main/src/ui/scripting/Script.ts"
    click ScriptReg "https://github.com/wowserhq/client/blob/main/src/ui/scripting/ScriptRegistry.ts"
    click ScriptCtx "https://github.com/wowserhq/client/blob/main/src/ui/scripting/ScriptingContext.ts"
    click GlobalScripts "https://github.com/wowserhq/client/tree/main/src/ui/scripting/globals/"
    click RenderBatch "https://github.com/wowserhq/client/blob/main/src/ui/rendering/RenderBatch.ts"
    click RenderMesh "https://github.com/wowserhq/client/blob/main/src/ui/rendering/RenderMesh.ts"
    click Renderer "https://github.com/wowserhq/client/blob/main/src/ui/rendering/Renderer.ts"

    %% Styling
    classDef core fill:#a8d1f0
    classDef graphics fill:#90EE90
    classDef ui fill:#FFE5B4
    classDef resource fill:#DDA0DD
    classDef script fill:#FFB6C1
    classDef render fill:#98FB98
```
