# dustywusty/dmud architecture

> Architecture diagram of the GitHub repository dustywusty/dmud, 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/dustywusty/dmud
- Repository: https://github.com/dustywusty/dmud

## Overview

##### Main Components

A. Network Layer
- TCP Server
- WebSocket Server
- Client Connections Handler

B. ECS Core
- World Manager
- Entity Manager
- Component Manager
- System Manager

C. Game Systems
- Combat System
- Movement System
- Spawn System

D. Components
- Health
- Combat
- Movement
- NPC
- Player
- Room
- Spawn

E. Game Logic
- Chat Handler
- Combat Manager
- Movement Manager
- Game State Manager

F. Resource Management
- Room Definitions (rooms.json)
- Configuration

- [Client Connections]
- ↕
- [Network Layer]
- ↕
- [Game Logic Layer]
- ↕
- [ECS Core]
- ↕
- [Systems & Components]
- ↕
- [Resource Layer]

##### Component Relationships

a) Network Flow:
- TCP/WebSocket clients → Server
- Server → Game Logic

b) ECS Relationships:
- World → Entities
- Entities → Components
- Systems → Components

c) Game Logic Flow:
- Game Manager → Systems
- Systems → Components
- Resource Manager → Game Logic

##### Specific Implementation Details

Important architectural elements:

a) Component System:
- [Component Manager]
- Health
- Combat
- Movement
- NPC
- Player
- Room
- Spawn

b) System Pipeline:
- [System Manager]
- Combat System
- Movement System
- Spawn System

##### Technical Details to Highlight

- Go-specific implementations
- Concurrent operations
- Resource loading and management
- State management within the ECS

## Diagram (Mermaid)

```mermaid
graph TB
    %% Styles and classes
    classDef network fill:#a8d1f0,stroke:#333
    classDef gamelogic fill:#90EE90,stroke:#333
    classDef ecs fill:#FFE4B5,stroke:#333
    classDef systems fill:#FFA07A,stroke:#333
    classDef components fill:#DDA0DD,stroke:#333
    classDef resources fill:#D3D3D3,stroke:#333

    %% Network Layer
    subgraph NetworkLayer["Network Layer"]
        TCP["TCP Server"]:::network
        WS["WebSocket Server"]:::network
        CH["Client Handler"]:::network
    end

    %% Game Logic Layer
    subgraph GameLogic["Game Logic Layer"]
        Chat["Chat Handler"]:::gamelogic
        CombatMgr["Combat Manager"]:::gamelogic
        MovementMgr["Movement Manager"]:::gamelogic
        GameState["Game State Manager"]:::gamelogic
    end

    %% ECS Core Layer
    subgraph ECSCore["ECS Core"]
        World["World Manager"]:::ecs
        Entity["Entity Manager"]:::ecs
        CompMgr["Component Manager"]:::ecs
        SysMgr["System Manager"]:::ecs
    end

    %% Systems Layer
    subgraph GameSystems["Game Systems"]
        CombatSys["Combat System"]:::systems
        MovementSys["Movement System"]:::systems
        SpawnSys["Spawn System"]:::systems
    end

    %% Components Layer
    subgraph Components["Components"]
        Health["Health"]:::components
        Combat["Combat"]:::components
        Movement["Movement"]:::components
        NPC["NPC"]:::components
        Player["Player"]:::components
        Room["Room"]:::components
        Spawn["Spawn"]:::components
    end

    %% Resource Layer
    subgraph Resources["Resource Layer"]
        RoomDef["Room Definitions"]:::resources
        Config["Configuration"]:::resources
    end

    %% Relationships
    TCP & WS --> CH
    CH --> GameLogic
    GameLogic --> World
    World --> Entity
    Entity --> CompMgr
    CompMgr --> Components
    SysMgr --> GameSystems
    GameSystems --> Components
    Resources --> GameLogic

    %% Click events
    click TCP "https://github.com/dustywusty/dmud/blob/main/internal/net/server.go"
    click WS "https://github.com/dustywusty/dmud/blob/main/internal/net/ws_client.go"
    click CH "https://github.com/dustywusty/dmud/blob/main/internal/net/tcp_client.go"
    click Chat "https://github.com/dustywusty/dmud/blob/main/internal/game/chat.go"
    click CombatMgr "https://github.com/dustywusty/dmud/blob/main/internal/game/combat.go"
    click MovementMgr "https://github.com/dustywusty/dmud/blob/main/internal/game/movement.go"
    click GameState "https://github.com/dustywusty/dmud/blob/main/internal/game/game.go"
    click World "https://github.com/dustywusty/dmud/blob/main/internal/ecs/world.go"
    click Entity "https://github.com/dustywusty/dmud/blob/main/internal/ecs/entity.go"
    click CompMgr "https://github.com/dustywusty/dmud/blob/main/internal/ecs/component.go"
    click SysMgr "https://github.com/dustywusty/dmud/blob/main/internal/ecs/system.go"
    click CombatSys "https://github.com/dustywusty/dmud/blob/main/internal/systems/combat.go"
    click MovementSys "https://github.com/dustywusty/dmud/blob/main/internal/systems/movement.go"
    click SpawnSys "https://github.com/dustywusty/dmud/blob/main/internal/systems/spawn.go"
    click Health "https://github.com/dustywusty/dmud/blob/main/internal/components/health.go"
    click Combat "https://github.com/dustywusty/dmud/blob/main/internal/components/combat.go"
    click Movement "https://github.com/dustywusty/dmud/blob/main/internal/components/movement.go"
    click NPC "https://github.com/dustywusty/dmud/blob/main/internal/components/npc.go"
    click Player "https://github.com/dustywusty/dmud/blob/main/internal/components/player.go"
    click Room "https://github.com/dustywusty/dmud/blob/main/internal/components/room.go"
    click Spawn "https://github.com/dustywusty/dmud/blob/main/internal/components/spawn.go"
    click RoomDef "https://github.com/dustywusty/dmud/blob/main/resources/rooms.json"
```
