# botiven/logger architecture

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

- Interactive diagram: https://gitdiagram.com/botiven/logger
- Repository: https://github.com/botiven/logger

## Overview

##### Project Type and Its Purpose
- This is a service written in Rust (as shown by Cargo.toml, Cargo.lock, rustfmt.toml, etc.) designed for logging Twitch chat activity.
- The project integrates with Twitch (see the src/twitch directory) to handle Twitch chat events/streams.
- It exposes API endpoints (under src/api/v1) for accessing and possibly analyzing logged data, such as charts, logs, and stats.
- There is a clear separation among the Twitch integration, API layer, and database communication.
- Database migrations (migrations directory) indicate relational data storage and schema management.

##### File Structure for Key Components
- Docker and environment files: Dockerfile, docker-compose.yml, .env and .env.example show containerization is used for deployment/configuration.
- src/api: Contains endpoints (v1) with modules for charts, logs, and stats. This is the main external interface.
- src/database: Contains modules to handle data operations corresponding with the API’s concerns (charts, logs, stats).
- src/twitch: Contains the integration logic to process Twitch chat (as in chat.rs).
- Global and utils: Provide shared logic and configuration support across components.
- Lists and migrations: Likely serve auxiliary tasks (e.g., bots.txt for filtering or configuration and SQL migration scripts for database initialization/evolution).

##### Key Components
a. Twitch Chat Module (src/twitch):
- Represents the service’s entry point for Twitch chat messages.
- It listens to Twitch events, parses chat data, and likely interfaces with the database.
b. API Layer (src/api/v1):
- Contains endpoints to retrieve logs, charts, and statistics.
- Acts as the interface for other frontends or administrative tools to query data.
c. Database Layer (src/database):
- Responsible for storing logged data. Modules correspond to the API endpoints (log, chart, stats).
- Migrations indicate that a relational database (or similar system) is used.
d. Shared Modules (src/global, src/utils):
- These support common functions, configurations, and error handling needed across the architecture.
e. Deployment & Containerization:
- Dockerfile and docker-compose.yml imply deployment in containerized environments.
- Environment configuration (.env) and ignore files show good practices for configuration management.

##### Relationships and Interactions
- The Twitch Chat Module fetches and processes real-time data directly from Twitch. Its processed output is then sent to the Database Layer.
- The API Layer, which consists of multiple endpoints (chart, log, stats), reads from (and possibly writes to) the Database Layer to serve client requests.
- Shared modules provide common libraries and utilities to both the Twitch Chat and API components.
- External clients or admin tools interact with the API Layer.
- Deployment components (Docker, docker-compose) wrap the entire service into containers which can be deployed consistently.

##### Architectural Patterns and Technologies
- Separation of concerns is key: channeling of real-time data from Twitch to storage, and then serving that data via API endpoints.
- The modular organization (separating API, database, twitch, etc.) points toward a clean “Service-Oriented” design, even if it’s not partitioned into microservices.
- Use of migrations indicates a standardized approach to schema management.
- Containerization suggests that the service is built to be deployed reliably across environments.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Deployment & Containerization
    subgraph "Deployment & Containerization"
        D1("Dockerfile"):::infra
        D2("docker-compose.yml"):::infra
        D3("Env Config (.env, .env.example)"):::infra
    end

    %% Twitch Integration
    subgraph "Twitch Integration"
        extT("Twitch Source"):::external
        T1("Twitch Chat Module"):::service
    end

    %% API Layer
    subgraph "API Layer"
        extC("External Clients"):::external
        APIG("API Gateway"):::api
        API1("API Endpoint: Chart"):::api
        API2("API Endpoint: Log"):::api
        API3("API Endpoint: Stats"):::api
    end

    %% Database Layer
    subgraph "Database Layer"
        DB("Relational Database"):::database
        DB1("Database Module: Chart"):::database
        DB2("Database Module: Log"):::database
        DB3("Database Module: Stats"):::database
    end

    %% Shared Modules
    subgraph "Shared Modules"
        SM1("Global Config"):::shared
        SM2("Utilities"):::shared
    end

    %% Database Migrations
    subgraph "Database Migrations"
        MIG1("Migration: 001_init.sql"):::migrations
        MIG2("Migration: 002_user_id.sql"):::migrations
    end

    %% Connections
    %% Deployment hosts the core services
    D1 -->|"hosts"| T1
    D1 -->|"hosts"| APIG
    D1 -->|"hosts"| DB
    D1 -->|"hosts"| SM1
    D1 -->|"hosts"| SM2

    %% Twitch Source sends events to Twitch Chat Module
    extT -->|"sendsTo"| T1
    %% Twitch Chat Module uses Shared Modules for common utilities
    T1 ---|"uses"| SM1
    T1 ---|"uses"| SM2
    %% Twitch Chat Module writes data to the Database
    T1 -->|"writesTo"| DB

    %% External Clients call the API Gateway
    extC -->|"calls"| APIG
    %% API Gateway routes requests to API Endpoints
    APIG -->|"routesTo"| API1
    APIG -->|"routesTo"| API2
    APIG -->|"routesTo"| API3
    %% API Gateway uses Shared Modules as well
    APIG ---|"uses"| SM1
    APIG ---|"uses"| SM2

    %% API Endpoints interact with the Database
    API1 -->|"readsFrom"| DB
    API2 -->|"readsFrom"| DB
    API3 -->|"readsFrom"| DB

    %% Database contains specific modules
    DB -->|"contains"| DB1
    DB -->|"contains"| DB2
    DB -->|"contains"| DB3

    %% Migrations apply to the Database
    MIG1 -->|"appliesTo"| DB
    MIG2 -->|"appliesTo"| DB

    %% Styling
    classDef infra fill:#cccccc,stroke:#333,stroke-width:2px;
    classDef external fill:#ffebcd,stroke:#d2691e,stroke-width:2px;
    classDef service fill:#add8e6,stroke:#00008b,stroke-width:2px;
    classDef api fill:#f9c74f,stroke:#ff793f,stroke-width:2px;
    classDef database fill:#90ee90,stroke:#006400,stroke-width:2px;
    classDef shared fill:#ffb6c1,stroke:#c71585,stroke-width:2px;
    classDef migrations fill:#d3d3d3,stroke:#808080,stroke-width:2px;

    %% Click Events
    click T1 "https://github.com/botiven/logger/blob/main/src/twitch/chat.rs"
    click API1 "https://github.com/botiven/logger/blob/main/src/api/v1/chart.rs"
    click API2 "https://github.com/botiven/logger/blob/main/src/api/v1/log.rs"
    click API3 "https://github.com/botiven/logger/blob/main/src/api/v1/stats.rs"
    click DB1 "https://github.com/botiven/logger/blob/main/src/database/chart.rs"
    click DB2 "https://github.com/botiven/logger/blob/main/src/database/log.rs"
    click DB3 "https://github.com/botiven/logger/blob/main/src/database/stats.rs"
    click SM1 "https://github.com/botiven/logger/blob/main/src/global/mod.rs"
    click SM2 "https://github.com/botiven/logger/blob/main/src/utils/mod.rs"
    click D1 "https://github.com/botiven/logger/tree/main/Dockerfile"
    click D2 "https://github.com/botiven/logger/blob/main/docker-compose.yml"
    click D3 "https://github.com/botiven/logger/blob/main/.env"
    click MIG1 "https://github.com/botiven/logger/blob/main/migrations/001_init.sql"
    click MIG2 "https://github.com/botiven/logger/blob/main/migrations/002_user_id.sql"
```
