# webdevcody/survive-the-night-game architecture

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

- Interactive diagram: https://gitdiagram.com/webdevcody/survive-the-night-game
- Repository: https://github.com/webdevcody/survive-the-night-game

## Overview

##### Main Components

A. Client-Side (packages/game-client)
- Game Engine Layer
- Renderer System
- Input Manager
- Camera Manager
- Asset Manager
- Sound Manager
- Client State Management
- UI Components
- HUD
- Inventory System
- Crafting Interface
- WebSocket Client Manager

B. Server-Side (packages/game-server)
- Game Server Core
- Entity Manager
- Manager
- Spatial Grid System
- Socket Manager
- Shared Components
- Entity System (ECS Architecture)
- Physics Engine
- Event System
- Recipe System

C. Dashboard (packages/dashboard)
- Next.js Frontend
- Administrative Interface

##### Relationship Flows to Illustrate

- Bidirectional communication between client and server via WebSocket
- Entity state synchronization flow
- Event propagation paths
- Player interaction flows
- Game state updates

##### Architectural Patterns to Highlight

A. Entity Component System (ECS)
- How entities (players, zombies, items) use extensions
- Relationship between shared entities and their client representations

B. Event-Driven Architecture
- Demonstrate the event flow system
- How server-sent events propagate

##### Specific Implementation Details

Create subsections showing:
- Entity Factory pattern implementation
- Extension system architecture
- Spatial partitioning system
- Game state synchronization mechanism

##### Technical Stack Elements

- TypeScript as the primary language
- WebSocket for real-time communication
- Next.js for dashboard
- HTML5 Canvas for game rendering
- Sound system architecture

**[Dashboard Layer (Next.js)]**
- ↕
**[Game Client Layer] ←→ [WebSocket Layer] ←→ [Game Server Layer]**
- ↓                                           ↓
**[Shared Components Layer (Entities, Events, Extensions)]**

##### Entity component system architecture

- Special indicators for critical systems

Keep the abstraction level high enough to show the overall architecture but detailed enough to illustrate the game's unique features like:
- The crafting system
- Zombie wave mechanics
- Player interaction systems
- World generation
- Base building mechanics

This will create a comprehensive visualization that accurately represents the game's architecture while maintaining clarity and usefulness for development purposes.

## Diagram (Mermaid)

```mermaid
graph TB
    %% Styles and Classes
    classDef client fill:#a8d1f0,stroke:#333
    classDef server fill:#90EE90,stroke:#333
    classDef shared fill:#FFE5B4,stroke:#333
    classDef dashboard fill:#DDA0DD,stroke:#333
    classDef critical fill:#FFB6C1,stroke:#333

    %% Dashboard Layer
    subgraph Dashboard
        DashFE["Dashboard Frontend"]
    end

    %% Client Layer
    subgraph GameClient["Game Client Layer"]
        GE["Game Engine/Renderer"]
        
        subgraph Managers["Client Managers"]
            IM["Input Manager"]
            CM["Camera Manager"]
            AM["Asset Manager"]
            SM["Sound Manager"]
            CSM["WebSocket Client Manager"]:::critical
        end
        
        subgraph ClientState["State & UI"]
            StateM["Client State Management"]
            UI["UI Components"]
            INV["Inventory System"]
            CRAFT["Crafting Interface"]
        end
        
        EF["Entity Factory"]
    end

    %% Server Layer
    subgraph GameServer["Game Server Layer"]
        subgraph ServerCore["Server Core"]
            EM["Entity Manager"]:::critical
            MM["Map Manager"]
            SG["Spatial Grid System"]
            SSM["Server Socket Manager"]:::critical
        end
    end

    %% Shared Components Layer
    subgraph SharedComponents["Shared Components"]
        ES["Entity System"]
        PE["Physics Engine"]
        EVS["Event System"]
        RS["Recipe System"]
        EXT["Extension System"]
    end

    %% Relationships
    DashFE --> SSM
    CSM <--> SSM
    GE --> StateM
    IM --> StateM
    CM --> StateM
    AM --> GE
    SM --> StateM
    UI --> StateM
    INV --> StateM
    CRAFT --> StateM
    EF --> StateM
    EM --> ES
    MM --> SG
    SSM --> EM
    ES --> PE
    ES --> EVS
    RS --> ES
    EXT --> ES

    %% Click Events
    click GE "https://github.com/webdevcody/survive-the-night-game/blob/main/packages/game-client/src/renderer.ts"
    click IM "https://github.com/webdevcody/survive-the-night-game/blob/main/packages/game-client/src/managers/input.ts"
    click CM "https://github.com/webdevcody/survive-the-night-game/blob/main/packages/game-client/src/managers/camera.ts"
    click AM "https://github.com/webdevcody/survive-the-night-game/blob/main/packages/game-client/src/managers/asset.ts"
    click SM "https://github.com/webdevcody/survive-the-night-game/blob/main/packages/game-client/src/managers/sound-manager.ts"
    click StateM "https://github.com/webdevcody/survive-the-night-game/blob/main/packages/game-client/src/state.ts"
    click CSM "https://github.com/webdevcody/survive-the-night-game/blob/main/packages/game-client/src/managers/client-socket-manager.ts"
    click UI "https://github.com/webdevcody/survive-the-night-game/tree/main/packages/game-client/src/ui/"
    click EM "https://github.com/webdevcody/survive-the-night-game/blob/main/packages/game-server/src/managers/entity-manager.ts"
    click MM "https://github.com/webdevcody/survive-the-night-game/blob/main/packages/game-server/src/managers/map-manager.ts"
    click SG "https://github.com/webdevcody/survive-the-night-game/blob/main/packages/game-server/src/managers/spatial-grid.ts"
    click SSM "https://github.com/webdevcody/survive-the-night-game/blob/main/packages/game-server/src/managers/server-socket-manager.ts"
    click ES "https://github.com/webdevcody/survive-the-night-game/tree/main/packages/game-server/src/shared/entities/"
    click PE "https://github.com/webdevcody/survive-the-night-game/blob/main/packages/game-server/src/shared/physics.ts"
    click EVS "https://github.com/webdevcody/survive-the-night-game/tree/main/packages/game-server/src/shared/events/"
    click RS "https://github.com/webdevcody/survive-the-night-game/tree/main/packages/game-server/src/shared/recipes/"
    click DashFE "https://github.com/webdevcody/survive-the-night-game/tree/main/packages/dashboard/src/app/"
    click EF "https://github.com/webdevcody/survive-the-night-game/blob/main/packages/game-client/src/entities/entity-factory.ts"
    click EXT "https://github.com/webdevcody/survive-the-night-game/tree/main/packages/game-server/src/shared/extensions/"
    click INV "https://github.com/webdevcody/survive-the-night-game/blob/main/packages/game-client/src/ui/inventory-bar.ts"
    click CRAFT "https://github.com/webdevcody/survive-the-night-game/blob/main/packages/game-client/src/ui/crafting-table.ts"

    %% Style Applications
    class GE,IM,CM,AM,SM,CSM,StateM,UI,INV,CRAFT,EF client
    class EM,MM,SG,SSM server
    class ES,PE,EVS,RS,EXT shared
    class DashFE dashboard
```
