# akrepkov/crazy_pong architecture

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

- Interactive diagram: https://gitdiagram.com/akrepkov/crazy_pong
- Repository: https://github.com/akrepkov/crazy_pong

## Overview

##### Project type and purpose
- This is a single-page, browser-based Pong clone written in vanilla JavaScript and HTML5 Canvas. Its primary function is to let users practice Pong with features like multi-ball mode, keyboard controls, and hash-based tab routing.

##### File structure
- Top-level files:
- README.md – project description
- index.js – (likely build/dev script or entry shim)
- package.json / package-lock.json – dependency metadata
- public/
- index.html – the shell page hosting the Canvas and controls
- styles.css – Flexbox-based responsive layout and UI styling
- src/
- app.js – application bootstrap, hash-based router, tab management
- controls.js – keyboard event handlers, mapping keys to paddle actions
- game.js – core game loop (requestAnimationFrame), physics (ball/paddle), scoring, game state
- node_modules/ – third-party packages (if any, though code is vanilla)

##### Key insights from README
- Hash-based routing (#practice) for view/tab switching
- Canvas rendering for paddles and balls
- ES6 classes for Ball and Paddle
- Game loop driven by requestAnimationFrame
- Visibility API to pause/resume or log tab focus changes

a. Browser Environment (container boundary)
b. UI Layer
- HTML (index.html)
- CSS (styles.css)
- Tabbed Navigation (hash router in app.js)
c. Input Layer
- Keyboard Event Listener (controls.js)
- Key Mapping (W/S and ↑/↓)
d. Game Engine
- Game Loop (requestAnimationFrame)
- Physics & Rules (Ball & Paddle ES6 classes, collision detection, scoring)
- Multi-ball Manager
e. Rendering Layer
- HTML5 Canvas API
f. Utility / Services
- Random Name Generator (logic in game.js or helper)
- Visibility Change Handler (document.visibilitychange)

##### Relationships and data flow
1. User presses key → controls.js captures event → updates paddle velocity/state
2. Game Loop tick (app.js calls game.js) → physics update → game state mutation
3. Renderer reads updated state → draws frame to Canvas
4. Collision or score event → game state triggers scoring logic → UI scoreboard updated
5. Hash change in URL → app.js router switches view (e.g., practice tab)

##### Architectural patterns and design principles
- Modular separation: input, game logic, rendering, and routing each in own file
- Single Responsibility: each ES6 class handles one domain object (Ball or Paddle)
- Event-driven loop: using requestAnimationFrame as the heartbeat

##### Specific elements
- Component names (app.js, controls.js, game.js, index.html, styles.css)

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Client Browser"
        subgraph "UI Layer"
            HTML["index.html"]:::ui
            CSS["styles.css"]:::ui
        end
        Router["app.js<br/>(Hash Router)"]:::router
        Input["controls.js<br/>(Keyboard Handlers)"]:::input
        subgraph "Game Core"
            Engine["game.js<br/>(Game Loop & Physics)"]:::logic
            Renderer["Canvas API<br/>(Renderer)"]:::render
        end
        Utils["game.js<br/>(NameGen & Visibility)"]:::util
    end

    HTML -->|"hashchange"| Router
    Input -->|"keypress event"| Engine
    Engine -->|"state update"| Renderer
    Renderer -->|"draw frame"| HTML
    Utils -->|"visibilitychange"| Engine

    %% Project Metadata & Scripts
    subgraph "Project Files"
        README["README.md"]:::meta
        Package["package.json"]:::meta
        IndexJS["index.js"]:::meta
    end

    %% Click Events
    click HTML "https://github.com/akrepkov/crazy_pong/blob/main/public/index.html"
    click CSS "https://github.com/akrepkov/crazy_pong/blob/main/public/styles.css"
    click Router "https://github.com/akrepkov/crazy_pong/blob/main/src/app.js"
    click Input "https://github.com/akrepkov/crazy_pong/blob/main/src/controls.js"
    click Engine "https://github.com/akrepkov/crazy_pong/blob/main/src/game.js"
    click Utils "https://github.com/akrepkov/crazy_pong/blob/main/src/game.js"
    click README "https://github.com/akrepkov/crazy_pong/blob/main/README.md"
    click Package "https://github.com/akrepkov/crazy_pong/blob/main/package.json"
    click IndexJS "https://github.com/akrepkov/crazy_pong/blob/main/index.js"

    %% Styles
    classDef ui fill:#D0E8FF,stroke:#0366d6,stroke-width:1px
    classDef input fill:#DFF2BF,stroke:#4F8A10,stroke-width:1px
    classDef router fill:#FFF5BA,stroke:#D4A017,stroke-width:1px
    classDef logic fill:#FFD2D2,stroke:#D8000C,stroke-width:1px
    classDef render fill:#FFE5B4,stroke:#FF8C00,stroke-width:1px
    classDef util fill:#E0E0E0,stroke:#737373,stroke-width:1px
    classDef meta fill:#F0E6FF,stroke:#6A0DAD,stroke-width:1px
    class HTML,CSS,Router,Input,Engine,Renderer,Utils ui,input,router,logic,render,util
    class README,Package,IndexJS meta
```
