# txuna/ping_pong architecture

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

- Interactive diagram: https://gitdiagram.com/txuna/ping_pong
- Repository: https://github.com/txuna/ping_pong

## Overview

##### Main Components

A. Client-Side (Ping_Client):
- Title Scene (Authentication/Connection)
- Room Management System
- World/Game Scene
- Network Communication Layer
- Player Management System

B. Server-Side (Ping_Server):
- Network Handler
- Player Management System
- Room Management System
- World Management System
- Game State Synchronization

**[Client Layer]**
- ↕
**[Network Layer]**
- ↕
**[Server Layer]**

##### Detailed Component Breakdown

Client Layer should show:
- Title Scene (Entry point)
- Room Management
- World Scene (Game logic)
- Player Instance
- Network Communication

Server Layer should show:
- Player Manager
- Room Manager
- World Manager
- Global State Management

##### Connection and Data Flow

→ Regular data flow
⇢ RPC (Remote Procedure Calls)
⇄ Bi-directional communication

##### Key Interactions to Highlight

a) Connection Flow:
**Title Scene → Network → Server Authentication → Player Registration**

b) Room Management Flow:
**Client Room Manager ⇄ Server Room Manager**

c) Game State Synchronization:
**Client World → Server World → Other Clients (0.03s intervals)**

##### Implementation Details

- Component name
- Key methods/functions
- State management
- Communication protocols

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph Client
        Title["Title Scene"]:::client
        RoomMgmtC["Room Management"]:::client
        WorldC["World Scene"]:::client
        PlayerMgmtC["Player Management"]:::client
        NetworkC["Network Layer"]:::client
        GlobalC["Global State"]:::client
        PlayerEntity["Player Entity"]:::client
        
        Title --> RoomMgmtC
        RoomMgmtC --> WorldC
        WorldC --> PlayerEntity
        PlayerMgmtC --> PlayerEntity
        NetworkC --> Title
        NetworkC --> RoomMgmtC
        NetworkC --> WorldC
        GlobalC --> Title
        GlobalC --> RoomMgmtC
        GlobalC --> WorldC
    end

    subgraph Server
        ServerMain["Server Main Handler"]:::server
        NetworkS["Network Handler"]:::server
        RoomMgmtS["Room Management"]:::server
        WorldMgmtS["World Management"]:::server
        PlayerMgmtS["Player Management"]:::server
        GlobalS["Global State"]:::server
        WorldInstance["World Instance"]:::server
        
        ServerMain --> NetworkS
        NetworkS --> RoomMgmtS
        NetworkS --> WorldMgmtS
        NetworkS --> PlayerMgmtS
        GlobalS --> RoomMgmtS
        GlobalS --> WorldMgmtS
        GlobalS --> PlayerMgmtS
        WorldMgmtS --> WorldInstance
    end

    %% Network Communications
    NetworkC <--> |"RPC Calls"| NetworkS
    WorldC <--> |"State Sync\n(0.03s)"| WorldInstance
    RoomMgmtC <--> |"Room State"| RoomMgmtS
    PlayerEntity <--> |"Position Updates"| PlayerMgmtS

    %% Styling
    classDef client fill:#3498db,stroke:#2980b9,color:white
    classDef server fill:#2ecc71,stroke:#27ae60,color:white
    
    %% Click Events
    click Title "https://github.com/txuna/ping_pong/blob/main/Ping_Client/Title.tscn"
    click RoomMgmtC "https://github.com/txuna/ping_pong/blob/main/Ping_Client/RoomManager.tscn"
    click WorldC "https://github.com/txuna/ping_pong/blob/main/Ping_Client/World.tscn"
    click PlayerMgmtC "https://github.com/txuna/ping_pong/blob/main/Ping_Client/PlayerManager.tscn"
    click NetworkC "https://github.com/txuna/ping_pong/blob/main/Ping_Client/Network.gd"
    click GlobalC "https://github.com/txuna/ping_pong/blob/main/Ping_Client/Global.gd"
    click PlayerEntity "https://github.com/txuna/ping_pong/blob/main/Ping_Client/Player.tscn"
    click ServerMain "https://github.com/txuna/ping_pong/blob/main/Ping_Server/Server.tscn"
    click NetworkS "https://github.com/txuna/ping_pong/blob/main/Ping_Server/Network.gd"
    click RoomMgmtS "https://github.com/txuna/ping_pong/blob/main/Ping_Server/RoomManager.tscn"
    click WorldMgmtS "https://github.com/txuna/ping_pong/blob/main/Ping_Server/WorldManager.tscn"
    click PlayerMgmtS "https://github.com/txuna/ping_pong/blob/main/Ping_Server/PlayerManager.tscn"
    click GlobalS "https://github.com/txuna/ping_pong/blob/main/Ping_Server/Global.gd"
    click WorldInstance "https://github.com/txuna/ping_pong/blob/main/Ping_Server/World.tscn"
```
