# pomdap/twitchteamlivestats architecture

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

- Interactive diagram: https://gitdiagram.com/pomdap/twitchteamlivestats
- Repository: https://github.com/pomdap/twitchteamlivestats

## Overview

##### Project Type and Purpose
- This is a small .NET console application (“TwitchTeamLiveStats”) that uses Twitch’s PubSub API to monitor viewer counts for a list of channels and writes various summary and per-channel files to a local output directory. It’s intended to be run during events or as a team-wide viewer counter (for example, inside OBS via Text (GDI+)).

##### High-Level Component Analysis
Top-level files and folders:
- Program.cs – application entry point
- appsettings.json – configuration for the TeamSupervisor and TeamWriter
- TwitchTeamLiveStats.csproj / .sln – .NET build artifacts

From the README, the code is organised around two main logical components:
a. TeamSupervisor – subscribes to Twitch PubSub, maintains channel live state and viewer counts, tracks timeouts for stale channels
b. TeamWriter – takes the statistics from the supervisor and writes them into files in the configured output directory

##### Key External Dependency
- Twitch PubSub API (external service over WebSocket/HTTP)

- Configuration Loader (reads appsettings.json)
- Program (composition root)
- TeamSupervisor
- TeamWriter
- Twitch PubSub Service (external)
- File System (Output Directory)

1. On startup, Program reads Configuration → passes ChannelIds and TimeoutInterval to TeamSupervisor; passes writer settings to TeamWriter.
2. TeamSupervisor establishes a connection to Twitch PubSub Service → subscribes to events for each ChannelId.
3. As messages arrive (viewer counts), TeamSupervisor updates its internal state and emits events or calls into TeamWriter.
4. TeamWriter writes/overwrites files in Output Directory:
– total.viewers, live.channels, total.channels
– {ChannelId}.viewers for each channel
5. File System persists these files for external consumption (e.g., OBS).

c. Architectural patterns / principles:
- Single-responsibility: Supervisor vs. Writer
- Dependency injection in Program.cs to wire Supervisor and Writer with configuration
- Event-driven flow: Supervisor publishes viewer updates → Writer consumes them
- External boundary clearly drawn around the Twitch PubSub service and the local file system

d. Relevant Technologies & Frameworks:
- .NET Console App (C#)
- Microsoft.Extensions.Configuration (for appsettings.json)
- Twitch PubSub WebSocket/HTTP API
- System.IO for file writes

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Composition Root
    subgraph "Composition Root"
        direction TB
        Program["Program.cs"]:::root
        ConfigLoader["Configuration Loader\n(appsettings.json)"]:::config
        Program -->|reads config| ConfigLoader
    end

    %% Core Services
    subgraph "Core Services"
        direction TB
        Supervisor["TeamSupervisor"]:::internal
        Writer["TeamWriter"]:::internal
    end

    %% External Systems
    subgraph "External Boundaries"
        direction TB
        PubSub((Twitch PubSub Service)):::external
        FileSystem[(Output Directory)]:::external
    end

    %% Project Artifacts
    subgraph "Repository Files"
        direction TB
        CSProj["TwitchTeamLiveStats.csproj"]:::repo
        SLN["TwitchTeamLiveStats.sln"]:::repo
        CI[".github/workflows/main.yml"]:::repo
        GitIgnore[".gitignore"]:::repo
        License["LICENSE"]:::repo
        Readme["README.md"]:::repo
    end

    %% Connections
    Program -->|injects ChannelIds & Timeout| Supervisor
    Program -->|injects WriterSettings| Writer
    Supervisor -->|Subscribe to events| PubSub
    PubSub -->|ViewerCountEvent| Supervisor
    Supervisor -->|event/callback| Writer
    Writer -->|writes files| FileSystem

    %% Click Events
    click Program "https://github.com/pomdap/twitchteamlivestats/blob/main/Program.cs"
    click ConfigLoader "https://github.com/pomdap/twitchteamlivestats/blob/main/appsettings.json"
    click CSProj "https://github.com/pomdap/twitchteamlivestats/blob/main/TwitchTeamLiveStats.csproj"
    click SLN "https://github.com/pomdap/twitchteamlivestats/blob/main/TwitchTeamLiveStats.sln"
    click CI "https://github.com/pomdap/twitchteamlivestats/blob/main/.github/workflows/main.yml"
    click GitIgnore "https://github.com/pomdap/twitchteamlivestats/blob/main/.gitignore"
    click License "https://github.com/pomdap/twitchteamlivestats/tree/main/LICENSE"
    click Readme "https://github.com/pomdap/twitchteamlivestats/blob/main/README.md"

    %% Styles
    classDef root fill:#b3e5fc,stroke:#0288d1,stroke-width:2px;
    classDef config fill:#c8e6c9,stroke:#2e7d32,stroke-width:2px;
    classDef internal fill:#bbdefb,stroke:#1976d2,stroke-width:2px;
    classDef external fill:#ffe0b2,stroke:#ef6c00,stroke-width:2px;
    classDef repo fill:#f5f5f5,stroke:#9e9e9e,stroke-width:1px;
```
