# kaic-eder/mahjong-match3 architecture

> Architecture diagram of the GitHub repository kaic-eder/mahjong-match3, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-08-17). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/kaic-eder/mahjong-match3
- Repository: https://github.com/kaic-eder/mahjong-match3

## Overview

#### Purpose and Runtime
This is a Unity 2D tile/board game project. Gameplay centers on generating a board of tile instances, identifying selectable matches, moving selected tiles into a tray/slot area, and progressing game state. The playable scene entry points are `Assets/Scenes/SampleScene.unity` and `Assets/Scenes/testes de board.unity`.

It runs in the Unity engine with Universal Render Pipeline 2D configuration under `Assets/Settings/Renderer2D.asset` and `Assets/Settings/UniversalRP.asset`.

#### Application Flow and State
`Assets/Scripts/GameFlowController.cs` is the likely top-level game orchestration boundary; `Assets/Scripts/GameState.cs` represents gameplay state. They coordinate board setup, player actions, and success/failure transitions rather than embedding that policy in individual tiles.

The runtime flow is broadly: load scene → initialize game/board → generate and spawn tiles → accept input → resolve matching/tray effects → update game state.

#### Board Construction Pipeline
The board subsystem is intentionally decomposed into model, generation, and view stages:
- `Assets/Scripts/Board/BoardLayout.cs` defines the board arrangement representation.
- `Assets/Scripts/Board/BoardLayoutGenerator.cs` produces layouts.
- `Assets/Scripts/Board/BoardContentGenerator.cs` assigns tile content while likely respecting matchability.
- `Assets/Scripts/Board/BoardSpawner.cs` instantiates the resulting content into Unity scene objects.
- `Assets/Scripts/Board/BoardController.cs` owns runtime board coordination.

`Assets/Scripts/Board/BoardCell.cs` is the cell-level unit connecting layout/content decisions to board occupancy and accessibility.

#### Solvability and Match Planning
Board generation appears coupled to planned solvability rather than purely random placement. `Assets/Scripts/Board/BoardSolver.cs` and `Assets/Scripts/Board/PlannedMatch.cs` provide a planning/validation layer, while `Assets/Scripts/MatchFinder.cs` identifies matching tiles during live gameplay.

This creates a key boundary: generator/solver logic determines legal content and intended match sequences before spawning; interaction logic consumes the live board state after spawning.

#### Tile Interaction and Presentation
`Assets/Scripts/TileInteractionHandler.cs` receives player tile-selection input and delegates behavior to `Assets/Scripts/TileController.cs`. Tile controllers should remain the Unity-object-facing layer: visual state, selection, availability, and transfer/removal behavior.

The tile asset is represented by `Assets/Prefabs/Tile-marreco.prefab`, with sprite resources rooted at `Assets/Images/Sprite/Tiles.png`.

#### Tray / Slot Resolution
`Assets/Scripts/SlotManager.cs` manages the destination collection for selected tiles and its capacity/order semantics. `Assets/Scripts/TrayAnimator.cs` supplies the visual movement/transition boundary for tray operations.

A typical action path is: interaction handler selects a tile → tile controller validates/removes or marks it → slot manager inserts it → match finder detects a completed set → game flow updates progression. Animation should not own game rules.

#### Input, Dependencies, and External Boundaries
Input uses Unity’s Input System action assets: `Assets/PlayerControls.inputactions` and generated wrapper `Assets/PlayerControls.cs`. The project includes DOTween as a bundled plugin at `Assets/Plugins/Demigiant/DOTween`; it is the principal third-party animation runtime, with settings in `Assets/Resources/DOTweenSettings.asset`.

No backend, persistence service, network API, or external SaaS integration is evident from the repository tree.

Main entry points: [`Assets/Scripts/Board/BoardController.cs`](https://github.com/kaic-eder/mahjong-match3/blob/main/Assets/Scripts/Board/BoardController.cs) (Board Controller), [`Assets/Scripts/GameFlowController.cs`](https://github.com/kaic-eder/mahjong-match3/blob/main/Assets/Scripts/GameFlowController.cs) (Game Flow Controller), [`Assets/Scripts/TileController.cs`](https://github.com/kaic-eder/mahjong-match3/blob/main/Assets/Scripts/TileController.cs) (Tile Controller), [`Assets/Scripts/Board/BoardLayoutGenerator.cs`](https://github.com/kaic-eder/mahjong-match3/blob/main/Assets/Scripts/Board/BoardLayoutGenerator.cs) (Layout Generator)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_unity["Unity Runtime"]
  node_scene["Playable Scenes<br/>Unity scenes<br/>[SampleScene.unity]"]
  node_urp["URP 2D<br/>render pipeline<br/>[UniversalRP.asset]"]
  node_tile_prefab["Tile Prefab<br/>Unity prefab"]
  node_dotween["DOTween<br/>animation plugin"]
end

subgraph group_board["Board Pipeline"]
  node_layout_generator["Layout Generator<br/>board generator"]
  node_board_layout["Board Layout<br/>layout model<br/>[BoardLayout.cs]"]
  node_board_solver["Board Solver<br/>solvability planner<br/>[BoardSolver.cs]"]
  node_planned_match["Planned Match<br/>match plan<br/>[PlannedMatch.cs]"]
  node_content_generator["Content Generator"]
  node_board_spawner["Board Spawner<br/>Unity object spawner<br/>[BoardSpawner.cs]"]
  node_board_controller["Board Controller<br/>runtime board coordinator<br/>[BoardController.cs]"]
  node_board_cell["Board Cell<br/>occupancy model<br/>[BoardCell.cs]"]
end

subgraph group_gameplay["Gameplay Interaction"]
  node_game_flow["Game Flow Controller<br/>orchestrator"]
  node_game_state["Game State<br/>state model<br/>[GameState.cs]"]
  node_input_actions["Player Controls<br/>Input System wrapper<br/>[PlayerControls.cs]"]
  node_interaction_handler["Tile Interaction Handler<br/>input adapter"]
  node_tile_controller["Tile Controller<br/>tile presentation controller<br/>[TileController.cs]"]
  node_slot_manager["Slot Manager<br/>tray rules<br/>[SlotManager.cs]"]
  node_match_finder["Match Finder<br/>live match resolver<br/>[MatchFinder.cs]"]
  node_tray_animator["Tray Animator<br/>animation adapter<br/>[TrayAnimator.cs]"]
end

node_scene -->|"starts"| node_game_flow
node_scene -->|"renders with"| node_urp
node_game_flow -->|"updates"| node_game_state
node_game_flow -->|"initializes"| node_board_controller
node_board_controller -->|"requests"| node_layout_generator
node_layout_generator -->|"produces"| node_board_layout
node_layout_generator -->|"plans with"| node_board_solver
node_board_solver -->|"creates"| node_planned_match
node_board_solver -->|"constrains"| node_content_generator
node_board_layout -->|"defines cells"| node_board_cell
node_content_generator -->|"assigns content"| node_board_cell
node_board_controller -->|"spawns through"| node_board_spawner
node_board_spawner -->|"instantiates"| node_tile_prefab
node_board_spawner -->|"creates"| node_tile_controller
node_input_actions -->|"provides input"| node_interaction_handler
node_interaction_handler -->|"selects"| node_tile_controller
node_tile_controller -->|"moves selected tile"| node_slot_manager
node_slot_manager -->|"checks completed sets"| node_match_finder
node_match_finder -->|"reports resolution"| node_game_flow
node_slot_manager -->|"triggers transition"| node_tray_animator
node_tray_animator -->|"animates with"| node_dotween
node_board_controller -->|"tracks live board"| node_tile_controller

click node_scene "https://github.com/kaic-eder/mahjong-match3/blob/main/Assets/Scenes/SampleScene.unity"
click node_urp "https://github.com/kaic-eder/mahjong-match3/blob/main/Assets/Settings/UniversalRP.asset"
click node_game_flow "https://github.com/kaic-eder/mahjong-match3/blob/main/Assets/Scripts/GameFlowController.cs"
click node_game_state "https://github.com/kaic-eder/mahjong-match3/blob/main/Assets/Scripts/GameState.cs"
click node_layout_generator "https://github.com/kaic-eder/mahjong-match3/blob/main/Assets/Scripts/Board/BoardLayoutGenerator.cs"
click node_board_layout "https://github.com/kaic-eder/mahjong-match3/blob/main/Assets/Scripts/Board/BoardLayout.cs"
click node_board_solver "https://github.com/kaic-eder/mahjong-match3/blob/main/Assets/Scripts/Board/BoardSolver.cs"
click node_planned_match "https://github.com/kaic-eder/mahjong-match3/blob/main/Assets/Scripts/Board/PlannedMatch.cs"
click node_content_generator "https://github.com/kaic-eder/mahjong-match3/blob/main/Assets/Scripts/Board/BoardContentGenerator.cs"
click node_board_spawner "https://github.com/kaic-eder/mahjong-match3/blob/main/Assets/Scripts/Board/BoardSpawner.cs"
click node_board_controller "https://github.com/kaic-eder/mahjong-match3/blob/main/Assets/Scripts/Board/BoardController.cs"
click node_board_cell "https://github.com/kaic-eder/mahjong-match3/blob/main/Assets/Scripts/Board/BoardCell.cs"
click node_input_actions "https://github.com/kaic-eder/mahjong-match3/blob/main/Assets/PlayerControls.cs"
click node_interaction_handler "https://github.com/kaic-eder/mahjong-match3/blob/main/Assets/Scripts/TileInteractionHandler.cs"
click node_tile_controller "https://github.com/kaic-eder/mahjong-match3/blob/main/Assets/Scripts/TileController.cs"
click node_tile_prefab "https://github.com/kaic-eder/mahjong-match3/blob/main/Assets/Prefabs/Tile-marreco.prefab"
click node_slot_manager "https://github.com/kaic-eder/mahjong-match3/blob/main/Assets/Scripts/SlotManager.cs"
click node_match_finder "https://github.com/kaic-eder/mahjong-match3/blob/main/Assets/Scripts/MatchFinder.cs"
click node_tray_animator "https://github.com/kaic-eder/mahjong-match3/blob/main/Assets/Scripts/TrayAnimator.cs"
click node_dotween "https://github.com/kaic-eder/mahjong-match3/tree/main/Assets/Plugins/Demigiant/DOTween"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_scene,node_urp,node_tile_prefab,node_dotween toneBlue
class node_layout_generator,node_board_layout,node_board_solver,node_planned_match,node_content_generator,node_board_spawner,node_board_controller,node_board_cell toneAmber
class node_game_flow,node_game_state,node_input_actions,node_interaction_handler,node_tile_controller,node_slot_manager,node_match_finder,node_tray_animator toneMint
```

## Components

### Unity Runtime

- [Playable Scenes](https://github.com/kaic-eder/mahjong-match3/blob/main/Assets/Scenes/SampleScene.unity): Unity scenes · SampleScene and board test scene are entry points. · `Assets/Scenes/SampleScene.unity`
- [URP 2D](https://github.com/kaic-eder/mahjong-match3/blob/main/Assets/Settings/UniversalRP.asset): render pipeline · `Assets/Settings/UniversalRP.asset`
- [Tile Prefab](https://github.com/kaic-eder/mahjong-match3/blob/main/Assets/Prefabs/Tile-marreco.prefab): Unity prefab · `Assets/Prefabs/Tile-marreco.prefab`
- [DOTween](https://github.com/kaic-eder/mahjong-match3/tree/main/Assets/Plugins/Demigiant/DOTween): animation plugin · `Assets/Plugins/Demigiant/DOTween`

### Board Pipeline

- [Layout Generator](https://github.com/kaic-eder/mahjong-match3/blob/main/Assets/Scripts/Board/BoardLayoutGenerator.cs): board generator · `Assets/Scripts/Board/BoardLayoutGenerator.cs`
- [Board Layout](https://github.com/kaic-eder/mahjong-match3/blob/main/Assets/Scripts/Board/BoardLayout.cs): layout model · `Assets/Scripts/Board/BoardLayout.cs`
- [Board Solver](https://github.com/kaic-eder/mahjong-match3/blob/main/Assets/Scripts/Board/BoardSolver.cs): solvability planner · `Assets/Scripts/Board/BoardSolver.cs`
- [Planned Match](https://github.com/kaic-eder/mahjong-match3/blob/main/Assets/Scripts/Board/PlannedMatch.cs): match plan · `Assets/Scripts/Board/PlannedMatch.cs`
- [Content Generator](https://github.com/kaic-eder/mahjong-match3/blob/main/Assets/Scripts/Board/BoardContentGenerator.cs): tile content generator · `Assets/Scripts/Board/BoardContentGenerator.cs`
- [Board Spawner](https://github.com/kaic-eder/mahjong-match3/blob/main/Assets/Scripts/Board/BoardSpawner.cs): Unity object spawner · `Assets/Scripts/Board/BoardSpawner.cs`
- [Board Controller](https://github.com/kaic-eder/mahjong-match3/blob/main/Assets/Scripts/Board/BoardController.cs): runtime board coordinator · `Assets/Scripts/Board/BoardController.cs`
- [Board Cell](https://github.com/kaic-eder/mahjong-match3/blob/main/Assets/Scripts/Board/BoardCell.cs): occupancy model · Connects layout, content, and tile accessibility. · `Assets/Scripts/Board/BoardCell.cs`

### Gameplay Interaction

- [Game Flow Controller](https://github.com/kaic-eder/mahjong-match3/blob/main/Assets/Scripts/GameFlowController.cs): orchestrator · `Assets/Scripts/GameFlowController.cs`
- [Game State](https://github.com/kaic-eder/mahjong-match3/blob/main/Assets/Scripts/GameState.cs): state model · `Assets/Scripts/GameState.cs`
- [Player Controls](https://github.com/kaic-eder/mahjong-match3/blob/main/Assets/PlayerControls.cs): Input System wrapper · `Assets/PlayerControls.cs`
- [Tile Interaction Handler](https://github.com/kaic-eder/mahjong-match3/blob/main/Assets/Scripts/TileInteractionHandler.cs): input adapter · `Assets/Scripts/TileInteractionHandler.cs`
- [Tile Controller](https://github.com/kaic-eder/mahjong-match3/blob/main/Assets/Scripts/TileController.cs): tile presentation controller · Owns Unity-facing selection, availability, and removal behavior. · `Assets/Scripts/TileController.cs`
- [Slot Manager](https://github.com/kaic-eder/mahjong-match3/blob/main/Assets/Scripts/SlotManager.cs): tray rules · Owns tray capacity and ordering semantics. · `Assets/Scripts/SlotManager.cs`
- [Match Finder](https://github.com/kaic-eder/mahjong-match3/blob/main/Assets/Scripts/MatchFinder.cs): live match resolver · `Assets/Scripts/MatchFinder.cs`
- [Tray Animator](https://github.com/kaic-eder/mahjong-match3/blob/main/Assets/Scripts/TrayAnimator.cs): animation adapter · Visualizes tray transitions without owning rules. · `Assets/Scripts/TrayAnimator.cs`

## Connections

- Playable Scenes → Game Flow Controller: starts
- Playable Scenes → URP 2D: renders with
- Game Flow Controller → Game State: updates
- Game Flow Controller → Board Controller: initializes
- Board Controller → Layout Generator: requests
- Layout Generator → Board Layout: produces
- Layout Generator → Board Solver: plans with
- Board Solver → Planned Match: creates
- Board Solver → Content Generator: constrains
- Board Layout → Board Cell: defines cells
- Content Generator → Board Cell: assigns content
- Board Controller → Board Spawner: spawns through
- Board Spawner → Tile Prefab: instantiates
- Board Spawner → Tile Controller: creates
- Player Controls → Tile Interaction Handler: provides input
- Tile Interaction Handler → Tile Controller: selects
- Tile Controller → Slot Manager: moves selected tile
- Slot Manager → Match Finder: checks completed sets
- Match Finder → Game Flow Controller: reports resolution
- Slot Manager → Tray Animator: triggers transition
- Tray Animator → DOTween: animates with
- Board Controller → Tile Controller: tracks live board
