# haste/tales-beyond architecture

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

- Interactive diagram: https://gitdiagram.com/haste/tales-beyond
- Repository: https://github.com/haste/tales-beyond

## Overview

##### Main Components

a. Browser Extension Components:
- Background Service Worker (from background.js)
- Content Scripts Layer
- User Interface Elements
- Storage System

b. External Services Integration:
- D&D Beyond Platform
- TaleSpire Platform

**┌─ Browser Extension Environment ─────────────────────────┐**

- ┌─ User Interface ─────┐    ┌─ Core Logic ────────┐  │
- Context Menus      │    │ - Character Handler  │  │
- Options Page       │    │ - Monster Handler    │  │
- Dialog Components  │    │ - Mods System       │  │
- ┬─┘    └─────────┬──────────┘  │

- ┌─ Background Service Worker ─────────┴──────────┐  │
- D&D Beyond Integration                       │  │
- TaleSpire Communication                      │  │
- ┬─────────────────────────┘  │

- ┼────────────────────────────┘

**┌────────────────────────┼────────────────────────────┐**
- External Services      │                            │
- ┌─────────────────┐  │  ┌────────────────┐        │
- D&D Beyond    │◄─┴─►│   TaleSpire    │        │
- ┘     └────────────────┘        │
- ┘

##### Component Details

a. Browser Extension Core:
- Manifest files (manifest.chrome.json and manifest.firefox.json)
- Background service worker
- Content script injection points
- Storage utilities (storage.js)

b. Feature Modules:
- Character handling (characters.js)
- Monster handling (monsters.js)
- Modification system (mods.js)
- Theme management (themes.js)

c. User Interface:
- Context menu system (contextmenu.js)
- Options page (options.html/js)
- Style system (scss directory)

##### Interaction Flows to Demonstrate

- How dice roll requests flow from D&D Beyond to TaleSpire
- How the observer pattern (observer.js) monitors D&D Beyond changes
- Storage interaction patterns
- How different clients (browser/symbiote) interact with the core system

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Styles
    classDef core fill:#2196F3,stroke:#1565C0,color:white
    classDef ui fill:#FF9800,stroke:#F57C00,color:white
    classDef service fill:#4CAF50,stroke:#388E3B,color:white
    classDef external fill:#9C27B0,stroke:#7B1FA2,color:white
    classDef storage fill:#607D8B,stroke:#455A64,color:white
    classDef config fill:#795548,stroke:#5D4037,color:white

    subgraph BrowserExtension["Browser Extension Environment"]
        subgraph UI["User Interface Layer"]
            ContextMenu["Context Menu System"]
            Options["Options Interface"]
            Themes["Theme Management"]
            Styles["Style System"]
        end

        subgraph Core["Core Logic Layer"]
            CharHandler["Character Handler"]
            MonsterHandler["Monster Handler"]
            ModSystem["Mods System"]
            Observer["Observer Pattern"]
        end

        subgraph Background["Background Service Worker"]
            BGWorker["Background Process"]
            Storage["Storage System"]
            DndBeyondInt["D&D Beyond Integration"]
            TaleSpireInt["TaleSpire Integration"]
        end

        subgraph Config["Configuration"]
            ChromeManifest["Chrome Manifest"]
            FirefoxManifest["Firefox Manifest"]
        end
    end

    subgraph External["External Services"]
        DndBeyond["D&D Beyond Platform"]
        TaleSpire["TaleSpire Platform"]
    end

    subgraph Build["Build System"]
        BuildFlow["Build & Release Workflow"]
    end

    %% Connections
    UI --> Core
    Core --> Background
    Background --> External
    DndBeyond <--> TaleSpire
    Config --> Background

    %% Class Assignments
    class CharHandler,MonsterHandler,ModSystem,Observer core
    class ContextMenu,Options,Themes,Styles ui
    class BGWorker,DndBeyondInt,TaleSpireInt service
    class Storage storage
    class DndBeyond,TaleSpire external
    class ChromeManifest,FirefoxManifest config
    class BuildFlow config

    %% Click Events
    click CharHandler "https://github.com/haste/tales-beyond/blob/main/src/characters.js"
    click MonsterHandler "https://github.com/haste/tales-beyond/blob/main/src/monsters.js"
    click ModSystem "https://github.com/haste/tales-beyond/blob/main/src/mods.js"
    click Observer "https://github.com/haste/tales-beyond/blob/main/src/utils/observer.js"
    click ContextMenu "https://github.com/haste/tales-beyond/blob/main/src/contextmenu.js"
    click Options "https://github.com/haste/tales-beyond/blob/main/src/options.js"
    click Themes "https://github.com/haste/tales-beyond/blob/main/src/themes.js"
    click Styles "https://github.com/haste/tales-beyond/tree/main/src/scss/"
    click BGWorker "https://github.com/haste/tales-beyond/blob/main/src/clients/browser/background.js"
    click Storage "https://github.com/haste/tales-beyond/blob/main/src/utils/storage.js"
    click DndBeyondInt "https://github.com/haste/tales-beyond/blob/main/src/utils/dndbeyond.js"
    click TaleSpireInt "https://github.com/haste/tales-beyond/blob/main/src/utils/talespire.js"
    click ChromeManifest "https://github.com/haste/tales-beyond/blob/main/src/clients/browser/manifest.chrome.json"
    click FirefoxManifest "https://github.com/haste/tales-beyond/blob/main/src/clients/browser/manifest.firefox.json"
    click BuildFlow "https://github.com/haste/tales-beyond/blob/main/.github/workflows/release.yml"
```
