# harshdeep61034/chitkaraverse architecture

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

- Interactive diagram: https://gitdiagram.com/harshdeep61034/chitkaraverse
- Repository: https://github.com/harshdeep61034/chitkaraverse

## Overview

##### Project Type and Purpose
- The project is a web-based virtual multiplayer metaverse, named “ChitkaraVerse,” built primarily with the Phaser game engine.
- Its core functionalities include interactive game UI, real-time multiplayer interactions, and WebRTC integration for one-to-one voice or video calls.
- The project is organized into two main parts: the Game UI (frontend) that handles game rendering and user interactions, and the ws-server (backend) that manages real-time communications.

##### Analyzing the File Structure
- Game-UI Directory:
- Contains HTML, TypeScript/TSX source files, CSS and configuration files (e.g., tailwind.config.js, vite configurations, tsconfig).
- The “src” folder breaks down into components (like the PhaserGame.tsx component), scenes (e.g., Boot.ts, Game.ts, Preloader.ts, GameOver.ts), pages, providers, and utility libraries (EventBus and socket implementations). This indicates a component-based architecture likely governing the various UI states and game scenes.
- Assets (images, tile sets, player sprites) in “public/assets” show emphasis on game-related graphics.
- ws-server Directory:
- Contains a minimal server implementation written in TypeScript (src/index.ts) and configuration files. Its primary role is to manage websocket connections for game state and messaging.

- Main Components:
- Game Client/Frontend:
▪ Built with React TypeScript (components in src/, pages, providers).
▪ Integrates the Phaser game engine through components such as PhaserGame.tsx.
▪ Manages game scenes and transitions (e.g., Boot, Preloader, Game, GameOver).
▪ Uses utility modules (EventBus.ts, socket.ts) for event handling and communications.
▪ Displays assets (dungeon tilesets, player sprites) hosted in the public directory.
- Websocket Server (ws-server):
▪ Acts as the backend communication hub, handling real-time data exchange and multiplayer interactivity.
- (Optional) WebRTC Module:

- Relationships & Data Flow:
- The Game Client communicates with the ws-server over WebSockets as indicated by references in the src/lib/socket.ts.
- Internal communication between game scenes and UI components is managed by the EventBus.
- External assets and configurations are loaded from the public folder during initialization.
- WebRTC functionalities (for user-to-user calls) integrate with the game network flow, indicating an additional module on top of the standard client-server data exchange.

##### Important Architectural Patterns and Design Principles
- A modular component-based architecture on the frontend. The source layout (components, pages, scenes) indicates a separation of concerns.
- Use of an event-driven mechanism (via the EventBus) for inter-component communication.
- For the backend, note the separation of the WebSocket server as a dedicated, potentially single-responsibility component managing connections.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Game UI Client Section
    subgraph "Game UI Client"
        %% UI Framework & Entry Point
        subgraph "UI Framework & Entry Point"
            UI1["index.html"]:::frontend
            UI2["main.tsx"]:::frontend
            UI3["App.tsx"]:::frontend
        end
        
        %% Pages & Providers
        subgraph "Pages & Providers"
            PP1["Pages"]:::frontend
            PP2["contextProvider.tsx"]:::frontend
        end
        
        %% Phaser Game Engine Integration
        subgraph "Phaser Game Integration"
            PG["PhaserGame.tsx"]:::gameengine
            subgraph "Scenes"
                S1["Boot.ts"]:::scenes
                S2["Preloader.ts"]:::scenes
                S3["Game.ts"]:::scenes
                S4["GameOver.ts"]:::scenes
            end
        end
        
        %% Utility Libraries
        subgraph "Utility Libraries"
            U1["EventBus.ts"]:::utils
            U2["socket.ts"]:::utils
        end
        
        %% Asset Management
        AM["Assets"]:::assets
        
        %% WebRTC Module
        RTC["WebRTC Module"]:::webrtc
    end

    %% Websocket Server / Backend Section
    subgraph "Websocket Server / Backend"
        WS["Server Implementation"]:::backend
    end

    %% Data Flow Connections
    UI3 -->|"routes"| PP1
    PP1 -->|"triggers_game"| PG
    AM -->|"asset_load"| PG
    U1 -->|"broadcasts_events"| PG
    U2 -->|"websocket_comm"| WS
    RTC -->|"webrtc_signalling"| WS
    PG -->|"manages"| S1
    PG -->|"manages"| S2
    PG -->|"manages"| S3
    PG -->|"manages"| S4

    %% Styles
    classDef frontend fill:#cce5ff,stroke:#0b5394,stroke-width:2px;
    classDef gameengine fill:#ffebcc,stroke:#e69138,stroke-width:2px;
    classDef scenes fill:#d9ead3,stroke:#6aa84f,stroke-width:2px;
    classDef utils fill:#fff2cc,stroke:#f1c232,stroke-width:2px;
    classDef assets fill:#d0e0e3,stroke:#3d85c6,stroke-width:2px;
    classDef webrtc fill:#f4cccc,stroke:#cc0000,stroke-width:2px;
    classDef backend fill:#e6e6e6,stroke:#999999,stroke-width:2px;

    %% Click Events
    click UI1 "https://github.com/harshdeep61034/chitkaraverse/blob/main/Game-UI/index.html"
    click UI2 "https://github.com/harshdeep61034/chitkaraverse/blob/main/Game-UI/src/main.tsx"
    click UI3 "https://github.com/harshdeep61034/chitkaraverse/blob/main/Game-UI/src/App.tsx"
    click PG "https://github.com/harshdeep61034/chitkaraverse/blob/main/Game-UI/src/components/PhaserGame.tsx"
    click S1 "https://github.com/harshdeep61034/chitkaraverse/blob/main/Game-UI/src/scenes/Boot.ts"
    click S2 "https://github.com/harshdeep61034/chitkaraverse/blob/main/Game-UI/src/scenes/Preloader.ts"
    click S3 "https://github.com/harshdeep61034/chitkaraverse/blob/main/Game-UI/src/scenes/Game.ts"
    click S4 "https://github.com/harshdeep61034/chitkaraverse/blob/main/Game-UI/src/scenes/GameOver.ts"
    click U1 "https://github.com/harshdeep61034/chitkaraverse/blob/main/Game-UI/src/lib/EventBus.ts"
    click U2 "https://github.com/harshdeep61034/chitkaraverse/blob/main/Game-UI/src/lib/socket.ts"
    click PP1 "https://github.com/harshdeep61034/chitkaraverse/tree/main/Game-UI/src/pages"
    click PP2 "https://github.com/harshdeep61034/chitkaraverse/blob/main/Game-UI/src/providers/contextProvider.tsx"
    click AM "https://github.com/harshdeep61034/chitkaraverse/tree/main/Game-UI/public/assets"
    click WS "https://github.com/harshdeep61034/chitkaraverse/blob/main/ws-server/src/index.ts"
```
