# aonghasmackay/mackaysmememachine architecture

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

- Interactive diagram: https://gitdiagram.com/aonghasmackay/mackaysmememachine
- Repository: https://github.com/aonghasmackay/mackaysmememachine

## Overview

##### Main Components

a) Discord Interface Layer
- Discord.js client connection
- Event handlers (from /events directory)
- Command handlers (from /commands directory)

b) Application Core
- Command processing logic
- Event processing system
- Authentication/Authorization (admin checks)

c) Database Layer
- Sequelize ORM
- Two main models: Users and Leaderboard
- Database connection management

d) Scheduled Tasks System
- Cron jobs for balance resets
- Leaderboard updates

e) Auxiliary Services
- Health check endpoint (Express server)
- Logging system

- Blue: Discord-related components
- Green: Core application logic
- Yellow: Database components
- Orange: Scheduled tasks
- Gray: Auxiliary services

**[Component Relationships]**

**┌─────────────────────────────────────┐**
- Discord API               │
- ┘
- ↕
**┌─────────────────────────────────────┐**
- Discord.js Client            │
- ┘

**┌─────────────────┐ ┌─────────────────┐**
- Event Handlers │ │ Command Handlers │
- ┘ └─────────────────┘
- ↓                  ↓
**┌─────────────────────────────────────┐**
- Core Logic Layer            │
- Score Processing                 │
- User Management                  │
- Admin Verification               │
- ┘

**┌─────────────┐ ┌─────────────┐ ┌─────────────┐**
- Sequelize  │ │ Cron Jobs   │ │  Express    │
- ORM      │ │ Scheduler   │ │HealthCheck  │
- ┘ └─────────────┘ └─────────────┘
- ↓              ↓               ↓
**┌─────────────┐ ┌─────────────┐ ┌─────────────┐**
- Database   │ │  Logging    │ │   Health    │
- (SQL)      │ │  System     │ │   Status    │
- ┘ └─────────────┘ └─────────────┘

##### Important Details

- Two main data models (Users and Leaderboard) in the database layer
- Two custom emoji reaction paths in the event handling system
- Daily balance reset and monthly leaderboard update cron jobs
- Admin-only command paths separately from regular commands
- Logging system's interaction with all components

##### Key Interactions to Emphasize

- Reaction events → Score processing → Database updates
- Command processing → Authorization → Action execution
- Scheduled tasks → Database operations
- Health check endpoint → System status

##### Additional Notes

- A note about the single-server limitation
- Configuration dependency (config.json)
- Debug mode paths
- Admin-only functionalities

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Styles and classes
    classDef discord fill:#7289DA,color:white
    classDef core fill:#4CAF50,color:white
    classDef database fill:#FFC107,color:black
    classDef scheduled fill:#FF9800,color:white
    classDef auxiliary fill:#9E9E9E,color:white
    
    %% Discord Interface Layer
    subgraph Discord
        DiscordAPI[Discord API]:::discord
        Client[Discord.js Client]:::discord
    end
    
    %% Event Handlers
    subgraph Events
        EventHandler[Event Handlers]:::discord
        ReactionHandler[Reaction Handler]:::discord
        CommandHandler[Command Handler]:::discord
        ConnectionHandler[Connection Handler]:::discord
    end
    
    %% Command Processing
    subgraph Commands
        AdminCommands[Admin Commands]:::core
        UserCommands[User Commands]:::core
    end
    
    %% Core Logic
    subgraph CoreLogic
        ScoreProcessing[Score Processing]:::core
        UserManagement[User Management]:::core
        AdminVerification[Admin Verification]:::core
    end
    
    %% Database Layer
    subgraph Database
        Sequelize[Sequelize ORM]:::database
        DBConnection[Database Connection]:::database
        Models[Database Models]:::database
        UsersModel[Users Model]:::database
        LeaderboardModel[Leaderboard Model]:::database
    end
    
    %% Scheduled Tasks
    subgraph Scheduled
        CronJobs[Cron Jobs]:::scheduled
        BalanceReset[Balance Reset]:::scheduled
        LeaderboardUpdate[Leaderboard Update]:::scheduled
    end
    
    %% Auxiliary Services
    subgraph Auxiliary
        HealthCheck[Health Check]:::auxiliary
        Logging[Logging System]:::auxiliary
    end
    
    %% Relationships
    DiscordAPI --> Client
    Client --> EventHandler
    EventHandler --> ReactionHandler & CommandHandler & ConnectionHandler
    CommandHandler --> AdminCommands & UserCommands
    AdminCommands & UserCommands --> CoreLogic
    CoreLogic --> Sequelize
    Sequelize --> DBConnection
    DBConnection --> Models
    Models --> UsersModel & LeaderboardModel
    CronJobs --> BalanceReset & LeaderboardUpdate
    BalanceReset & LeaderboardUpdate --> DBConnection
    
    %% Click events
    click Client "https://github.com/AonghasMackay/MackaysMemeMachine/blob/main/index.js"
    click ReactionHandler "https://github.com/AonghasMackay/MackaysMemeMachine/blob/main/events/messageReactionAdd.js"
    click CommandHandler "https://github.com/AonghasMackay/MackaysMemeMachine/blob/main/events/interactionCreate.js"
    click ConnectionHandler "https://github.com/AonghasMackay/MackaysMemeMachine/blob/main/events/ready.js"
    click EventHandler "https://github.com/AonghasMackay/MackaysMemeMachine/tree/main/events"
    click AdminCommands "https://github.com/AonghasMackay/MackaysMemeMachine/tree/main/commands"
    click UserCommands "https://github.com/AonghasMackay/MackaysMemeMachine/tree/main/commands"
    click DBConnection "https://github.com/AonghasMackay/MackaysMemeMachine/blob/main/lib/databaseConnection.js"
    click UsersModel "https://github.com/AonghasMackay/MackaysMemeMachine/blob/main/models/users.js"
    click LeaderboardModel "https://github.com/AonghasMackay/MackaysMemeMachine/blob/main/models/leaderboard.js"
    click BalanceReset "https://github.com/AonghasMackay/MackaysMemeMachine/blob/main/cronJobs/resetBalance.js"
    click LeaderboardUpdate "https://github.com/AonghasMackay/MackaysMemeMachine/blob/main/cronJobs/leaderboardUpdate.js"
    click HealthCheck "https://github.com/AonghasMackay/MackaysMemeMachine/blob/main/lib/healthCheck.js"
    click Logging "https://github.com/AonghasMackay/MackaysMemeMachine/blob/main/logging/logging.js"
    click AdminVerification "https://github.com/AonghasMackay/MackaysMemeMachine/blob/main/lib/isUserAdmin.js"
```
