# skarpelen/comfort-chat-foundry-vtt architecture

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

- Interactive diagram: https://gitdiagram.com/skarpelen/comfort-chat-foundry-vtt
- Repository: https://github.com/skarpelen/comfort-chat-foundry-vtt

## Overview

Comfort Chat is a Foundry VTT module for formatting emote/description messages and transforming character speech with accents and drunk-speech effects. The main flow handles chat input, resolves the speaker’s actor state, transforms eligible in-character text, and creates chat messages; users can configure speech through chat commands or actor-sheet controls. EMM formatting is a separate branch of chat handling. The README describes a generic template rather than these features, so the graph follows the sampled implementation; hook wiring beyond the shown registrations is left unverified.

Main entry points: [`src/ts/features/speech/pipeline.ts`](https://github.com/skarpelen/comfort-chat-foundry-vtt/blob/master/src/ts/features/speech/pipeline.ts) (Speech pipeline), [`src/ts/features/speech/drunkEffectState.ts`](https://github.com/skarpelen/comfort-chat-foundry-vtt/blob/master/src/ts/features/speech/drunkEffectState.ts) (Drunk effect state), [`src/ts/features/emm/index.ts`](https://github.com/skarpelen/comfort-chat-foundry-vtt/blob/master/src/ts/features/emm/index.ts) (EMM chat hooks), [`src/ts/features/speech/index.ts`](https://github.com/skarpelen/comfort-chat-foundry-vtt/blob/master/src/ts/features/speech/index.ts) (Speech hooks)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_integration["Foundry integration"]
  node_feature_registration["Feature registration<br/>[index.ts]"]
end

subgraph group_emm["Emote messages"]
  node_emm_hooks["EMM chat hooks<br/>[index.ts]"]
end

subgraph group_speech["Speech transformation"]
  node_speech_hooks["Speech hooks<br/>[index.ts]"]
  node_speech_pipeline["Speech pipeline<br/>[pipeline.ts]"]
  node_accent_data["Accent registry<br/>[accentRegistry.ts]"]
  node_accent_transform["Accent transformation"]
  node_drunk_transform["Drunk transformation<br/>[drunk.ts]"]
  node_actor_state["Actor speech state"]
  node_drunk_state["Drunk effect state"]
  node_speech_commands["Speech commands<br/>[commands.ts]"]
  node_sheet_controls["Actor-sheet controls<br/>[sheetSpeechUi.ts]"]
  node_status_effects["Status effects<br/>[statusEffects.ts]"]
end

subgraph group_support["Settings and state"]
  node_settings["Debug settings<br/>[settings.ts]"]
  node_logger["Logger<br/>[log.ts]"]
end

node_user(("Foundry user"))
node_foundry{{"Foundry VTT"}}

node_user -->|"uses"| node_foundry
node_foundry -.->|"dispatches chat"| node_emm_hooks
node_foundry -.->|"dispatches hooks"| node_speech_hooks
node_feature_registration -->|"imports"| node_emm_hooks
node_feature_registration -->|"imports"| node_speech_hooks
node_emm_hooks -->|"transforms plain chat"| node_speech_pipeline
node_emm_hooks -->|"creates messages"| node_foundry
node_emm_hooks -->|"processes descriptions"| node_foundry
node_speech_hooks -->|"registers commands"| node_speech_commands
node_speech_hooks -->|"registers hooks"| node_sheet_controls
node_speech_hooks -->|"registers effects"| node_status_effects
node_speech_pipeline -->|"reads actor state"| node_actor_state
node_speech_pipeline -->|"gets accent"| node_accent_data
node_speech_pipeline -->|"applies accent"| node_accent_transform
node_speech_pipeline -->|"reads level"| node_drunk_state
node_speech_pipeline -->|"applies drunk speech"| node_drunk_transform
node_accent_data -->|"builds accent data"| node_accent_transform
node_actor_state -->|"reads drunk level"| node_drunk_state
node_drunk_state -->|"clamps level"| node_drunk_transform
node_drunk_state -->|"uses status identifiers"| node_status_effects
node_speech_commands -->|"sets accent"| node_actor_state
node_speech_commands -->|"sets drunk level"| node_drunk_state
node_sheet_controls -->|"sets accent"| node_actor_state
node_sheet_controls -->|"sets drunk level"| node_drunk_state
node_logger -->|"checks debug flag"| node_settings

click node_feature_registration "https://github.com/skarpelen/comfort-chat-foundry-vtt/blob/master/src/ts/features/index.ts"
click node_emm_hooks "https://github.com/skarpelen/comfort-chat-foundry-vtt/blob/master/src/ts/features/emm/index.ts"
click node_speech_hooks "https://github.com/skarpelen/comfort-chat-foundry-vtt/blob/master/src/ts/features/speech/index.ts"
click node_speech_pipeline "https://github.com/skarpelen/comfort-chat-foundry-vtt/blob/master/src/ts/features/speech/pipeline.ts"
click node_accent_data "https://github.com/skarpelen/comfort-chat-foundry-vtt/blob/master/src/ts/features/speech/accentRegistry.ts"
click node_accent_transform "https://github.com/skarpelen/comfort-chat-foundry-vtt/blob/master/src/ts/features/speech/replacementAccent.ts"
click node_drunk_transform "https://github.com/skarpelen/comfort-chat-foundry-vtt/blob/master/src/ts/features/speech/drunk.ts"
click node_actor_state "https://github.com/skarpelen/comfort-chat-foundry-vtt/blob/master/src/ts/features/speech/actorSpeechState.ts"
click node_drunk_state "https://github.com/skarpelen/comfort-chat-foundry-vtt/blob/master/src/ts/features/speech/drunkEffectState.ts"
click node_speech_commands "https://github.com/skarpelen/comfort-chat-foundry-vtt/blob/master/src/ts/features/speech/commands.ts"
click node_sheet_controls "https://github.com/skarpelen/comfort-chat-foundry-vtt/blob/master/src/ts/features/speech/sheetSpeechUi.ts"
click node_status_effects "https://github.com/skarpelen/comfort-chat-foundry-vtt/blob/master/src/ts/features/speech/statusEffects.ts"
click node_settings "https://github.com/skarpelen/comfort-chat-foundry-vtt/blob/master/src/ts/settings.ts"
click node_logger "https://github.com/skarpelen/comfort-chat-foundry-vtt/blob/master/src/ts/log.ts"

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_feature_registration,node_user toneBlue
class node_emm_hooks toneAmber
class node_speech_hooks,node_speech_pipeline,node_accent_data,node_accent_transform,node_drunk_transform,node_actor_state,node_drunk_state,node_speech_commands,node_sheet_controls,node_status_effects toneMint
class node_settings,node_logger toneRose
class node_foundry toneIndigo
```

## Components

### Foundry integration

- [Feature registration](https://github.com/skarpelen/comfort-chat-foundry-vtt/blob/master/src/ts/features/index.ts): `src/ts/features/index.ts`

### Emote messages

- [EMM chat hooks](https://github.com/skarpelen/comfort-chat-foundry-vtt/blob/master/src/ts/features/emm/index.ts): `src/ts/features/emm/index.ts`

### Speech transformation

- [Speech hooks](https://github.com/skarpelen/comfort-chat-foundry-vtt/blob/master/src/ts/features/speech/index.ts): `src/ts/features/speech/index.ts`
- [Speech pipeline](https://github.com/skarpelen/comfort-chat-foundry-vtt/blob/master/src/ts/features/speech/pipeline.ts): `src/ts/features/speech/pipeline.ts`
- [Accent registry](https://github.com/skarpelen/comfort-chat-foundry-vtt/blob/master/src/ts/features/speech/accentRegistry.ts): `src/ts/features/speech/accentRegistry.ts`
- [Accent transformation](https://github.com/skarpelen/comfort-chat-foundry-vtt/blob/master/src/ts/features/speech/replacementAccent.ts): `src/ts/features/speech/replacementAccent.ts`
- [Drunk transformation](https://github.com/skarpelen/comfort-chat-foundry-vtt/blob/master/src/ts/features/speech/drunk.ts): `src/ts/features/speech/drunk.ts`
- [Actor speech state](https://github.com/skarpelen/comfort-chat-foundry-vtt/blob/master/src/ts/features/speech/actorSpeechState.ts): `src/ts/features/speech/actorSpeechState.ts`
- [Drunk effect state](https://github.com/skarpelen/comfort-chat-foundry-vtt/blob/master/src/ts/features/speech/drunkEffectState.ts): `src/ts/features/speech/drunkEffectState.ts`
- [Speech commands](https://github.com/skarpelen/comfort-chat-foundry-vtt/blob/master/src/ts/features/speech/commands.ts): `src/ts/features/speech/commands.ts`
- [Actor-sheet controls](https://github.com/skarpelen/comfort-chat-foundry-vtt/blob/master/src/ts/features/speech/sheetSpeechUi.ts): `src/ts/features/speech/sheetSpeechUi.ts`
- [Status effects](https://github.com/skarpelen/comfort-chat-foundry-vtt/blob/master/src/ts/features/speech/statusEffects.ts): `src/ts/features/speech/statusEffects.ts`

### Settings and state

- [Debug settings](https://github.com/skarpelen/comfort-chat-foundry-vtt/blob/master/src/ts/settings.ts): `src/ts/settings.ts`
- [Logger](https://github.com/skarpelen/comfort-chat-foundry-vtt/blob/master/src/ts/log.ts): `src/ts/log.ts`

### Other components

- **Foundry user**
- **Foundry VTT**

## Connections

- Foundry user → Foundry VTT: uses
- Foundry VTT → EMM chat hooks: dispatches chat
- Foundry VTT → Speech hooks: dispatches hooks
- Feature registration → EMM chat hooks: imports (evidence: `src/ts/features/index.ts`)
- Feature registration → Speech hooks: imports (evidence: `src/ts/features/index.ts`)
- EMM chat hooks → Speech pipeline: transforms plain chat (evidence: `src/ts/features/emm/index.ts`)
- EMM chat hooks → Foundry VTT: creates messages (evidence: `src/ts/features/emm/index.ts`)
- EMM chat hooks → Foundry VTT: processes descriptions (evidence: `src/ts/features/emm/index.ts`)
- Speech hooks → Speech commands: registers commands (evidence: `src/ts/features/speech/index.ts`)
- Speech hooks → Actor-sheet controls: registers hooks (evidence: `src/ts/features/speech/index.ts`)
- Speech hooks → Status effects: registers effects (evidence: `src/ts/features/speech/index.ts`)
- Speech pipeline → Actor speech state: reads actor state (evidence: `src/ts/features/speech/pipeline.ts`)
- Speech pipeline → Accent registry: gets accent (evidence: `src/ts/features/speech/pipeline.ts`)
- Speech pipeline → Accent transformation: applies accent (evidence: `src/ts/features/speech/pipeline.ts`)
- Speech pipeline → Drunk effect state: reads level (evidence: `src/ts/features/speech/pipeline.ts`)
- Speech pipeline → Drunk transformation: applies drunk speech (evidence: `src/ts/features/speech/pipeline.ts`)
- Accent registry → Accent transformation: builds accent data (evidence: `src/ts/features/speech/accentRegistry.ts`)
- Actor speech state → Drunk effect state: reads drunk level (evidence: `src/ts/features/speech/actorSpeechState.ts`)
- Drunk effect state → Drunk transformation: clamps level (evidence: `src/ts/features/speech/drunkEffectState.ts`)
- Drunk effect state → Status effects: uses status identifiers (evidence: `src/ts/features/speech/drunkEffectState.ts`)
- Speech commands → Actor speech state: sets accent (evidence: `src/ts/features/speech/commands.ts`)
- Speech commands → Drunk effect state: sets drunk level (evidence: `src/ts/features/speech/commands.ts`)
- Actor-sheet controls → Actor speech state: sets accent (evidence: `src/ts/features/speech/sheetSpeechUi.ts`)
- Actor-sheet controls → Drunk effect state: sets drunk level (evidence: `src/ts/features/speech/sheetSpeechUi.ts`)
- Logger → Debug settings: checks debug flag (evidence: `src/ts/log.ts`)
