# kralamoure/dofus architecture

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

- Interactive diagram: https://gitdiagram.com/kralamoure/dofus
- Repository: https://github.com/kralamoure/dofus

## Overview

##### Project type and purpose
- Project type: Go library / domain service package.
- Purpose: Provide domain types for Dofus entities (accounts, users, chat channels, etc.), a service layer for account-related operations, and declare a `Storer` interface for persistence.

##### Main components
a. Domain Types Layer (`dofustyp` package)
- Entities: AccountName, Community, Email, Gender, Hash, Nickname, Password, ChatChannel.
- Purpose: Define value objects and aggregate roots for the domain.
b. Core Domain Package (root files: `account.go`, `user.go`, `store.go`)
- Domain interfaces and glue code.
- `Storer` interface declaration (in `store.go`).
c. Service Layer (`dofussvc` package)
- Services: account‐related methods (`CreateAccount`, `GetUser`, etc.).
- Objects: `dofussvc.Go` orchestrates calls to domain types and Storer.
d. External Persistence / Implementation
- Out-of-tree package: `dofuspg` implements the `Storer` interface for PostgreSQL.
e. Client Code
- The importing application that calls into `dofus` to manage accounts.

##### Relationships and interactions
- The Service Layer depends on the Domain Types Layer and the `Storer` interface.
- The Domain Types are passed into services, validated, and manipulated.
- The Service Layer invokes `Storer` methods to persist or retrieve domain aggregates.
- External Persistence (e.g., `dofuspg`) implements `Storer` and interacts with a database.
- Client code calls into the Service Layer.

##### Architectural patterns and design principles
- Layered architecture: separation of domain types, domain interfaces, and services.
- Dependency Inversion: services depend on the `Storer` interface (not a concrete DB).
- Modularity: three Go packages (`dofustyp`, root, `dofussvc`).
- Single Responsibility: each package handles a distinct concern.

## Diagram (Mermaid)

```mermaid
graph TB
    Client["Client Application"]:::client

    subgraph "dofus library"
        subgraph "Domain Types Layer"
            DTpkg["dofustyp/"]:::domain
            AN["AccountName"]:::domain
            CC["ChatChannel"]:::domain
            CM["Community"]:::domain
            DTfile["dofustyp.go"]:::domain
            EM["Email"]:::domain
            GD["Gender"]:::domain
            HS["Hash"]:::domain
            NN["Nickname"]:::domain
            PW["Password"]:::domain
        end

        subgraph "Core Domain"
            Account["account.go"]:::core
            User["user.go"]:::core
            Store["store.go (Storer)"]:::core
        end

        subgraph "Service Layer"
            SvcImpl["dofussvc.go"]:::service
            SvAcct["account.go"]:::service
            SvUser["user.go"]:::service
        end
    end

    External["dofuspg (PostgreSQL Adapter)"]:::external
    DB[(PostgreSQL DB)]:::db

    Client -->|"uses"| SvcImpl
    Client -->|"uses"| SvAcct
    Client -->|"uses"| SvUser

    SvcImpl -->|"reads/writes"| DTpkg
    SvAcct -->|"CreateAccount()"| Store
    SvUser -->|"GetUser()"| Store
    SvcImpl -->|"calls Storer"| Store

    Store -->|"implemented by"| External
    External -->|"SQL queries"| DB

    click DTpkg "https://github.com/kralamoure/dofus/tree/main/dofustyp/"
    click AN "https://github.com/kralamoure/dofus/blob/main/dofustyp/account_name.go"
    click CC "https://github.com/kralamoure/dofus/blob/main/dofustyp/chat_channel.go"
    click CM "https://github.com/kralamoure/dofus/blob/main/dofustyp/community.go"
    click DTfile "https://github.com/kralamoure/dofus/blob/main/dofustyp/dofustyp.go"
    click EM "https://github.com/kralamoure/dofus/blob/main/dofustyp/email.go"
    click GD "https://github.com/kralamoure/dofus/blob/main/dofustyp/gender.go"
    click HS "https://github.com/kralamoure/dofus/blob/main/dofustyp/hash.go"
    click NN "https://github.com/kralamoure/dofus/blob/main/dofustyp/nickname.go"
    click PW "https://github.com/kralamoure/dofus/blob/main/dofustyp/password.go"

    click Account "https://github.com/kralamoure/dofus/blob/main/account.go"
    click User "https://github.com/kralamoure/dofus/blob/main/user.go"
    click Store "https://github.com/kralamoure/dofus/blob/main/store.go"

    click SvcImpl "https://github.com/kralamoure/dofus/blob/main/dofussvc/dofussvc.go"
    click SvAcct "https://github.com/kralamoure/dofus/blob/main/dofussvc/account.go"
    click SvUser "https://github.com/kralamoure/dofus/blob/main/dofussvc/user.go"

    classDef domain fill:#ADD8E6,stroke:#333,stroke-width:1px
    classDef core fill:#90EE90,stroke:#333,stroke-width:1px
    classDef service fill:#FFA500,stroke:#333,stroke-width:1px
    classDef external fill:#D3D3D3,stroke:#333,stroke-width:1px
    classDef db fill:#CCCCCC,stroke:#333,stroke-width:1px
    classDef client fill:#FFFFE0,stroke:#333,stroke-width:1px
```
