RegisterComponent, expose a public API, and can depend on or extend other components.
Component Structure
A typical component looks like this:All public methods use
function(self, ...) and are called with colon syntax: Component:Method(args). The self parameter is automatic with : calls.Core Components
Provided bymythic-base, these are the essential components every resource depends on:
Callbacks
Client-server callback system (request-response)
Logger
Centralized logging with levels and Discord webhooks
Database
MongoDB and MySQL database operations
Middleware
Event middleware for pre/post processing
Fetch
Player and character data access
DataStore
Key-value persistent data storage
Feature Components
Registered by feature resources (mythic-inventory, mythic-jobs, etc.) to expose their APIs:
Creating Components
Basic Component
Component with Dependencies
UseRequestDependencies to ensure required components are loaded first:
The RetrieveComponents Pattern
Most resources use a standard pattern where RetrieveComponents() pulls all needed components into local variables:
RetrieveComponents(), you use the local variables directly instead of X everywhere.
Component Patterns
Service Pattern
Stateless components that provide services:Manager Pattern
Components that manage a collection of entities:Extending Components
UseExtendComponent to add functionality to an existing component without modifying the original resource:
Component Communication
Direct Method Calls
Event-Based Communication
Best Practices
Single Responsibility
Single Responsibility
Each component should have one clear purpose:
Always Use RequestDependencies
Always Use RequestDependencies
Never assume components are available immediately:
Error Handling
Error Handling
Always handle errors gracefully:
Use Protected for Core Components
Use Protected for Core Components
Prevent accidental overrides of critical components:
Next Steps
Proxy Pattern
Deep dive into RegisterComponent, FetchComponent, etc.
Event System
Complement components with events and callbacks
Resource Structure
How to organize resources using components
API Reference
Complete API documentation