# hozngvan/endlessrunnergame architecture

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

- Interactive diagram: https://gitdiagram.com/hozngvan/endlessrunnergame
- Repository: https://github.com/hozngvan/endlessrunnergame

## Overview

##### Project type and purpose
- This is a browser-based endless runner game written in JavaScript and delivered as a single-page front-end application. The game logic lives entirely in the client, leveraging an HTML5 canvas or WebGL context (via index.html) and a set of JS modules under the js/ directory. Textures and other assets live in the textures/ folder.

##### File structure
- index.html
- Entry point: declares the canvas, includes your bundled or individual JS files
- js/
- main.js: game initialization, asset loading, start of the game loop
- game.js: orchestrates the game loop (update, render)
- world.js: world‐building logic, ground tiling, environment generation
- obstacleManager.js: generates, spawns and recycles obstacles
- player.js: handles player state, input and collision checks
- ui.js: draws on‐screen UI (score, game over, menus)
- textures/: PNGs, JPEGs, material definitions, USD composer files for your 3D/texturing pipeline

##### Information from the README
- Title “Endless Runner Game” confirms the front-end game nature. No additional architecture notes provided.

a. Main components
- Browser / Canvas Context
- Asset Loader
- Game Loop Manager (game.js)
- World Manager (world.js)
- Obstacle Manager (obstacleManager.js)
- Player Controller (player.js)
- UI Manager (ui.js)
- Renderer
- External textures & material assets

b. Relationships & data flow
1. index.html → loads main.js
2. main.js → Asset Loader → loads textures into GPU
3. main.js → instantiates Game Loop Manager
4. Game Loop Manager each tick:
– reads user Input → Player Controller → updates player state
– invokes World Manager → extends ground, recycles old tiles
– invokes Obstacle Manager → spawns/moves obstacles, checks collisions
– invokes UI Manager → updates score, displays status
– sends updated scene graph to Renderer → draws frame to Canvas
5. Texture files → consumed by Asset Loader → provided to Renderer

c. Architectural patterns & design principles
- Modular single-page architecture: each JS file encapsulates a core subsystem
- Central game loop dispatching update & render calls (typical game-engine pattern)
- Separation of concerns: world generation, obstacle handling, player logic, UI rendering

d. Key technologies
- Vanilla JavaScript (ES6 modules or namespaces)
- HTML5 Canvas or WebGL context in index.html
- Asset format: JPG, USD Composer (.usdc), MaterialX (.mtlx)
- (Optional) Build tool (webpack/parcel) as indicated by package.json

##### Recommendation
- Be precise in naming each module exactly as in the js/ directory
- Textures folder as an external asset source feeding into the Asset Loader

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Browser / Canvas"
        Browser["Browser / Canvas Context"]:::external
        Canvas["Canvas / WebGL Context"]:::asset
        AssetLoader["Asset Loader (main.js)"]:::asset
        GameLoop["Game Loop Manager (game.js)"]:::core
        WorldManager["World Manager (world.js)"]:::core
        ObstacleManager["Obstacle Manager (obstacleManager.js)"]:::core
        PlayerController["Player Controller (player.js)"]:::core
        UIManager["UI Manager (ui.js)"]:::ui
        Renderer["Renderer"]:::asset
    end

    ExternalTextures["External Textures & Assets"]:::external

    Browser -->|"loads index.html"| AssetLoader
    AssetLoader -->|"loadTexture()"| ExternalTextures
    AssetLoader -->|"instantiates"| GameLoop

    GameLoop -->|"tick() triggers"| PlayerController
    GameLoop -->|"tick() triggers"| WorldManager
    GameLoop -->|"tick() triggers"| ObstacleManager
    GameLoop -->|"tick() triggers"| UIManager
    GameLoop -->|"tick() triggers render()"| Renderer

    Renderer -->|"draw() to canvas"| Canvas

    PlayerController -->|"update state"| GameLoop
    WorldManager -->|"update world"| GameLoop
    ObstacleManager -->|"collision checks"| GameLoop
    UIManager -->|"update UI"| GameLoop

    click Browser "https://github.com/hozngvan/endlessrunnergame/blob/master/index.html"
    click AssetLoader "https://github.com/hozngvan/endlessrunnergame/blob/master/js/main.js"
    click GameLoop "https://github.com/hozngvan/endlessrunnergame/blob/master/js/game.js"
    click WorldManager "https://github.com/hozngvan/endlessrunnergame/blob/master/js/world.js"
    click ObstacleManager "https://github.com/hozngvan/endlessrunnergame/blob/master/js/obstacleManager.js"
    click PlayerController "https://github.com/hozngvan/endlessrunnergame/blob/master/js/player.js"
    click UIManager "https://github.com/hozngvan/endlessrunnergame/blob/master/js/ui.js"
    click Renderer "https://github.com/hozngvan/endlessrunnergame/blob/master/js/game.js"
    click ExternalTextures "https://github.com/hozngvan/endlessrunnergame/tree/master/textures/"

    classDef core fill:#cfe2ff,stroke:#333,stroke-width:1px;
    classDef ui fill:#d9ead3,stroke:#333,stroke-width:1px;
    classDef asset fill:#ffe599,stroke:#333,stroke-width:1px;
    classDef external fill:#f0f0f0,stroke:#333,stroke-width:1px;
```
