|
| 1 | +# Trakli Plugin System |
| 2 | + |
| 3 | +## Plugin Structure |
| 4 | + |
| 5 | +Plugins should follow this directory structure: |
| 6 | + |
| 7 | +``` |
| 8 | +plugins/ |
| 9 | +├── example/ # Plugin directory (must match plugin ID) |
| 10 | +│ ├── src/ # Plugin source code |
| 11 | +│ │ ├── Http/ # Controllers, Middleware, etc. |
| 12 | +│ │ │ └── Controllers/ # Controller classes |
| 13 | +│ │ ├── Models/ # Eloquent models |
| 14 | +│ │ └── ExampleServiceProvider.php # Service provider |
| 15 | +│ ├── resources/ # Views, assets, translations |
| 16 | +│ │ ├── assets/ # Frontend assets (CSS, JS, images) |
| 17 | +│ │ └── views/ # Blade templates |
| 18 | +│ ├── routes/ # Route files |
| 19 | +│ │ └── web.php # Web routes |
| 20 | +│ ├── composer.json # Composer dependencies |
| 21 | +│ └── plugin.json # Plugin manifest |
| 22 | +``` |
| 23 | + |
| 24 | +## Plugin Manifest (plugin.json) |
| 25 | + |
| 26 | +Each plugin must have a `plugin.json` file in its root directory with the following structure: |
| 27 | + |
| 28 | +```json |
| 29 | +{ |
| 30 | + "id": "example", |
| 31 | + "name": "Example Plugin", |
| 32 | + "description": "A brief description of what this plugin does.", |
| 33 | + "version": "1.0.0", |
| 34 | + "namespace": "Trakli\\ExamplePlugin", |
| 35 | + "provider": "Trakli\\ExamplePlugin\\ExampleServiceProvider", |
| 36 | + "enabled": true, |
| 37 | + "requires": { |
| 38 | + "php": ">=8.1", |
| 39 | + "laravel/framework": "^10.0" |
| 40 | + } |
| 41 | +} |
| 42 | +``` |
| 43 | + |
| 44 | +### Field Descriptions |
| 45 | + |
| 46 | +- **id**: (Required) A unique identifier for your plugin (e.g., `example`). This should match the plugin's directory name exactly and use only lowercase alphanumeric characters and hyphens. |
| 47 | +- **name**: (Required) Human-readable name of the plugin. |
| 48 | +- **description**: Brief description of what the plugin does. |
| 49 | +- **version**: Current version of the plugin (following [SemVer](https://semver.org/)). |
| 50 | +- **namespace**: Base PHP namespace for the plugin's classes. Should follow the format: `Trakli\\{PluginName}` where PluginName is in StudlyCase. |
| 51 | +- **provider**: Fully qualified class name of the service provider. |
| 52 | +- **enabled**: Whether the plugin is enabled by default. |
| 53 | +- **requires**: (Optional) PHP and package dependencies. |
| 54 | + |
| 55 | +## Naming Conventions |
| 56 | + |
| 57 | +### Plugin ID |
| 58 | +- Use only lowercase alphanumeric characters and hyphens (e.g., `example`, `user-import`) |
| 59 | +- Must match the plugin's directory name exactly |
| 60 | +- Keep it short but descriptive |
| 61 | +- Examples: |
| 62 | + - `analytics` |
| 63 | + - `payments` |
| 64 | + - `user-import` |
| 65 | + |
| 66 | +### Namespace |
| 67 | +- Follow PSR-4 autoloading standards |
| 68 | +- Use the format: `Trakli\\{PluginName}` where PluginName is in StudlyCase |
| 69 | +- Examples: |
| 70 | + - ID: `analytics` → Namespace: `Trakli\\Analytics` |
| 71 | + - ID: `user-import` → Namespace: `Trakli\\UserImport` |
| 72 | + |
| 73 | +### Directory Structure |
| 74 | +- The plugin directory name must exactly match the plugin ID |
| 75 | +- Use `kebab-case` for file and directory names |
| 76 | +- Follow Laravel's standard directory structure |
| 77 | + |
| 78 | +## Best Practices |
| 79 | + |
| 80 | +1. **Unique IDs**: Always use a unique ID for your plugin to avoid conflicts. |
| 81 | +2. **Version Control**: Include your plugin in version control with its dependencies. |
| 82 | +3. **Dependencies**: Clearly specify all dependencies in `composer.json`. |
| 83 | +4. **Configuration**: Use Laravel's configuration system for plugin settings. |
| 84 | +5. **Migrations**: Include database migrations in the `database/migrations` directory. |
| 85 | +6. **Assets**: Publish assets using Laravel's asset publishing. |
| 86 | +7. **Documentation**: Include a README.md in your plugin's root directory. |
| 87 | + |
| 88 | +## Example Plugin |
| 89 | + |
| 90 | +See the `example` directory for a complete example plugin implementation. |
0 commit comments