# emilhadiev/towerdefense architecture

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

- Interactive diagram: https://gitdiagram.com/emilhadiev/towerdefense
- Repository: https://github.com/emilhadiev/towerdefense

## Overview

##### Overall Project Type and Purpose
- Recognize the project is a Unity-based game. Its source code is organized in the Assets folder with significant subdivisions such as Scripts (for game logic, character behaviors, state machines, abilities, and UI), Prefabs (for game objects like bullets, players, enemies, etc.), Scenes (sample game scenes with configuration for NavMesh and lighting), and Resources (for in-game assets).
- The heavy presence of Zenject (the “Plugins/Zenject” folder along with numerous integration tests, installers, bindings, factories, providers, etc.) indicates that dependency injection is central to how components interact and are instantiated at runtime. This simplifies testing and decouples systems.

##### Main Architectural Components
a. Game Modules/Subsystems:
– Animation, character controllers, enemy AI, state machines, abilities, bullet movement, and UI systems.
– Specific modules are hinted at in directories: “Character”, “Ability”, “Bullets”, “Attacker”, “Health”, “StateMachine”, “Sound”, “Spawner”, etc.
b. Data and Resource Layers:
– Assets, prefabs, scenes, and resources like TextMesh Pro resources, Materials, and Audio files.
c. Zenject Dependency Injection Framework:
– Acts as a central container that holds installers, binding scripts, provider managers, and factories. There are installer directories found in the Scripts (and Zenject folders) that dictate how game objects and services are created and wired.
d. Core Unity Components:
– The Scenes (like “SampleScene”), GameObjects (players, enemies, bullets) and Prefabs, accompanied by scripts that control behavior.
e. Utility and Infrastructure Layers:
– There are common utility scripts (e.g., for easing animations, managing pools, scene loading, debugging) and integration tests that ensure proper wiring.

##### Relationships and Interactions
- How each subsystem interacts via dependency injection. For instance, the Zenject “DiContainer” (or installer nodes) facilitates the instantiation of game components (such as enemy characters, player controllers, and bullet behaviors).

##### Architectural Patterns and Technical Details to Emphasize
- Component-Based Architecture: Show how various scripts (e.g., “Player.cs”, “Enemy.cs”) attach to prefabs, and how these prefabs are used in scenes.
- Use of Dependency Injection: Emphasize Zenject’s role, illustrating a central “DiContainer” or “Installer” that binds interfaces to concrete implementations. Indicate factories, providers, and subcontainers (used for scene-specific or prefab-specific dependency injection).
- Design Principles: Mark how loose coupling and testability are achieved via Zenject and modular code (highlight integration tests, multiple binding strategies from the many “Test…” folders).

##### Putting It All Together
a. A central node representing Zenject’s DiContainer or a “Core Installer”. From there, branch out to nodes representing key installers and managers (e.g., “GameInstaller”, “EnemyInstaller”, “PlayerInstaller”).
b. From each installer node, branch further to specific subsystems:
– For example, “EnemyInstaller” connects to the “Enemy State Machine”, “Enemy Movement”, and “Enemy Attack Zone” nodes.
– “PlayerInstaller” connects to “Player Controller”, “Player Health”, “UI Updates”, and “Input Handlers”.

- A high-level overview of Unity’s scene and prefab structure, highlighting key game objects.
- A detailed view of the DI container (Zenject) that shows how installers and bindings wire different modules together.
- The modular separation between game logic (characters, abilities, health, movement) and infrastructure (DI, resource management).

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Infrastructure Layer: DI
    subgraph "Infrastructure Layer: DI"
        DiContainer["Zenject DiContainer"]:::di
        ZenjectLibrary["Zenject Library"]:::di
        GameInstaller["Game Installer"]:::di
        EnemyInstaller["Enemy Installer"]:::di
        PlayerInstaller["Player Installer"]:::di
    end

    %% Unity Core Elements
    subgraph "Unity Core Elements"
        Scenes["Scenes"]:::unity
        Prefabs["Prefabs"]:::unity
    end

    %% Game Logic Layer
    subgraph "Game Logic Layer"
        CharacterSystems["Character Systems"]:::logic
        AbilitySystems["Ability Systems"]:::logic
        BulletMechanics["Bullet Mechanics"]:::logic
        AttackBehaviors["Attack Behaviors"]:::logic
        HealthSystems["Health Systems"]:::logic
        StateMachine["State Machine"]:::logic
        SpawnerSystems["Spawner Systems"]:::logic
        SoundManagement["Sound Management"]:::logic
    end

    %% Data and Resource Layers
    subgraph "Data and Resource Layers"
        GameData["Game Data"]:::resources
        RuntimeResources["Runtime Resources"]:::resources
        MaterialsAudio["Materials & Audio"]:::resources
    end

    %% Animation Components
    subgraph "Animation Components"
        Animation["Animation Assets"]:::animation
    end

    %% UI and View Layers
    subgraph "UI and View Layers"
        UIPrefabs["UI Prefabs"]:::ui
        UIScripts["UI Scripts"]:::ui
    end

    %% Utility and Debug Layers
    subgraph "Utility and Debug Layers"
        DebugUtil["Debug & Util"]:::utility
        TMP["TextMesh Pro"]:::utility
    end

    %% Connections
    %% Scene initialization
    Scenes -->|"loads"| DiContainer

    %% Zenject DI flow
    ZenjectLibrary --> DiContainer
    DiContainer -->|"injects"| GameInstaller
    DiContainer -->|"injects"| EnemyInstaller
    DiContainer -->|"injects"| PlayerInstaller

    %% Installer to Game Logic dependencies
    GameInstaller -->|"configures"| CharacterSystems
    GameInstaller -->|"configures"| AbilitySystems
    GameInstaller -->|"configures"| BulletMechanics
    GameInstaller -->|"configures"| SpawnerSystems

    EnemyInstaller -->|"configures"| AttackBehaviors
    EnemyInstaller -->|"configures"| StateMachine
    EnemyInstaller -->|"configures"| SoundManagement

    PlayerInstaller -->|"configures"| CharacterSystems
    PlayerInstaller -->|"configures"| HealthSystems
    PlayerInstaller -->|"configures"| AttackBehaviors

    %% Data and Resources flows
    GameData -->|"provides"| CharacterSystems
    RuntimeResources -->|"loaded_by"| Prefabs
    MaterialsAudio -->|"used_by"| UIPrefabs

    %% Animation flow
    Animation -->|"animates"| Prefabs

    %% UI interactions
    UIScripts -->|"updates"| UIPrefabs

    %% Utility support
    DebugUtil -->|"supports"| GameInstaller
    TMP -->|"renders"| UIScripts

    %% Linking Unity Core Elements with Game Logic
    Prefabs -->|"instantiates"| CharacterSystems

    %% Styles
    classDef di fill:#F9E79F,stroke:#D4AC0D,stroke-width:2px;
    classDef logic fill:#AED6F1,stroke:#2471A3,stroke-width:2px;
    classDef unity fill:#A9DFBF,stroke:#27AE60,stroke-width:2px;
    classDef resources fill:#FAD7A0,stroke:#D68910,stroke-width:2px;
    classDef animation fill:#D2B4DE,stroke:#7D3C98,stroke-width:2px;
    classDef ui fill:#F5CBA7,stroke:#E67E22,stroke-width:2px;
    classDef utility fill:#CCD1D1,stroke:#566573,stroke-width:2px;

    %% Click Events
    click Scenes "https://github.com/emilhadiev/towerdefense/tree/master/Assets/Scenes"
    click Prefabs "https://github.com/emilhadiev/towerdefense/tree/master/Assets/Prefab"
    click CharacterSystems "https://github.com/emilhadiev/towerdefense/tree/master/Assets/Scripts/Character"
    click AbilitySystems "https://github.com/emilhadiev/towerdefense/tree/master/Assets/Scripts/Ability"
    click BulletMechanics "https://github.com/emilhadiev/towerdefense/tree/master/Assets/Scripts/Bullets"
    click AttackBehaviors "https://github.com/emilhadiev/towerdefense/tree/master/Assets/Scripts/Attacker"
    click HealthSystems "https://github.com/emilhadiev/towerdefense/tree/master/Assets/Scripts/Health"
    click StateMachine "https://github.com/emilhadiev/towerdefense/tree/master/Assets/Scripts/StateMachine"
    click SpawnerSystems "https://github.com/emilhadiev/towerdefense/tree/master/Assets/Scripts/Spawner"
    click SoundManagement "https://github.com/emilhadiev/towerdefense/tree/master/Assets/Scripts/Sound"
    click ZenjectLibrary "https://github.com/emilhadiev/towerdefense/tree/master/Assets/Plugins/Zenject"
    click GameInstaller "https://github.com/emilhadiev/towerdefense/tree/master/Assets/Scripts/Zenject"
    click EnemyInstaller "https://github.com/emilhadiev/towerdefense/tree/master/Assets/Scripts/Zenject"
    click PlayerInstaller "https://github.com/emilhadiev/towerdefense/tree/master/Assets/Scripts/Zenject"
    click GameData "https://github.com/emilhadiev/towerdefense/tree/master/Assets/Scripts/Data"
    click RuntimeResources "https://github.com/emilhadiev/towerdefense/tree/master/Assets/Resources"
    click Animation "https://github.com/emilhadiev/towerdefense/tree/master/Assets/Animations"
    click UIPrefabs "https://github.com/emilhadiev/towerdefense/tree/master/Assets/Prefab/UI"
    click UIScripts "https://github.com/emilhadiev/towerdefense/tree/master/Assets/Scripts/View/UI"
    click DebugUtil "https://github.com/emilhadiev/towerdefense/tree/master/Assets/Scripts/DEBUG"
    click TMP "https://github.com/emilhadiev/towerdefense/tree/master/Assets/TextMesh Pro"
```
