# un-35/3d_ponggame architecture

> Architecture diagram of the GitHub repository un-35/3d_ponggame, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-10-15). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/un-35/3d_ponggame
- Repository: https://github.com/un-35/3d_ponggame

## Overview

##### Project Type and Purpose
- This is a full-stack real-time 3D Pong game.
- Frontend: Three.js powered UI and game logic delivered via Vite.
- Backend: Django web server with Django Channels providing WebSocket endpoints for three game modes (local, remote, tournament).
- Database: SQLite for persistence (scores, tournament brackets, etc.).

##### File Structure
- Top level:
- backend/ – Django project (“backend/backend/” contains settings, URLs, ASGI/WGI entry points).
- backend/game/ – Django app with WebSocket consumers (BallConsumer.py, consumers.py), routing.py, models.py, views.py.
- frontend/ – Vite project with Three.js assets (Ball.js, Paddle.js, game-mode.js, manage-scores.js).
- requirements.txt and venv/ – Python dependencies and virtual environment.
- Configuration and entry scripts:
- backend/asgi.py + routing.py in game/ define channel routes (/ws/local-game/, etc.).
- frontend/vite.config.js and index.html boot the dev server.

##### Key Architecture Insights from README
- Technology stack reinforces WebSocket–based real-time communication via Django Channels and Daphne ASGI server.
- Three game modes map to three WebSocket endpoints.
- Frontend subscribes to game state updates (ball position, scores) over JSON messages.

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Client Layer
    subgraph "Client (Browser)"
        Ball["Ball.js"]:::client
        Paddle["Paddle.js"]:::client
        Main["main.js"]:::client
        WSClient["game-mode.js"]:::client
        ScoresUI["manage-scores.js"]:::client
    end

    %% Dev/Build & Config
    subgraph "Dev/Build & Config"
        ViteConfig["vite.config.js"]:::config
        IndexHTML["index.html"]:::config
        PackageJSON["package.json"]:::config
        PackageLock["package-lock.json"]:::config
        Req["requirements.txt"]:::config
    end

    %% Server Setup
    subgraph "Server Setup"
        ASGI["asgi.py"]:::backend
        WSGI["wsgi.py"]:::backend
        ManagePy["manage.py"]:::backend
    end

    %% Django Project Configuration
    subgraph "Django Project Configuration"
        Settings["settings.py"]:::backend
        Urls["urls.py"]:::backend
    end

    %% Django App Routing
    subgraph "Django App Routing"
        GameRouting["routing.py"]:::backend
        GameURLs["urls.py"]:::backend
    end

    %% WebSocket Consumers
    subgraph "WebSocket Consumers"
        BallCons["BallConsumer.py"]:::backend
        Cons["consumers.py"]:::backend
    end

    %% Database & Persistence
    subgraph "Persistence & Admin"
        Models["models.py"]:::backend
        SQLite["db.sqlite3"]:::db
        Admin["admin.py"]:::backend
        Migrations["migrations/"]:::backend
    end

    %% Flows
    ViteConfig -->|"serves bundles"|Ball
    ViteConfig -->|"serves bundles"|Paddle
    ViteConfig -->|"serves bundles"|Main
    ViteConfig -->|"serves bundles"|WSClient
    ViteConfig -->|"serves bundles"|ScoresUI
    IndexHTML -->|"serves UI"|Ball
    IndexHTML -->|"serves UI"|Paddle
    IndexHTML -->|"serves UI"|Main
    IndexHTML -->|"serves UI"|WSClient
    IndexHTML -->|"serves UI"|ScoresUI

    WSClient -->|"WebSocket Handshake"|ASGI
    ASGI -->|"routes WS"|GameRouting
    GameRouting -->|"forwards to"|BallCons
    GameRouting -->|"forwards to"|Cons
    BallCons -->|"DB read/write"|Models
    Cons -->|"DB read/write"|Models
    Models -->|"persists"|SQLite
    BallCons -->|"broadcast updates"|WSClient
    Cons -->|"broadcast updates"|WSClient

    %% Click Events
    click Ball "https://github.com/un-35/3d_ponggame/blob/main/frontend/src/Ball.js"
    click Paddle "https://github.com/un-35/3d_ponggame/blob/main/frontend/src/Paddle.js"
    click Main "https://github.com/un-35/3d_ponggame/blob/main/frontend/src/main.js"
    click WSClient "https://github.com/un-35/3d_ponggame/blob/main/frontend/src/game-mode.js"
    click ScoresUI "https://github.com/un-35/3d_ponggame/blob/main/frontend/src/manage-scores.js"
    click ViteConfig "https://github.com/un-35/3d_ponggame/blob/main/frontend/vite.config.js"
    click IndexHTML "https://github.com/un-35/3d_ponggame/blob/main/frontend/index.html"
    click PackageJSON "https://github.com/un-35/3d_ponggame/blob/main/frontend/package.json"
    click PackageLock "https://github.com/un-35/3d_ponggame/blob/main/frontend/package-lock.json"
    click Req "https://github.com/un-35/3d_ponggame/blob/main/requirements.txt"
    click ASGI "https://github.com/un-35/3d_ponggame/blob/main/backend/backend/asgi.py"
    click WSGI "https://github.com/un-35/3d_ponggame/blob/main/backend/backend/wsgi.py"
    click ManagePy "https://github.com/un-35/3d_ponggame/blob/main/backend/manage.py"
    click Settings "https://github.com/un-35/3d_ponggame/blob/main/backend/backend/settings.py"
    click Urls "https://github.com/un-35/3d_ponggame/blob/main/backend/backend/urls.py"
    click GameRouting "https://github.com/un-35/3d_ponggame/blob/main/backend/game/routing.py"
    click GameURLs "https://github.com/un-35/3d_ponggame/blob/main/backend/game/urls.py"
    click BallCons "https://github.com/un-35/3d_ponggame/blob/main/backend/game/BallConsumer.py"
    click Cons "https://github.com/un-35/3d_ponggame/blob/main/backend/game/consumers.py"
    click Models "https://github.com/un-35/3d_ponggame/blob/main/backend/game/models.py"
    click SQLite "https://github.com/un-35/3d_ponggame/blob/main/backend/db.sqlite3"
    click Admin "https://github.com/un-35/3d_ponggame/blob/main/backend/game/admin.py"
    click Migrations "https://github.com/un-35/3d_ponggame/tree/main/backend/game/migrations/"

    %% Styles
    classDef client fill:#D0E8FF,stroke:#3178C6,stroke-width:1px
    classDef backend fill:#FFD8A8,stroke:#D97706,stroke-width:1px
    classDef db fill:#D0FFD6,stroke:#059669,stroke-width:1px
    classDef config fill:#F0F0F0,stroke:#6B7280,stroke-width:1px
```
