# mrlegowatch/roleplayingcore architecture

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

- Interactive diagram: https://gitdiagram.com/mrlegowatch/roleplayingcore
- Repository: https://github.com/mrlegowatch/roleplayingcore

## Overview

RolePlayingCore is a reusable Swift library for tabletop RPG rules and character data. Its principal workflow loads JSON game content into GameData, then uses that content to construct or randomly generate a Player with species, class, background, abilities, equipment, and spell state. Separate domain modules provide currency, item, and spell models, while common utilities support measurements, display ordering, names, and random choices. The README also describes a SwiftUI example app, but its source is not present in the supplied tree; relationships are limited to documented capabilities and indexed references.

Main entry points: [`Sources/RolePlayingCore/Configuration/GameData.swift`](https://github.com/mrlegowatch/roleplayingcore/blob/development/Sources/RolePlayingCore/Configuration/GameData.swift) (Game data loader), [`Sources/RolePlayingCore/Player/Player.swift`](https://github.com/mrlegowatch/roleplayingcore/blob/development/Sources/RolePlayingCore/Player/Player.swift) (Player character), [`Sources/RolePlayingCore/CharacterGenerator/CharacterGenerator.swift`](https://github.com/mrlegowatch/roleplayingcore/blob/development/Sources/RolePlayingCore/CharacterGenerator/CharacterGenerator.swift) (Character generator), [`Sources/RolePlayingCore/Items/Item.swift`](https://github.com/mrlegowatch/roleplayingcore/blob/development/Sources/RolePlayingCore/Items/Item.swift) (Item models)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_configuration["Game data"]
  node_game_data["Game data loader<br/>[GameData.swift]"]
  node_errors["Load errors"]
end

subgraph group_character["Character domain"]
  node_species["Species traits"]
  node_classes["Class traits<br/>[ClassTraits.swift]"]
  node_backgrounds["Background traits"]
  node_abilities["Ability scores<br/>[Ability.swift]"]
  node_player["Player character<br/>[Player.swift]"]
  node_appearance["Character appearance"]
end

subgraph group_equipment["Equipment and currency"]
  node_inventory["Inventory<br/>[Inventory.swift]"]
  node_items["Item catalogue<br/>[Items.swift]"]
  node_item_types["Item models<br/>[Item.swift]"]
  node_currencies["Currency catalogue<br/>[Currencies.swift]"]
  node_money["Money values<br/>[Money.swift]"]
end

subgraph group_magic["Spellcasting"]
  node_spells["Spell catalogue<br/>[Spells.swift]"]
  node_spell["Spell model<br/>[Spell.swift]"]
  node_spellbook["Spellbook state<br/>[Spellbook.swift]"]
end

subgraph group_utilities["Generation utilities"]
  node_generator["Character generator"]
  node_names["Name generator"]
  node_character_names["Character name lists"]
  node_random["Random selection"]
  node_common["Common measurements<br/>[Weight.swift]"]
end

node_client(("Library client"))

node_client -->|"loads content"| node_game_data
node_game_data -.->|"reports failures"| node_errors
node_game_data -->|"loads"| node_currencies
node_game_data -->|"loads"| node_items
node_game_data -->|"loads"| node_backgrounds
node_game_data -->|"loads"| node_species
node_game_data -->|"loads"| node_classes
node_game_data -->|"loads"| node_spells
node_client -->|"requests generation"| node_generator
node_generator -->|"uses content"| node_game_data
node_generator -->|"constructs"| node_player
node_generator -.->|"generates names"| node_names
node_names -->|"uses lists"| node_character_names
node_names -->|"selects randomly"| node_random
node_player -->|"resolves"| node_species
node_player -->|"resolves"| node_classes
node_player -->|"calculates from"| node_abilities
node_player -->|"stores"| node_appearance
node_player -->|"stores"| node_inventory
node_player -->|"stores"| node_spellbook
node_items -->|"collects"| node_item_types
node_inventory -->|"holds"| node_item_types
node_money -->|"uses denominations"| node_currencies
node_spellbook -->|"tracks spells"| node_spell
node_spells -->|"collects"| node_spell
node_item_types -->|"has cost"| node_money
node_item_types -->|"has weight"| node_common

click node_game_data "https://github.com/mrlegowatch/roleplayingcore/blob/development/Sources/RolePlayingCore/Configuration/GameData.swift"
click node_errors "https://github.com/mrlegowatch/roleplayingcore/blob/development/Sources/RolePlayingCore/Configuration/GameDataError.swift"
click node_species "https://github.com/mrlegowatch/roleplayingcore/blob/development/Sources/RolePlayingCore/Player/SpeciesTraits.swift"
click node_classes "https://github.com/mrlegowatch/roleplayingcore/blob/development/Sources/RolePlayingCore/Player/ClassTraits.swift"
click node_backgrounds "https://github.com/mrlegowatch/roleplayingcore/blob/development/Sources/RolePlayingCore/Player/BackgroundTraits.swift"
click node_abilities "https://github.com/mrlegowatch/roleplayingcore/blob/development/Sources/RolePlayingCore/Player/Ability.swift"
click node_player "https://github.com/mrlegowatch/roleplayingcore/blob/development/Sources/RolePlayingCore/Player/Player.swift"
click node_appearance "https://github.com/mrlegowatch/roleplayingcore/blob/development/Sources/RolePlayingCore/Player/PlayerAppearance.swift"
click node_inventory "https://github.com/mrlegowatch/roleplayingcore/blob/development/Sources/RolePlayingCore/Items/Inventory.swift"
click node_items "https://github.com/mrlegowatch/roleplayingcore/blob/development/Sources/RolePlayingCore/Items/Items.swift"
click node_item_types "https://github.com/mrlegowatch/roleplayingcore/blob/development/Sources/RolePlayingCore/Items/Item.swift"
click node_currencies "https://github.com/mrlegowatch/roleplayingcore/blob/development/Sources/RolePlayingCore/Currency/Currencies.swift"
click node_money "https://github.com/mrlegowatch/roleplayingcore/blob/development/Sources/RolePlayingCore/Currency/Money.swift"
click node_spells "https://github.com/mrlegowatch/roleplayingcore/blob/development/Sources/RolePlayingCore/Spellcasting/Spells.swift"
click node_spell "https://github.com/mrlegowatch/roleplayingcore/blob/development/Sources/RolePlayingCore/Spellcasting/Spell.swift"
click node_spellbook "https://github.com/mrlegowatch/roleplayingcore/blob/development/Sources/RolePlayingCore/Spellcasting/Spellbook.swift"
click node_generator "https://github.com/mrlegowatch/roleplayingcore/blob/development/Sources/RolePlayingCore/CharacterGenerator/CharacterGenerator.swift"
click node_names "https://github.com/mrlegowatch/roleplayingcore/blob/development/Sources/RolePlayingCore/CharacterGenerator/NameGenerator.swift"
click node_character_names "https://github.com/mrlegowatch/roleplayingcore/blob/development/Sources/RolePlayingCore/Common/CharacterNames.swift"
click node_random "https://github.com/mrlegowatch/roleplayingcore/blob/development/Sources/RolePlayingCore/Common/RandomIndexGenerator.swift"
click node_common "https://github.com/mrlegowatch/roleplayingcore/blob/development/Sources/RolePlayingCore/Common/Weight.swift"

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_game_data,node_errors,node_client toneBlue
class node_species,node_classes,node_backgrounds,node_abilities,node_player,node_appearance toneAmber
class node_inventory,node_items,node_item_types,node_currencies,node_money toneMint
class node_spells,node_spell,node_spellbook toneRose
class node_generator,node_names,node_character_names,node_random,node_common toneIndigo
```

## Components

### Game data

- [Game data loader](https://github.com/mrlegowatch/roleplayingcore/blob/development/Sources/RolePlayingCore/Configuration/GameData.swift): `Sources/RolePlayingCore/Configuration/GameData.swift`
- [Load errors](https://github.com/mrlegowatch/roleplayingcore/blob/development/Sources/RolePlayingCore/Configuration/GameDataError.swift): `Sources/RolePlayingCore/Configuration/GameDataError.swift`

### Character domain

- [Species traits](https://github.com/mrlegowatch/roleplayingcore/blob/development/Sources/RolePlayingCore/Player/SpeciesTraits.swift): `Sources/RolePlayingCore/Player/SpeciesTraits.swift`
- [Class traits](https://github.com/mrlegowatch/roleplayingcore/blob/development/Sources/RolePlayingCore/Player/ClassTraits.swift): `Sources/RolePlayingCore/Player/ClassTraits.swift`
- [Background traits](https://github.com/mrlegowatch/roleplayingcore/blob/development/Sources/RolePlayingCore/Player/BackgroundTraits.swift): `Sources/RolePlayingCore/Player/BackgroundTraits.swift`
- [Ability scores](https://github.com/mrlegowatch/roleplayingcore/blob/development/Sources/RolePlayingCore/Player/Ability.swift): `Sources/RolePlayingCore/Player/Ability.swift`
- [Player character](https://github.com/mrlegowatch/roleplayingcore/blob/development/Sources/RolePlayingCore/Player/Player.swift): `Sources/RolePlayingCore/Player/Player.swift`
- [Character appearance](https://github.com/mrlegowatch/roleplayingcore/blob/development/Sources/RolePlayingCore/Player/PlayerAppearance.swift): `Sources/RolePlayingCore/Player/PlayerAppearance.swift`

### Equipment and currency

- [Inventory](https://github.com/mrlegowatch/roleplayingcore/blob/development/Sources/RolePlayingCore/Items/Inventory.swift): `Sources/RolePlayingCore/Items/Inventory.swift`
- [Item catalogue](https://github.com/mrlegowatch/roleplayingcore/blob/development/Sources/RolePlayingCore/Items/Items.swift): `Sources/RolePlayingCore/Items/Items.swift`
- [Item models](https://github.com/mrlegowatch/roleplayingcore/blob/development/Sources/RolePlayingCore/Items/Item.swift): `Sources/RolePlayingCore/Items/Item.swift`
- [Currency catalogue](https://github.com/mrlegowatch/roleplayingcore/blob/development/Sources/RolePlayingCore/Currency/Currencies.swift): `Sources/RolePlayingCore/Currency/Currencies.swift`
- [Money values](https://github.com/mrlegowatch/roleplayingcore/blob/development/Sources/RolePlayingCore/Currency/Money.swift): `Sources/RolePlayingCore/Currency/Money.swift`

### Spellcasting

- [Spell catalogue](https://github.com/mrlegowatch/roleplayingcore/blob/development/Sources/RolePlayingCore/Spellcasting/Spells.swift): `Sources/RolePlayingCore/Spellcasting/Spells.swift`
- [Spell model](https://github.com/mrlegowatch/roleplayingcore/blob/development/Sources/RolePlayingCore/Spellcasting/Spell.swift): `Sources/RolePlayingCore/Spellcasting/Spell.swift`
- [Spellbook state](https://github.com/mrlegowatch/roleplayingcore/blob/development/Sources/RolePlayingCore/Spellcasting/Spellbook.swift): `Sources/RolePlayingCore/Spellcasting/Spellbook.swift`

### Generation utilities

- [Character generator](https://github.com/mrlegowatch/roleplayingcore/blob/development/Sources/RolePlayingCore/CharacterGenerator/CharacterGenerator.swift): `Sources/RolePlayingCore/CharacterGenerator/CharacterGenerator.swift`
- [Name generator](https://github.com/mrlegowatch/roleplayingcore/blob/development/Sources/RolePlayingCore/CharacterGenerator/NameGenerator.swift): `Sources/RolePlayingCore/CharacterGenerator/NameGenerator.swift`
- [Character name lists](https://github.com/mrlegowatch/roleplayingcore/blob/development/Sources/RolePlayingCore/Common/CharacterNames.swift): `Sources/RolePlayingCore/Common/CharacterNames.swift`
- [Random selection](https://github.com/mrlegowatch/roleplayingcore/blob/development/Sources/RolePlayingCore/Common/RandomIndexGenerator.swift): `Sources/RolePlayingCore/Common/RandomIndexGenerator.swift`
- [Common measurements](https://github.com/mrlegowatch/roleplayingcore/blob/development/Sources/RolePlayingCore/Common/Weight.swift): `Sources/RolePlayingCore/Common/Weight.swift`

### Other components

- **Library client**

## Connections

- Library client → Game data loader: loads content
- Game data loader → Load errors: reports failures
- Game data loader → Currency catalogue: loads (evidence: `Sources/RolePlayingCore/Configuration/GameData.swift`)
- Game data loader → Item catalogue: loads (evidence: `Sources/RolePlayingCore/Configuration/GameData.swift`)
- Game data loader → Background traits: loads (evidence: `Sources/RolePlayingCore/Configuration/GameData.swift`)
- Game data loader → Species traits: loads (evidence: `Sources/RolePlayingCore/Configuration/GameData.swift`)
- Game data loader → Class traits: loads (evidence: `Sources/RolePlayingCore/Configuration/GameData.swift`)
- Game data loader → Spell catalogue: loads (evidence: `Sources/RolePlayingCore/Configuration/GameData.swift`)
- Library client → Character generator: requests generation
- Character generator → Game data loader: uses content (evidence: `Sources/RolePlayingCore/CharacterGenerator/CharacterGenerator.swift`)
- Character generator → Player character: constructs (evidence: `Sources/RolePlayingCore/CharacterGenerator/CharacterGenerator.swift`)
- Character generator → Name generator: generates names
- Name generator → Character name lists: uses lists (evidence: `Sources/RolePlayingCore/CharacterGenerator/NameGenerator.swift`)
- Name generator → Random selection: selects randomly (evidence: `Sources/RolePlayingCore/CharacterGenerator/NameGenerator.swift`)
- Player character → Species traits: resolves (evidence: `Sources/RolePlayingCore/Player/Player.swift`)
- Player character → Class traits: resolves (evidence: `Sources/RolePlayingCore/Player/Player.swift`)
- Player character → Ability scores: calculates from (evidence: `Sources/RolePlayingCore/Player/Player.swift`)
- Player character → Character appearance: stores (evidence: `Sources/RolePlayingCore/Player/Player.swift`)
- Player character → Inventory: stores (evidence: `Sources/RolePlayingCore/Player/Player.swift`)
- Player character → Spellbook state: stores (evidence: `Sources/RolePlayingCore/Player/Player.swift`)
- Item catalogue → Item models: collects (evidence: `Sources/RolePlayingCore/Items/Items.swift`)
- Inventory → Item models: holds (evidence: `Sources/RolePlayingCore/Items/Inventory.swift`)
- Money values → Currency catalogue: uses denominations (evidence: `Sources/RolePlayingCore/Currency/Money.swift`)
- Spellbook state → Spell model: tracks spells (evidence: `Sources/RolePlayingCore/Spellcasting/Spellbook.swift`)
- Spell catalogue → Spell model: collects (evidence: `Sources/RolePlayingCore/Spellcasting/Spells.swift`)
- Item models → Money values: has cost (evidence: `Sources/RolePlayingCore/Items/Item.swift`)
- Item models → Common measurements: has weight (evidence: `Sources/RolePlayingCore/Items/Item.swift`)
