# yoshimoshi4/dndsim architecture

> Architecture diagram of the GitHub repository yoshimoshi4/dndsim, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-09-17). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/yoshimoshi4/dndsim
- Repository: https://github.com/yoshimoshi4/dndsim

## Overview

#### Purpose and Entry Point
DnDSim is a desktop tactical RPG/battle simulator and content editor. It models characters, enemies, items, terrain, party setup, and turn-based grid combat using local JSON-backed saves. `Main.java` is the application entry point; `UI/AppController.java` is the likely top-level navigation/controller boundary.

#### Application Navigation and Screens
The UI is organized as JavaFX-style views for the main menu, character sheets, asset editing, battle setup, battle execution, and victory presentation. Controllers/views coordinate user-driven transitions rather than exposing a network API.
- `UI/AppController.java`
- `UI/MainMenuView.java`
- `UI/AssetEditorView.java`
- `UI/CharacterSheetView.java`
- `UI/Battle/BattleView.java`

#### Domain Model and Persistence
`Objects/Entity.java` defines shared entity behavior, with combatants and map objects specialized into enemies, pickups, and terrain. `EntityRes` contains serializable resource/domain definitions for character sheets, status, inventory/item categories, and party composition. JSON save directories are the persistent content store, likely read/written through Gson.
- `Objects/Entity.java`
- `Objects/Enemy.java`
- `EntityRes/CharSheet.java`
- `EntityRes/ItemDatabase.java`
- `saves/entities/party/Hana_Shiroi.json`
- `saves/party.json`

#### Assets, Inventory, and Content Editing
Items are polymorphic resource records—weapon, armor, accessory, consumable, ammunition, crafting, and key items—with abilities and type adaptation supporting JSON deserialization. The asset editor and databases make game content editable independently of active battles.
- `EntityRes/Item.java`
- `EntityRes/ItemTypeAdapter.java`
- `EntityRes/Weapon.java`
- `EntityRes/ItemAbility.java`
- `UI/AssetEditorView.java`
- `saves/items/weapons/Shortbarrel_Shotgun.json`

#### Battle Grid and Map Assembly
Battle setup creates a grid populated by entities, pickups, and terrain. `BattleGrid` holds the logical board while `BattleGridCanvas` and shape/theme classes render it. Terrain definitions are local JSON content mediated by a terrain database.
- `UI/Battle/BattleGrid.java`
- `UI/Battle/BattleGridCanvas.java`
- `Objects/GridObject.java`
- `Objects/TerrainObject.java`
- `UI/TerrainDatabase.java`
- `saves/terrain/Acid.json`

#### Combat and Turn Lifecycle
`BattleState` is the central mutable battle-session boundary. `CombatManager` resolves combat actions against state/grid/entities, while `TurnManager` controls turn order and progression. UI bindings and panels project battle state into health displays, timeline, dice interaction, and terminal victory flow.
- `UI/Battle/BattleState.java`
- `UI/Battle/CombatManager.java`
- `UI/Battle/TurnManager.java`
- `UI/Battle/EntityHealthBinding.java`
- `UI/Battle/TimelinePane.java`
- `UI/Battle/VictoryView.java`

#### Rendering, Assets, and Runtime Dependencies
The runtime is Java with JavaFX UI libraries. Gson provides JSON serialization, and Ikonli supplies icon rendering. Sprite and CSS resources support visual presentation; no server, database, or cloud service is represented.
- `lib/gson-2.10.1.jar`
- `lib/ikonli-javafx-12.4.0.jar`
- `UI/SpriteUtils.java`
- `resources/sprites/party`
- `resources/styles/dark-theme.css`

Main entry points: [`UI/Battle/BattleView.java`](https://github.com/yoshimoshi4/dndsim/blob/main/UI/Battle/BattleView.java) (Battle view), [`UI/AppController.java`](https://github.com/yoshimoshi4/dndsim/blob/main/UI/AppController.java) (App controller), [`UI/Battle/BattleState.java`](https://github.com/yoshimoshi4/dndsim/blob/main/UI/Battle/BattleState.java) (Battle state), [`saves/party.json`](https://github.com/yoshimoshi4/dndsim/blob/main/saves/party.json) (JSON save content)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_ui["JavaFX UI"]
  node_main{{"Application entry<br/>Java launcher<br/>[Main.java]"}}
  node_app_controller["App controller<br/>navigation controller<br/>[AppController.java]"]
  node_main_menu["Main menu<br/>JavaFX view<br/>[MainMenuView.java]"]
  node_character_sheet["Character sheet<br/>JavaFX view"]
  node_asset_editor["Asset editor<br/>JavaFX view"]
  node_battle_view["Battle view<br/>JavaFX view<br/>[BattleView.java]"]
end

subgraph group_domain["Domain &amp; Content"]
  node_entity["Entity hierarchy<br/>domain base class<br/>[Entity.java]"]
  node_enemy["Enemy<br/>combatant model<br/>[Enemy.java]"]
  node_character_data["Character &amp; party data<br/>serializable domain model<br/>[CharSheet.java]"]
  node_item_system["Polymorphic items<br/>resource model<br/>[Item.java]"]
  node_item_adapter["Item type adapter<br/>JSON adapter"]
end

subgraph group_battle["Battle Runtime"]
  node_battle_grid["Battle grid<br/>board model<br/>[BattleGrid.java]"]
  node_terrain["Terrain objects<br/>map object model<br/>[TerrainObject.java]"]
  node_battle_state["Battle state<br/>mutable session<br/>[BattleState.java]"]
  node_combat_manager["Combat manager<br/>action resolver<br/>[CombatManager.java]"]
  node_turn_manager["Turn manager<br/>turn lifecycle<br/>[TurnManager.java]"]
  node_battle_canvas["Grid canvas<br/>JavaFX renderer"]
  node_battle_panels["Battle HUD &amp; victory<br/>JavaFX presentation<br/>[VictoryView.java]"]
end

subgraph group_storage["Local Resources"]
  node_json_saves[("JSON save content<br/>local persistence<br/>[party.json]")]
  node_visual_resources["Sprites &amp; dark theme<br/>application resources<br/>[dark-theme.css]"]
end

node_main -->|"starts"| node_app_controller
node_app_controller -->|"navigates"| node_main_menu
node_app_controller -->|"navigates"| node_character_sheet
node_app_controller -->|"navigates"| node_asset_editor
node_app_controller -->|"navigates"| node_battle_view
node_entity -->|"specializes"| node_enemy
node_character_data -.->|"defines combatants"| node_entity
node_item_adapter -->|"deserializes"| node_item_system
node_asset_editor -->|"edits"| node_item_system
node_asset_editor -->|"reads / writes"| node_json_saves
node_character_sheet -->|"edits"| node_character_data
node_json_saves -.->|"loads"| node_character_data
node_json_saves -.->|"loads"| node_item_system
node_json_saves -.->|"loads"| node_terrain
node_battle_view -->|"drives"| node_battle_state
node_battle_state -->|"owns session board"| node_battle_grid
node_battle_grid -->|"places"| node_entity
node_battle_grid -->|"places"| node_terrain
node_combat_manager -->|"resolves actions"| node_battle_state
node_turn_manager -->|"advances turns"| node_battle_state
node_battle_view -->|"submits actions"| node_combat_manager
node_battle_view -->|"uses turn order"| node_turn_manager
node_battle_canvas -->|"renders"| node_battle_grid
node_battle_view -->|"contains"| node_battle_canvas
node_battle_panels -->|"projects"| node_battle_state
node_battle_view -->|"shows"| node_battle_panels
node_visual_resources -.->|"styles sprites"| node_battle_canvas

click node_main "https://github.com/yoshimoshi4/dndsim/blob/main/Main.java"
click node_app_controller "https://github.com/yoshimoshi4/dndsim/blob/main/UI/AppController.java"
click node_main_menu "https://github.com/yoshimoshi4/dndsim/blob/main/UI/MainMenuView.java"
click node_character_sheet "https://github.com/yoshimoshi4/dndsim/blob/main/UI/CharacterSheetView.java"
click node_asset_editor "https://github.com/yoshimoshi4/dndsim/blob/main/UI/AssetEditorView.java"
click node_battle_view "https://github.com/yoshimoshi4/dndsim/blob/main/UI/Battle/BattleView.java"
click node_entity "https://github.com/yoshimoshi4/dndsim/blob/main/Objects/Entity.java"
click node_enemy "https://github.com/yoshimoshi4/dndsim/blob/main/Objects/Enemy.java"
click node_character_data "https://github.com/yoshimoshi4/dndsim/blob/main/EntityRes/CharSheet.java"
click node_item_system "https://github.com/yoshimoshi4/dndsim/blob/main/EntityRes/Item.java"
click node_item_adapter "https://github.com/yoshimoshi4/dndsim/blob/main/EntityRes/ItemTypeAdapter.java"
click node_battle_grid "https://github.com/yoshimoshi4/dndsim/blob/main/UI/Battle/BattleGrid.java"
click node_terrain "https://github.com/yoshimoshi4/dndsim/blob/main/Objects/TerrainObject.java"
click node_battle_state "https://github.com/yoshimoshi4/dndsim/blob/main/UI/Battle/BattleState.java"
click node_combat_manager "https://github.com/yoshimoshi4/dndsim/blob/main/UI/Battle/CombatManager.java"
click node_turn_manager "https://github.com/yoshimoshi4/dndsim/blob/main/UI/Battle/TurnManager.java"
click node_battle_canvas "https://github.com/yoshimoshi4/dndsim/blob/main/UI/Battle/BattleGridCanvas.java"
click node_battle_panels "https://github.com/yoshimoshi4/dndsim/blob/main/UI/Battle/VictoryView.java"
click node_json_saves "https://github.com/yoshimoshi4/dndsim/blob/main/saves/party.json"
click node_visual_resources "https://github.com/yoshimoshi4/dndsim/blob/main/resources/styles/dark-theme.css"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_main,node_app_controller,node_main_menu,node_character_sheet,node_asset_editor,node_battle_view toneBlue
class node_entity,node_enemy,node_character_data,node_item_system,node_item_adapter toneAmber
class node_battle_grid,node_terrain,node_battle_state,node_combat_manager,node_turn_manager,node_battle_canvas,node_battle_panels toneMint
class node_json_saves,node_visual_resources toneRose
```

## Components

### JavaFX UI

Desktop navigation, editing, and battle presentation.

- [Application entry](https://github.com/yoshimoshi4/dndsim/blob/main/Main.java): Java launcher · `Main.java`
- [App controller](https://github.com/yoshimoshi4/dndsim/blob/main/UI/AppController.java): navigation controller · Top-level boundary for user-driven screen transitions. · `UI/AppController.java`
- [Main menu](https://github.com/yoshimoshi4/dndsim/blob/main/UI/MainMenuView.java): JavaFX view · `UI/MainMenuView.java`
- [Character sheet](https://github.com/yoshimoshi4/dndsim/blob/main/UI/CharacterSheetView.java): JavaFX view · `UI/CharacterSheetView.java`
- [Asset editor](https://github.com/yoshimoshi4/dndsim/blob/main/UI/AssetEditorView.java): JavaFX view · Edits reusable game content independently of battles. · `UI/AssetEditorView.java`
- [Battle view](https://github.com/yoshimoshi4/dndsim/blob/main/UI/Battle/BattleView.java): JavaFX view · `UI/Battle/BattleView.java`

### Domain & Content

Shared game entities, character data, and item definitions.

- [Entity hierarchy](https://github.com/yoshimoshi4/dndsim/blob/main/Objects/Entity.java): domain base class · Shared behavior for combatants and map objects. · `Objects/Entity.java`
- [Enemy](https://github.com/yoshimoshi4/dndsim/blob/main/Objects/Enemy.java): combatant model · `Objects/Enemy.java`
- [Character & party data](https://github.com/yoshimoshi4/dndsim/blob/main/EntityRes/CharSheet.java): serializable domain model · `EntityRes/CharSheet.java`
- [Polymorphic items](https://github.com/yoshimoshi4/dndsim/blob/main/EntityRes/Item.java): resource model · Item categories and abilities are adapted for JSON deserialization. · `EntityRes/Item.java`
- [Item type adapter](https://github.com/yoshimoshi4/dndsim/blob/main/EntityRes/ItemTypeAdapter.java): JSON adapter · `EntityRes/ItemTypeAdapter.java`

### Battle Runtime

Grid assembly, mutable session state, and turn resolution.

- [Battle grid](https://github.com/yoshimoshi4/dndsim/blob/main/UI/Battle/BattleGrid.java): board model · Logical board populated with entities, pickups, and terrain. · `UI/Battle/BattleGrid.java`
- [Terrain objects](https://github.com/yoshimoshi4/dndsim/blob/main/Objects/TerrainObject.java): map object model · `Objects/TerrainObject.java`
- [Battle state](https://github.com/yoshimoshi4/dndsim/blob/main/UI/Battle/BattleState.java): mutable session · Central boundary for an active battle session. · `UI/Battle/BattleState.java`
- [Combat manager](https://github.com/yoshimoshi4/dndsim/blob/main/UI/Battle/CombatManager.java): action resolver · `UI/Battle/CombatManager.java`
- [Turn manager](https://github.com/yoshimoshi4/dndsim/blob/main/UI/Battle/TurnManager.java): turn lifecycle · `UI/Battle/TurnManager.java`
- [Grid canvas](https://github.com/yoshimoshi4/dndsim/blob/main/UI/Battle/BattleGridCanvas.java): JavaFX renderer · `UI/Battle/BattleGridCanvas.java`
- [Battle HUD & victory](https://github.com/yoshimoshi4/dndsim/blob/main/UI/Battle/VictoryView.java): JavaFX presentation · Projects health, timeline, dice interaction, and terminal results. · `UI/Battle/VictoryView.java`

### Local Resources

JSON saves and visual resources bundled with the desktop app.

- [JSON save content](https://github.com/yoshimoshi4/dndsim/blob/main/saves/party.json): local persistence · Local party, entity, item, and terrain definitions. · `saves/party.json`
- [Sprites & dark theme](https://github.com/yoshimoshi4/dndsim/blob/main/resources/styles/dark-theme.css): application resources · `resources/styles/dark-theme.css`

## Connections

- Application entry → App controller: starts
- App controller → Main menu: navigates
- App controller → Character sheet: navigates
- App controller → Asset editor: navigates
- App controller → Battle view: navigates
- Entity hierarchy → Enemy: specializes
- Character & party data → Entity hierarchy: defines combatants
- Item type adapter → Polymorphic items: deserializes
- Asset editor → Polymorphic items: edits
- Asset editor → JSON save content: reads / writes
- Character sheet → Character & party data: edits
- JSON save content → Character & party data: loads
- JSON save content → Polymorphic items: loads
- JSON save content → Terrain objects: loads
- Battle view → Battle state: drives
- Battle state → Battle grid: owns session board
- Battle grid → Entity hierarchy: places
- Battle grid → Terrain objects: places
- Combat manager → Battle state: resolves actions
- Turn manager → Battle state: advances turns
- Battle view → Combat manager: submits actions
- Battle view → Turn manager: uses turn order
- Grid canvas → Battle grid: renders
- Battle view → Grid canvas: contains
- Battle HUD & victory → Battle state: projects
- Battle view → Battle HUD & victory: shows
- Sprites & dark theme → Grid canvas: styles sprites
