# itsme-to/itsmybot architecture

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

- Interactive diagram: https://gitdiagram.com/itsme-to/itsmybot
- Repository: https://github.com/itsme-to/itsmybot

## Overview

##### Main Components
- Bot Core: This is the heart of the application (located in src/core). It includes foundational modules such as contracts, builders, configuration, and resource management.
- Core Services: Under src/core/services, you have a number of services such as:
– Command Service: Processes commands, located in services/commands.
– Event Service: Handles various Discord events (message, interaction, presence, etc.) found under services/events.
– Action Service: Executes actions like sending messages or adding roles (services/actions).
– Engine Service: Manages scripts, custom commands, and event broadcasting.
– Condition Service: Checks conditions that determine if specific actions should run.
– Component Service: Handles various interactive components.
– Expansions, Leaderboards, Plugins, and Users services: Each of these adds additional functionality.
- Resources & Configuration: Resources (YAML and TS files) define commands, config, and language settings. They are used by both the core and plugin system.
- Plugin System: Found in src/plugins, this allows third-party or extended functionalities to be added and managed, interfacing with and extending core services.

##### Relationships and Interactions
- The Bot Core orchestrates calls to core services based on Discord events.
- Core services (command, event, action, etc.) are interconnected; for example, receiving an event might trigger a command execution which in turn queries the condition and then performs an action.
- The plugin system dynamically loads plugins, which typically register their own commands, events, and resources. Plugins depend on core contracts to integrate.
- Central configuration and resource files (YAML/TS) are shared across modules to ensure consistency in settings, commands, and language definitions.

##### Important Architectural Patterns
- Modular Design: Separation between the core engine and plugins allows for extensibility.
- Service-Oriented Architecture: Each service (commands, events, actions, conditions, etc.) is structured as an independent module with a clear contract for interaction.
- Configuration-Driven Behaviour: YAML and TS configuration files drive runtime behavior, offering flexibility and easier maintenance.

## Diagram (Mermaid)

```mermaid
graph TD
    %% External Entity
    API["Discord API"]:::external

    %% Bot Core Layer
    subgraph "Bot Core Layer"
        BCore["Bot Core"]:::core
    end

    %% Core Services
    subgraph "Core Services"
        CmdService["Command Service"]:::service
        EventService["Event Service"]:::service
        ActionService["Action Service"]:::service
        EngineService["Engine Service"]:::service
        ConditionService["Condition Service"]:::service
        ComponentService["Component Service"]:::service
        ExpansionsService["Expansions Service"]:::service
        LeaderboardsService["Leaderboards Service"]:::service
        PluginsService["Plugins Service"]:::service
        UsersService["Users Service"]:::service
    end

    %% Configuration & Resources
    subgraph "Configuration & Resources"
        Config["Configuration & Resources"]:::config
    end

    %% Plugin System
    subgraph "Plugin System"
        PluginSystem["Plugin System"]:::plugin
    end

    %% Connections
    API -->|"SendsEvents"| BCore
    BCore -->|"ProcessesCommands"| CmdService
    BCore -->|"ProcessesEvents"| EventService
    BCore -->|"DelegatesActions"| ActionService
    BCore -->|"ExecutesScripts"| EngineService
    BCore -->|"EvaluatesTriggers"| ConditionService
    BCore -->|"ManagesComponents"| ComponentService
    BCore -->|"HandlesExpansions"| ExpansionsService
    BCore -->|"ManagesLeaderboards"| LeaderboardsService
    BCore -->|"ManagesPlugins"| PluginsService
    BCore -->|"ManagesUsers"| UsersService
    BCore -->|"ReadsConfig"| Config
    PluginSystem -->|"RegistersCommands"| CmdService
    PluginSystem -->|"RegistersEvents"| EventService
    PluginSystem -->|"ExtendsActions"| ActionService
    PluginSystem -->|"ProvidesCustomScripts"| EngineService
    BCore -->|"SendsMessages"| API

    %% Click Events
    click BCore "https://github.com/itsme-to/itsmybot/tree/main/src/core"
    click CmdService "https://github.com/itsme-to/itsmybot/tree/main/src/core/services/commands"
    click EventService "https://github.com/itsme-to/itsmybot/tree/main/src/core/services/events"
    click ActionService "https://github.com/itsme-to/itsmybot/tree/main/src/core/services/actions"
    click EngineService "https://github.com/itsme-to/itsmybot/tree/main/src/core/services/engine"
    click ConditionService "https://github.com/itsme-to/itsmybot/tree/main/src/core/services/conditions"
    click ComponentService "https://github.com/itsme-to/itsmybot/tree/main/src/core/services/components"
    click ExpansionsService "https://github.com/itsme-to/itsmybot/tree/main/src/core/services/expansions"
    click LeaderboardsService "https://github.com/itsme-to/itsmybot/tree/main/src/core/services/leaderboards"
    click PluginsService "https://github.com/itsme-to/itsmybot/tree/main/src/core/services/plugins"
    click UsersService "https://github.com/itsme-to/itsmybot/tree/main/src/core/services/users"
    click Config "https://github.com/itsme-to/itsmybot/tree/main/src/core/resources"
    click PluginSystem "https://github.com/itsme-to/itsmybot/tree/main/src/plugins"

    %% Styling Classes
    classDef core fill:#ace,stroke:#333,stroke-width:2px;
    classDef service fill:#def,stroke:#333,stroke-width:2px;
    classDef config fill:#fed,stroke:#333,stroke-width:2px;
    classDef plugin fill:#cfc,stroke:#333,stroke-width:2px;
    classDef external fill:#fcc,stroke:#333,stroke-width:2px;
```
