# diamondg23/thelegendofzelda architecture

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

- Interactive diagram: https://gitdiagram.com/diamondg23/thelegendofzelda
- Repository: https://github.com/diamondg23/thelegendofzelda

## Overview

##### Project Type and Purpose
- This is a standalone, desktop Java application that combines:
- A 2D tile-based game engine (“main” module)
- An integrated tile/map editor (“editor” module)
- It uses Java 9+ modules (module-info.java), Swing/AWT UI components (MyFrame, MyButton, MyLabel), and a custom MVC-inspired structure for input, rendering, and resource management.

##### High-Level Components
a. Presentation Layer (Views & UI)
– EditorUI, EditorPanel                                (src/editor)
– GamePanel, MyFrame, MyButton, MyLabel                 (src/main)
b. Input Controllers
– KeyboardController, MouseController                   (src/controllers)
c. Domain/Business Logic
– TileManager, TileRenderer                             (src/tile)
– EditorTileManager, EditorTileRenderer                 (src/editor)
d. Model Entities
– Tile, Sprite, SpriteSheet                             (src/tile)
e. Resource & File System
– res/maps/*.txt (map definitions)
– res/spritesheet (image assets)
– I/O routines embedded in TileManager/EditorTileManager
f. Platform & Infrastructure
– Java Module System (module-info.java)
– Build output (bin/) and Eclipse project settings

##### Relationships & Data Flows
1. User interacts with the UI (EditorUI or GamePanel) →
2. UI hands events to Controllers (KeyboardController, MouseController) →
3. Controllers invoke Domain logic (TileManager or EditorTileManager) →
4. Domain logic loads or manipulates Model Entities (Tile, Sprite, SpriteSheet) via Resource layer →
6. Save/load operations read/write map files under res/maps.

##### Architectural Patterns & Principles
- MVC (or Model-View-Controller) separation:
- Model = Tile, Sprite, SpriteSheet, map data
- View = Swing panels & frames
- Controller = KeyboardController, MouseController
- Single responsibility: editor classes vs. runtime classes separated into distinct packages.
- Modularization via Java modules (module-info.java).

##### Key Details to Capture
- Separate the Editor and Game runtimes but show shared core (tile & resource management).
- Java Module boundary.
- Both user input flow and resource I/O flow.

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph "Java Module System"
        subgraph "Editor Module"
            EditorUI["EditorUI"]:::ui
            EditorPanel["EditorPanel"]:::ui
            EditorTileManager["EditorTileManager"]:::domain
            EditorTileRenderer["EditorTileRenderer"]:::domain
        end
        subgraph "Game Module"
            MyFrame["MyFrame"]:::ui
            GamePanel["GamePanel"]:::ui
            MyButton["MyButton"]:::ui
            MyLabel["MyLabel"]:::ui
            TileManager["TileManager"]:::domain
            TileRenderer["TileRenderer"]:::domain
        end
        subgraph "Controllers Package"
            KeyboardController["KeyboardController"]:::controller
            MouseController["MouseController"]:::controller
        end
        subgraph "Model Entities"
            Tile["Tile"]:::model
            Sprite["Sprite"]:::model
            SpriteSheet["SpriteSheet"]:::model
        end
        res_maps[(res/maps)]:::resource
        res_sprites[(res/spritesheet)]:::resource
    end

    %% UI to Controllers
    EditorUI -->|"mouseEvent/keyboardEvent"| MouseController
    EditorUI -->|"mouseEvent/keyboardEvent"| KeyboardController
    GamePanel -->|"mouseEvent/keyboardEvent"| MouseController
    GamePanel -->|"mouseEvent/keyboardEvent"| KeyboardController

    %% Controllers to Domain
    MouseController -->|"invokeEditorAction()"| EditorTileManager
    KeyboardController -->|"invokeEditorAction()"| EditorTileManager
    MouseController -->|"invokeGameAction()"| TileManager
    KeyboardController -->|"invokeGameAction()"| TileManager

    %% Domain to Model Entities
    EditorTileManager -->|"loadEntity() / manipulate"| Tile
    EditorTileManager -->|"loadEntity() / manipulate"| Sprite
    EditorTileManager -->|"loadEntity() / manipulate"| SpriteSheet
    TileManager -->|"loadEntity() / manipulate"| Tile
    TileManager -->|"loadEntity() / manipulate"| Sprite
    TileManager -->|"loadEntity() / manipulate"| SpriteSheet

    %% Domain to Resources
    EditorTileManager <-->|"loadMap()/saveMap()"| res_maps
    TileManager <-->|"loadMap()/saveMap()"| res_maps
    EditorTileManager -->|"loadSprites()"| res_sprites
    TileManager -->|"loadSprites()"| res_sprites

    %% Renderer to UI
    EditorTileRenderer -->|"draw()"| EditorPanel
    TileRenderer -->|"draw()"| GamePanel

    %% Resource Store to Model Entities
    res_sprites -->|"imageData"| SpriteSheet

    %% Click events
    click EditorUI "https://github.com/diamondg23/thelegendofzelda/blob/main/src/editor/EditorUI.java"
    click EditorPanel "https://github.com/diamondg23/thelegendofzelda/blob/main/src/editor/EditorPanel.java"
    click GamePanel "https://github.com/diamondg23/thelegendofzelda/blob/main/src/main/GamePanel.java"
    click MyFrame "https://github.com/diamondg23/thelegendofzelda/blob/main/src/main/MyFrame.java"
    click MyButton "https://github.com/diamondg23/thelegendofzelda/blob/main/src/main/MyButton.java"
    click MyLabel "https://github.com/diamondg23/thelegendofzelda/blob/main/src/main/MyLabel.java"
    click KeyboardController "https://github.com/diamondg23/thelegendofzelda/blob/main/src/controllers/KeyboardController.java"
    click MouseController "https://github.com/diamondg23/thelegendofzelda/blob/main/src/controllers/MouseController.java"
    click TileManager "https://github.com/diamondg23/thelegendofzelda/blob/main/src/tile/TileManager.java"
    click TileRenderer "https://github.com/diamondg23/thelegendofzelda/blob/main/src/tile/TileRenderer.java"
    click EditorTileManager "https://github.com/diamondg23/thelegendofzelda/blob/main/src/editor/EditorTileManager.java"
    click EditorTileRenderer "https://github.com/diamondg23/thelegendofzelda/blob/main/src/editor/EditorTileRenderer.java"
    click Tile "https://github.com/diamondg23/thelegendofzelda/blob/main/src/tile/Tile.java"
    click Sprite "https://github.com/diamondg23/thelegendofzelda/blob/main/src/tile/Sprite.java"
    click SpriteSheet "https://github.com/diamondg23/thelegendofzelda/blob/main/src/tile/SpriteSheet.java"
    click res_maps "https://github.com/diamondg23/thelegendofzelda/tree/main/res/maps/"
    click res_sprites "https://github.com/diamondg23/thelegendofzelda/tree/main/res/spritesheet/"
    click module-info "https://github.com/diamondg23/thelegendofzelda/blob/main/src/module-info.java"

    classDef ui fill:#ADD8E6,stroke:#000,stroke-width:1px
    classDef controller fill:#90EE90,stroke:#000,stroke-width:1px
    classDef domain fill:#FFA500,stroke:#000,stroke-width:1px
    classDef model fill:#FFD700,stroke:#000,stroke-width:1px
    classDef resource fill:#D3D3D3,stroke:#000,stroke-width:1px
```
