# jerberlin/dndgame architecture

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

- Interactive diagram: https://gitdiagram.com/jerberlin/dndgame
- Repository: https://github.com/jerberlin/dndgame

## Overview

##### Project Type & Purpose
- The README makes it clear that this is a digital role-playing game inspired by Dungeons & Dragons. The game has well-defined roles (players, game master), game actions, characters, and an XP system.
- The project follows a layered “domain-driven” architecture with clear separations between the model definitions, repository (data access) implementations, and service (business logic) layers.

##### Analyzing the File Structure
- At the top level, you have a go.mod (indicating a Go project), and an organized “internal” directory that further contains:
- /model: Contains domain objects for actions, characters, game, game master, and player. Each has its own directory with implementation and tests.
- /repo: Provides repository implementations for each domain model. Notice that all repositories have an “inmemory.go” implementation, meaning an in-memory storage is used here.
- /service: Contains business logic services for game, game master, and player functionalities.
- The neat separation among models, repositories, and services suggests a layered architecture where domain logic is separated from persistence concerns.

##### Key Components in the System
- Domain Model Layer: Composed of the key entities – Game, Character, Player, Game Master, and Action. These represent the core business objects following the RPG game rules.
- Repository Layer: Each model has a corresponding repository (like ActionRepository, CharacterRepository, etc.) implementing storage with “inmemory” implementations. This layer abstracts how data is persisted/managed.
- Service Layer: Contains game logic and orchestrates operations (like game state management, player actions, and game master decisions). Key services include GameService, GamemasterService, and PlayerService.
- Additional elements (not in separate directories but implicit): The interactions based on XP management, action approval flows, and character interaction (as defined in the README).

##### Diagramming the Architecture
- Also, indicate interactions between Service and Model layers, since services use the models to enforce business rules and game logic.

##### Architectural Patterns/Design Principles
- Layered Architecture: Emphasize the separation between the presentation (if applicable), domain (models), persistence (repositories), and application logic (services).
- Domain-Driven Design: Each game concept is encapsulated within its own package, reflecting clear bounded contexts.
- In-memory Data Handling: Although this is a temporary persistence mechanism, it is clearly abstracted behind repository interfaces.

##### Including Relevant Technologies
- Since this is a Go project (denoted by go.mod), note that the implementation leverages Go modules.
- Testing is integral as seen from the accompanying _test.go files for models and services.
- That the in-memory implementations might be replaced or extended in production with a more robust persistence layer.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Domain Model Layer
    subgraph "Domain Models"
        D1["Action Model"]:::domain
        D2["Character Model"]:::domain
        D3["Game Model"]:::domain
        D4["Gamemaster Model"]:::domain
        D5["Player Model"]:::domain
    end

    %% Repository Layer
    subgraph "Repositories"
        R1["Action Repository"]:::repo
        R2["Character Repository"]:::repo
        R3["Game Repository"]:::repo
        R4["Gamemaster Repository"]:::repo
        R5["Player Repository"]:::repo
    end

    %% Service Layer
    subgraph "Services"
        S1["Game Service"]:::service
        S2["Gamemaster Service"]:::service
        S3["Player Service"]:::service
    end

    %% Service to Repository Connections
    S1 -->|"uses"| R1
    S1 -->|"uses"| R2
    S1 -->|"uses"| R3
    S2 -->|"uses"| R4
    S3 -->|"uses"| R5

    %% Service to Domain Model Connections
    S1 -->|"operates_on"| D1
    S1 -->|"operates_on"| D2
    S1 -->|"operates_on"| D3
    S2 -->|"operates_on"| D4
    S3 -->|"operates_on"| D5

    %% Click Events for Domain Models
    click D1 "https://github.com/jerberlin/dndgame/blob/main/internal/model/action/action.go"
    click D2 "https://github.com/jerberlin/dndgame/blob/main/internal/model/character/character.go"
    click D3 "https://github.com/jerberlin/dndgame/blob/main/internal/model/game/game.go"
    click D4 "https://github.com/jerberlin/dndgame/blob/main/internal/model/gamemaster/gamemaster.go"
    click D5 "https://github.com/jerberlin/dndgame/blob/main/internal/model/player/player.go"

    %% Click Events for Repositories
    click R1 "https://github.com/jerberlin/dndgame/blob/main/internal/repo/action/inmemory.go"
    click R2 "https://github.com/jerberlin/dndgame/blob/main/internal/repo/character/inmemory.go"
    click R3 "https://github.com/jerberlin/dndgame/blob/main/internal/repo/game/inmemory.go"
    click R4 "https://github.com/jerberlin/dndgame/blob/main/internal/repo/gamemaster/inmemory.go"
    click R5 "https://github.com/jerberlin/dndgame/blob/main/internal/repo/player/inmemory.go"

    %% Click Events for Services
    click S1 "https://github.com/jerberlin/dndgame/blob/main/internal/service/game/gameservice.go"
    click S2 "https://github.com/jerberlin/dndgame/blob/main/internal/service/gamemaster/gamemasterservice.go"
    click S3 "https://github.com/jerberlin/dndgame/blob/main/internal/service/player/playerservice.go"

    %% Styles
    classDef domain fill:#bbdefb,stroke:#0d47a1,stroke-width:2px;
    classDef repo fill:#c8e6c9,stroke:#1b5e20,stroke-width:2px;
    classDef service fill:#ffe0b2,stroke:#e65100,stroke-width:2px;
```
