# wout-m/discord-net-bots architecture

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

- Interactive diagram: https://gitdiagram.com/wout-m/discord-net-bots
- Repository: https://github.com/wout-m/discord-net-bots

## Overview

##### Main Components
- Core Library: The heart of the application, represented by the Discord.Bots.Core project. It includes configuration files, event handling classes (e.g., ReadyEvent, GuildEvent, InteractionEvent, MessageEvent), modules (AdminModule, BirthdayModule, ButtonModule, etc.), job scheduling components (BirthdayJob, JobFactory, QuartzExtension), models, and services.
- Individual Bot Projects: There are several bots such as Discord.Bots.ExWi, Discord.Bots.KGB, Discord.Bots.The_Wanderers_Helper, and a test project (Discord.Bots.Test). Each one has its own Program.cs, which functions as the entry point and ties into the core library.
- External Integrations and APIs: The bots interact with external services—for instance, the Open Trivia API, the InspiroBot API, and the various Discord APIs (using Discord.NET). Also note Quartz.NET for job scheduling.
- CI/CD and Deployment Environment: The presence of .github/workflows files points to automated builds/deployments for the different bots. The README and Dockerfile instructions indicate that Docker containers running on a Raspberry Pi (optionally managed via Portainer) are used for hosting.

##### Relationships and Interactions
- The Bot Projects (ExWi, KGB, Wanderers Helper, Test) depend on and reference the Core library, using its modules, events, and services to perform functions.
- The Core library’s event service listens and routes Discord events (like messages, reactions, new guild activity) to appropriate modules and jobs.
- External APIs (Open Trivia, InspiroBot) are integrated via modules to provide dynamic content or fun functionalities.
- Scheduled tasks (birthday checks) are managed by Quartz.NET through the job components in the core.
- The CI/CD pipeline (depicted by the GitHub workflows) builds and tests the solution, then packages the bots into Docker images for deployment.

##### Architectural Patterns and Design Principles
- Modular Design: The clear separation of shared functionality (in the Core project) from the various bot entry points emphasizes modularity and reuse.
- Event-Driven Architecture: The event handling system in the Core library suggests an event-driven approach, where Discord events trigger corresponding modules or services.
- Containerized Deployment: The Dockerfile and hosting instructions indicate that the bots are containerized for easier deployment and scalability.

##### Relevant Technologies and Frameworks
- .NET 6.0: The project’s primary runtime environment.
- Discord.NET: The library for creating Discord bots.
- Quartz.NET: Used for scheduled jobs (e.g., birthday checks).
- Docker: For containerizing and deploying the bots on a Raspberry Pi.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Core Library and its internal components
    subgraph "Core Library"
        CL["Discord.Bots.Core"]:::core
        conf["Config Service (Config)"]:::core
        events["Event Handling Service (Events)"]:::core
        modules["Modules (Commands)"]:::core
        jobs["Job Scheduling (Jobs)"]:::core
        services["Services"]:::core
    end

    %% Bot Entry Points
    subgraph "Bot Entry Points"
        exwi["ExWi Bot"]:::bot
        kgb["KGB Bot"]:::bot
        wanderers["The Wanderers Helper Bot"]:::bot
        test["Test Bot"]:::bot
    end

    %% External Services and Integrations
    subgraph "External Services"
        discapi["Discord API"]:::external
        trivia["OpenTriviaAPI"]:::external
        inspiro["InspiroBot API"]:::external
        quartz["Quartz.NET"]:::external
    end

    %% CI/CD and Deployment
    subgraph "Deployment & CI/CD"
        cicd["CI/CD Pipeline"]:::cicd
        docker["Docker Container"]:::deploy
        raspberry["Raspberry Pi"]:::deploy
    end

    %% Relationships between Bot Entry Points and Core Library
    exwi -->|"references"| CL
    kgb -->|"references"| CL
    wanderers -->|"references"| CL
    test -->|"references"| CL

    %% Internal Core Library relationships
    CL -->|"initializes"| conf
    CL -->|"listensFor"| events
    events -->|"dispatchesTo"| modules
    CL -->|"schedules"| jobs
    CL -->|"utilizes"| services

    %% External interactions
    discapi -->|"sendsEventsTo"| events
    modules -->|"calls"| trivia
    modules -->|"calls"| inspiro
    jobs -->|"runsVia"| quartz

    %% CI/CD and Deployment flow
    cicd -->|"builds"| docker
    docker -->|"deploysTo"| raspberry
    cicd -->|"triggersDeploy"| exwi
    cicd -->|"triggersDeploy"| kgb
    cicd -->|"triggersDeploy"| wanderers
    cicd -->|"triggersDeploy"| test

    %% Click Events for components
    click CL "https://github.com/wout-m/discord-net-bots/blob/main/Discord.Bots.Core"
    click conf "https://github.com/wout-m/discord-net-bots/blob/main/Discord.Bots.Core/Config/Config.cs"
    click events "https://github.com/wout-m/discord-net-bots/tree/main/Discord.Bots.Core/Events"
    click modules "https://github.com/wout-m/discord-net-bots/tree/main/Discord.Bots.Core/Modules"
    click jobs "https://github.com/wout-m/discord-net-bots/tree/main/Discord.Bots.Core/Jobs"
    click services "https://github.com/wout-m/discord-net-bots/tree/main/Discord.Bots.Core/Services"
    click exwi "https://github.com/wout-m/discord-net-bots/blob/main/Discord.Bots.ExWi/Program.cs"
    click kgb "https://github.com/wout-m/discord-net-bots/blob/main/Discord.Bots.KGB/Program.cs"
    click wanderers "https://github.com/wout-m/discord-net-bots/blob/main/Discord.Bots.The_Wanderers_Helper/Program.cs"
    click test "https://github.com/wout-m/discord-net-bots/blob/main/Discord.Bots.Test/Program.cs"
    click cicd "https://github.com/wout-m/discord-net-bots/tree/main/.github/workflows"

    %% Styles and Colors
    classDef core fill:#AED6F1,stroke:#1B4F72,stroke-width:2px;
    classDef bot fill:#FAD7A0,stroke:#B9770E,stroke-width:2px;
    classDef external fill:#F9E79F,stroke:#B7950B,stroke-width:2px;
    classDef cicd fill:#A9DFBF,stroke:#27AE60,stroke-width:2px;
    classDef deploy fill:#D2B4DE,stroke:#8E44AD,stroke-width:2px;
```
