# jslegenddev/javascript-metroidvania architecture

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

- Interactive diagram: https://gitdiagram.com/jslegenddev/javascript-metroidvania
- Repository: https://github.com/jslegenddev/javascript-metroidvania

## Overview

##### Main Components Organization

a) Game Engine Layer
- Kaboom.js at the foundation level
- It to the core game systems via the kaboomLoader.js

b) Core Game Architecture
Following major systems:
- Scene Management System
- Entity Management System
- State Management System
- UI System
- Asset Management System

##### Detailed Component Breakdown

Create distinct sections for each major system:

a) Scene Management (maps & scenes folders)
- Relationship between room1.js, room2.js, and roomUtils.js
- To corresponding map files (room1.json, room2.json)
- Scene loading and transition flows

b) Entity System (entities folder)
- Branch out to specific entities:
- player.js
- enemyBoss.js
- enemyDrone.js
- healthCartridge.js
- Inheritance and interaction patterns

c) State Management
- GlobalStateManager.js as a central hub
- State flow to other systems
- Game state persistence patterns

d) UI System
- HealthBar.js and notificationBox.js components
- Their connection to the state management system
- Event handling flow

e) Asset Management
- Assets by type (sounds, sprites, palette)
- Loading patterns and resource management

Use the following visual elements:

- Rectangles: For major systems and components
- Rounded rectangles: For individual entities and UI elements
- Hexagons: For asset containers
- Blue: Core engine components
- Green: Game logic and entities
- Yellow: UI elements
- Purple: Asset management
- Red: State management

##### Key Relationships to Highlight

- How main.js orchestrates the entire system
- How globalStateManager.js interfaces with all major systems
- Demonstrate the relationship between scenes and their corresponding map files
- How entities interact with the state management system
- UI component updates based on state changes

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Legend
        L1[Component]:::component
        L2([System]):::system
        L3[(Asset Store)]:::asset
        L4{{Engine}}:::engine
        L5[/UI Element/]:::ui
    end

    subgraph "Game Engine Layer"
        KaboomEngine{{Kaboom.js}}:::engine
        KaboomLoader[KaboomLoader]
    end

    subgraph "Core Systems"
        SceneSystem([Scene Management]):::system
        EntitySystem([Entity Management]):::system
        StateSystem([State Management]):::system
        UISystem([UI System]):::system
        AssetSystem([Asset Management]):::system
    end

    subgraph "Scene Management"
        Room1[Room1]
        Room2[Room2]
        RoomUtils[RoomUtils]
        Room1Map[(Room1 Map)]:::asset
        Room2Map[(Room2 Map)]:::asset
    end

    subgraph "Entity Management"
        SharedLogic[Entity Shared Logic]
        Player[Player]
        EnemyBoss[Enemy Boss]
        EnemyDrone[Enemy Drone]
        HealthCartridge[Health Cartridge]
    end

    subgraph "State Management"
        GlobalState[Global State Manager]
    end

    subgraph "UI Components"
        HealthBar[/Health Bar/]:::ui
        NotificationBox[/Notification Box/]:::ui
    end

    subgraph "Asset Management"
        Sounds[(Sounds)]:::asset
        Sprites[(Sprites)]:::asset
        Palette[(Color Palette)]:::asset
    end

    Main[Main Game Controller]

    %% Relationships
    KaboomEngine --> KaboomLoader
    KaboomLoader --> Main

    Main --> SceneSystem
    Main --> EntitySystem
    Main --> StateSystem
    Main --> UISystem
    Main --> AssetSystem

    SceneSystem --> Room1
    SceneSystem --> Room2
    SceneSystem --> RoomUtils
    Room1 -.-> Room1Map
    Room2 -.-> Room2Map

    EntitySystem --> SharedLogic
    SharedLogic --> Player
    SharedLogic --> EnemyBoss
    SharedLogic --> EnemyDrone
    SharedLogic --> HealthCartridge

    StateSystem --> GlobalState
    GlobalState -.-> Player
    GlobalState -.-> UISystem

    UISystem --> HealthBar
    UISystem --> NotificationBox

    AssetSystem --> Sounds
    AssetSystem --> Sprites
    AssetSystem --> Palette

    %% Styling
    classDef engine fill:#2d5af1,stroke:#333,stroke-width:2px
    classDef system fill:#f1b52d,stroke:#333,stroke-width:2px
    classDef component fill:#42b883,stroke:#333,stroke-width:2px
    classDef asset fill:#9c42b8,stroke:#333,stroke-width:2px
    classDef ui fill:#f15d2d,stroke:#333,stroke-width:2px

    %% Click events
    click KaboomEngine "https://github.com/JSLegendDev/JavaScript-Metroidvania/blob/master/lib/kaboom.mjs"
    click KaboomLoader "https://github.com/JSLegendDev/JavaScript-Metroidvania/blob/master/src/kaboomLoader.js"
    click Room1 "https://github.com/JSLegendDev/JavaScript-Metroidvania/blob/master/src/scenes/room1.js"
    click Room2 "https://github.com/JSLegendDev/JavaScript-Metroidvania/blob/master/src/scenes/room2.js"
    click RoomUtils "https://github.com/JSLegendDev/JavaScript-Metroidvania/blob/master/src/scenes/roomUtils.js"
    click Room1Map "https://github.com/JSLegendDev/JavaScript-Metroidvania/blob/master/maps/room1.json"
    click Room2Map "https://github.com/JSLegendDev/JavaScript-Metroidvania/blob/master/maps/room2.json"
    click SharedLogic "https://github.com/JSLegendDev/JavaScript-Metroidvania/blob/master/src/entities/entitySharedLogic.js"
    click Player "https://github.com/JSLegendDev/JavaScript-Metroidvania/blob/master/src/entities/player.js"
    click EnemyBoss "https://github.com/JSLegendDev/JavaScript-Metroidvania/blob/master/src/entities/enemyBoss.js"
    click EnemyDrone "https://github.com/JSLegendDev/JavaScript-Metroidvania/blob/master/src/entities/enemyDrone.js"
    click HealthCartridge "https://github.com/JSLegendDev/JavaScript-Metroidvania/blob/master/src/entities/healthCartridge.js"
    click GlobalState "https://github.com/JSLegendDev/JavaScript-Metroidvania/blob/master/src/state/globalStateManager.js"
    click HealthBar "https://github.com/JSLegendDev/JavaScript-Metroidvania/blob/master/src/ui/healthBar.js"
    click NotificationBox "https://github.com/JSLegendDev/JavaScript-Metroidvania/blob/master/src/ui/notificationBox.js"
    click Sounds "https://github.com/JSLegendDev/JavaScript-Metroidvania/tree/master/assets/sounds"
    click Sprites "https://github.com/JSLegendDev/JavaScript-Metroidvania/tree/master/assets/sprites"
    click Palette "https://github.com/JSLegendDev/JavaScript-Metroidvania/blob/master/assets/palette.pal"
    click Main "https://github.com/JSLegendDev/JavaScript-Metroidvania/blob/master/src/main.js"
```
