# deadpyxel/tabulanil-sanity-dnd5e architecture

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

- Interactive diagram: https://gitdiagram.com/deadpyxel/tabulanil-sanity-dnd5e
- Repository: https://github.com/deadpyxel/tabulanil-sanity-dnd5e

## Overview

##### Main Components Identification

a. Core Module Integration
- FoundryVTT Core System (v11+)
- DnD5e Game System (v3.0+)
- Tabulanil Sanity Module

b. Feature Components
- Sanity Calculator
- Actor Sheet Integration
- Token HUD Integration
- Chat Message System
- Attribute Change Observer

##### Component Relationships

Use the following connection types:
- Double lines: API integration points

##### Implementation Details

Specific connections for:
- Mental attribute observers to sanity calculator
- Token HUD modifications
- Actor sheet extensions
- Chat message template rendering
- Localization system integration

##### Key Workflows

Main workflows:
- Sanity calculation from mental attributes
- Sanity value updates
- Insanity state changes and notifications
- Token HUD interaction flow

##### Technical Elements

Technical aspects:
- Module initialization process
- Hook registration points
- Template rendering system
- Style injection (styles/tabulanil-sanity.css)

Remember to show the module's boundaries clearly to distinguish between existing FoundryVTT functionality and the new features added by this module.

## Diagram (Mermaid)

```mermaid
graph TB
    %% Define styles
    classDef core fill:#2374ab,color:white
    classDef ui fill:#57a773,color:white
    classDef logic fill:#ff8c42,color:white
    classDef integration fill:#845ec2,color:white
    classDef external fill:#gray,color:white

    %% External Systems
    subgraph External
        FVTT[FoundryVTT Core v11+]:::external
        DND[DnD5e System v3.0+]:::external
    end

    %% User Interface Layer
    subgraph UI
        THUD[Token HUD Component]:::ui
        SHEET[Actor Sheet Component]:::ui
        CHAT[Chat Message Display]:::ui
        TEMPLATE["Chat Templates"]:::ui
        STYLES["UI Styling"]:::ui
    end

    %% Core Logic Layer
    subgraph Logic
        CALC[Sanity Calculator]:::logic
        EVENTS[Event Handlers]:::logic
        STATE[State Management]:::logic
        LOCAL[Localization System]:::logic
        CONFIG[Module Configuration]:::logic
    end

    %% Integration Layer
    subgraph Integration
        HOOKS[FoundryVTT API Hooks]:::integration
        CORE[Core Module Integration]:::integration
        D5INT[DnD5e Integration]:::integration
        PERSIST[Data Persistence]:::integration
    end

    %% Relationships
    FVTT --> HOOKS
    DND --> D5INT
    HOOKS --> CORE
    D5INT --> CORE
    CORE --> STATE
    STATE --> CALC
    CALC --> THUD
    CALC --> SHEET
    EVENTS --> CHAT
    CHAT --> TEMPLATE
    LOCAL --> CHAT
    CONFIG --> CORE
    STYLES --> THUD
    STYLES --> SHEET
    STYLES --> CHAT
    PERSIST --> STATE

    %% Click events
    click CORE "https://github.com/deadpyxel/tabulanil-sanity-dnd5e/blob/main/modules/tabulanil-sanity.js"
    click CONFIG "https://github.com/deadpyxel/tabulanil-sanity-dnd5e/blob/main/module.json"
    click TEMPLATE "https://github.com/deadpyxel/tabulanil-sanity-dnd5e/blob/main/templates/chat-card.hbs"
    click STYLES "https://github.com/deadpyxel/tabulanil-sanity-dnd5e/blob/main/styles/tabulanil-sanity.css"
    click LOCAL "https://github.com/deadpyxel/tabulanil-sanity-dnd5e/blob/main/languages/en.json"

    %% Legend
    subgraph Legend
        L1[UI Components]:::ui
        L2[Logic Components]:::logic
        L3[Integration Points]:::integration
        L4[External Systems]:::external
    end
```
