# dannovikov/tts architecture

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

- Interactive diagram: https://gitdiagram.com/dannovikov/tts
- Repository: https://github.com/dannovikov/tts

## Overview

##### Project Type and Purpose
- This is a lightweight full‑stack web application whose single goal is to take Twitch chat messages and play them as text‑to‑speech in a streaming overlay.
- The “frontend” is a static HTML/JS page loaded via a browser source (e.g., OBS). The “backend” is a Node.js server that (a) connects to Twitch’s chat API, (b) optionally filters/augments messages (e.g., via OpenAI), and (c) pushes events down to the frontend.

##### File Structure Analysis
- Top‑level files:
- server.js  → the Express (or HTTP) server entry point
- package.json/.gitignore/.prettierrc  → Node.js tooling & config
- todo.txt  → developer notes
- public/ directory:
- index.html → the overlay page you drop into OBS
- app.js     → client‑side logic (connects back to server, invokes browser TTS)
- No separate “src” vs “dist”—it’s a simple static+server layout.

##### Insights from README
- The server runs on port 3000 by default, serving both static assets and a stream endpoint at `/?username=…`.
- Consumers add a Browser Source pointing at your server URL; the JS code in app.js opens a WebSocket or SSE to receive chat payloads.
- The server optionally uses an OpenAI API key (via a local file) to moderate or enrich messages before relaying them.

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph "External Services"
        Twitch["Twitch Chat API"]:::external
        OpenAI["OpenAI API"]:::external
    end

    subgraph "Server"
        direction TB
        ChatConnector["Twitch Chat Connector"]:::backend
        MessageProcessor["Message Processor (optional OpenAI)"]:::backend
        SSEEndpoint["SSE/WebSocket Endpoint"]:::backend
        StaticServer["Static Asset Host"]:::backend
    end

    subgraph "Client / OBS"
        direction TB
        OBS["OBS Browser Source"]:::frontend
        OverlayPage["Overlay Page"]:::frontend
        ClientLogic["Client Logic (SSE/WebSocket + SpeechSynthesis)"]:::frontend
    end

    subgraph "Project Files"
        direction TB
        ServerJS["server.js"]:::backend
        Package["package.json"]:::config
        Todo["todo.txt"]:::config
        Gitignore[".gitignore"]:::config
        Prettierrc[".prettierrc"]:::config
        Readme["README.md"]:::config
    end

    Twitch --> ChatConnector
    ChatConnector --> MessageProcessor
    MessageProcessor --> OpenAI
    OpenAI --> MessageProcessor
    MessageProcessor --> SSEEndpoint
    SSEEndpoint --> ClientLogic
    StaticServer --> OverlayPage
    OverlayPage --> ClientLogic
    OBS --> OverlayPage

    ServerJS --> ChatConnector
    ServerJS --> MessageProcessor
    ServerJS --> SSEEndpoint
    ServerJS --> StaticServer

    click ServerJS "https://github.com/dannovikov/tts/blob/main/server.js"
    click ChatConnector "https://github.com/dannovikov/tts/blob/main/server.js"
    click MessageProcessor "https://github.com/dannovikov/tts/blob/main/server.js"
    click SSEEndpoint "https://github.com/dannovikov/tts/blob/main/server.js"
    click OverlayPage "https://github.com/dannovikov/tts/blob/main/public/index.html"
    click ClientLogic "https://github.com/dannovikov/tts/blob/main/public/app.js"
    click Package "https://github.com/dannovikov/tts/blob/main/package.json"
    click Todo "https://github.com/dannovikov/tts/blob/main/todo.txt"
    click Gitignore "https://github.com/dannovikov/tts/blob/main/.gitignore"
    click Prettierrc "https://github.com/dannovikov/tts/blob/main/.prettierrc"
    click Readme "https://github.com/dannovikov/tts/blob/main/README.md"

    classDef external fill:#B3D4FC,stroke:#0366d6,color:#0366d6
    classDef backend fill:#D5E8D4,stroke:#2F855A,color:#2F855A
    classDef frontend fill:#FBD38D,stroke:#DD6B20,color:#DD6B20
    classDef config fill:#EDEDED,stroke:#888888,color:#333333
```
