| name | plugin-architecture |
| description | Build pluggable authentication features using the plugin system with initialization, migrations, routes, and service registration. |
Plugin Architecture & Lifecycle
When to use this skill
- Create new authentication plugins (OAuth2, Magic Link, JWT, etc.)
- Extend authentication with custom features
- Define plugin configuration and metadata
- Handle plugin initialization, migrations, and lifecycle
- Provide HTTP routes through a plugin
- Hook into core authentication events
Key principles
- Interface-driven: Plugins implement optional interfaces
- Composition: Dependencies via context, not inheritance
- Self-contained: Each plugin has its own services, repositories, handlers
- Lazy initialization: Heavy operations in Init(), not constructors
- Event-driven: Plugins hook into core events
- Service registry: Plugins register services for other plugins
Pattern
Plugin lifecycle:
- Define metadata (ID, name, version)
- Implement Init to retrieve services, create repositories/services
- Implement optional Routes, Migrations, Middleware
- Register custom services with registry
- Implement Close for cleanup
Example
See plugins/email-password/plugin.go for:
- EmailPasswordPlugin metadata and Init pattern
- Service retrieval and registration
- Routes definition and handler wiring
- Lifecycle management (Close)
Common mistakes
- Initializing in constructor instead of Init()
- Not retrieving services from registry (use Get with type assertion)
- Forgetting type assertions on service retrieval
- Registering services with wrong names
- Not implementing Close()
- Direct plugin-to-plugin dependencies instead of service registry
- Not handling initialization errors
References