# ezxmora/friskainet architecture

> Architecture diagram of the GitHub repository ezxmora/friskainet, 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/ezxmora/friskainet
- Repository: https://github.com/ezxmora/friskainet

## Overview

##### Main Components
- Bot Core (app.js): This is the entry point where the bot is initialized and configured.
- Command Manager: Located in the “commands” directory, it is subdivided into categories (economy, fun, moderation, music, utility). This component dispatches specific commands based on user inputs.
- Event Handler: Found under the “events” folder, it listens for Discord events such as message creation, member updates, and reaction additions. Also includes the “music-events” folder explicitly catering to music-related events.
- Loader Classes: In the “classes” directory, several loaders such as EventLoader, JobLoader, and MusicEventLoader are used to dynamically load and integrate commands, events, and other functionalities.
- Job Scheduler: The “jobs” folder indicates scheduled or background processes such as fetching members or purging temporary roles.
- Database Module: The “libs/database” folder outlines models for commands, users, rules, warnings, etc., which suggests an SQL database layer that's central to maintaining persistent state.
- External APIs and Utility Libraries: In the “libs/apis” and “libs/utils.js”, you have integrations with external services (e.g., Kanye quotes, NSFW content, urban dictionary) and generic utilities that help process data.
- Resources & Scripts: The “resources” folder includes configuration files and scripts for tasks like deploying database commands or rules, which help during setup and maintenance.
- DevOps & CI/CD: With Dockerfiles, docker-compose.yml, and GitHub workflows (.github/workflows), containerization and automated release processes are clearly part of the design.

##### Relationships and Interactions
- The Bot Core acts as the primary orchestrator and communicates with the Discord API.
- When a Discord event occurs (e.g., a message is sent), the Event Handler triggers the appropriate loader which, in turn, routes it to a matching command from the Command Manager.
- The Command Manager may also call the Database Module for reading/writing data (for economy tracking, user stats, etc.) and use External APIs for additional data.
- The Job Scheduler runs scripts periodically, interfacing with both the Database Module and the Command/Event Framework to perform background tasks.
- Loader classes dynamically load the functionalities (commands, events, and music events) and provide modular extensions to the bot.
- External libraries such as ffmpeg (as indicated in the README) are used during music streaming and processing.

##### Architectural Patterns and Design Principles
- Modular Design: Commands and events are clearly separated into directories, indicating a plug-and-play system where each module is independent.
- Event-Driven Architecture: The bot reacts to various Discord-driven events; thus, the flow from events to command execution is central.
- Separation of Concerns: Distinct folders for “commands”, “events”, “jobs”, and “database” facilitate maintainability and scalability.
- Containerization & CI/CD: Usage of Docker and GitHub workflows shows a DevOps approach that ensures smooth deployment and integrations.

##### Putting It All Together
- Bot Core then branching out to event handling and command handling.
- Modular loaders feeding into these handlers.
- Database as a central module that supports multiple components.
- External APIs and libraries (ffmpeg, Node.js environment) that support command functionalities.
- Finally, note the Docker and CI/CD pipelines to emphasize deployment processes.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% External Entities
    subgraph "External Entities"
        Discord["Discord API"]:::external
        Node["Node.js Environment"]:::external
        FFM["ffmpeg"]:::external
    end

    %% Bot Core Layer
    subgraph "Bot Core Layer"
        BotCore["Bot Core (app.js)"]:::service
        CommandManager["Command Manager (commands/)"]:::service
        EventHandler["Event Handler (events/)"]:::service

        subgraph "Loader Classes"
            EventLoader["EventLoader.js"]:::service
            JobLoader["JobLoader.js"]:::service
            MusicEventLoader["MusicEventLoader.js"]:::service
        end

        subgraph "Job Scheduler"
            JobDir["jobs/"]:::service
            FetchMembers["fetchMembers.js"]:::service
            PurgeColorRoles["purgeColorRoles.js"]:::service
            PurgeVolatile["purgeVolatile.js"]:::service
        end

        subgraph "Database Module"
            Database["Database Module"]:::database
            Models["models"]:::database
        end

        subgraph "External APIs & Utilities"
            APIs["External APIs (libs/apis/)"]:::api
            Kanye["kanye.js"]:::api
            NSFW["nsfw.js"]:::api
            Urban["urban.js"]:::api
            Utils["Utility Libraries (libs/utils.js)"]:::utility
        end
    end

    %% Resources & Deployment
    subgraph "Resources & Deployment"
        subgraph "Resources & Scripts"
            Resources["resources/"]:::resource
            Config["config.js"]:::resource
            DeployDB["deploy-db-commands.js"]:::resource
            DeployRules["deploy-rules-roles.js"]:::resource
            Slots["slots-symbols.js"]:::resource
        end
        subgraph "CI/CD & Containerization"
            Workflows[".github/workflows/"]:::cicd
            DockerImage["docker-image.yml"]:::cicd
            ReleasePlease["release-please.yml"]:::cicd
            Dockerfile["Dockerfile"]:::cicd
            DockerCompose["docker-compose.yml"]:::cicd
            Others[".dockerignore/.editorconfig"]:::cicd
        end
    end

    %% Connections between components
    Discord -->|"triggers"| BotCore
    Node --> BotCore
    BotCore -->|"dispatches"| CommandManager
    BotCore -->|"routes"| EventHandler

    %% Loader Classes feed functionality
    EventLoader -->|"loads events"| EventHandler
    EventLoader -->|"loads commands"| CommandManager

    %% Job Scheduler interactions
    JobDir -->|"schedules tasks"| BotCore
    FetchMembers -->|"updates"| Database
    PurgeColorRoles -->|"updates"| Database
    PurgeVolatile -->|"updates"| Database

    %% Database interactions
    CommandManager -->|"reads/writes"| Database
    EventHandler -->|"reads/writes"| Database

    %% External APIs and Utilities used by Command Manager & Event Handler
    CommandManager -->|"integrates"| APIs
    CommandManager -->|"uses"| Utils
    EventHandler -->|"integrates"| APIs

    %% External APIs details
    APIs --> Kanye
    APIs --> NSFW
    APIs --> Urban

    %% Music specific dependency
    EventHandler -->|"processes music"| FFM

    %% Resources integration
    Resources -->|"configures"| BotCore
    Resources -->|"deploys"| Database

    %% CI/CD integration
    Workflows -->|"orchestrates"| BotCore
    Workflows -->|"deploys"| Resources

    %% Styling directives
    classDef service fill:#d1e8ff,stroke:#2f74c0,stroke-width:2px;
    classDef external fill:#ffe0b2,stroke:#fb8c00,stroke-width:2px;
    classDef database fill:#ffe082,stroke:#ff6f00,stroke-width:2px;
    classDef api fill:#c8e6c9,stroke:#388e3c,stroke-width:2px;
    classDef utility fill:#f8bbd0,stroke:#c2185b,stroke-width:2px;
    classDef resource fill:#dcedc8,stroke:#7cb342,stroke-width:2px;
    classDef cicd fill:#e1bee7,stroke:#8e24aa,stroke-width:2px;

    %% Click Events for Bot Core Layer Components
    click BotCore "https://github.com/ezxmora/friskainet/blob/main/app.js"
    click CommandManager "https://github.com/ezxmora/friskainet/tree/main/commands/"
    click EventHandler "https://github.com/ezxmora/friskainet/tree/main/events/"
    click EventLoader "https://github.com/ezxmora/friskainet/blob/main/classes/EventLoader.js"
    click JobLoader "https://github.com/ezxmora/friskainet/blob/main/classes/JobLoader.js"
    click MusicEventLoader "https://github.com/ezxmora/friskainet/blob/main/classes/MusicEventLoader.js"
    click JobDir "https://github.com/ezxmora/friskainet/tree/main/jobs/"
    click FetchMembers "https://github.com/ezxmora/friskainet/blob/main/jobs/fetchMembers.js"
    click PurgeColorRoles "https://github.com/ezxmora/friskainet/blob/main/jobs/purgeColorRoles.js"
    click PurgeVolatile "https://github.com/ezxmora/friskainet/blob/main/jobs/purgeVolatile.js"
    click Database "https://github.com/ezxmora/friskainet/tree/main/libs/database/"
    click Models "https://github.com/ezxmora/friskainet/tree/main/libs/database/models/"
    click APIs "https://github.com/ezxmora/friskainet/tree/main/libs/apis/"
    click Kanye "https://github.com/ezxmora/friskainet/blob/main/libs/apis/kanye.js"
    click NSFW "https://github.com/ezxmora/friskainet/blob/main/libs/apis/nsfw.js"
    click Urban "https://github.com/ezxmora/friskainet/blob/main/libs/apis/urban.js"
    click Utils "https://github.com/ezxmora/friskainet/blob/main/libs/utils.js"

    %% Click Events for Resources & Deployment
    click Resources "https://github.com/ezxmora/friskainet/tree/main/resources/"
    click Config "https://github.com/ezxmora/friskainet/blob/main/resources/config.js"
    click DeployDB "https://github.com/ezxmora/friskainet/blob/main/resources/scripts/deploy-db-commands.js"
    click DeployRules "https://github.com/ezxmora/friskainet/blob/main/resources/scripts/deploy-rules-roles.js"
    click Slots "https://github.com/ezxmora/friskainet/blob/main/resources/slots-symbols.js"
    click Workflows "https://github.com/ezxmora/friskainet/tree/main/.github/workflows/"
    click DockerImage "https://github.com/ezxmora/friskainet/blob/main/.github/workflows/docker-image.yml"
    click ReleasePlease "https://github.com/ezxmora/friskainet/blob/main/.github/workflows/release-please.yml"
    click Dockerfile "https://github.com/ezxmora/friskainet/tree/main/Dockerfile"
    click DockerCompose "https://github.com/ezxmora/friskainet/blob/main/docker-compose.yml"
    click Others "https://github.com/ezxmora/friskainet/blob/main/.dockerignore"
```
