# flybywiresim/discord-bot-utils architecture

> Architecture diagram of the GitHub repository flybywiresim/discord-bot-utils, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2024-12-28). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/flybywiresim/discord-bot-utils
- Repository: https://github.com/flybywiresim/discord-bot-utils

## Overview

##### Main Components

a. Core Bot Infrastructure:
- Discord.js Client (entry point through src/client.ts)
- Event Handler System (src/events directory)
- Command Handler System (src/commands directory)
- Database Integration (src/lib/db.ts)
- Cache Manager (src/lib/cache/cacheManager.ts)
- Configuration System (src/lib/config.ts)

b. Command Categories (organize by functionality):
- Moderation Commands
- Utility Commands
- Context Menu Commands
- FAQ System
- Infraction System
- Birthday System
- Prefix Commands System

c. External Services Integration:
- Discord API
- MongoDB (implied by schema files)
- GitHub Integration
- VATSIM Integration
- WolframAlpha Integration

##### Relationship Flows to Highlight

**[Discord API] <---> [Bot Client]**

- [Event System] [Commands]    [Services]

- [Event Handlers]   |        [External APIs]

- [Command Handlers]

- [Database/Cache]

##### Key Subsystems to Detail

- Moderation System (infractions, bans, timeouts)
- FAQ Management System
- Prefix Commands System
- Scheduler Jobs System
- Logging System

##### Integration Points

Integration points with:
- Discord API endpoints
- Database connections
- External API connections (VATSIM, GitHub, etc.)
- Cache interaction points

##### Additional Elements

Supporting components:
- Configuration management flow
- Error handling pathways
- Logging system connections
- Scheduler job flows

Remember to include:
- Version information and date
- Critical dependencies and their versions
- Main data flow directions
- System boundaries and interfaces

This will provide a comprehensive view of the bot's architecture while maintaining clarity and usefulness for development and maintenance purposes.

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph Core["Core Bot Infrastructure"]
        Client["Discord.js Client"]
        EventHandler["Event Handler System"]
        CommandHandler["Command Handler System"]
        DB["Database Integration"]
        Cache["Cache Manager"]
        Config["Configuration System"]
    end

    subgraph Commands["Command Categories"]
        direction TB
        ModCmds["Moderation Commands"]
        UtilCmds["Utility Commands"]
        CtxCmds["Context Menu Commands"]
        FAQ["FAQ System"]
        Infr["Infraction System"]
        Birth["Birthday System"]
        Prefix["Prefix Commands"]
    end

    subgraph External["External Services"]
        Discord["Discord API"]
        Mongo["MongoDB"]
        GitHub["GitHub API"]
        VATSIM["VATSIM API"]
        Wolfram["WolframAlpha API"]
    end

    subgraph Support["Support Systems"]
        EventLog["Event Logging"]
        Scheduler["Scheduler System"]
        CmdDeploy["Command Deployment"]
    end

    Discord <--> Client
    Client --> EventHandler
    Client --> CommandHandler
    
    CommandHandler --> ModCmds
    CommandHandler --> UtilCmds
    CommandHandler --> CtxCmds
    CommandHandler --> FAQ
    CommandHandler --> Infr
    CommandHandler --> Birth
    CommandHandler --> Prefix
    
    DB <--> Cache
    Cache <--> CommandHandler
    Config --> Client
    
    ModCmds --> DB
    UtilCmds --> DB
    FAQ --> DB
    Infr --> DB
    Birth --> DB
    Prefix --> DB
    
    UtilCmds --> GitHub
    UtilCmds --> VATSIM
    UtilCmds --> Wolfram
    
    EventHandler --> EventLog
    Scheduler --> Cache
    CmdDeploy --> Client

    %% Click Events
    click Client "https://github.com/flybywiresim/discord-bot-utils/blob/staging/src/client.ts"
    click EventHandler "https://github.com/flybywiresim/discord-bot-utils/tree/staging/src/events/"
    click CommandHandler "https://github.com/flybywiresim/discord-bot-utils/blob/staging/src/commands/index.ts"
    click DB "https://github.com/flybywiresim/discord-bot-utils/blob/staging/src/lib/db.ts"
    click Cache "https://github.com/flybywiresim/discord-bot-utils/blob/staging/src/lib/cache/cacheManager.ts"
    click Config "https://github.com/flybywiresim/discord-bot-utils/blob/staging/src/lib/config.ts"
    click ModCmds "https://github.com/flybywiresim/discord-bot-utils/tree/staging/src/commands/moderation/"
    click UtilCmds "https://github.com/flybywiresim/discord-bot-utils/tree/staging/src/commands/utils/"
    click CtxCmds "https://github.com/flybywiresim/discord-bot-utils/tree/staging/src/commands/context/"
    click FAQ "https://github.com/flybywiresim/discord-bot-utils/tree/staging/src/commands/moderation/faq/"
    click Infr "https://github.com/flybywiresim/discord-bot-utils/tree/staging/src/commands/moderation/infractions/"
    click Birth "https://github.com/flybywiresim/discord-bot-utils/tree/staging/src/commands/utils/birthday/"
    click Prefix "https://github.com/flybywiresim/discord-bot-utils/tree/staging/src/commands/moderation/prefixCommands/"
    click GitHub "https://github.com/flybywiresim/discord-bot-utils/tree/staging/src/commands/utils/github/"
    click VATSIM "https://github.com/flybywiresim/discord-bot-utils/tree/staging/src/commands/utils/vatsim/"
    click Wolfram "https://github.com/flybywiresim/discord-bot-utils/blob/staging/src/commands/utils/wolframAlpha.ts"
    click EventLog "https://github.com/flybywiresim/discord-bot-utils/tree/staging/src/events/logging/"
    click Scheduler "https://github.com/flybywiresim/discord-bot-utils/tree/staging/src/lib/schedulerJobs/"
    click CmdDeploy "https://github.com/flybywiresim/discord-bot-utils/blob/staging/src/scripts/deployCommands.ts"

    classDef core fill:#2374ab
    classDef commands fill:#48a9a6
    classDef external fill:#e4a0f7
    classDef support fill:#f7d6a0
    
    class Client,EventHandler,CommandHandler,DB,Cache,Config core
    class ModCmds,UtilCmds,CtxCmds,FAQ,Infr,Birth,Prefix commands
    class Discord,Mongo,GitHub,VATSIM,Wolfram external
    class EventLog,Scheduler,CmdDeploy support
```
