# eldanveloper/pac-man architecture

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

- Interactive diagram: https://gitdiagram.com/eldanveloper/pac-man
- Repository: https://github.com/eldanveloper/pac-man

## Overview

##### Project type and purpose
- This is a single-page, front-end web game (“Pacman”) built entirely in HTML, CSS (via assets), and vanilla JavaScript.
- There is no backend or server-side logic beyond serving the static files; all game logic, rendering, and state management lives in the browser.

##### File structure
- index.html: entry point—the HTML scaffold that loads the scripts and assets.
- assets/: contains images, audio, sprites used by the game.
- game.js: the main orchestrator—initializes the canvas, game loop, map, score, win/lose conditions, restart logic.
- pacman.js: encapsulates Pac-Man’s state (position, speed, lives), input handling (keyboard events), movement, collision detection, rendering.
- ghost.js: encapsulates each ghost’s AI (movement patterns, target logic, speed), collision detection, rendering.

##### README for additional insights
- Confirms modular design: one file per major component (game engine, Pac-Man, ghosts).
- Emphasizes JavaScript, HTML, and static asset usage.
- No external services, APIs, or server dependencies.

##### Detail without overthinking
- Break the system into as many logical components as it contains (loader, engine, input, entities, assets, renderer).

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph "Browser / Client"
        direction TB
        index["index.html (Loader)"]:::loader
        subgraph "Modules"
            direction TB
            asset["Asset Manager"]:::asset
            engine["Game Engine"]:::engine
            subgraph "Entities"
                direction TB
                pacman["Pac-Man Module"]:::entity
                ghost["Ghost Module"]:::entity
            end
        end
    end

    subgraph "Game Loop"
        direction TB
        input["Input System"]:::input
        update["Update Cycle"]:::engine
        render["Render Pipeline"]:::render
    end

    %% Loading sequence
    index -->|"loads"| asset
    index -->|"loads"| engine
    index -->|"loads"| pacman
    index -->|"loads"| ghost

    %% Event streams and data flows
    input -.->|"keyboard event"| pacman
    update -->|"invoke update"| pacman
    update -->|"invoke update"| ghost
    pacman -->|"position & collision"| update
    ghost -->|"position & collision"| update
    asset -->|"sprite & sound"| render
    update -->|"state data"| render
    render -->|"next frame"| input

    %% Orchestration
    engine -->|"starts loop"| input
    engine -->|"orchestrates"| update
    engine -->|"orchestrates"| render

    %% Click Events
    click index "https://github.com/eldanveloper/pac-man/blob/main/index.html"
    click asset "https://github.com/eldanveloper/pac-man/tree/main/assets/"
    click engine "https://github.com/eldanveloper/pac-man/blob/main/game.js"
    click pacman "https://github.com/eldanveloper/pac-man/blob/main/pacman.js"
    click ghost "https://github.com/eldanveloper/pac-man/blob/main/ghost.js"

    %% Styles
    classDef loader fill:#AED581,stroke:#333,stroke-width:1px
    classDef engine fill:#A5D6A7,stroke:#333,stroke-width:1px
    classDef asset fill:#FFF59D,stroke:#333,stroke-width:1px
    classDef entity fill:#80CBC4,stroke:#333,stroke-width:1px
    classDef input fill:#FFE082,stroke:#333,stroke-width:1px,stroke-dasharray:5 5
    classDef render fill:#80DEEA,stroke:#333,stroke-width:1px
```
