Plugin Development Guide β
This guide will help you understand how to develop custom plugins for Gin-Vue-Admin, including plugin directory structure, development standards and best practices.
Overview β
The Gin-Vue-Admin plugin system adopts a modular design, supporting frontend-backend separated plugin architecture. Each plugin contains independent frontend (web) and backend (server) parts, which can be seamlessly integrated into the main project.
Plugin Features β
- Modular Design: Frontend-backend separation, clear structure
- Hot Swappable: Support dynamic loading and unloading
- Standardized: Unified directory structure and development standards
- Extensible: Rich APIs and hook functions
- Easy Maintenance: Independent configuration and dependency management
Quick Start β
Prerequisites β
- Familiar with Vue 3 + TypeScript frontend development
- Familiar with Go + Gin backend development
- Understand Gin-Vue-Admin project structure
- Have basic plugin development concepts
Development Process β
- Plan Plugin Functionality: Clarify plugin functional requirements and technical solutions
- Create Plugin Structure: Create plugin files according to standard directory structure
- Develop Frontend Components: Implement user interface and interaction logic
- Develop Backend Interfaces: Implement business logic and data processing
- Test and Debug: Ensure plugin functionality works normally
- Package and Release: Generate plugin package and publish to plugin market
Standardized Plugin Directory β
Frontend (Web) Directory Structure β
Plugin Name/
ββ web/
ββ plugin/
ββ Plugin Name/ # Plugin root directory (required)
ββ api/ # API interface files (optional)
ββ view/ # Page components (optional)
β ββ index.vue # Main page
β ββ components/ # Page sub-components
ββ components/ # Public components (optional)
β ββ PluginComponent.vue # Plugin component
β ββ index.ts # Component export
ββ utils/ # Utility functions (optional)
ββ index.ts # Utility functions
ββ constants.ts # Constant definitionsBackend (Server) Directory Structure β
Tip
Backend plugins can use automatic plugin template tools to generate basic structure, improving development efficiency.
Plugin Name/
ββ server/
ββ plugin/
ββ Plugin Name/ # Plugin root directory (required)
ββ api/ # API controllers (optional)
β ββ api.go # Main API interfaces
β ββ enter.go # API entry file
ββ config/ # Configuration structure (optional)
β ββ config.go # Configuration definitions
ββ global/ # Global variables (optional)
β ββ global.go # Global variable definitions
ββ model/ # Data models (optional)
β ββ model.go # Data models
β ββ request/ # Request models
β β ββ main.go # Request parameter structures
β ββ response/ # Response models
β ββ main.go # Response data structures
ββ router/ # Route registration (optional)
ββ router.go # Route definitions
β ββ enter.go # Route entry
ββ service/ # Business logic (optional)
β ββ service.go # Main business logic
β ββ enter.go # Service entry file
ββ utils/ # Utility functions (optional)
β ββ plugin.go # Utility functions
ββ middleware/ # Middleware (optional)
β ββ plugin.go # Custom middleware
ββ initialize/ # Initialization (optional)
β ββ router.go # Route initialization
β ββ gorm.go # Database initialization
β ββ viper.go # Configuration initialization
ββ plugin.go # Plugin entry file (required)
ββ README.md # Plugin documentation (recommended)Development Standards β
Naming Conventions β
- Plugin Name: Use lowercase letters and hyphens, such as
user-management - File Naming: Follow project naming conventions, Go files use underscores, Vue files use PascalCase
- API Paths: Use RESTful style, such as
/api/plugin/user-management/users - Component Naming: Use PascalCase, such as
UserManagement
Code Standards β
- Frontend Code: Follow Vue 3 + TypeScript best practices
- Backend Code: Follow Go coding standards and Gin framework conventions
- Comment Standards: Provide clear function and interface comments
- Error Handling: Unified error handling and logging
Version Management β
- Use semantic versioning (Semantic Versioning)
- Clearly specify version information in
package.json - Provide version update logs
Backend Configuration β
Define plugin information in server/plugin/plugin_name/plugin.go:
go
package plugin_name
import (
"github.com/flipped-aurora/gin-vue-admin/server/global"
"github.com/flipped-aurora/gin-vue-admin/server/plugin/plugin_name/router"
)
type Plugin struct{}
func CreatePlugin() *Plugin {
return &Plugin{}
}
func (*Plugin) Register(group *gin.RouterGroup) {
router.RouterGroupApp.InitPluginRouter(group)
}
func (*Plugin) RouterPath() string {
return "plugin-name"
}Development Environment Configuration β
- Frontend Development: Develop and debug in the main project's
webdirectory - Backend Development: Develop and debug in the main project's
serverdirectory - Hot Reload: Support hot reloading for both frontend and backend code
Best Practices β
Performance Optimization β
- Lazy Loading: Use Vue's asynchronous components and route lazy loading
- Code Splitting: Split code reasonably to avoid overly large files
- Caching Strategy: Use caching effectively to improve response speed
- Database Optimization: Optimize query statements and index design
Security Considerations β
- Input Validation: Strictly validate user input data
- Permission Control: Integrate the main project's permission management system
- SQL Injection Protection: Use parameterized queries
- XSS Protection: Escape output content
Error Handling β
- Unified Error Codes: Use the project's unified error code specifications
- Log Recording: Record key operations and error information
- User-Friendly: Provide clear error messages
- Fallback Handling: Ensure plugin exceptions do not affect the main system
Testing Strategy β
- Unit Testing: Write unit tests for core business logic
- Integration Testing: Test the integration of the plugin with the main system
- End-to-End Testing: Test complete user operation flows
- Performance Testing: Verify the plugin's performance
Common Issues β
Plugin Fails to Load β
- Check if the plugin directory structure is correct
- Ensure the plugin configuration file format is correct
- View console error messages
- Check if plugin dependencies are installed
Route Conflicts β
- Ensure plugin route paths are unique
- Avoid conflicts with main system routes
- Use plugin prefixes to distinguish routes
Style Conflicts β
- Use CSS Modules or scoped styles
- Avoid global style pollution
- Use plugin-specific CSS class name prefixes
Database Migration β
- Provide database migration scripts
- Support version upgrades and rollbacks
- Pay attention to database compatibility


