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
Modularity - Each feature is a self-contained module
Extensibility - Easy to add new features via module system
Reliability - Graceful error handling and recovery
Performance - Async operations, connection pooling, caching
Maintainability - Clean code structure, clear API boundaries
Configurability - Highly configurable via YAML files
Interoperability - Integrates with popular plugins (LuckPerms, PlaceholderAPI, Vault)
Architecture Patterns
1. Module Pattern
Implementation: Base
Moduleclass with abstract methodsPurpose: 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
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
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
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
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
Code Generation
Random 6-character alphanumeric codes
Stored securely in database
Expire after configurable time (default 5 minutes)
One-time use only
Account Linking
Bidirectional mapping (UUID ↔ Discord ID)
Prevent duplicate linking
Update usernames on verification
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:
For Small Servers (1-50 players)
SQLite is sufficient
Default connection pool is adequate
No changes needed
For Medium Servers (50-200 players)
Consider MySQL or PostgreSQL
Increase connection pool size to 15-20
Monitor slow queries
For Large Servers (200+ players)
Use dedicated MySQL/PostgreSQL server
Tune connection pool (20-30 connections)
Enable query caching
Consider read replicas
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
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
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
Connection Pool
HikariCP
5.0.1
Database connection pool
HTTP Client
HTTP Client
OkHttp
4.10.0
Webhook and API requests
JSON Processing
JSON
Gson
2.10.1
JSON serialization/deserialization
Logging
Logging API
SLF4J
2.0.9
Logging facade
Implementation
Logback
1.4.11
Logging implementation
Alternative
Log4j2
2.17.1
Alternative logging
Optional Dependencies
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
Extend the Module class
Register in ModuleManager
Add configuration
Database Extensions
Add table creation
Add repository methods
Custom Commands
Implement CommandExecutor
Register in onEnable()
Monitoring and Debugging
Logging Levels
INFO - Normal operations
WARNING - Recoverable errors, missing optional dependencies
SEVERE - Critical errors, failed initialization
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
Discord Connection
Check if bot is ready
Verify guild connection
Check channel accessibility
Database Health
Connection pool status
Query performance
Connection errors
Module Status
Enabled/disabled modules
Module-specific health checks
Configuration validation
Future Architecture Considerations
Microservices Migration Path
For very large deployments, consider splitting into:
Minecraft Plugin - Event collection only
Discord Bot Service - Independent microservice
API Gateway - REST API for communication
Database Service - Centralized data layer
Authentication Service - User verification
Notification Service - Alert system
Event-Driven Architecture
Implement message queue for high-load scenarios:
Event Producer - Minecraft plugin publishes events
Message Queue - RabbitMQ, Kafka, or Redis
Event Consumers - Process asynchronously
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:
Centralized Database - Shared across servers
Event Synchronization - Redis Pub/Sub
Load Balancer - Distribute Discord traffic
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
