# diegolrs/2048 architecture

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

- Interactive diagram: https://gitdiagram.com/diegolrs/2048
- Repository: https://github.com/diegolrs/2048

## Overview

##### Project type and purpose
- This is a Unity-based educational clone of the 2048 puzzle game.
- It uses Unity’s scene/prefab system for UI, game board, and blocks, driven by C# scripts and animations.

##### File structure
- Top-level Unity folders
- Assets/Runtime: game assets (Animations, Prefabs, Scenes, Scripts, Data)
- Assets/Plugins/Demigiant/DOTween: third-party tweening library
- Assets/TextMesh Pro: text rendering package
- ProjectSettings & Packages: Unity project and package configs
- Under Runtime/Scripts
- Core: BoardManager, GameEndValidator, GameMode, SwipeHandler
- Components: Block, BlockAnimationController, BlockSpace, BoardRenderer
- Shift: ShiftInputs, ShiftManager
- Under Runtime/Animations & Runtime/Prefabs
- Animators/animation clips for merges
- Prefabs for blocks, board renderer, HUDs

##### README for additional insights
- Unity 2021.1.27f targeting Android/iOS
- DOTween is used for animations

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Platform
    subgraph "Unity Engine (Runtime Host)" 
        UEngine["Unity Engine"]:::platform
        Scene["Main.unity"]:::scene
    end

    %% Input Layer
    subgraph "Input Layer" 
        SI["ShiftInputs"]:::input
        SH["SwipeHandler"]:::input
    end

    %% Core Logic
    subgraph "Core Logic" 
        SM["ShiftManager"]:::core
        BM["BoardManager"]:::core
        GE["GameEndValidator"]:::core
        GM["GameMode"]:::core
    end

    %% Data Layer
    subgraph "Data Layer" 
        BTScript["BlockTypeSO.cs"]:::data
        BTAsset["BlockTypeSO.asset"]:::data
    end

    %% Presentation Layer
    subgraph "Presentation Layer" 
        BSPrefab["Block.prefab"]:::presentation
        BSSPrefab["BlockSpace.prefab"]:::presentation
        BRPrefab["BoardRenderer.prefab"]:::presentation
        GOHUD["GameOverHUD.prefab"]:::presentation
        GWHUD["GameWonHUD.prefab"]:::presentation
        BScript["Block.cs"]:::presentation
        BSScript["BlockSpace.cs"]:::presentation
        BRScript["BoardRenderer.cs"]:::presentation
    end

    %% Animation Layer
    subgraph "Animation Layer" 
        BAC["BlockAnimationController.cs"]:::animation
        AC["Block.controller"]:::animation
        MA["MergeAnimation.anim"]:::animation
        DTS["DOTweenSettings.asset"]:::animation
    end

    %% External Libraries
    subgraph "External Libraries" 
        DT["DOTween"]:::external
        TMP["TextMesh Pro"]:::external
    end

    %% User Interaction
    UserTouch["User Touch Input"]:::external

    %% Flow
    UserTouch -->|"touch detected"| SH
    SI --> SH
    SH -->|"detect swipe"| SM
    SM -->|"process shift"| BM
    BM -->|"check end game"| GE
    BM -->|"update mode"| GM
    BM -->|"lookup data"| BTScript
    BTScript --> BTAsset

    BM -->|"spawn/update view"| BRScript
    BRScript --> BRPrefab
    BRPrefab --> BSPrefab
    BRPrefab --> BSSPrefab
    BRScript --> BScript
    BRScript --> BSScript

    GE -->|"on game over"| GOHUD
    GE -->|"on game won"| GWHUD

    BM -->|"merge event"| BAC
    BAC --> AC
    BAC --> MA
    BAC --> DTS
    DTS --> DT
    BRScript --> TMP

    %% Click Events
    click Scene "https://github.com/diegolrs/2048/blob/main/Assets/Runtime/Scenes/Main.unity"
    click SI "https://github.com/diegolrs/2048/blob/main/Assets/Runtime/Scripts/Shift/ShiftInputs.cs"
    click SH "https://github.com/diegolrs/2048/blob/main/Assets/Runtime/Scripts/Core/SwipeHandler.cs"
    click SM "https://github.com/diegolrs/2048/blob/main/Assets/Runtime/Scripts/Shift/ShiftManager.cs"
    click BM "https://github.com/diegolrs/2048/blob/main/Assets/Runtime/Scripts/Core/BoardManager.cs"
    click GE "https://github.com/diegolrs/2048/blob/main/Assets/Runtime/Scripts/Core/GameEndValidator.cs"
    click GM "https://github.com/diegolrs/2048/blob/main/Assets/Runtime/Scripts/Core/GameMode.cs"
    click BTAsset "https://github.com/diegolrs/2048/blob/main/Assets/Runtime/Data/BlockTypeSO.asset"
    click BTScript "https://github.com/diegolrs/2048/blob/main/Assets/Runtime/Scripts/Components/Block/BlockTypeSO.cs"
    click BSPrefab "https://github.com/diegolrs/2048/blob/main/Assets/Runtime/Prefabs/Components/Block.prefab"
    click BSSPrefab "https://github.com/diegolrs/2048/blob/main/Assets/Runtime/Prefabs/Components/BlockSpace.prefab"
    click BRPrefab "https://github.com/diegolrs/2048/blob/main/Assets/Runtime/Prefabs/Components/BoardRenderer.prefab"
    click GOHUD "https://github.com/diegolrs/2048/blob/main/Assets/Runtime/Prefabs/UI/GameOverHUD.prefab"
    click GWHUD "https://github.com/diegolrs/2048/blob/main/Assets/Runtime/Prefabs/UI/GameWonHUD.prefab"
    click BScript "https://github.com/diegolrs/2048/blob/main/Assets/Runtime/Scripts/Components/Block/Block.cs"
    click BSScript "https://github.com/diegolrs/2048/blob/main/Assets/Runtime/Scripts/Components/BlockSpace.cs"
    click BRScript "https://github.com/diegolrs/2048/blob/main/Assets/Runtime/Scripts/Components/BoardRenderer.cs"
    click BAC "https://github.com/diegolrs/2048/blob/main/Assets/Runtime/Scripts/Components/Block/BlockAnimationController.cs"
    click AC "https://github.com/diegolrs/2048/blob/main/Assets/Runtime/Animations/Block/Block.controller"
    click MA "https://github.com/diegolrs/2048/blob/main/Assets/Runtime/Animations/Block/MergeAnimation.anim"
    click DTS "https://github.com/diegolrs/2048/blob/main/Assets/Runtime/DOTweenSettings.asset"
    click DT "https://github.com/diegolrs/2048/tree/main/Assets/Plugins/Demigiant/DOTween"
    click TMP "https://github.com/diegolrs/2048/tree/main/Assets/TextMesh Pro"

    %% Styles
    classDef platform fill:#eef2f3,stroke:#333,stroke-width:1px;
    classDef scene fill:#d0e7ff,stroke:#333,stroke-width:1px;
    classDef input fill:#cde5ff,stroke:#0366d6,stroke-width:1px;
    classDef core fill:#d4f4dd,stroke:#1a7f37,stroke-width:1px;
    classDef data fill:#f0f0f0,stroke:#666,stroke-width:1px;
    classDef presentation fill:#ffe4b2,stroke:#d97706,stroke-width:1px;
    classDef animation fill:#f3e5f5,stroke:#6a1b9a,stroke-width:1px;
    classDef external fill:#e0e0e0,stroke:#555,stroke-width:1px;
```
