mengstack-api/internal/kernel/plugin/plugin.go
MengStack Dev df809f1045
Some checks failed
CI / Build & Test (push) Failing after 1m31s
feat: user CRUD API + dashboard stats + kernel infrastructure
- Add user management endpoints (list/create/get/update/delete) with pagination and search
- Add dashboard stats endpoint with tenant/user/online counts and growth metrics
- Add tenant resolver middleware for multi-tenant request scoping
- Add i18n kernel with zh/en message files and AcceptLanguage middleware
- Add WebSocket hub/handler for real-time communication
- Add job scheduler kernel with cron support
- Add plugin sandbox for isolated execution
- Add storage kernel (local filesystem)
- Add event bus kernel for pub/sub
- Add cache kernel abstraction
- Add database migration runner and version upgrade checker
- Add rate limiting middleware with Redis backend
- Add SQL migrations for rbac, audit_logs, settings, notifications, examples
- Extend user repository with list/delete/count operations
- Register all module routes with tenant resolver
2026-10-03 03:42:58 +08:00

59 lines
1.9 KiB
Go

// Package plugin defines the contract for MengStack plugins.
//
// A plugin is a self-contained extension that follows the same 4-layer
// architecture as built-in modules. Each plugin provides:
//
// - FxOption: dependency injection wiring (repositories, services, handlers)
// - SetupRoutes: HTTP route registration on the Gin engine
// - Init: optional startup hook for background workers, caches, etc.
//
// To create a plugin:
// 1. Create a package under internal/modules/<name>/
// 2. Follow the 4-layer pattern: domain → infrastructure → application → interfaces
// 3. Implement the Plugin interface
// 4. Register in internal/app/app.go's plugin list
package plugin
import (
"io/fs"
"github.com/gin-gonic/gin"
"go.uber.org/fx"
"mengstack/internal/kernel/tenant"
)
// Metadata describes a plugin's identity.
type Metadata struct {
Name string
Version string
Description string
}
// Plugin is the contract every MengStack plugin must implement.
type Plugin interface {
// Metadata returns the plugin's identity.
Metadata() Metadata
// Permissions returns the plugin's declared permissions.
// The sandbox enforces these at runtime — operations not declared are rejected.
Permissions() Permissions
// FxOption returns the fx.Module for dependency injection.
FxOption() fx.Option
// SetupRoutes registers HTTP routes on the Gin engine.
// authMW is the JWT authentication middleware.
// tenantResolver resolves tenant ID from request headers/query.
SetupRoutes(engine *gin.Engine, authMW gin.HandlerFunc, tenantResolver tenant.Resolver)
// Init is called after all dependencies are resolved and before
// the HTTP server starts. Use it for background workers, warm-up
// caches, or external service connections.
// Returning nil indicates success.
Init() error
// MigrationsFS returns the plugin's embedded migration SQL files.
// Return nil if the plugin has no migrations.
MigrationsFS() fs.FS
}