# djthegr8/rolex architecture

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

- Interactive diagram: https://gitdiagram.com/djthegr8/rolex
- Repository: https://github.com/djthegr8/rolex

## Overview

##### Project type and purpose
- Rolex/Hermes is a .NET Core 3.1 Discord bot. It’s a backend “service” that connects to Discord via the Discord API, listens for commands, routes them to one of many modular command handlers, and optionally persists or caches data in SQLite or Redis.

##### File structure
- Top level:
- Dockerfile, VS solution (.sln), scripts for pull & restart
- Hermes/Program.cs & Hermes.csproj – entry point & project definition
- Hermes/Modules – command handlers, organized by feature area (General, Moderation, Developer, etc.)
- Hermes/Modules/Services – core abstractions (ICommands, InteractionHandler, SQLite, RedisClass, etc.)
- Hermes/Utilities – supporting classes (Collectors, PaginatedMessage, TaskEx, extension methods)
- Data folder (created at runtime under bin/Debug/netcoreapp3.1/Data) containing token.txt and rolex.db
- Configuration/deployment files: .gitignore, Dockerfile, GitHub Actions workflow (.github/workflows/dotnet.yml)

##### README for additional insights
- Sets up a SQLite database via Entity Framework Core
- Reads Discord bot token from Data/token.txt
- No frontend/UI – all interaction via Discord API

##### Main components, relationships, and key patterns
a. Components:
1. Bot Core (Program.cs → host builder, service registration)
2. Discord Gateway Client (Discord.Net library)
3. InteractionHandler (wires incoming messages/interactions to Services/Commands)
4. Command Modules (each folder under Modules implements ICommand or DiscordCommandClass)
5. Services Layer (common abstractions: SQLite persistence, Redis cache, permission checks, Punishment logic)
6. Utilities (message collectors, pagination, extension methods)
7. Persistence: SQLite (EF Core auto‐migration to rolex.db)
8. Cache: Redis (optional, via RedisClass)
9. External: Discord API (REST + Gateway), Webhooks
b. Relationships & data flow:
- Program.cs starts the Discord client and registers Services & Utilities in the DI container
- Discord Gateway emits an event for a message or interaction → InteractionHandler
- InteractionHandler resolves the matching ICommand/DiscordCommandClass from Services
- Command module executes business logic (may read/write sqlite via Settings or SQLite service, may read/write RedisClass)
- Command may post a response back to Discord (via Discord.Net) or fire a webhook
c. Architectural patterns:
- Modular command pattern – each command in its own class, loaded by reflection or DI
- Dependency Injection – .NET Core built‐in DI container
- Repository/Service abstraction – data access via Service classes (SQLite, Redis)
- Event‐driven – reacting to Discord events
d. Key technologies:
- .NET Core 3.1, C#
- Discord.Net library
- EF Core (SQLite provider)
- Redis (StackExchange.Redis or similar)
- Docker for containerization
- GitHub Actions for CI/CD

##### Details
- Specific module areas (General, Moderation, Developer, Emojis, Role Editor, Webhooks) as sub‐blocks or annotations
- Service layer interfaces (ICommands, RequiredPermissions) connecting to modules
- That EF Core auto-migrates and persists to rolex.db in the Data folder
- Where token.txt is read at startup for authentication

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% External Dependencies
    DiscordAPI["Discord Gateway & REST API"]:::external
    SQLiteDB["SQLite Database (rolex.db)"]:::external
    RedisCache["Redis Cache"]:::external

    %% Bot Service
    subgraph "Bot Service"
        Core["Bot Core\n(Host Builder & Service Registration)"]:::internal
        ProjectDef["Project Definition\n(.NET Core 3.1)"]:::internal
        subgraph "Runtime Components"
            InteractionHandler["InteractionHandler"]:::internal
            CommandModules["Command Modules"]:::internal
        end
        subgraph "Services & Persistence"
            ServicesLayer["Services Layer\n(abstractions & data access)"]:::services
            SQLiteService["SQLite Persistence Service"]:::services
            RedisService["Redis Cache Service"]:::services
        end
        subgraph "Utilities"
            Utilities["Utilities\n(Collectors, Pagination, Extensions)"]:::services
        end
    end

    %% Data Flow
    Core -->|"starts & registers"| DiscordAPI
    DiscordAPI -->|"MessageReceived event"| InteractionHandler
    InteractionHandler -->|"Resolve & Execute ICommand"| CommandModules
    CommandModules -->|"uses"| ServicesLayer
    ServicesLayer -->|"DB Query/Auto-Migrate"| SQLiteService
    ServicesLayer -->|"Cache Get/Set"| RedisService
    SQLiteService -->|"Persist & Read"| SQLiteDB
    RedisService -->|"Connect"| RedisCache
    CommandModules -->|"Respond via Discord.Net"| DiscordAPI
    Core -->|"reads token"| SQLiteDB

    %% Click Events
    click Core "https://github.com/djthegr8/rolex/blob/master/Hermes/Program.cs"
    click ProjectDef "https://github.com/djthegr8/rolex/blob/master/Hermes/Hermes.csproj"
    click InteractionHandler "https://github.com/djthegr8/rolex/blob/master/Hermes/Modules/Services/InteractionHandler.cs"
    click CommandModules "https://github.com/djthegr8/rolex/blob/master/Hermes/Modules/General/Help.cs"
    click ServicesLayer "https://github.com/djthegr8/rolex/blob/master/Hermes/Modules/Services/CommandModuleBase.cs"
    click SQLiteService "https://github.com/djthegr8/rolex/blob/master/Hermes/Modules/Services/SQLite.cs"
    click RedisService "https://github.com/djthegr8/rolex/blob/master/Hermes/Modules/Services/RedisClass.cs"
    click Utilities "https://github.com/djthegr8/rolex/blob/master/Hermes/Utilities/PaginatedMessage.cs"

    %% Styles
    classDef internal fill:#cce5ff,stroke:#004085,color:#004085
    classDef services fill:#d4edda,stroke:#155724,color:#155724
    classDef external fill:#fff3cd,stroke:#856404,color:#856404
```
