# ptlc8/physics-custom-vehicles architecture

> Architecture diagram of the GitHub repository ptlc8/physics-custom-vehicles, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-02-07). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/ptlc8/physics-custom-vehicles
- Repository: https://github.com/ptlc8/physics-custom-vehicles

## Overview

##### Main Components

A. Client-Side (Frontend):
- HTML5 Canvas Layer (for rendering)
- Box2D Physics Engine (WASM implementation)
- Game Logic Components:
- Vehicle Construction System
- Physics Simulation Interface
- User Interface
- Client-side Assets

B. Server-Side (Backend):
- Node.js Server
- Game State Management
- Physics Synchronization
- Multiplayer Coordination (if present)

**[Client Layer]**
- ↕
**[Server Layer]**
- ↕
**[Physics Engine]**

##### Component Details

A. Client Components (Top):
- [Browser]
- ↓
- [HTML5 Canvas] ← [Static Assets]
- ↓
- [Box2D WASM] ← [Physics Simulation]
- ↓
- [Game Logic] → [Vehicle Editor]

B. Server Components (Middle):
- [Node.js Server]
- ↓
- [Game State Manager]
- ↓
- [Physics Synchronization]

C. Shared Components:
- Box2D Physics Engine (shown spanning both client and server)
- Game State (shared between client and server)

##### Key Elements to Highlight

- Box2D WASM integration (crucial for physics)
- Client-server communication path
- Game state flow
- Physics calculation pipeline
- Asset loading pipeline

##### Specific Implementation Details

- The separation between client (/static) and server (root) code
- The physics engine implementation (Box2D WASM)
- The game logic components (scripts directory)
- The asset management system

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph Client
        Browser["Web Browser"]
        Canvas["HTML5 Canvas"]:::canvas
        ClientAssets["Static Assets"]:::assets
        ClientPhysics["Box2D WASM"]:::physics
        GameLogic["Game Logic"]:::gamelogic
        VehicleEditor["Vehicle Editor"]:::editor
        AudioEngine["Audio Engine"]:::audio
        ClientInterface["Client Interface"]:::client
    end

    subgraph Server
        NodeServer["Node.js Server"]:::server
        GameServer["Game Server"]:::server
        GameState["Game State Manager"]:::state
        PhysicsSync["Physics Synchronization"]:::physics
        ServerConfig["Server Configuration"]:::config
    end

    subgraph GameComponents
        PlayerMgmt["Player Management"]:::component
        GameModes["Game Modes"]:::component
        MapSystem["Map System"]:::component
        GroundSystem["Ground System"]:::component
        WorldPhysics["World Physics"]:::physics
        PhysicsItems["Physics Items"]:::physics
    end

    Browser --> Canvas
    Canvas --> ClientPhysics
    ClientAssets --> Canvas
    ClientPhysics --> GameLogic
    GameLogic --> VehicleEditor
    AudioEngine --> GameLogic
    ClientInterface --> GameLogic

    NodeServer --> GameServer
    GameServer --> GameState
    GameState --> PhysicsSync
    ServerConfig --> NodeServer

    GameState --> GameComponents
    PhysicsSync --> WorldPhysics
    WorldPhysics --> PhysicsItems

    GameComponents --> GameLogic

    %% Click Events
    click Canvas "https://github.com/ptlc8/physics-custom-vehicles/blob/master/static/index.html"
    click ClientPhysics "https://github.com/ptlc8/physics-custom-vehicles/blob/master/static/Box2D.wasm"
    click NodeServer "https://github.com/ptlc8/physics-custom-vehicles/blob/master/server.js"
    click GameServer "https://github.com/ptlc8/physics-custom-vehicles/blob/master/pcvServer.js"
    click ServerConfig "https://github.com/ptlc8/physics-custom-vehicles/blob/master/ecosystem.config.js"
    click GameLogic "https://github.com/ptlc8/physics-custom-vehicles/blob/master/scripts/game.js"
    click PlayerMgmt "https://github.com/ptlc8/physics-custom-vehicles/blob/master/scripts/player.js"
    click GameModes "https://github.com/ptlc8/physics-custom-vehicles/blob/master/scripts/gamemodes.js"
    click MapSystem "https://github.com/ptlc8/physics-custom-vehicles/blob/master/scripts/map.js"
    click GroundSystem "https://github.com/ptlc8/physics-custom-vehicles/blob/master/scripts/ground.js"
    click WorldPhysics "https://github.com/ptlc8/physics-custom-vehicles/blob/master/scripts/physics/world.js"
    click PhysicsItems "https://github.com/ptlc8/physics-custom-vehicles/blob/master/scripts/physics/items.js"
    click ClientInterface "https://github.com/ptlc8/physics-custom-vehicles/blob/master/static/scripts/client.js"
    click AudioEngine "https://github.com/ptlc8/physics-custom-vehicles/blob/master/static/scripts/ambiengine.js"
    click ClientAssets "https://github.com/ptlc8/physics-custom-vehicles/tree/master/static/assets"

    %% Styles
    classDef canvas fill:#9cf,stroke:#333
    classDef assets fill:#ddd,stroke:#333
    classDef physics fill:#ff9,stroke:#333
    classDef gamelogic fill:#9fc,stroke:#333
    classDef editor fill:#f9c,stroke:#333
    classDef audio fill:#c9f,stroke:#333
    classDef client fill:#9cf,stroke:#333
    classDef server fill:#6c6,stroke:#333
    classDef state fill:#fc9,stroke:#333
    classDef config fill:#ccc,stroke:#333
    classDef component fill:#9cf,stroke:#333
```
