# orkuneser/mergemechanic architecture

> Architecture diagram of the GitHub repository orkuneser/mergemechanic, 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/orkuneser/mergemechanic
- Repository: https://github.com/orkuneser/mergemechanic

## Overview

##### Project type and purpose
- This is a Unity-based game project (“MergeMechanic”) whose core mechanic is merging items on a grid.
- The README simply points to a demo GIF, so most domain knowledge comes from the folder named `[MergeMechanic]` under `Assets`.

##### File structure
- Top-level:
- Assets/
- Packages/ (Unity Package Manifest and lock)
- ProjectSettings/ (Unity build/editor settings)
- Plugins & ThirdParty: DOTween, TextMeshPro, various editor tools (BOXOPHOBIC, Lean Touch, Hierarchy 2) all integrated as asmdef modules.
- Assets/[MergeMechanic]:
- Materials: tile & item materials
- Prefabs: item prefabs per level
- Scenes: one main sample scene
- Scripts/Data: ScriptableObject assets defining Item levels (Item0.asset…)
- Scripts/Runtime:
- ItemScripts: controllers (spawn, movement, merge), data classes (Item, ItemSO)
- TileScripts: controllers for tile behavior and ray interactions, Tile SO
- UI: Spawn button logic
- Utilities: Singleton base class

##### README
- No architectural text; it’s purely visual. File structure is your main guide.

a. Main components
- Unity Engine/Editor (host runtime & build pipeline)
- MergeMechanic module
– Data layer (ScriptableObjects under Scripts/Data)
– Runtime layer
· Item subsystem (Item controllers, models)
· Tile subsystem (Tile controllers, models)
· UI subsystem (SpawnButton)
· Utilities (Singleton)
- Asset layer (Materials, Prefabs, Scenes)
- External services/plugins
– DOTween (animation engine)
– TextMeshPro (UI text)
– ThirdParty editor-only tools (BOXOPHOBIC, Lean Touch) – note “Editor” vs “Runtime” asmdef

b. Relationships & interactions
- Scene loads Prefabs + assigns scripts
- UI → SpawnButton.cs invokes ItemSpawnController
- ItemSpawnController uses Data (ItemSO) to instantiate Prefabs
- ItemMovementController, ItemMergeController respond to user input (via Unity’s EventSystem or raycasts)
- TileRayController detects grid taps → routes to ItemRayController
- Merge logic updates Tile & Item state → triggers DOTween animations for movement/merge
- TextMeshPro renders any text feedback
- Utility Singleton used for any global managers

c. Architectural patterns
- MVC-like separation:
– Model = ScriptableObjects (ItemSO, Tile metadata)
– Controller = Runtime controllers handling input & game logic
– View = Prefabs + Animations (DOTween)
- Scriptable-Object data driven approach for levels/items
- Singleton for shared managers

d. Key technologies & frameworks
- Unity Engine (Scenes, GameObjects, components)
- C# scripts organized by asmdef
- DOTween for tweening/movement
- TextMeshPro for UI
- Editor-only modules for tooling

##### Detail
- Assembly definitions (asmdef) boundaries for clarity
- Both Editor-only and Runtime-only plugins
- Don’t be afraid to break out sub-modules (Item vs Tile vs UI vs Utilities)

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Unity Engine/Editor
    subgraph "Unity Engine/Editor"
        UE["ProjectSettings/"]:::engine
        US["UserSettings/"]:::engine
    end

    %% MergeMechanic Data Layer
    subgraph "MergeMechanic Data Layer"
        direction TB
        ItemData((Item0.asset, Item1.asset, Item2.asset)):::data
    end

    %% MergeMechanic Runtime
    subgraph "MergeMechanic Runtime"
        direction TB

        subgraph "Item Subsystem"
            ISC["ItemSpawnController"]:::logic
            IMoC["ItemMovementController"]:::logic
            IMeC["ItemMergeController"]:::logic
            IRC["ItemRayController"]:::logic
            IPC["ItemPositionController"]:::logic
            ISclC["ItemScaleController"]:::logic
            IModel["Item.cs"]:::logic
            ICol["ItemCollider.cs"]:::logic
            ISO["ItemSO.cs"]:::data
        end

        subgraph "Tile Subsystem"
            TC["TileController"]:::logic
            TCoC["TileColorController"]:::logic
            TRC["TileRayController"]:::logic
            TModel["Tile.cs"]:::logic
        end

        subgraph "UI Subsystem"
            SB["SpawnButton.cs"]:::ui
        end

        subgraph "Utilities"
            Sgl["Singleton.cs"]:::logic
        end
    end

    %% Asset Layer
    subgraph "Assets"
        direction TB
        subgraph Materials
            GM["Level1Mat.mat, Level2Mat.mat, Level3Mat.mat"]:::asset
            TM["tileMat.mat"]:::asset
        end
        subgraph Prefabs
            IL0["ItemLevel0.prefab"]:::asset
            IL1["ItemLevel1.prefab"]:::asset
            IL2["ItemLevel2.prefab"]:::asset
        end
        SS["SampleScene.unity"]:::asset
    end

    %% Plugins
    subgraph "Plugins & Third-Party"
        direction TB
        DT["DOTween"]:::plugin
        TP["TextMeshPro"]:::plugin
        ET["Editor Tools"]:::plugin
    end

    %% Connections
    SS -->|loads| IL0
    SS -->|loads| IL1
    SS -->|loads| IL2
    IL0 -->|has component| ISC
    IL0 -->|has component| IMoC
    IL0 -->|has component| IMeC
    IL0 -->|has component| IRC
    IL0 -->|has component| IPC
    ISC -->|uses data| ItemData
    IMoC -->|uses DOTween| DT
    IMeC -->|uses DOTween| DT
    IRC -->|handles input from| TRC
    TRC -->|detects taps on| SS
    SB -->|spawns via| ISC
    SB -->|updates UI text| TP
    ISO -->|drives| ISC
    ISO -->|drives| IMoC
    ISO -->|drives| IMeC
    TC -->|uses| TModel
    TC -->|responds to| TRC
    ISC -->|instantiates| IL0
    IMoC -->|animates| GM
    SB -->|component on| SS
    Sgl -->|global manager| ISC
    Sgl -->|global manager| TC

    %% Click Events
    click UE "https://github.com/orkuneser/mergemechanic/tree/main/ProjectSettings/"
    click US "https://github.com/orkuneser/mergemechanic/tree/main/UserSettings/"
    click ItemData "https://github.com/orkuneser/mergemechanic/tree/main/Assets/[MergeMechanic]/Scripts/Data/"
    click ISC "https://github.com/orkuneser/mergemechanic/blob/main/Assets/[MergeMechanic]/Scripts/Runtime/ItemScripts/Controllers/ItemSpawnController.cs"
    click IMoC "https://github.com/orkuneser/mergemechanic/blob/main/Assets/[MergeMechanic]/Scripts/Runtime/ItemScripts/Controllers/ItemMovementController.cs"
    click IMeC "https://github.com/orkuneser/mergemechanic/blob/main/Assets/[MergeMechanic]/Scripts/Runtime/ItemScripts/Controllers/ItemMergeController.cs"
    click IRC "https://github.com/orkuneser/mergemechanic/blob/main/Assets/[MergeMechanic]/Scripts/Runtime/ItemScripts/Controllers/ItemRayController.cs"
    click IPC "https://github.com/orkuneser/mergemechanic/blob/main/Assets/[MergeMechanic]/Scripts/Runtime/ItemScripts/Controllers/ItemPositionController.cs"
    click ISclC "https://github.com/orkuneser/mergemechanic/blob/main/Assets/[MergeMechanic]/Scripts/Runtime/ItemScripts/ItemScaleController.cs"
    click IModel "https://github.com/orkuneser/mergemechanic/blob/main/Assets/[MergeMechanic]/Scripts/Runtime/ItemScripts/Item.cs"
    click ICol "https://github.com/orkuneser/mergemechanic/blob/main/Assets/[MergeMechanic]/Scripts/Runtime/ItemScripts/ItemCollider.cs"
    click ISO "https://github.com/orkuneser/mergemechanic/blob/main/Assets/[MergeMechanic]/Scripts/Runtime/ItemScripts/ItemSO.cs"
    click TC "https://github.com/orkuneser/mergemechanic/blob/main/Assets/[MergeMechanic]/Scripts/Runtime/TileScripts/Controllers/TileController.cs"
    click TCoC "https://github.com/orkuneser/mergemechanic/blob/main/Assets/[MergeMechanic]/Scripts/Runtime/TileScripts/Controllers/TileColorController.cs"
    click TRC "https://github.com/orkuneser/mergemechanic/blob/main/Assets/[MergeMechanic]/Scripts/Runtime/TileScripts/Controllers/TileRayController.cs"
    click TModel "https://github.com/orkuneser/mergemechanic/blob/main/Assets/[MergeMechanic]/Scripts/Runtime/TileScripts/Tile.cs"
    click SB "https://github.com/orkuneser/mergemechanic/blob/main/Assets/[MergeMechanic]/Scripts/Runtime/UI/SpawnButton.cs"
    click Sgl "https://github.com/orkuneser/mergemechanic/blob/main/Assets/[MergeMechanic]/Scripts/Runtime/Utilities/Singleton.cs"
    click GM "https://github.com/orkuneser/mergemechanic/tree/main/Assets/[MergeMechanic]/Materials/GridObjectMaterials/"
    click TM "https://github.com/orkuneser/mergemechanic/tree/main/Assets/[MergeMechanic]/Materials/"
    click IL0 "https://github.com/orkuneser/mergemechanic/blob/main/Assets/[MergeMechanic]/Prefabs/Items/ItemLevel0.prefab"
    click IL1 "https://github.com/orkuneser/mergemechanic/blob/main/Assets/[MergeMechanic]/Prefabs/Items/ItemLevel1.prefab"
    click IL2 "https://github.com/orkuneser/mergemechanic/blob/main/Assets/[MergeMechanic]/Prefabs/Items/ItemLevel2.prefab"
    click SS "https://github.com/orkuneser/mergemechanic/blob/main/Assets/[MergeMechanic]/Scenes/SampleScene.unity"
    click DT "https://github.com/orkuneser/mergemechanic/tree/main/Assets/Plugins/Demigiant/DOTween/"
    click TP "https://github.com/orkuneser/mergemechanic/tree/main/Assets/TextMesh Pro/"
    click ET "https://github.com/orkuneser/mergemechanic/tree/main/Assets/ThirdParty/"

    %% Styles
    classDef engine fill:#f2f2f2,stroke:#333,stroke-width:1px
    classDef data fill:#c6f5c6,stroke:#2d7a2d,stroke-width:1px
    classDef logic fill:#c6daf5,stroke:#1e4e8c,stroke-width:1px
    classDef ui fill:#f5d0a6,stroke:#a85400,stroke-width:1px
    classDef asset fill:#e0c6f5,stroke:#5a2d7a,stroke-width:1px
    classDef plugin fill:#d0d0d0,stroke:#666,stroke-width:1px
```
