# diasurgical/devilutionx architecture

> Architecture diagram of the GitHub repository diasurgical/devilutionx, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2024-12-28). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/diasurgical/devilutionx
- Repository: https://github.com/diasurgical/devilutionx

## Overview

##### Main Components Overview
The system should be divided into these major components:

a) Core Game Engine
- Source/engine/* - Core engine components (rendering, sound, assets)
- Source/DiabloUI/* - User interface system
- Source/controls/* - Input handling system

b) Game Logic
- Source/* (root) - Main game mechanics and state management
- Source/levels/* - Level generation and management
- Source/items/* - Item system
- Source/qol/* - Quality of life improvements

c) Platform Layer
- Multiple platform-specific implementations (Android, iOS, Switch, PS4, etc.)
- Located in platform/* directories

d) Network Layer
- Source/dvlnet/* - Networking implementation
- Multiplayer support components

##### Key Architectural Elements

**┌─────────────────────────────────────────────┐**
- User Interface                 │
- (DiabloUI, Controls, Input Management)     │
- ┤
- Game Logic                     │
- (Player, Items, Monsters, Quests, etc.)    │
- ┤
- Core Engine                    │
- (Rendering, Sound, Assets, Memory)         │
- ┤
- Platform Layer                 │
- (SDL2, Platform-specific implementations)  │
- ┘

##### Detailed Component Breakdown

a) Rendering Pipeline:
**Assets → Asset Loading → Rendering Engine → Display**

b) Input System:
**Platform Input → Input Manager → Control System → Game Logic**

c) Network Stack:
**Network Interface → Protocol Handler → Game State Sync**

##### Implementation Notes

- Use rectangles for modules/components
- Use hexagons for external interfaces
- Version information and date
- Dependencies (SDL2, Lua, etc.)

##### Additional Elements

- Configuration management (CMake system)
- Test framework integration
- Platform-specific compilation paths
- QoL feature integration points

Remember to include notes about the modding support architecture, as it's a key feature of DevilutionX.

## Diagram (Mermaid)

```mermaid
graph TB
    %% Style definitions
    classDef core fill:#b3d9ff,stroke:#333,stroke-width:2px
    classDef ui fill:#ffd9b3,stroke:#333,stroke-width:2px
    classDef input fill:#ffb366,stroke:#333,stroke-width:2px
    classDef game fill:#b3ffb3,stroke:#333,stroke-width:2px
    classDef network fill:#e6b3ff,stroke:#333,stroke-width:2px
    classDef platform fill:#d9d9d9,stroke:#333,stroke-width:2px
    classDef qol fill:#ffff99,stroke:#333,stroke-width:2px

    subgraph UI["User Interface Layer"]
        DiabloUI["DiabloUI System"]
        MenuSystem["Menu System"]
        DialogSystem["Dialog System"]
    end

    subgraph Input["Input Management"]
        Controls["Core Controls"]
        Controller["Controller Support"]
        Touch["Touch Controls"]
        Keyboard["Keyboard Input"]
    end

    subgraph Core["Core Engine"]
        Render["Rendering Engine"]
        Sound["Sound System"]
        Assets["Asset Management"]
        Memory["Memory Management"]
    end

    subgraph GameLogic["Game Logic"]
        Levels["Level Generation"]
        Items["Item System"]
        Monsters["Monster System"]
        Quests["Quest System"]
    end

    subgraph Network["Network Layer"]
        NetCore["Core Networking"]
        Protocol["Protocol Implementation"]
        TCP["TCP Support"]
    end

    subgraph Platform["Platform Layer"]
        Android["Android Support"]
        iOS["iOS Support"]
        Switch["Switch Support"]
        Vita["Vita Support"]
    end

    subgraph QoL["Quality of Life"]
        AutoPickup["Auto Pickup"]
        ChatLog["Chat Log"]
        ItemLabels["Item Labels"]
        MonHealth["Monster Health Bar"]
        XPBar["Experience Bar"]
    end

    %% Relationships
    UI --> Core
    Input --> Core
    Core --> GameLogic
    GameLogic --> Network
    Core --> Platform
    QoL --> GameLogic

    %% Click events
    click DiabloUI "https://github.com/diasurgical/devilutionX/tree/master/Source/DiabloUI/"
    click MenuSystem "https://github.com/diasurgical/devilutionX/blob/master/Source/DiabloUI/mainmenu.cpp"
    click DialogSystem "https://github.com/diasurgical/devilutionX/blob/master/Source/DiabloUI/dialogs.cpp"
    click Controls "https://github.com/diasurgical/devilutionX/tree/master/Source/controls/"
    click Controller "https://github.com/diasurgical/devilutionX/blob/master/Source/controls/devices/game_controller.cpp"
    click Touch "https://github.com/diasurgical/devilutionX/tree/master/Source/controls/touch/"
    click Keyboard "https://github.com/diasurgical/devilutionX/blob/master/Source/controls/devices/kbcontroller.cpp"
    click Render "https://github.com/diasurgical/devilutionX/tree/master/Source/engine/render/"
    click Sound "https://github.com/diasurgical/devilutionX/blob/master/Source/engine/sound.cpp"
    click Assets "https://github.com/diasurgical/devilutionX/blob/master/Source/engine/assets.cpp"
    click Memory "https://github.com/diasurgical/devilutionX/blob/master/Source/engine/backbuffer_state.cpp"
    click Levels "https://github.com/diasurgical/devilutionX/tree/master/Source/levels/"
    click Items "https://github.com/diasurgical/devilutionX/tree/master/Source/items/"
    click Monsters "https://github.com/diasurgical/devilutionX/blob/master/Source/monster.cpp"
    click Quests "https://github.com/diasurgical/devilutionX/blob/master/Source/quests.cpp"
    click NetCore "https://github.com/diasurgical/devilutionX/tree/master/Source/dvlnet/"
    click Protocol "https://github.com/diasurgical/devilutionX/blob/master/Source/dvlnet/protocol_zt.cpp"
    click TCP "https://github.com/diasurgical/devilutionX/blob/master/Source/dvlnet/tcp_client.cpp"
    click Android "https://github.com/diasurgical/devilutionX/tree/master/Source/platform/android/"
    click iOS "https://github.com/diasurgical/devilutionX/tree/master/Source/platform/ios/"
    click Switch "https://github.com/diasurgical/devilutionX/tree/master/Source/platform/switch/"
    click Vita "https://github.com/diasurgical/devilutionX/tree/master/Source/platform/vita/"
    click AutoPickup "https://github.com/diasurgical/devilutionX/blob/master/Source/qol/autopickup.cpp"
    click ChatLog "https://github.com/diasurgical/devilutionX/blob/master/Source/qol/chatlog.cpp"
    click ItemLabels "https://github.com/diasurgical/devilutionX/blob/master/Source/qol/itemlabels.cpp"
    click MonHealth "https://github.com/diasurgical/devilutionX/blob/master/Source/qol/monhealthbar.cpp"
    click XPBar "https://github.com/diasurgical/devilutionX/blob/master/Source/qol/xpbar.cpp"

    %% Styling
    class DiabloUI,MenuSystem,DialogSystem ui
    class Controls,Controller,Touch,Keyboard input
    class Render,Sound,Assets,Memory core
    class Levels,Items,Monsters,Quests game
    class NetCore,Protocol,TCP network
    class Android,iOS,Switch,Vita platform
    class AutoPickup,ChatLog,ItemLabels,MonHealth,XPBar qol
```
