# wxyz-abcd/node-haxball architecture

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

- Interactive diagram: https://gitdiagram.com/wxyz-abcd/node-haxball
- Repository: https://github.com/wxyz-abcd/node-haxball

## Overview

##### Core API Layer
- Main API object containing all exported components
- Enums (OperationType, VariableType, etc.)
- Core utility classes (Utils, EventFactory)

##### Room Management Layer
- Room class as the central component
- Connection handling (WebSocket/WebRTC)
- State management
- Event system

##### Extension System
- Plugin system
- Renderer system
- Library system
- Language system
- RoomConfig system

##### Implementation Layer
- Core physics engine components
- Stream handling (Reader/Writer)
- Network protocol implementation

##### Environment Integration
- Browser integration
- Node.js integration
- Proxy server communication

**[Client Applications]**
- ↑↓
**[Environment Layer]**
- Browser  ←→  Node.js
- ↑↓
**[API Interface Layer]**
- Exported Components
- Enums & Constants
- ↑↓
**[Core Services Layer]**
- Room Management  →  Event System
- ↑↓              ↑↓
- State Management ←→ Physics Engine
- ↑↓
**[Extension Layer]**
- Plugins ←→ Libraries
- ↑↓        ↑↓
- Renderer ←→ RoomConfig
- ↑↓
**[Implementation Layer]**
- Network Protocol
- Stream Handling
- ↑↓
**[External Services]**
- WebSocket/WebRTC
- Proxy Server

Design Guidelines:

- Blue for core API components
- Green for extension systems
- Orange for implementation details
- Gray for external services

- Double lines for primary data paths

##### Important notes
- Version compatibility
- Environment requirements
- Key configuration options

##### Integration with external services

This will provide a clear understanding of:
- How different components interact
- Where custom code can be integrated
- How data flows through the system
- Where potential bottlenecks might occur
- How the system scales and extends

## Diagram (Mermaid)

```mermaid
graph TB
    %% Styles
    classDef api fill:#a8d1f0,stroke:#333
    classDef room fill:#90ee90,stroke:#333
    classDef extension fill:#ffd700,stroke:#333
    classDef implementation fill:#ffa07a,stroke:#333
    classDef external fill:#d3d3d3,stroke:#333
    
    %% Client Applications Layer
    ClientApps["Client Applications"]:::external
    
    %% Environment Layer
    subgraph EnvLayer["Environment Layer"]
        Browser["Browser Integration"]:::api
        NodeJS["Node.js Integration"]:::api
    end
    
    %% API Interface Layer
    subgraph APILayer["API Interface Layer"]
        MainAPI["Main API"]:::api
        TypeDefs["Type Definitions"]:::api
        CommonImpl["Common Implementation"]:::api
    end
    
    %% Core Services Layer
    subgraph CoreLayer["Core Services Layer"]
        RoomMgmt["Room Management"]:::room
        EventSystem["Event System"]:::room
        StateMgmt["State Management"]:::room
        PhysicsEngine["Physics Engine"]:::implementation
    end
    
    %% Extension Layer
    subgraph ExtLayer["Extension Layer"]
        PluginSystem["Plugin System"]:::extension
        LibSystem["Library System"]:::extension
        RenderSystem["Renderer System"]:::extension
        RoomConfig["RoomConfig System"]:::extension
        LangSystem["Language System"]:::extension
    end
    
    %% Implementation Layer
    subgraph ImplLayer["Implementation Layer"]
        NetworkProto["Network Protocol"]:::implementation
        StreamHandler["Stream Handling"]:::implementation
        ReplaySystem["Replay System"]:::implementation
    end
    
    %% External Services Layer
    subgraph ExtServices["External Services"]
        WebRTC["WebSocket/WebRTC"]:::external
        ProxyServer["Proxy Server"]:::external
        TokenGen["Token Generator"]:::external
    end
    
    %% Testing Layer
    subgraph TestLayer["Testing & Validation"]
        UnitTests["Unit Tests"]:::implementation
        BrowserTests["Browser Tests"]:::implementation
        NodeTests["Node Tests"]:::implementation
    end
    
    %% Relationships
    ClientApps <--> EnvLayer
    Browser <--> NodeJS
    EnvLayer <--> APILayer
    APILayer <--> CoreLayer
    CoreLayer <--> ExtLayer
    CoreLayer <--> ImplLayer
    ImplLayer <--> ExtServices
    CoreLayer <--> TestLayer
    
    RoomMgmt <--> EventSystem
    StateMgmt <--> PhysicsEngine
    PluginSystem <--> LibSystem
    RenderSystem <--> RoomConfig
    
    %% Click Events
    click MainAPI "https://github.com/wxyz-abcd/node-haxball/blob/main/src/api.js"
    click TypeDefs "https://github.com/wxyz-abcd/node-haxball/blob/main/src/index.d.ts"
    click CommonImpl "https://github.com/wxyz-abcd/node-haxball/blob/main/src/indexCommon.js"
    click RoomMgmt "https://github.com/wxyz-abcd/node-haxball/blob/main/examples_web/src/room.js"
    click RoomConfig "https://github.com/wxyz-abcd/node-haxball/tree/main/examples/roomConfigs/"
    click PluginSystem "https://github.com/wxyz-abcd/node-haxball/tree/main/examples/plugins/"
    click RenderSystem "https://github.com/wxyz-abcd/node-haxball/tree/main/examples/renderers/"
    click LibSystem "https://github.com/wxyz-abcd/node-haxball/tree/main/examples/libraries/"
    click LangSystem "https://github.com/wxyz-abcd/node-haxball/tree/main/examples/languages/"
    click StreamHandler "https://github.com/wxyz-abcd/node-haxball/blob/main/examples_web/src/streamWatcher.js"
    click ReplaySystem "https://github.com/wxyz-abcd/node-haxball/blob/main/examples_web/src/replayViewer.js"
    click Browser "https://github.com/wxyz-abcd/node-haxball/tree/main/examples_web/src/"
    click NodeJS "https://github.com/wxyz-abcd/node-haxball/blob/main/src/index.js"
    click ProxyServer "https://github.com/wxyz-abcd/node-haxball/blob/main/streamingServer/src/index.js"
    click TokenGen "https://github.com/wxyz-abcd/node-haxball/tree/main/tokenGenerator/src/"
    click UnitTests "https://github.com/wxyz-abcd/node-haxball/blob/main/unit_tests/test.js"
    click BrowserTests "https://github.com/wxyz-abcd/node-haxball/blob/main/unit_tests/test_browser.html"
    click NodeTests "https://github.com/wxyz-abcd/node-haxball/blob/main/unit_tests/test_node.js"
```
