# kennycha/phy-topster architecture

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

- Interactive diagram: https://gitdiagram.com/kennycha/phy-topster
- Repository: https://github.com/kennycha/phy-topster

## Overview

##### Main Components

a. Client-Side Application Structure:
- Rendering Engine (Three.js)
- Physics Engine (Cannon-es)
- Core Components
- State Management
- Asset Management

##### Detailed Component Breakdown

Core Components Layer:
- With the physics and rendering engines
- Relationship to shader systems (vertex.glsl and fragment.glsl)

Asset Management:
- Connection to public/assets directory

State Management:
- Observer pattern implementation
- How it connects to core components

**[Browser Environment]**
- ↓
**[Vite Development Server]**
- ↓
**[Application Entry (main.ts)]**

**[Three.js Renderer] ←→ [Cannon-es Physics]**
- ↓
**[Core Components]**

**[Asset Management] → [State Management]**

##### Important Details to Capture

- How the shader system (vertex.glsl and fragment.glsl) integrates with Three.js
- Relationship between physics objects and their visual representations
- Demonstrate how the observer pattern manages state changes
- Asset loading pipeline from public directory to runtime usage

##### Technical Stack Representation

**[TypeScript]**
**[Three.js / Cannon-es]**
**[WebGL]**
**[Browser Runtime]**

##### Development Tooling (Secondary Layer)
- Vite's role in development
- TypeScript compilation process
- Demonstrate GitHub Pages deployment flow

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Browser
        ViteServer["Vite Dev Server"]:::devtools
        WebGL["WebGL Context"]:::runtime
    end

    subgraph Application
        Main["Main Entry Point"]:::core
        ThreeJS["Three.js Renderer"]:::external
        CannonES["Cannon-es Physics"]:::external
        
        subgraph CoreComponents["Core Components"]
            Cd["CD Component"]:::core
            FakeCd["Fake CD"]:::core
            Ground["Ground"]:::core
            MyObject["My Object"]:::core
            Topster["Topster"]:::core
        end

        subgraph ShaderSystem["Shader System"]
            VertexShader["Vertex Shader"]:::shader
            FragmentShader["Fragment Shader"]:::shader
        end

        subgraph AssetManagement["Asset Management"]
            TextureLoader["Texture Loader"]:::asset
            AssetsDir["Assets Directory"]:::asset
            IconsDir["Icons Storage"]:::asset
            TexturesDir["Textures Storage"]:::asset
        end

        subgraph StateManagement["State Management"]
            Observer["Observer Pattern"]:::state
        end

        subgraph Config["Configuration"]
            ViteConfig["Vite Config"]:::config
            TSConfig["TypeScript Config"]:::config
            GHPages["GitHub Pages Deploy"]:::config
        end
    end

    Main --> ThreeJS
    Main --> CannonES
    ThreeJS <--> CannonES
    
    CoreComponents --> ThreeJS
    CoreComponents --> CannonES
    
    ShaderSystem --> ThreeJS
    
    AssetManagement --> CoreComponents
    Observer --> CoreComponents
    
    ViteServer --> Main
    WebGL --> ThreeJS

    %% Click Events
    click Main "https://github.com/kennycha/phy-topster/blob/main/src/main.ts"
    click Cd "https://github.com/kennycha/phy-topster/blob/main/src/core/Cd.ts"
    click FakeCd "https://github.com/kennycha/phy-topster/blob/main/src/core/FakeCd.ts"
    click Ground "https://github.com/kennycha/phy-topster/blob/main/src/core/Ground.ts"
    click MyObject "https://github.com/kennycha/phy-topster/blob/main/src/core/MyObject.ts"
    click Topster "https://github.com/kennycha/phy-topster/blob/main/src/core/Topster.ts"
    click VertexShader "https://github.com/kennycha/phy-topster/blob/main/src/core/shaders/vertex.glsl"
    click FragmentShader "https://github.com/kennycha/phy-topster/blob/main/src/core/shaders/fragment.glsl"
    click TextureLoader "https://github.com/kennycha/phy-topster/blob/main/src/core/loaders/textureLoader.ts"
    click AssetsDir "https://github.com/kennycha/phy-topster/tree/main/public/assets"
    click IconsDir "https://github.com/kennycha/phy-topster/tree/main/public/assets/icons"
    click TexturesDir "https://github.com/kennycha/phy-topster/tree/main/public/assets/textures"
    click Observer "https://github.com/kennycha/phy-topster/blob/main/src/state/observer.ts"
    click ViteConfig "https://github.com/kennycha/phy-topster/blob/main/vite.config.ts"
    click TSConfig "https://github.com/kennycha/phy-topster/blob/main/tsconfig.json"
    click GHPages "https://github.com/kennycha/phy-topster/blob/main/.github/workflows/githubpages.yml"

    %% Styles
    classDef core fill:#3498db,stroke:#2980b9,color:white
    classDef external fill:#2ecc71,stroke:#27ae60,color:white
    classDef shader fill:#e67e22,stroke:#d35400,color:white
    classDef asset fill:#f1c40f,stroke:#f39c12,color:black
    classDef state fill:#9b59b6,stroke:#8e44ad,color:white
    classDef config fill:#95a5a6,stroke:#7f8c8d,color:white
    classDef runtime fill:#e74c3c,stroke:#c0392b,color:white
    classDef devtools fill:#1abc9c,stroke:#16a085,color:white
```
