# adammyhre/unity-inventory-system architecture

> Architecture diagram of the GitHub repository adammyhre/unity-inventory-system, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-02-13). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/adammyhre/unity-inventory-system
- Repository: https://github.com/adammyhre/unity-inventory-system

## Overview

##### Project Type and Purpose
- This is a Unity-based project that implements an inventory system intended for use within a game or interactive simulation. Its purpose is to demonstrate comprehensive inventory management (from UI and interaction to persistence and scene management) while using Unity’s UI Toolkit.
- The README confirms that the project supports drag & drop UI, data binding for logic, and save/load persistence. It also relies on external libraries (like Eflatun.SceneReference) and Unity’s Addressables, suggesting modularity and future extensibility.

##### Analyzing the File Structure
- The main code resides inside the Assets/_Project folder, signifying it is organized as a Unity project.
- The “Scripts” folder is further divided into several subdirectories indicating separate modules:
- Inventory: Likely following an MVC or similar pattern given the presence of InventoryController, InventoryModel, InventoryView, Item, Slot, ItemDatabase, etc.
- Persistence: Contains files for data serialization, file I/O (FileDataService), save/load logic (SaveLoadSystem), and an editor extension for the Save Manager.
- SceneManagement: Contains bootstrapping logic, scene loader, scene grouping/management components, and also editor scripts to assist with scene management in the Unity Editor.
- Utility: Provides singleton support and other helper functionalities.
- Extensions and Helpers: Provide additional support methods (for binary reading/writing, GUID handling, and UI extensions) which contribute to quality code reuse and robust data handling.
- The presence of UI files (Inventory.uss, Inventory.uxml) indicates a clear separation of visual presentation (UI) from underlying business logic.

a. Main Components:
- Inventory Module: Representing the data (InventoryData, InventoryModel), logic (InventoryController), view (InventoryView, UI files), and items management (Item, Slot, ItemDatabase).
- Persistence Module: Handling data storage and retrieval, serialization (JsonSerializer, ISerializer), file services (FileDataService), and the overall save/load process (SaveLoadSystem).
- Scene Management Module: Managing scene bootstrapping and transitions via SceneLoader, SceneGroup, SceneGroupManager, along with related editor utilities.
- Extension and Utility Services: Providing helper functions (binary/data extensions, GUID handling) and persistent singleton management.
- External Integrations: Incorporate libraries like Eflatun.SceneReference and Unity’s Addressables, which play roles in scene referencing, asset management, and asynchronous loading.

b. Relationships and Interactions:
- The Inventory Module interacts with the Persistence Module when saving or retrieving inventory data.
- The UI is decoupled through InventoryView and connected to InventoryController which acts as the mediator between the view and model.
- Scene Management interacts with the Inventory system during scene transitions (e.g., to persist player data or load specific inventories) and with persistence for saving state.
- Utility and Helper functions are used across the modules to handle common tasks such as data binding, serialization, and UI manipulation.

c. Architectural Patterns and Design Principles:
- The code structure hints at an MVC or Model-View-Controller separation in the Inventory module.
- Single Responsibility Principle is observed by separating persistence, scene management, and UI responsibilities.
- Use of editor folders for Unity-specific customizations shows an extension pattern for integrated development environments.

d. Relevant Technologies, Frameworks, and Libraries:
- Unity Engine (version 2023.2 or above) is the primary platform.
- UI Toolkit (for building dynamic and procedural UIs).
- Eflatun.SceneReference for managing scene references, and the Addressables package for asset management.
- Built-in C# libraries and project-specific helper/extension methods to support robust functionalities.

##### Final Steps
- Further break down each module (for example, Inventory module splits into InventoryModel, InventoryView, and InventoryController).
- Components for persistence and scene management, showing their interactions with the Inventory module.
- Helper or extension services that support these modules.

This detailed yet modular view will provide a clear understanding of the key architectural components and their interactions for the Unity Inventory System. It makes explicit the separation among UI, logic, persistence, scene management, and helper functionalities while incorporating external service integrations, and it should serve as a comprehensive guide for further development or debugging by the principal software engineer.

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Inventory Module"
        INV_UI["Inventory View"]:::inventory
        INV_Logic["Inventory Controller"]:::inventory
        INV_Data["Inventory Model/Data"]:::inventory
        INV_Items["Items & Slots"]:::inventory
        INV_Drag["Drag & Drop Handler"]:::inventory
    end

    INV_UI -->|"triggers"| INV_Logic
    INV_Logic -->|"updates"| INV_Data
    INV_Logic -->|"manages"| INV_Items
    INV_UI -->|"handlesDrag"| INV_Drag

    subgraph "Persistence Module"
        PERSIST_Data["Data Services & Serialization"]:::persistence
        PERSIST_SaveLoad["SaveLoad System"]:::persistence
        PERSIST_Editor["Persistence Editor Support"]:::persistence
    end

    PERSIST_Data -->|"supports"| PERSIST_SaveLoad
    INV_Logic -->|"persistsData"| PERSIST_SaveLoad

    subgraph "Scene Management Module"
        SCENE_Bootstrap["Bootstrapper"]:::scene
        SCENE_Loader["Scene Loader"]:::scene
        SCENE_Group["Scene Grouping"]:::scene
        SCENE_Editor["Scene Editor Integration"]:::scene
    end

    SCENE_Bootstrap -->|"initiates"| SCENE_Loader
    SCENE_Loader -->|"managesScenes"| SCENE_Group
    SCENE_Loader -->|"savesState"| PERSIST_SaveLoad
    SCENE_Loader -->|"affectsInventory"| INV_Logic

    subgraph "Extensions & Utility"
        EXT_Extensions["Extension Methods"]:::extension
        EXT_Helpers["Helper Functions"]:::extension
        UTIL_Singleton["Persistent Singleton"]:::extension
    end

    INV_Logic -->|"uses"| EXT_Helpers
    PERSIST_SaveLoad -->|"uses"| EXT_Extensions
    SCENE_Bootstrap -->|"uses"| UTIL_Singleton

    EXT_Integrations["External Libraries (Eflatun.SceneReference,Addressables)"]:::external
    SCENE_Loader -->|"integrates"| EXT_Integrations

    subgraph "Legend"
        L1["Inventory Module"]:::inventory
        L2["Persistence Module"]:::persistence
        L3["Scene Management Module"]:::scene
        L4["Extensions & Utility"]:::extension
        L5["External Integration"]:::external
    end

    click INV_Logic "https://github.com/adammyhre/unity-inventory-system/blob/master/Assets/_Project/Scripts/Inventory/InventoryController.cs"
    click INV_Data "https://github.com/adammyhre/unity-inventory-system/blob/master/Assets/_Project/Scripts/Inventory/InventoryModel.cs"
    click INV_UI "https://github.com/adammyhre/unity-inventory-system/blob/master/Assets/_Project/Scripts/Inventory/InventoryView.cs"
    click INV_Items "https://github.com/adammyhre/unity-inventory-system/blob/master/Assets/_Project/Scripts/Inventory/Item.cs"
    click INV_Drag "https://github.com/adammyhre/unity-inventory-system/blob/master/Assets/_Project/Scripts/Inventory/Manipulators/PanelDragManipulator.cs"

    click PERSIST_Data "https://github.com/adammyhre/unity-inventory-system/blob/master/Assets/_Project/Scripts/Persistence/FileDataService.cs"
    click PERSIST_SaveLoad "https://github.com/adammyhre/unity-inventory-system/blob/master/Assets/_Project/Scripts/Persistence/SaveLoadSystem.cs"
    click PERSIST_Editor "https://github.com/adammyhre/unity-inventory-system/blob/master/Assets/_Project/Scripts/Persistence/Editor/SaveManagerEditor.cs"

    click SCENE_Bootstrap "https://github.com/adammyhre/unity-inventory-system/blob/master/Assets/_Project/Scripts/SceneManagement/Bootstrapper.cs"
    click SCENE_Loader "https://github.com/adammyhre/unity-inventory-system/blob/master/Assets/_Project/Scripts/SceneManagement/SceneLoader.cs"
    click SCENE_Group "https://github.com/adammyhre/unity-inventory-system/blob/master/Assets/_Project/Scripts/SceneManagement/SceneGroup.cs"
    click SCENE_Editor "https://github.com/adammyhre/unity-inventory-system/blob/master/Assets/_Project/Scripts/SceneManagement/Editor/SceneLoaderEditor.cs"

    click EXT_Extensions "https://github.com/adammyhre/unity-inventory-system/tree/master/Assets/_Project/Scripts/Inventory/Extensions"
    click EXT_Helpers "https://github.com/adammyhre/unity-inventory-system/tree/master/Assets/_Project/Scripts/Inventory/Helpers"
    click UTIL_Singleton "https://github.com/adammyhre/unity-inventory-system/blob/master/Assets/_Project/Scripts/Utility/PersistentSingleton.cs"

    classDef inventory fill:#ADD8E6,stroke:#000,stroke-width:1px;
    classDef persistence fill:#90EE90,stroke:#000,stroke-width:1px;
    classDef scene fill:#FFFFB3,stroke:#000,stroke-width:1px;
    classDef extension fill:#FFC0CB,stroke:#000,stroke-width:1px;
    classDef external fill:#D3D3D3,stroke:#000,stroke-width:1px;
    classDef legend fill:#fff,stroke:#333,stroke-dasharray: 5 5,stroke-width:1px;
```
