# peter-kish/gloot architecture

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

- Interactive diagram: https://gitdiagram.com/peter-kish/gloot
- Repository: https://github.com/peter-kish/gloot

## Overview

##### Project Type & Purpose
- This is a Godot engine plugin, specifically an inventory system (GLoot) that provides a universal framework to manage inventory items, item prototypes (organized into prototrees), inventory constraints (grid, weight, item count), and integrated UI controls for display.
- The system is used within games to allow dynamic property management of items, inventory operations (add, remove, transfer), and serialization/deserialization support.

##### File Structure
- The project is organized as an add-on (located in the "addons/gloot" directory) with subdirectories for:
- core: Contains the underlying logic for constraints (e.g., grid, weight, item count), inventory, prototree management, and utilities.
- editor: Contains editor plugins and custom editor nodes (e.g., inventory editor, item editor) to enhance the Godot inspector and in-editor workflow.
- There are also directories for examples, tests, docs, and additional tools (like scripts for generating documentation).

##### Main Components of the System
a. Core Components:
- Inventory (and InventoryItem) – The heart of the system for managing item stacks.
- Prototree & Prototype – Manage how item prototypes (with inheritance and properties overriding) are stored and used.
- Inventory Constraints – Classes that enforce limitations (GridConstraint, WeightConstraint, ItemCountConstraint) on inventories.
- Supporting utility components such as constraint management utilities and serialization support.
b. Editor Integration:
- Inventory Editor, Item Editor, and various custom docks or controls that interface with the Godot Editor.
c. UI Controls:
- Custom control nodes (CtrlInventory, CtrlInventoryCapacity, CtrlInventoryGrid, CtrlItemSlot) that provide interactive inventory displays and interactions.
d. Tests & Examples:
- A well-structured test suite and example scenes demonstrating different use cases and ensuring robustness.

##### Relationships & Interactions
- Editor plugins wrap around both the core and UI components to allow real-time editing and customization within the Godot editor.

##### Architectural Patterns and Design Principles
- The plugin follows a modular design pattern by separating the core logic, UI controls, and editor improvements into different directories—this separation should be highlighted.
- Serialization and deserialization methods point to a design that treats objects as data (dictionaries/JSON resources) for persistence or network transmission.

- Significant libraries or Godot-specific resources (e.g., use of TSCN scenes for UI), if relevant to understanding how components integrate.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Core System Subgraph
    subgraph "Core System"
        inv("Inventory"):::core
        invItem("InventoryItem"):::core
        protoTree("Prototree"):::core
        prototype("Prototype"):::core
        constraintManager("ConstraintManager"):::core
        gridConstraint("GridConstraint"):::core
        weightConstraint("WeightConstraint"):::core
        itemCountConstraint("ItemCountConstraint"):::core
    end

    %% UI Layer Subgraph
    subgraph "UI Layer"
        ctrlInv("CtrlInventory"):::ui
        ctrlInvCapacity("CtrlInventoryCapacity"):::ui
        ctrlInvGrid("CtrlInventoryGrid"):::ui
        ctrlInvItem("CtrlInventoryItem"):::ui
        ctrlItemSlot("CtrlItemSlot"):::ui
    end

    %% Editor Integration Subgraph
    subgraph "Editor Integration"
        invEditor("InventoryEditor"):::editor
        itemEditor("ItemEditor"):::editor
        itemSlotEditor("ItemSlotEditor"):::editor
    end

    %% Tests & Examples Subgraph
    subgraph "Tests & Examples"
        tests("Tests"):::test
        examples("Examples"):::test
    end

    %% Relationships in Core System
    inv -->|"managesConstraints"| constraintManager
    constraintManager -->|"applies"| gridConstraint
    constraintManager -->|"applies"| weightConstraint
    constraintManager -->|"applies"| itemCountConstraint
    protoTree -->|"contains"| prototype
    protoTree -->|"configures"| invItem
    inv -->|"contains"| invItem

    %% Relationships from Core to UI Layer
    inv -->|"displays"| ctrlInv
    inv -->|"updates"| ctrlInvCapacity
    inv -->|"feeds"| ctrlInvGrid
    inv -->|"populates"| ctrlInvItem
    inv -->|"syncs"| ctrlItemSlot

    %% Relationships in Editor Integration
    invEditor -->|"edits"| inv
    itemEditor -->|"edits"| invItem
    itemSlotEditor -->|"edits"| ctrlItemSlot

    %% Relationships from Tests & Examples to Core System
    tests -->|"validates"| inv
    examples -->|"demonstrates"| inv

    %% Click Events for Core System
    click inv "https://github.com/peter-kish/gloot/blob/master/addons/gloot/core/inventory.gd"
    click invItem "https://github.com/peter-kish/gloot/blob/master/addons/gloot/core/inventory_item.gd"
    click protoTree "https://github.com/peter-kish/gloot/blob/master/addons/gloot/core/prototree/proto_tree.gd"
    click prototype "https://github.com/peter-kish/gloot/blob/master/addons/gloot/core/prototree/prototype.gd"
    click constraintManager "https://github.com/peter-kish/gloot/blob/master/addons/gloot/core/constraints/constraint_manager.gd"
    click gridConstraint "https://github.com/peter-kish/gloot/blob/master/addons/gloot/core/constraints/grid_constraint.gd"
    click weightConstraint "https://github.com/peter-kish/gloot/blob/master/addons/gloot/core/constraints/weight_constraint.gd"
    click itemCountConstraint "https://github.com/peter-kish/gloot/blob/master/addons/gloot/core/constraints/item_count_constraint.gd"

    %% Click Events for UI Controls
    click ctrlInv "https://github.com/peter-kish/gloot/blob/master/addons/gloot/ui/ctrl_inventory.gd"
    click ctrlInvCapacity "https://github.com/peter-kish/gloot/blob/master/addons/gloot/ui/ctrl_inventory_capacity.gd"
    click ctrlInvGrid "https://github.com/peter-kish/gloot/blob/master/addons/gloot/ui/ctrl_inventory_grid.gd"
    click ctrlInvItem "https://github.com/peter-kish/gloot/blob/master/addons/gloot/ui/ctrl_inventory_item.gd"
    click ctrlItemSlot "https://github.com/peter-kish/gloot/blob/master/addons/gloot/ui/ctrl_item_slot.gd"

    %% Click Events for Editor Integration
    click invEditor "https://github.com/peter-kish/gloot/blob/master/addons/gloot/editor/inventory_editor/inventory_editor.gd"
    click itemEditor "https://github.com/peter-kish/gloot/blob/master/addons/gloot/editor/item_editor/properties_editor.gd"
    click itemSlotEditor "https://github.com/peter-kish/gloot/blob/master/addons/gloot/editor/item_slot_editor/item_slot_editor.gd"

    %% Click Events for Tests & Examples
    click tests "https://github.com/peter-kish/gloot/tree/master/tests/"
    click examples "https://github.com/peter-kish/gloot/tree/master/examples/"

    %% Styles
    classDef core fill:#FFCCCC,stroke:#900,stroke-width:2px;
    classDef ui fill:#CCFFCC,stroke:#090,stroke-width:2px;
    classDef editor fill:#CCCCFF,stroke:#009,stroke-width:2px;
    classDef test fill:#FFFFCC,stroke:#990,stroke-width:2px;
```
