# ashyboxy/bread-framework architecture

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

- Interactive diagram: https://gitdiagram.com/ashyboxy/bread-framework
- Repository: https://github.com/ashyboxy/bread-framework

## Overview

##### Main Components

A. Core Framework Layer:
- Client Class (Entry point)
- Event Handler System
- Command Handler System
- Database Interface (BreadDB)

B. Command Management Layer:
- Base Command Classes
- Guild Commands
- General Commands

C. Event Management Layer:
- Discord Events Handling
- Custom Event Processing

D. Utility Layer:
- Logger System
- Discord Utils
- Internationalization System

**┌─ External Layer ─────────────────────┐**
- Discord.js API                       │
- ┬─────────────────────┘
- ↓
**┌─ Core Layer ──────────────────────────────────────┐**
- ┌─────────────┐ ┌──────────────┐ ┌─────────────┐ │
- Client Class │→│Event Handler │→│Command Hand.│ │
- ┘ └──────────────┘ └─────────────┘ │
- ┬──────────────────────────┘
- ↓
**┌─ Feature Layer ───────────────────────────────────┐**
- ┌─────────────┐ ┌──────────────┐ ┌─────────────┐ │
- Commands     │ │Events        │ │Database     │ │
- ┘ └──────────────┘ └─────────────┘ │
- ┬──────────────────────────┘
- ↓
**┌─ Support Layer ───────────────────────────────────┐**
- ┌─────────────┐ ┌──────────────┐ ┌─────────────┐ │
- Utils        │ │Localization  │ │Logger       │ │
- ┘ └──────────────┘ └─────────────┘ │
- ┘

##### Important Relationships

- Command flow from interaction events to command execution
- Database interactions with commands
- Localization string loading paths
- Logger integration points

##### Implementation Details

- ESM Loader configuration
- Command registration flow
- Event handling pipeline
- Database interaction patterns
- Guild-specific command handling

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% External Layer
    subgraph External["External Layer"]
        DiscordAPI["Discord.js API"]:::external
    end

    %% Core Layer
    subgraph Core["Core Framework Layer"]
        Client["Client Class"]:::core
        EventHandler["Event Handler"]:::core
        CommandHandler["Command Handler"]:::core
        BreadDB["BreadDB"]:::database
    end

    %% Feature Layer
    subgraph Features["Feature Layer"]
        direction TB
        subgraph CommandMgmt["Command Management"]
            BaseCommand["Base Command"]:::command
            GuildCommand["Guild Command"]:::command
            CommandExamples["Command Examples"]:::command
        end

        subgraph EventMgmt["Event Management"]
            InteractionEvent["Interaction Events"]:::event
            MessageEvent["Message Events"]:::event
            ReadyEvent["Ready Events"]:::event
        end

        subgraph Interfaces["Interface Definitions"]
            DBInterface["Database Interface"]:::interface
            LogInterface["Logger Interface"]:::interface
            ConfigInterface["Config Interface"]:::interface
        end
    end

    %% Support Layer
    subgraph Support["Support Layer"]
        direction TB
        subgraph Utils["Utilities"]
            Logger["Logger System"]:::utility
            DiscordUtils["Discord Utils"]:::utility
            MentionUtils["Mention Utils"]:::utility
            RandomUtils["Random Number Utils"]:::utility
        end

        subgraph I18n["Internationalization"]
            StringHandler["String Handler"]:::i18n
            LangFiles["Language Files"]:::i18n
        end
    end

    %% Connections
    DiscordAPI <--> Client
    Client --> EventHandler
    Client --> CommandHandler
    Client --> BreadDB
    EventHandler --> InteractionEvent
    EventHandler --> MessageEvent
    EventHandler --> ReadyEvent
    CommandHandler --> BaseCommand
    BaseCommand --> GuildCommand
    GuildCommand --> CommandExamples
    BreadDB --> DBInterface
    Logger --> LogInterface
    Client --> ConfigInterface
    CommandHandler --> StringHandler
    StringHandler --> LangFiles

    %% Styles
    classDef core fill:#3498db,stroke:#2980b9,color:white
    classDef command fill:#2ecc71,stroke:#27ae60,color:white
    classDef event fill:#e74c3c,stroke:#c0392b,color:white
    classDef utility fill:#f1c40f,stroke:#f39c12,color:black
    classDef database fill:#e67e22,stroke:#d35400,color:white
    classDef interface fill:#9b59b6,stroke:#8e44ad,color:white
    classDef i18n fill:#1abc9c,stroke:#16a085,color:white
    classDef external fill:#95a5a6,stroke:#7f8c8d,color:white

    %% Click Events
    click Client "https://github.com/AshyBoxy/bread-framework/blob/master/src/Classes/Client.ts"
    click EventHandler "https://github.com/AshyBoxy/bread-framework/blob/master/src/Classes/EventHandler.ts"
    click CommandHandler "https://github.com/AshyBoxy/bread-framework/blob/master/src/Classes/Command.ts"
    click BreadDB "https://github.com/AshyBoxy/bread-framework/blob/master/src/Classes/BreadDB.ts"
    click BaseCommand "https://github.com/AshyBoxy/bread-framework/blob/master/src/Classes/Command.ts"
    click GuildCommand "https://github.com/AshyBoxy/bread-framework/blob/master/src/Classes/GuildCommand.ts"
    click CommandExamples "https://github.com/AshyBoxy/bread-framework/tree/master/src/Commands"
    click InteractionEvent "https://github.com/AshyBoxy/bread-framework/blob/master/src/Events/interactionCreate.ts"
    click MessageEvent "https://github.com/AshyBoxy/bread-framework/blob/master/src/Events/messageCreate.ts"
    click ReadyEvent "https://github.com/AshyBoxy/bread-framework/blob/master/src/Events/ready.ts"
    click Logger "https://github.com/AshyBoxy/bread-framework/blob/master/src/Utils/logger.ts"
    click DiscordUtils "https://github.com/AshyBoxy/bread-framework/blob/master/src/Utils/discord.ts"
    click MentionUtils "https://github.com/AshyBoxy/bread-framework/blob/master/src/Utils/mentions.ts"
    click RandomUtils "https://github.com/AshyBoxy/bread-framework/blob/master/src/Utils/randomNumber.ts"
    click StringHandler "https://github.com/AshyBoxy/bread-framework/blob/master/src/strings/index.ts"
    click LangFiles "https://github.com/AshyBoxy/bread-framework/tree/master/src/strings"
    click DBInterface "https://github.com/AshyBoxy/bread-framework/blob/master/src/Interfaces/Database.ts"
    click LogInterface "https://github.com/AshyBoxy/bread-framework/blob/master/src/Interfaces/Logger.ts"
    click ConfigInterface "https://github.com/AshyBoxy/bread-framework/blob/master/src/Interfaces/Config.ts"
```
