# trunkyfgc/trunky-overlay architecture

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

- Interactive diagram: https://gitdiagram.com/trunkyfgc/trunky-overlay
- Repository: https://github.com/trunkyfgc/trunky-overlay

## Overview

##### Main Components

a) Frontend Layer:
- Svelte Application (in /static)
- Scoreboard View
- Control Center View
- Browser Source (OBS Integration point)

b) Backend Layer:
- Rust Server
- WebSocket Communication System
- Static File Serving

c) Core Libraries:
- embed_static: Static file embedding
- parser: Data parsing functionality
- socket: WebSocket handling

##### Architecture Pattern

**[Frontend Layer]**

- Scoreboard View (Browser/OBS)
- State Management
- Player List Store
- Scoreboard Store

- Control Center View (Browser)
- Control Interface

- Shared Components
- WebSocket Client

**[Backend Layer]**

- Rust Server
- Static File Server
- WebSocket Handler
- State Management

**[Libraries]**

- embed_static
- parser
- socket

##### Key Elements to Highlight

a) Data Flow:

- Frontend Components: Blue
- Backend Components: Green
- WebSocket Communications: Purple
- Static File Serving: Gray
- Libraries: Orange

##### Implementation Details

**[OBS Layer]**
- ↓
**[Frontend Views]**
- ↕
**[WebSocket Layer]**
- ↕
**[Backend Server]**
- ↓
**[Core Libraries]**

##### Additional Notes

- Notes about the development setup (Node.js and Rust requirements)
- Port (8080) and endpoints (/app/scoreboard.html, /app/control.html)
- Build process flow from source to final binary

##### Technical Stack Indicators

- Svelte for frontend framework
- Rust for backend server
- WebSocket for real-time communication
- Tailwind CSS for styling
- TypeScript for type safety
- Vite for development server

Remember to indicate that this is a single binary application where the frontend is embedded into the Rust server, making it easy to distribute and deploy.

## Diagram (Mermaid)

```mermaid
graph TB
    %% Styles and classes
    classDef rust fill:#FFA07A,stroke:#8B4513,color:black
    classDef javascript fill:#87CEEB,stroke:#4682B4,color:black
    classDef socket fill:#98FB98,stroke:#006400,color:black
    classDef store fill:#DDA0DD,stroke:#800080,color:black

    %% Legend
    subgraph Legend
        R[Rust Component]:::rust
        J[JavaScript Component]:::javascript
        S[Socket Communication]:::socket
        ST[Store Management]:::store
    end

    %% Rust Backend Layer
    subgraph Backend
        MainServer[Main Server]:::rust
        Socket[Socket Library]:::rust
        Parser[Parser Library]:::rust
        EmbedStatic[Embed Static Library]:::rust

        MainServer ---> Socket
        MainServer ---> Parser
        MainServer ---> EmbedStatic
    end

    %% JavaScript Frontend Layer
    subgraph Frontend
        SvelteFrontend[Svelte Frontend]:::javascript
        Scoreboard[Scoreboard Module]:::javascript
        PlayerList[Player List Module]:::javascript
        Control[Control Interface]:::javascript
        SocketStore[Shared Socket Store]:::socket
        ScoreboardModels[Scoreboard Models]:::javascript
    end

    %% Store Layer
    subgraph Store
        StateManagement[State Management]:::store
        ScoreboardStore[Scoreboard Store]:::store
        PlayerListStore[Player List Store]:::store

        StateManagement --> ScoreboardStore
        StateManagement --> PlayerListStore
    end

    %% Component connections
    SvelteFrontend ---> Scoreboard
    SvelteFrontend ---> PlayerList
    SvelteFrontend ---> Control
    
    Scoreboard ---> SocketStore
    PlayerList ---> SocketStore
    Control ---> SocketStore
    
    Scoreboard ---> ScoreboardModels
    Scoreboard ---> StateManagement
    PlayerList ---> StateManagement

    %% Cross-layer communication
    SocketStore -.->|WebSocket| Socket

    %% Click events
    click MainServer "https://github.com/trunkyfgc/trunky-overlay/blob/main/src/main.rs"
    click Socket "https://github.com/trunkyfgc/trunky-overlay/blob/main/libs/socket/src/lib.rs"
    click Parser "https://github.com/trunkyfgc/trunky-overlay/blob/main/libs/parser/src/lib.rs"
    click EmbedStatic "https://github.com/trunkyfgc/trunky-overlay/blob/main/libs/embed_static/src/lib.rs"
    click SvelteFrontend "https://github.com/trunkyfgc/trunky-overlay/tree/main/static/src/routes"
    click Scoreboard "https://github.com/trunkyfgc/trunky-overlay/tree/main/static/src/lib/scoreboard"
    click PlayerList "https://github.com/trunkyfgc/trunky-overlay/tree/main/static/src/lib/player-list"
    click Control "https://github.com/trunkyfgc/trunky-overlay/blob/main/static/src/routes/control/+page.svelte"
    click SocketStore "https://github.com/trunkyfgc/trunky-overlay/blob/main/static/src/lib/shared/socket-singleton.ts"
    click ScoreboardModels "https://github.com/trunkyfgc/trunky-overlay/tree/main/static/src/lib/scoreboard/model"
    click StateManagement "https://github.com/trunkyfgc/trunky-overlay/tree/main/static/src/lib/scoreboard/store"
```
