# gregersn/whathappened architecture

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

- Interactive diagram: https://gitdiagram.com/gregersn/whathappened
- Repository: https://github.com/gregersn/whathappened

## Overview

##### Main Components

a) Frontend Layer:
- TypeScript-based frontend (evidenced by frontend/ directory)
- Organized by features: campaign, character sheets, handouts, widgets
- Webpack build system for asset compilation

b) Backend Layer:
- Flask-based Python application
- Modular blueprint structure for different features
- Authentication system
- Database interactions via SQLAlchemy
- Migration system using Alembic

c) Database Layer:
- SQL database (implied by SQLAlchemy usage)
- Multiple related tables for users, campaigns, characters, etc.

##### Key Architectural Elements

**[Client Layer]**
- ↕️ HTTP/WebSocket
**[Application Layer]**
- ↕️ ORM
**[Data Layer]**

##### Component Breakdown

Frontend Components (Blue):
- Character Sheet Management
- Campaign Management
- Handout System
- Authentication UI
- Asset Management

Backend Components (Green):
- Auth Module (/auth)
- Campaign Module (/campaign)
- Character Module (/character)
- Content Module (/content)
- User Assets Module (/userassets)
- Sheet Mechanics Engine (/sheets/mechanics)

Database Components (Yellow):
- User Tables
- Campaign Tables
- Character Tables
- Asset Tables
- Content Tables

##### Interaction Flows

→ Regular data flow
⇢ Authentication flow
⇄ WebSocket connections (future feature)

##### Additional Elements

- External email service (for password reset)
- Static asset storage
- Migration system
- Template rendering engine

##### Technical Details to Note

- Flask blueprints architecture
- SQLAlchemy ORM
- Jinja2 templating
- TypeScript/Webpack frontend
- Authentication system
- Database migration system

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Client
        FE["Frontend Application"]:::frontend
        CM["Campaign Management"]:::frontend
        CS["Character Sheets"]:::frontend
        HS["Handout System"]:::frontend
        WD["Widgets"]:::frontend
    end

    subgraph "Application Layer"
        AM["Authentication Module"]:::backend
        CaM["Campaign Module"]:::backend
        ChM["Character Module"]:::backend
        CoM["Content Module"]:::backend
        UAM["User Assets Module"]:::backend
        SME["Sheet Mechanics Engine"]:::backend
        EM["Email Handler"]:::backend
        
        subgraph "Game Systems"
            CoC["Call of Cthulhu 7e"]:::gamesystem
            TfL["Tales from the Loop"]:::gamesystem
            SS["Sheet Schemas"]:::gamesystem
        end
        
        subgraph "Template System"
            MT["Main Templates"]:::template
            CT["Character Templates"]:::template
            CaT["Campaign Templates"]:::template
        end
    end

    subgraph "Data Layer"
        DB[(Database Core)]:::database
        MS["Migration System"]:::database
        BM["Base Models"]:::database
    end

    subgraph "Asset Storage"
        SA["Static Assets"]:::storage
        UA["User Assets"]:::storage
    end

    %% Frontend Connections
    FE --> AM
    FE --> CaM
    FE --> ChM
    FE --> CoM
    FE --> UAM

    %% Module Connections
    AM --> DB
    CaM --> DB
    ChM --> DB
    CoM --> DB
    UAM --> DB
    SME --> ChM

    %% Game System Connections
    ChM --> CoC
    ChM --> TfL
    CoC & TfL --> SS

    %% Template Connections
    ChM --> CT
    CaM --> CaT
    AM & CaM & ChM --> MT

    %% Asset Connections
    UAM --> UA
    CoM --> SA

    %% Database Connections
    DB --> MS
    DB --> BM

    %% Email Connection
    AM --> EM

    %% Click Events
    click FE "https://github.com/gregersn/whathappened/tree/master/frontend/src/"
    click CM "https://github.com/gregersn/whathappened/tree/master/frontend/src/campaign/"
    click CS "https://github.com/gregersn/whathappened/tree/master/frontend/src/sheet/"
    click HS "https://github.com/gregersn/whathappened/tree/master/frontend/src/handout/"
    click WD "https://github.com/gregersn/whathappened/tree/master/frontend/src/widgets/"
    click AM "https://github.com/gregersn/whathappened/tree/master/src/whathappened/auth/"
    click CaM "https://github.com/gregersn/whathappened/tree/master/src/whathappened/campaign/"
    click ChM "https://github.com/gregersn/whathappened/tree/master/src/whathappened/character/"
    click CoM "https://github.com/gregersn/whathappened/tree/master/src/whathappened/content/"
    click UAM "https://github.com/gregersn/whathappened/tree/master/src/whathappened/userassets/"
    click SME "https://github.com/gregersn/whathappened/tree/master/src/whathappened/sheets/mechanics/"
    click DB "https://github.com/gregersn/whathappened/tree/master/src/whathappened/database/"
    click MS "https://github.com/gregersn/whathappened/tree/master/src/whathappened/migrations/"
    click BM "https://github.com/gregersn/whathappened/blob/master/src/whathappened/models.py"
    click CoC "https://github.com/gregersn/whathappened/tree/master/src/whathappened/character/coc7e/"
    click TfL "https://github.com/gregersn/whathappened/tree/master/src/whathappened/character/tftl/"
    click SS "https://github.com/gregersn/whathappened/tree/master/src/whathappened/sheets/schema/"
    click MT "https://github.com/gregersn/whathappened/tree/master/src/whathappened/templates/"
    click CT "https://github.com/gregersn/whathappened/tree/master/src/whathappened/templates/character/"
    click CaT "https://github.com/gregersn/whathappened/tree/master/src/whathappened/templates/campaign/"
    click SA "https://github.com/gregersn/whathappened/tree/master/src/whathappened/static/"
    click UA "https://github.com/gregersn/whathappened/tree/master/src/whathappened/userassets/"
    click EM "https://github.com/gregersn/whathappened/blob/master/src/whathappened/email.py"

    %% Styles
    classDef frontend fill:#2196F3,stroke:#1565C0,color:white
    classDef backend fill:#4CAF50,stroke:#2E7D32,color:white
    classDef database fill:#FFC107,stroke:#FFA000,color:black
    classDef gamesystem fill:#9C27B0,stroke:#7B1FA2,color:white
    classDef template fill:#FF5722,stroke:#E64A19,color:white
    classDef storage fill:#795548,stroke:#5D4037,color:white
```
