# arsalanyavari/flappy-bird architecture

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

- Interactive diagram: https://gitdiagram.com/arsalanyavari/flappy-bird
- Repository: https://github.com/arsalanyavari/flappy-bird

## Overview

##### Project type and purpose
- This is a single-page, front-end web game (Flappy Bird clone) built with pure JavaScript, HTML, and CSS.
- The purpose is to practice DOM manipulation, game loops, asset loading, and browser APIs without any back-end or build toolchain.

##### File structure
- Top-level files:
– index.html: the game’s entry point
– script.js: main game logic & loop
– style.css: presentation rules
– assets/: static resources (pics & sounds)
– examples/: demo snapshots or variations
- No backend or server-side code → all execution happens in the browser.
- Asset directory separation (pics vs. sounds) suggests an asset loader module in script.js.

##### README for additional insights
- Confirms it’s a pure-JS implementation for practice.
- No extra libraries or frameworks (e.g., React, WebGL) are used.
- Hosted as a static site (GitHub Pages).

a. Main components to represent:
- Browser Environment (host)
- index.html (DOM scaffold + canvas or container)
- CSS Engine (style.css)
- JavaScript Layer (script.js) broken into sub-modules:
– Asset Loader (images & audio)
– Input Handler (mouse/tap/keyboard)
– Game Loop / Scheduler
– Game State Manager (bird, pipes, score)
– Renderer (draws frames on canvas or DOM)
– Audio Manager (plays sounds)
– UI Overlay (scoreboard, “Game Over” screen)
- Static Assets (assets/pics, assets/sounds)

b. Relationships and interactions:
- index.html → loads style.css & script.js
- On load, script.js initializes:
– Asset Loader fetches images & audio from assets/
– Once ready, Game Loop starts
- Game Loop invokes in each tick:
– Input Handler → updates intended actions (flap)
– Game State Manager → computes new positions, collision
– Renderer → draws bird, pipes, background
– Audio Manager → triggers sounds on events (hit, score)
- UI Overlay listens to state for score updates & game-over

c. Architectural patterns & design principles:
- Modular separation of concerns (loader, logic, rendering, I/O)
- Single responsibility modules (each has one well-defined role)
- Event-driven updates via the game loop
- Resource abstraction (Asset Loader encapsulates raw fetch logic)

- HTML5 (canvas or div elements)
- CSS3 for layout and styling
- Vanilla JavaScript (ES6+)
- Browser APIs (requestAnimationFrame, Audio API, event listeners)

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Browser Environment
    BrowserEnv["Browser Environment"]:::browser

    %% HTML and CSS entry
    Index["index.html (DOM Scaffold)"]:::static
    Style["style.css (CSS Engine)"]:::static
    Script["script.js (Game Logic)"]:::module

    BrowserEnv -->|loads| Index
    Index -->|includes| Style
    Index -->|includes| Script

    %% Static Assets
    subgraph "Static Assets" 
        direction TB
        Pics["assets/pics/"]:::static
        Sounds["assets/sounds/"]:::static
    end

    %% Game Engine Modules
    subgraph "Game Engine" 
        direction TB
        Loader["Asset Loader"]:::module
        Input["Input Handler"]:::module
        Loop["Game Loop / Scheduler"]:::module
        State["Game State Manager"]:::module
        Render["Renderer"]:::module
        Audio["Audio Manager"]:::module
        Overlay["UI Overlay"]:::module
    end

    %% Load sequence
    Script -->|initializes| Loader
    Loader -->|fetch assets| Pics
    Loader -->|fetch assets| Sounds
    Loader -->|onReady| Loop

    %% Game Loop flow
    Loop -->|tick| Input
    Loop -->|tick| State
    Loop -->|tick| Render
    Loop -->|tick| Audio
    State -->|updates| Overlay
    Input -->|events| State
    State -->|data| Render
    State -->|events| Audio

    %% API Usage
    Loop -->|uses requestAnimationFrame| BrowserEnv
    Audio -->|uses Audio API| BrowserEnv
    Input -->|uses Event Listeners| BrowserEnv

    %% Examples
    Examples["examples/"]:::static
    BrowserEnv -->|can view| Examples

    %% Click events
    click Index "https://github.com/arsalanyavari/flappy-bird/blob/master/index.html"
    click Style "https://github.com/arsalanyavari/flappy-bird/blob/master/style.css"
    click Script "https://github.com/arsalanyavari/flappy-bird/blob/master/script.js"
    click Pics "https://github.com/arsalanyavari/flappy-bird/tree/master/assets/pics/"
    click Sounds "https://github.com/arsalanyavari/flappy-bird/tree/master/assets/sounds/"
    click Examples "https://github.com/arsalanyavari/flappy-bird/tree/master/examples/"

    %% Styles
    classDef browser fill:#f5a623,stroke:#000,color:#000
    classDef static fill:#54a0ff,stroke:#000,color:#fff
    classDef module fill:#1dd1a1,stroke:#000,color:#000
```
