# adanalife/tripbot architecture

> Architecture diagram of the GitHub repository adanalife/tripbot, 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/adanalife/tripbot
- Repository: https://github.com/adanalife/tripbot

## Overview

##### Main Components

a) Frontend Layer:
- OBS Studio (streaming interface)
- VLC Player (video playback)
- On-screen Elements (pkg/onscreens-server)

b) Backend Services:
- Tripbot (main chatbot service)
- VLC Server (video management service)
- Database (PostgreSQL based on migrations)

c) External Services:
- Twitch API Integration
- SMS Service Integration

##### Architecture Representation

**[Presentation Layer]**
- OBS Studio
- On-screen Elements
- Video Player (VLC)

**[Application Layer]**
- Tripbot Service
- VLC Server
- Background Jobs
- Chat Commands Handler

**[Data Layer]**
- PostgreSQL Database
- Video Assets
- GPS Data

##### Key Relationships

- Bidirectional communication between Tripbot and Twitch
- Video server's interaction with VLC player
- Database connections from both Tripbot and VLC server
- On-screen elements' data flow
- Chat commands flow from Twitch to Tripbot

##### Component Details

Specific modules from the codebase:
- Chat Commands Handler (pkg/chatbot)
- Video Management (pkg/video)
- User Management (pkg/users)
- Scoreboard System (pkg/scoreboards)
- Event System (pkg/events)

##### Infrastructure Elements

Deployment-related components:
- Nginx configuration
- Kubernetes clusters
- Docker containers
- Volume mounts for video assets

##### Additional Elements

Supporting features:
- Background cron jobs
- GPS data collection
- Leaderboard system
- Authentication flow

Key Recommendations:
##### Scaling points (especially for Kubernetes deployments)

This will create a comprehensive system design that accurately represents the project's architecture while maintaining clarity and usefulness for both development and deployment purposes.

## Diagram (Mermaid)

```mermaid
graph TB
    %% Define styles
    classDef presentation fill:#9370DB,stroke:#333,stroke-width:2px
    classDef application fill:#4682B4,stroke:#333,stroke-width:2px
    classDef data fill:#DAA520,stroke:#333,stroke-width:2px
    classDef external fill:#98FB98,stroke:#333,stroke-width:2px
    classDef infra fill:#A9A9A9,stroke:#333,stroke-width:2px

    subgraph Presentation
        OBS[OBS Studio]:::presentation
        VLC[VLC Player]:::presentation
        OnScreen[On-screen Elements]:::presentation
    end

    subgraph Application
        Tripbot[Tripbot Service]:::application
        VLCServer[VLC Server]:::application
        ChatHandler[Chat Commands Handler]:::application
        BackgroundJobs[Background Jobs]:::application
        UserMgmt[User Management]:::application
        ScoreSystem[Scoreboard System]:::application
        EventSys[Event System]:::application
        Monitor[Monitoring]:::application
    end

    subgraph Data
        DB[(PostgreSQL)]:::data
        VideoAssets[Video Assets]:::data
        GPSData[GPS Data]:::data
    end

    subgraph External
        TwitchAPI[Twitch API]:::external
        SMSService[SMS Service]:::external
    end

    subgraph Infrastructure
        Docker[Docker]:::infra
        K8s[Kubernetes]:::infra
        Nginx[Nginx]:::infra
    end

    %% Relationships
    Tripbot --> DB
    Tripbot --> TwitchAPI
    VLCServer --> VLC
    ChatHandler --> Tripbot
    TwitchAPI --> ChatHandler
    OnScreen --> Tripbot
    BackgroundJobs --> DB
    UserMgmt --> DB
    ScoreSystem --> DB
    EventSys --> DB
    VLCServer --> VideoAssets
    Monitor --> DB

    %% Click events
    click Tripbot "https://github.com/adanalife/tripbot/blob/develop/cmd/tripbot/tripbot.go"
    click VLCServer "https://github.com/adanalife/tripbot/blob/develop/cmd/vlc-server/vlc-server.go"
    click OnScreen "https://github.com/adanalife/tripbot/tree/develop/pkg/onscreens-server/"
    click DB "https://github.com/adanalife/tripbot/tree/develop/db/migrate/"
    click ChatHandler "https://github.com/adanalife/tripbot/tree/develop/pkg/chatbot/"
    click VideoAssets "https://github.com/adanalife/tripbot/tree/develop/pkg/video/"
    click UserMgmt "https://github.com/adanalife/tripbot/tree/develop/pkg/users/"
    click ScoreSystem "https://github.com/adanalife/tripbot/tree/develop/pkg/scoreboards/"
    click EventSys "https://github.com/adanalife/tripbot/tree/develop/pkg/events/"
    click TwitchAPI "https://github.com/adanalife/tripbot/tree/develop/pkg/twitch/"
    click OBS "https://github.com/adanalife/tripbot/tree/develop/configs/obs-studio/"
    click Docker "https://github.com/adanalife/tripbot/tree/develop/infra/docker/"
    click K8s "https://github.com/adanalife/tripbot/tree/develop/infra/k8s/"
    click VLC "https://github.com/adanalife/tripbot/tree/develop/pkg/vlc-client/"
    click BackgroundJobs "https://github.com/adanalife/tripbot/tree/develop/pkg/background/"
    click Monitor "https://github.com/adanalife/tripbot/tree/develop/pkg/instrumentation/"

    %% Legend
    classDef legend fill:#f9f9f9,stroke:#333,stroke-width:1px
    class Legend legend
    Legend["Legend<br/>🟣 Presentation<br/>🔵 Application<br/>🟡 Data<br/>🟢 External<br/>⚫ Infrastructure"]:::legend
```
