# zonh-off/beetopiagame architecture

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

- Interactive diagram: https://gitdiagram.com/zonh-off/beetopiagame
- Repository: https://github.com/zonh-off/beetopiagame

## Overview

##### Project type and purpose
- This is a Unity-based 2D game (“BeetopiaGame”) built entirely in the Unity Editor.
- It uses Unity Scenes, GameObjects, MonoBehaviours, ScriptableObjects and a manager-based architecture to drive game logic, data loading, entity spawning, crafting and UI.

##### High-level file structure analysis
- Assets/Beetopia/Scenes: Unity scene definitions (Level0.unity).
- Assets/Beetopia/Scripts: C# code, subdivided into Core (entry point, managers, systems, interfaces), Entities (MonoBehaviours for bees, placed objects), ScriptableObjects (data definitions), Utils and View (UI code).
- Assets/Beetopia/ScriptableObjects: Data assets for entities, items, placeables, recipes.
- Assets/Beetopia/Prefabs & Art & Audio & Shaders: Visual, audio, prefab assets.
- Assets/Plugins: Third-party libraries (DOTween, Graphy, NaughtyAttributes, TextMeshPro).
- ProjectSettings & Packages: Unity configuration and package manifests.

##### Main components
a. Unity Engine + Editor (top-level container)
b. Entry Point
– EntryPoint.cs initializes core services.
c. Core Managers (singletons orchestrating subsystems)
– DataManager: loads ScriptableObjects into GameData/GameAssets
– GameManager: high-level state machine
– InputManager: receives player input
– EntityManager & UnitsManager: spawn and track bee units
– TaskManager & QuestManager: generate and track player objectives
– PlacementManager & ObjectPlaceSystem (with PlacingState/RemovingState)
– WorldExpansionManager: handles map growth
– SaveManager/FileManager: persistence
d. Systems
– UnitsSpawnSystem: entity instantiation
– SaveSystem: file I/O
e. Data Layer
– ScriptableObjects folder: entity definitions, item definitions, recipes, placeable object definitions
– GridDatabase: map data
f. Entities & Components
– BeeUnitBehaviour, BasePlacedObject, CraftingObject, StorageObject, CropObject, WaterWellObject
– Implement core interfaces: IInteractable, IHarvest, IItemStorage, IRecipeStorage, IPlacementState, ITask
g. UI Layer
– View prefabs (pfButtonWithIconUI, pfInventoryCanvas, pfTooltipCanvas, pfSelectRecipeWorldCanvas, etc.)
– View side-panel controllers (BeeListUI, StorageUI, ShopUI, WorldExpansionUI)
– WelcomeUI, Debug Text
h. Plugins & Tools
– DOTween: animations and tweens
– Graphy: in-game performance monitor
– NaughtyAttributes: editor enhancements
– TextMeshPro: rich text UI

##### Relationships and data flow
1. At scene load, EntryPoint instantiates DataManager → loads all ScriptableObjects into in-memory structures.
2. GameManager initializes all sub-managers in sequence (Input → Entity → Task → Quest → Placement → WorldExpansion).
3. InputManager reads from Unity’s Input System asset (PlayerInputActions) and dispatches to GameManager or directly to PlacementManager / EntityManager.
4. EntityManager & UnitsSpawnSystem use GameAssets data to spawn BeeUnitBehaviour instances on the grid from GridDatabase.
5. PlacementManager + ObjectPlaceSystem enforce placement rules and update the world state via IPlacementState implementations.
6. TaskManager generates tasks (CollectWorldItemTask, DeliverItemTask, etc.) that QuestManager wraps into quests.
7. UI Layer subscribes to managers’ events, reads current game state, and updates canvases (inventory, tooltips, side-panels).
8. SaveManager periodically (or on command) serializes GameData to disk via FileManager.

##### Architectural patterns and principles
- Data-driven design via ScriptableObjects
- Manager singleton facades for subsystems
- Component-based entities (MonoBehaviour + interfaces)
- State pattern in PlacementManager (PlacingState, RemovingState, PreviewSystem)
- Separation of concerns: Core vs. Entities vs. View vs. Data

##### Technologies & frameworks to call out
- Unity 2021+ with Universal RP
- C# 8.0 MonoBehaviours & ScriptableObjects
- Unity Input System (PlayerInputActions.inputactions)
- DOTween (animation/tween library)
- TextMeshPro (UI text rendering)
- Graphy (performance debug overlay)
- NaughtyAttributes (editor scripting)

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph "Unity Engine + Editor"
        EP["EntryPoint"]:::core
        DM["DataManager"]:::core
        GA["GameAssets"]:::data
        GD["GameData"]:::data
        GDB["GridDatabase"]:::data
        SO["ScriptableObjects"]:::data
        Interfaces["Core Interfaces"]:::data

        GM["GameManager"]:::core
        CM["CameraManager"]:::core
        IM["InputManager"]:::core
        PIA["PlayerInputActions"]:::core
        UM["UnitsManager"]:::core
        USS["UnitsSpawnSystem"]:::system
        EM["EntityManager Prefab"]:::core
        TM["TaskManager"]:::core
        TList["Tasks"]:::core
        QM["QuestManager"]:::core
        PM["PlacementManager"]:::core
        PS["ObjectPlaceSystem"]:::system
        PS1["PlacingState"]:::system
        RS["RemovingState"]:::system
        PV["PreviewSystem"]:::system
        WEM["WorldExpansionManager"]:::core
        SM["SaveManager"]:::core
        FM["FileManager"]:::system

        BUB["BeeUnitBehaviour"]:::entity
        PO["PlacedObject Components"]:::entity

        UI["UI Prefabs"]:::ui
        UIC["UI Controllers"]:::ui

        Plugins["Plugins"]:::plugin
    end

    %% Boot Sequence
    EP --> DM
    DM --> GA
    DM --> GD
    DM --> GDB
    DM --> SO
    DM --> GM

    %% Game Manager and Sub-managers
    GM --> IM
    GM --> UM
    GM --> TM
    TM --> TList
    TList --> QM
    GM --> PM
    GM --> WEM
    GM --> SM

    %% Input flow
    IM --> GM
    IM --> PM
    IM --> UM

    %% Entity spawning
    UM --> USS
    USS --> BUB
    UDATA(GA & GD & GDB) --> USS

    %% Placement System
    PM --> PS
    PS --> PS1
    PS --> RS
    PS --> PV

    %% Save System
    SM --> FM

    %% Data-driven Entities
    SO --> PO
    Interfaces -.-> BUB
    Interfaces -.-> PO

    %% UI Updates
    GM --> UIC
    TM --> UIC
    QM --> UIC
    PM --> UIC

    %% Plugins Integration
    Plugins -.-> EP
    Plugins -.-> IM
    Plugins -.-> UI

    %% Click Events
    click EP "https://github.com/zonh-off/beetopiagame/blob/main/Assets/Beetopia/Scripts/Core/EntryPoint.cs"
    click DM "https://github.com/zonh-off/beetopiagame/blob/main/Assets/Beetopia/Scripts/Core/Data/DataManager.cs"
    click GA "https://github.com/zonh-off/beetopiagame/blob/main/Assets/Beetopia/Scripts/Core/Data/GameAssets.cs"
    click GD "https://github.com/zonh-off/beetopiagame/blob/main/Assets/Beetopia/Scripts/Core/Data/GameData.cs"
    click GDB "https://github.com/zonh-off/beetopiagame/blob/main/Assets/Beetopia/Scripts/Core/Data/GridDatabase.cs"
    click GM "https://github.com/zonh-off/beetopiagame/blob/main/Assets/Beetopia/Scripts/Core/Game/GameManager.cs"
    click CM "https://github.com/zonh-off/beetopiagame/blob/main/Assets/Beetopia/Scripts/Core/Game/CameraManager.cs"
    click IM "https://github.com/zonh-off/beetopiagame/blob/main/Assets/Beetopia/Scripts/Core/Game/InputManager.cs"
    click PIA "https://github.com/zonh-off/beetopiagame/blob/main/Assets/Beetopia/Scripts/Core/Game/PlayerInputActions.cs"
    click UM "https://github.com/zonh-off/beetopiagame/blob/main/Assets/Beetopia/Scripts/Core/Game/UnitsManager.cs"
    click USS "https://github.com/zonh-off/beetopiagame/blob/main/Assets/Beetopia/Scripts/Core/Game/UnitsSpawnSystem.cs"
    click EM "https://github.com/zonh-off/beetopiagame/blob/main/Assets/Beetopia/Prefabs/Managers/EntityManager.prefab"
    click TM "https://github.com/zonh-off/beetopiagame/blob/main/Assets/Beetopia/Scripts/Core/Tasks/TaskManager.cs"
    click TList "https://github.com/zonh-off/beetopiagame/tree/main/Assets/Beetopia/Scripts/Core/Tasks/TaskList"
    click QM "https://github.com/zonh-off/beetopiagame/blob/main/Assets/Beetopia/Scripts/Core/Quests/QuestManager.cs"
    click PM "https://github.com/zonh-off/beetopiagame/blob/main/Assets/Beetopia/Scripts/Core/Placement/PlacementManager.cs"
    click PS "https://github.com/zonh-off/beetopiagame/blob/main/Assets/Beetopia/Scripts/Core/Placement/ObjectPlaceSystem.cs"
    click PS1 "https://github.com/zonh-off/beetopiagame/blob/main/Assets/Beetopia/Scripts/Core/Placement/States/PlacingState.cs"
    click RS "https://github.com/zonh-off/beetopiagame/blob/main/Assets/Beetopia/Scripts/Core/Placement/States/RemovingState.cs"
    click PV "https://github.com/zonh-off/beetopiagame/blob/main/Assets/Beetopia/Scripts/Core/Placement/States/PreviewSystem.cs"
    click WEM "https://github.com/zonh-off/beetopiagame/blob/main/Assets/Beetopia/Scripts/Core/World/WorldExpansionManager.cs"
    click SM "https://github.com/zonh-off/beetopiagame/blob/main/Assets/Beetopia/Scripts/Core/SaveSystem/SaveManager.cs"
    click FM "https://github.com/zonh-off/beetopiagame/blob/main/Assets/Beetopia/Scripts/Core/SaveSystem/FileManager.cs"
    click SO "https://github.com/zonh-off/beetopiagame/tree/main/Assets/Beetopia/ScriptableObjects"
    click Interfaces "https://github.com/zonh-off/beetopiagame/tree/main/Assets/Beetopia/Scripts/Core/Interfaces"
    click BUB "https://github.com/zonh-off/beetopiagame/blob/main/Assets/Beetopia/Scripts/Entities/Bees/BeeUnitBehaviour.cs"
    click PO "https://github.com/zonh-off/beetopiagame/tree/main/Assets/Beetopia/Scripts/Entities/PlacedObjects"
    click UI "https://github.com/zonh-off/beetopiagame/tree/main/Assets/Beetopia/Prefabs/View"
    click UIC "https://github.com/zonh-off/beetopiagame/tree/main/Assets/Beetopia/Scripts/View"
    click Plugins "https://github.com/zonh-off/beetopiagame/tree/main/Assets/Plugins/Demigiant/DOTween"
    classDef core fill:#D0E8FF,stroke:#0366D6,stroke-width:2px
    classDef data fill:#E0FFD8,stroke:#228B22,stroke-width:2px
    classDef system fill:#FFE4B5,stroke:#FF8C00,stroke-width:2px
    classDef entity fill:#FFFACD,stroke:#DAA520,stroke-width:2px
    classDef ui fill:#F0D9FF,stroke:#800080,stroke-width:2px
    classDef plugin fill:#E8E8E8,stroke:#696969,stroke-width:2px
```
