# imkennyyip/flappy-bird-java architecture

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

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

## Overview

##### Project type and purpose
- This is a simple desktop game written in Java using the built‑in AWT/Swing graphics libraries. It implements the Flappy Bird game mechanics (game loop, rendering, input handling, physics, collision detection, scoring).

##### File structure
- App.java: entry point. Creates window, initializes the game.
- FlappyBird.java: contains the core game classes (game loop, state, rendering, input logic).
- README.md: describes the tutorial, but no additional layers (no frontend/backend split, no database).

##### Main components
a. Presentation/UI Layer
- JFrame
- GamePanel (extends JPanel; handles paintComponent)
- Swing/AWT Event Dispatcher Thread
b. Core Game Engine
- GameLoop (runs at fixed FPS; calls update() and repaint())
- InputHandler (MouseListener/KeyListener to detect “flap” events)
c. Game Model & Logic
- Bird (position, velocity, jump() method)
- PipeManager (generates/moves pipes)
- CollisionDetector (checks bird vs. pipes/ground)
- ScoreManager (increments on each successful pipe pass)
d. External Libraries
- java.awt (Graphics, Image, event interfaces)
- javax.swing (JFrame, JPanel)

##### Relationships & Interactions
- The App class initializes the JFrame and adds the GamePanel.
- GamePanel registers InputHandler and starts the GameLoop.
- Each tick of the GameLoop does:
1. InputHandler reads user clicks → invokes Bird.jump().
2. PipeManager updates pipe positions.
3. Bird.update() applies gravity and velocity.
4. CollisionDetector checks for intersections → if collision, ends game.
5. ScoreManager updates score if Bird passes a pipe.
6. GamePanel.repaint() invokes paintComponent(Graphics) → Renderer draws Bird, Pipes, Score.
- Event Dispatcher Thread dispatches mouse events to InputHandler.

##### Architectural patterns & principles
- Separation of Concerns: UI vs. game logic vs. model components.
- Single Threaded Game Loop pattern.
- MVC‐light: Model (game objects & state), View (GamePanel rendering), Controller (InputHandler, GameLoop).

##### Elements
- Clear labels: component name + role.
- External dependency note (AWT/Swing libraries).

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph "UI Layer"
        AppNode["App (JFrame init)"]:::ui
        GamePanel["GamePanel (JPanel)"]:::ui
    end

    subgraph "Engine Layer"
        GameLoop["GameLoop (fixed‑FPS loop)"]:::engine
        InputHandler["InputHandler (Mouse/KeyListener)"]:::engine
    end

    subgraph "Model Layer"
        Bird["Bird (position, velocity)"]:::model
        PipeManager["PipeManager"]:::model
        CollisionDetector["CollisionDetector"]:::model
        ScoreManager["ScoreManager"]:::model
    end

    subgraph "External Libraries"
        AWT["java.awt / javax.swing"]:::external
    end

    EDT["EventDispatcher Thread"]:::external

    %% UI interactions
    AppNode -->|"initializes & adds"| GamePanel
    GamePanel -->|"starts"| GameLoop

    %% Event flow
    EDT -->|"mouseClicked"| InputHandler
    InputHandler -->|".jump()"| Bird

    %% Game loop update calls
    GameLoop -->|".update()"| Bird
    GameLoop -->|".update()"| PipeManager
    GameLoop -->|".checkCollision()"| CollisionDetector
    GameLoop -->|".updateScore()"| ScoreManager
    GameLoop -->|".repaint()"| GamePanel

    %% Rendering
    GamePanel -->|"paintComponent(Graphics)"| AWT

    %% Click events
    click AppNode "https://github.com/imkennyyip/flappy-bird-java/blob/master/App.java"
    click GamePanel "https://github.com/imkennyyip/flappy-bird-java/blob/master/FlappyBird.java"
    click GameLoop "https://github.com/imkennyyip/flappy-bird-java/blob/master/FlappyBird.java"
    click InputHandler "https://github.com/imkennyyip/flappy-bird-java/blob/master/FlappyBird.java"
    click Bird "https://github.com/imkennyyip/flappy-bird-java/blob/master/FlappyBird.java"
    click PipeManager "https://github.com/imkennyyip/flappy-bird-java/blob/master/FlappyBird.java"
    click CollisionDetector "https://github.com/imkennyyip/flappy-bird-java/blob/master/FlappyBird.java"
    click ScoreManager "https://github.com/imkennyyip/flappy-bird-java/blob/master/FlappyBird.java"
    click README "https://github.com/imkennyyip/flappy-bird-java/blob/master/README.md"

    %% Styles
    classDef ui fill:#ADD8E6,stroke:#000,stroke-width:1px
    classDef engine fill:#90EE90,stroke:#000,stroke-width:1px
    classDef model fill:#FFA500,stroke:#000,stroke-width:1px
    classDef external fill:#D3D3D3,stroke:#000,stroke-width:1px
```
