| title | Global Event Bus |
|---|---|
| description | Type-safe event system for decoupled communication between core systems and plugins in DeployStack. |
The Global Event Bus enables decoupled communication between core systems and plugins through a type-safe event system. Core systems emit events when important actions occur, and plugins can react without direct coupling to business logic.
Key features:
- Type Safety: Full TypeScript integration with strongly-typed event data
- Plugin Isolation: Secure event listener registration with error isolation
- Performance: Fire-and-forget event processing
- Security: Events cannot be intercepted or modified by plugins
Events follow the domain.action pattern, aligned with the permission structure:
user.registered,user.login,user.logout,user.updated,user.deletedteam.created,team.updated,team.member_added,team.member_removedsettings.updated,settings.smtp_configured,settings.github_configuredmcp.server_installed,mcp.server_uninstalled,mcp.server_configured
interface EventData<T = any> {
userId?: string;
teamId?: string;
data: T;
}
interface EventContext {
db: AnyDatabase | null;
logger: FastifyBaseLogger;
user?: { id: string; email: string; roleId: string; };
request?: { ip: string; userAgent?: string; requestId: string; };
timestamp: Date;
}import { EVENT_NAMES } from '../events';
EVENT_NAMES.USER_REGISTERED // 'user.registered'
EVENT_NAMES.TEAM_CREATED // 'team.created'
EVENT_NAMES.SETTINGS_UPDATED // 'settings.updated'Emit events after successful operations:
// After successful user registration
server.eventBus?.emitWithContext(
EVENT_NAMES.USER_REGISTERED,
{ userId: newUser.id, data: { user: newUser, source: 'email_registration' } },
eventContext
);Plugins register event listeners in their configuration:
class EmailNotificationPlugin implements Plugin {
eventListeners: EventListeners = {
[EVENT_NAMES.USER_REGISTERED]: this.handleUserRegistered.bind(this)
};
private async handleUserRegistered(eventData: EventData, context: EventContext) {
await this.sendWelcomeEmail(eventData.data.user);
}
}For detailed plugin event listener examples, see the Plugin System Documentation.
Events are emitted for user lifecycle (user.*), team management (team.*), settings changes (settings.*), and MCP operations (mcp.*). Each event includes relevant data and context.
For complete event schemas and data structures, see the event type definitions.