# vagnernerves/flappy-bird architecture

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

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

## Overview

##### Project type and purpose
- This is a single-page mobile game (a Flappy Bird clone) built with React Native and Expo.
- It uses TypeScript for type safety, react-native-game-engine for game loop and entity management, and Matter.js for physics simulation.

##### File structure
- Top-level entry:
- App.tsx – root component, sets up the Game Engine and navigation between screens.
- app.json, babel.config.js, tsconfig.json – Expo and TypeScript configuration.
- src/@types – custom TypeScript definitions (e.g. images).
- src/assets – static assets (images, logo).
- src/components – UI/game components: Bird, Floor, Obstacle (each with index.tsx and styles.ts).
- src/entities – entity definitions and registration for the game engine (logic and initial parameters).
- src/screens – screen hierarchy:
- Home – wrapper for game;
- Home/Game – hosts the game engine and two sub-screens: Start and GameOver;
- src/utils – helper functions (physics setup, randomization).

##### README for additional insights
- Technologies section confirms: Expo, React Native, TypeScript, SplashScreen, react-native-game-engine, Matter.js.
- Purpose: tap to make bird fly, pass through obstacles.

##### Components
a. Mobile Client (React Native/Expo)
- App container (App.tsx)
- Navigation/Screen Manager
b. Game Engine Layer (react-native-game-engine)
- Entity Manager (Bird, Floor, Obstacle)
- Game Loop (update, physics, render)
c. Physics Engine (Matter.js)
- World/Engine instance
- Bodies and constraints
d. UI Components & Screens
- Start Screen (awaiting tap)
- Game Screen (active play)
- GameOver Screen (score display, restart)
e. Utilities & Assets
- Physics utilities (src/utils/physics.ts)
- Randomization (src/utils/ramdom.ts)
- Image assets loader (Expo Asset)

##### Relationships and data flows
- User taps → Input handler in Game Engine → triggers physics impulse on Bird entity
- Game Loop tick → Physics Engine updates positions → Entities update state → Components render updated positions
- Entity state changes → Screen transitions (Start → Game → GameOver)
- Asset loader feeds images to components before initial render

##### Architectural patterns & design principles
- Component-based UI (React Native)
- Entity-Component pattern (react-native-game-engine)
- Separation of concerns: game logic (entities + utils), rendering (components + styles), configuration (tsconfig, Expo)

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% External Runtime
    Expo["Expo Runtime"]:::external
    click Expo "https://github.com/vagnernerves/flappy-bird/blob/master/app.json"

    %% Mobile Client Layer
    App["App.tsx"]:::client
    Expo --> App
    click App "https://github.com/vagnernerves/flappy-bird/blob/master/App.tsx"

    %% Navigation / Screen Manager
    Navigation["Screen Manager\n(src/screens)"]:::client
    App --> Navigation
    click Navigation "https://github.com/vagnernerves/flappy-bird/tree/master/src/screens"

    %% Screens Cluster
    subgraph "Screens (src/screens)" 
        direction TB
        HomeScreen["Home Screen"]:::ui
        StartScreen["Start Screen"]:::ui
        GameScreen["Game Screen"]:::ui
        GameOverScreen["GameOver Screen"]:::ui

        HomeScreen --> StartScreen
        StartScreen --> GameScreen
        GameScreen --> GameOverScreen
    end
    click HomeScreen "https://github.com/vagnernerves/flappy-bird/blob/master/src/screens/Home/index.tsx"
    click StartScreen "https://github.com/vagnernerves/flappy-bird/blob/master/src/screens/Home/Game/Start/index.tsx"
    click GameScreen "https://github.com/vagnernerves/flappy-bird/blob/master/src/screens/Home/Game/index.tsx"
    click GameOverScreen "https://github.com/vagnernerves/flappy-bird/blob/master/src/screens/Home/Game/GameOver/index.tsx"

    Navigation --> HomeScreen

    %% Game Engine Layer
    subgraph "Game Engine Layer\n(react-native-game-engine)" 
        direction TB
        GameLoop["Game Loop & Engine\n(src/screens/Home/Game/index.tsx)"]:::engine
        EntityManager["Entity Manager\n(src/entities/index.ts)"]:::engine

        GameLoop --> EntityManager
        EntityManager --> GameLoop
    end
    click GameLoop "https://github.com/vagnernerves/flappy-bird/blob/master/src/screens/Home/Game/index.tsx"
    click EntityManager "https://github.com/vagnernerves/flappy-bird/blob/master/src/entities/index.ts"

    GameScreen --> GameLoop

    %% Physics Engine
    PhysicsEngine["Matter.js Engine\n(Physics)"]:::physics
    GameLoop --> PhysicsEngine
    PhysicsEngine --> EntityManager

    %% Components Cluster
    subgraph "Game Components (src/components)"
        direction TB
        BirdComp["Bird"]:::component
        FloorComp["Floor"]:::component
        ObstacleComp["Obstacle"]:::component

        EntityManager --> BirdComp
        EntityManager --> FloorComp
        EntityManager --> ObstacleComp

        GameLoop --> BirdComp
        GameLoop --> FloorComp
        GameLoop --> ObstacleComp

        BirdComp --> GameLoop
        FloorComp --> GameLoop
        ObstacleComp --> GameLoop
    end
    click BirdComp "https://github.com/vagnernerves/flappy-bird/blob/master/src/components/Bird/index.tsx"
    click FloorComp "https://github.com/vagnernerves/flappy-bird/blob/master/src/components/Floor/index.tsx"
    click ObstacleComp "https://github.com/vagnernerves/flappy-bird/blob/master/src/components/Obstacle/index.tsx"

    %% Utilities & Assets
    subgraph "Utilities & Assets (src/utils, src/assets, src/@types)"
        direction TB
        PhysicsUtil["Physics Utils\n(src/utils/physics.ts)"]:::util
        RandomUtil["Randomization Util\n(src/utils/ramdom.ts)"]:::util
        Assets["Image Assets Loader\n(src/assets/images)"]:::util
        Types["Type Definitions\n(src/@types/imagens.d.ts)"]:::util

        PhysicsUtil --> PhysicsEngine
        RandomUtil --> EntityManager
        Assets --> HomeScreen
        Assets --> StartScreen
        Assets --> GameScreen
        Assets --> GameOverScreen
        Types --> App
    end
    click PhysicsUtil "https://github.com/vagnernerves/flappy-bird/blob/master/src/utils/physics.ts"
    click RandomUtil "https://github.com/vagnernerves/flappy-bird/blob/master/src/utils/ramdom.ts"
    click Assets "https://github.com/vagnernerves/flappy-bird/tree/master/src/assets/images"
    click Types "https://github.com/vagnernerves/flappy-bird/blob/master/src/@types/imagens.d.ts"

    %% Styles
    classDef client fill:#E0F7FA,stroke:#006064,color:#000
    classDef ui fill:#BBDEFB,stroke:#0D47A1,color:#000
    classDef engine fill:#C8E6C9,stroke:#1B5E20,color:#000
    classDef component fill:#C8E6C9,stroke:#1B5E20,color:#000
    classDef physics fill:#FFE0B2,stroke:#EF6C00,color:#000
    classDef util fill:#E0E0E0,stroke:#424242,color:#000
    classDef external fill:#F3E5F5,stroke:#4A148C,color:#000
```
