# zibbp/ganymede architecture

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

- Interactive diagram: https://gitdiagram.com/zibbp/ganymede
- Repository: https://github.com/zibbp/ganymede

## Overview

##### Main System Components

a) Frontend Layer:
- Next.js-based web application (in `/frontend`)
- User interface components for VOD management, live streams, and chat
- Authentication and user management interfaces

b) Backend Layer:
- Go-based API server (in `/cmd/server`)
- Worker service (in `/cmd/worker`)
- Task management system (in `/internal/tasks`)

c) Database Layer:
- PostgreSQL database
- Entity relationships (defined in `/ent`)

d) Storage Layer:
- Video storage system
- Temporary storage
- Logs storage
- Configuration storage

##### Key Interactions and Flows

a) Content Archiving Flow:
**Twitch Platform -> Worker Service -> Storage System**
- > Chat Processing -> Chat Rendering
- > Video Processing

b) User Interaction Flow:
**User -> Frontend -> API Server -> Database**
- > Video/Chat Playback System

##### Architectural Patterns

Patterns:

a) Microservices Architecture:
- Server service
- Worker service
- Frontend service
- Database service

b) Task Queue System:
- Task distribution
- Queue management
- Task execution flow

##### Integration Points

External integrations:

a) Authentication:
- Local auth system
- OAuth/SSO integration
- Twitch API integration

b) Content Sources:
- Twitch VOD API
- Twitch Live Stream API
- Chat data sources (BTTV, FFZ, SevenTV)

##### Specific Implementation Details

Technical components:

a) API Layer:
- HTTP transport (`/internal/transport/http`)
- WebSocket connections for real-time features
- API endpoints structure

b) Data Processing:
- Video processing pipeline
- Chat processing and rendering
- Storage management

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Frontend
        UI["User Interface"]:::frontend
        AuthUI["Authentication UI"]:::frontend
        VideoPlayer["Video Player"]:::frontend
        UI --> AuthUI
        UI --> VideoPlayer
    end

    subgraph Backend
        APIServer["API Server"]:::backend
        Worker["Worker Service"]:::backend
        TaskMgr["Task Management"]:::backend
        QueueMgr["Queue Manager"]:::backend
        AuthSystem["Auth System"]:::backend

        APIServer --> TaskMgr
        APIServer --> QueueMgr
        Worker --> TaskMgr
        Worker --> QueueMgr
        APIServer --> AuthSystem
    end

    subgraph Storage
        DB[(PostgreSQL)]:::database
        VideoStore[("Video Storage")]:::storage
        TempStore[("Temp Storage")]:::storage
        LogStore[("Logs")]:::storage
        ConfigStore[("Config")]:::storage
    end

    subgraph "External Services"
        TwitchAPI{{"Twitch API"}}:::external
        BTTVAPI{{"BTTV API"}}:::external
        FFZAPI{{"FFZ API"}}:::external
        SevenTV{{"SevenTV API"}}:::external
    end

    subgraph "Processing Pipeline"
        ChatProc["Chat Processing"]:::process
        VideoProc["Video Processing"]:::process
        Worker --> ChatProc
        Worker --> VideoProc
    end

    %% Frontend Connections
    UI --> APIServer
    AuthUI --> AuthSystem

    %% Backend Connections
    APIServer --> DB
    Worker --> DB
    ChatProc --> DB
    VideoProc --> VideoStore
    ChatProc --> LogStore

    %% External Connections
    Worker --> TwitchAPI
    ChatProc --> BTTVAPI
    ChatProc --> FFZAPI
    ChatProc --> SevenTV

    %% Storage Connections
    VideoProc --> TempStore
    Worker --> ConfigStore

    %% Click Events
    click UI "https://github.com/Zibbp/ganymede/tree/main/frontend/app/components"
    click AuthUI "https://github.com/Zibbp/ganymede/tree/main/frontend/app/components/authentication"
    click VideoPlayer "https://github.com/Zibbp/ganymede/tree/main/frontend/app/components/videos"
    click APIServer "https://github.com/Zibbp/ganymede/blob/main/cmd/server/main.go"
    click Worker "https://github.com/Zibbp/ganymede/blob/main/cmd/worker/main.go"
    click TaskMgr "https://github.com/Zibbp/ganymede/blob/main/internal/tasks/tasks.go"
    click ChatProc "https://github.com/Zibbp/ganymede/blob/main/internal/tasks/chat.go"
    click VideoProc "https://github.com/Zibbp/ganymede/blob/main/internal/tasks/video.go"
    click DB "https://github.com/Zibbp/ganymede/blob/main/ent/client.go"
    click AuthSystem "https://github.com/Zibbp/ganymede/blob/main/internal/auth/auth.go"
    click TwitchAPI "https://github.com/Zibbp/ganymede/blob/main/internal/platform/twitch.go"
    click QueueMgr "https://github.com/Zibbp/ganymede/blob/main/internal/queue/queue.go"

    %% Styling
    classDef frontend fill:#3498db,stroke:#2980b9,color:white
    classDef backend fill:#2ecc71,stroke:#27ae60,color:white
    classDef database fill:#9b59b6,stroke:#8e44ad,color:white
    classDef storage fill:#95a5a6,stroke:#7f8c8d,color:white
    classDef external fill:#f1c40f,stroke:#f39c12,color:black
    classDef process fill:#e74c3c,stroke:#c0392b,color:white

    %% Legend
    subgraph Legend
        Frontend_L["Frontend"]:::frontend
        Backend_L["Backend"]:::backend
        Database_L[(Database)]:::database
        Storage_L[("Storage")]:::storage
        External_L{{"External"}}:::external
        Process_L["Process"]:::process
    end
```
