Architecture

Table of Contents


System Overview

XDiscordUltimate is a comprehensive Minecraft Spigot plugin that provides bidirectional integration between Minecraft servers and Discord. The system follows a modular architecture with clear separation of concerns, enabling easy extensibility and maintainability.

Key Design Goals

  1. Modularity - Each feature is a self-contained module

  2. Extensibility - Easy to add new features via module system

  3. Reliability - Graceful error handling and recovery

  4. Performance - Async operations, connection pooling, caching

  5. Maintainability - Clean code structure, clear API boundaries

  6. Configurability - Highly configurable via YAML files

  7. Interoperability - Integrates with popular plugins (LuckPerms, PlaceholderAPI, Vault)


Architecture Patterns

1. Module Pattern

  • Implementation: Base Module class with abstract methods

  • Purpose: Encapsulates each feature into independent, self-contained unit

  • Benefits:

    • Easy to enable/disable features

    • Clear separation of concerns

    • Simplifies testing and debugging

    • Allows selective feature loading

2. Manager Pattern

  • Implementation: Central manager classes (ModuleManager, DiscordManager, DatabaseManager)

  • Purpose: Centralized management of related components

  • Benefits:

    • Single point of control

    • Simplified initialization

    • Better resource management

    • Consistent lifecycle management

3. Repository Pattern

  • Implementation: DatabaseManager acts as data access layer

  • Purpose: Abstract database operations from business logic

  • Benefits:

    • Separation of data access logic

    • Database vendor abstraction

    • Easier testing with mock data

    • Centralized query optimization

4. Observer Pattern

  • Implementation: Event listeners for Bukkit and Discord events

  • Purpose: Loose coupling between components

  • Benefits:

    • Easy to add new listeners

    • Decoupled event handling

    • Better testability

    • Flexible event routing

5. Dependency Injection

  • Implementation: Plugin instance passed to all components

  • Purpose: Inversion of control for dependencies

  • Benefits:

    • Reduced coupling

    • Easier testing (can inject mocks)

    • Clear dependency relationships

    • Simplified configuration


System Components

High-Level Architecture Diagram


Module System Architecture

Module Lifecycle

Module Structure

Module Dependencies


Database Design

Entity Relationship Diagram

Database Connection Architecture

Database Schema Details

verified_users Table

Purpose: Maps Minecraft accounts to Discord accounts for verification system

Column
Type
Constraints
Index

minecraft_uuid

VARCHAR(36)

PRIMARY KEY

PK

discord_id

VARCHAR(20)

NOT NULL, UNIQUE

INDEX

verified_at

TIMESTAMP

DEFAULT CURRENT_TIMESTAMP

-

minecraft_name

VARCHAR(16)

-

-

discord_name

VARCHAR(32)

-

-

Indexes:

  • PRIMARY KEY on minecraft_uuid

  • UNIQUE on discord_id

  • INDEX on discord_id (for lookup by Discord)

verification_codes Table

Purpose: Temporary storage for verification codes

Column
Type
Constraints
Index

discord_id

VARCHAR(20)

PRIMARY KEY

PK

code

VARCHAR(10)

NOT NULL, UNIQUE

INDEX

username

VARCHAR(16)

-

-

created_at

BIGINT

NOT NULL

INDEX

expires_at

BIGINT

NOT NULL

INDEX

Indexes:

  • PRIMARY KEY on discord_id

  • UNIQUE on code

  • INDEX on expires_at (for cleanup)

tickets Table

Purpose: Support ticket management

Column
Type
Constraints
Index

id

INTEGER

PRIMARY KEY, AUTO_INCREMENT

PK

minecraft_uuid

VARCHAR(36)

NOT NULL, FK

INDEX

discord_channel_id

VARCHAR(20)

-

-

status

VARCHAR(20)

DEFAULT 'OPEN'

INDEX

created_at

TIMESTAMP

DEFAULT CURRENT_TIMESTAMP

-

closed_at

TIMESTAMP

NULL

-

subject

TEXT

-

-

Indexes:

  • PRIMARY KEY on id

  • INDEX on minecraft_uuid

  • INDEX on status

player_stats Table

Purpose: Player statistics tracking

Column
Type
Constraints
Index

minecraft_uuid

VARCHAR(36)

PRIMARY KEY

PK

joins

INTEGER

DEFAULT 0

-

messages_sent

INTEGER

DEFAULT 0

-

deaths

INTEGER

DEFAULT 0

-

playtime_minutes

INTEGER

DEFAULT 0

INDEX

last_seen

TIMESTAMP

DEFAULT CURRENT_TIMESTAMP

-

first_join

TIMESTAMP

DEFAULT CURRENT_TIMESTAMP

-

Indexes:

  • PRIMARY KEY on minecraft_uuid

  • INDEX on playtime_minutes (for leaderboards)


Discord Integration Architecture

Discord Bot Architecture

JDA Configuration

Message Flow Architecture


Event Flow Diagrams

Player Join Event Flow

Verification Flow

Support Ticket Flow

Chat Bridge Flow


Component Interaction

Initialization Sequence

Module Dependency Graph

Data Flow Architecture


Deployment Architecture

Server Deployment Diagram

Configuration Deployment


Security Architecture

Security Layers

Verification Security

  1. Code Generation

    • Random 6-character alphanumeric codes

    • Stored securely in database

    • Expire after configurable time (default 5 minutes)

    • One-time use only

  2. Account Linking

    • Bidirectional mapping (UUID ↔ Discord ID)

    • Prevent duplicate linking

    • Update usernames on verification

  3. Protection Against

    • SQL injection (parameterized queries)

    • Replay attacks (code expiry)

    • Unauthorized verification (permission checks)

    • Data corruption (transaction isolation)

Permission Model


Scalability Considerations

Database Scalability

Current Implementation:

  • HikariCP connection pooling (max 10 connections)

  • Async database operations using CompletableFuture

  • Optimized queries with indexes

  • Database-agnostic (SQLite, MySQL, PostgreSQL)

Scalability Recommendations:

  1. For Small Servers (1-50 players)

    • SQLite is sufficient

    • Default connection pool is adequate

    • No changes needed

  2. For Medium Servers (50-200 players)

    • Consider MySQL or PostgreSQL

    • Increase connection pool size to 15-20

    • Monitor slow queries

  3. For Large Servers (200+ players)

    • Use dedicated MySQL/PostgreSQL server

    • Tune connection pool (20-30 connections)

    • Enable query caching

    • Consider read replicas

  4. For Very Large Servers (500+ players)

    • Implement database sharding

    • Use caching layer (Redis)

    • Consider micro-services architecture

    • Implement horizontal scaling

Discord Rate Limits

JDA Rate Limit Management:

  • JDA handles rate limits automatically

  • Respect Retry-After headers

  • Queue messages during rate limit

  • Batch operations when possible

Best Practices:

  • Avoid rapid-fire message sending

  • Use webhooks for chat bridge (better rate limit handling)

  • Cache channel lookups

  • Use bulk operations for role updates

Minecraft Server Scalability

Threading Model:

  • Discord operations on separate threads (async)

  • Database operations on separate threads

  • Event processing on main server thread

  • Config reloads on main server thread

Performance Optimization:

  • Use async for all blocking operations

  • Cache frequently accessed data

  • Use scheduled tasks for periodic operations

  • Limit webhook message rate

  • Clean up expired data regularly


Technology Stack

Core Technologies

Category
Technology
Version
Purpose

Minecraft Server

Spigot/Paper API

1.16.5-R0.1+

Minecraft server integration

Java Runtime

OpenJDK

17+

Runtime environment

Discord Integration

JDA

5.0.0-beta.18

Discord API wrapper

Build Tool

Gradle

7.0+

Build automation

Shadow Plugin

Gradle Shadow

8.3.0

Uber-JAR creation

Database Technologies

Database
Driver
Version
Notes

SQLite

sqlite-jdbc

3.42.0.0

Default, embedded

MySQL

mysql-connector-j

8.0.33

Production recommended

PostgreSQL

postgresql

42.6.0

Alternative option

Connection Pooling

Component
Library
Version
Purpose

Connection Pool

HikariCP

5.0.1

Database connection pool

HTTP Client

Component
Library
Version
Purpose

HTTP Client

OkHttp

4.10.0

Webhook and API requests

JSON Processing

Component
Library
Version
Purpose

JSON

Gson

2.10.1

JSON serialization/deserialization

Logging

Component
Library
Version
Purpose

Logging API

SLF4J

2.0.9

Logging facade

Implementation

Logback

1.4.11

Logging implementation

Alternative

Log4j2

2.17.1

Alternative logging

Optional Dependencies

Plugin
Version
Purpose
Integration

LuckPerms

5.4+

Permission system

Prefix/suffix, groups

PlaceholderAPI

2.11.3+

Placeholder expansion

Custom placeholders

Vault

1.7+

Economy API

Future economy features


Extension Points

Creating Custom Modules

  1. Extend the Module class

  1. Register in ModuleManager

  1. Add configuration

Database Extensions

  1. Add table creation

  1. Add repository methods

Custom Commands

  1. Implement CommandExecutor

  1. Register in onEnable()


Monitoring and Debugging

Logging Levels

  1. INFO - Normal operations

  2. WARNING - Recoverable errors, missing optional dependencies

  3. SEVERE - Critical errors, failed initialization

  4. DEBUG - Detailed debug information (only when enabled)

Debug Mode

Enable debug mode in config:

This will:

  • Log all database operations

  • Log Discord API interactions

  • Log module lifecycle events

  • Log configuration loading

Metrics

The plugin includes BStats integration:

  • Plugin usage statistics

  • Anonymous metrics (disabled by default)

  • Can be disabled in config

Health Checks

  1. Discord Connection

    • Check if bot is ready

    • Verify guild connection

    • Check channel accessibility

  2. Database Health

    • Connection pool status

    • Query performance

    • Connection errors

  3. Module Status

    • Enabled/disabled modules

    • Module-specific health checks

    • Configuration validation


Future Architecture Considerations

Microservices Migration Path

For very large deployments, consider splitting into:

  1. Minecraft Plugin - Event collection only

  2. Discord Bot Service - Independent microservice

  3. API Gateway - REST API for communication

  4. Database Service - Centralized data layer

  5. Authentication Service - User verification

  6. Notification Service - Alert system

Event-Driven Architecture

Implement message queue for high-load scenarios:

  1. Event Producer - Minecraft plugin publishes events

  2. Message Queue - RabbitMQ, Kafka, or Redis

  3. Event Consumers - Process asynchronously

  4. Database - Store results

Caching Layer

Add Redis for caching:

  • User verification status

  • Discord guild data

  • Player statistics

  • Configuration cache

  • Session data

Horizontal Scaling

Support multiple Minecraft servers:

  1. Centralized Database - Shared across servers

  2. Event Synchronization - Redis Pub/Sub

  3. Load Balancer - Distribute Discord traffic

  4. Session Management - Distributed caching


This architecture documentation provides a comprehensive overview of XDiscordUltimate's design, implementation, and extensibility. The modular architecture ensures maintainability and allows for easy extension while the clear separation of concerns makes it easy to understand and modify.

Last updated