This document describes the refactoring of the module system to integrate the internachi/modular pattern, providing better composer-based autoloading, Laravel package discovery, and seamless integration with Filament 5 and custom themes.
- Added:
internachi/modular^3.0 to composer dependencies - Created:
config/modular.phpconfiguration file - Updated:
composer.jsonto includeModules\namespace in PSR-4 autoload
File: app/Providers/ModularServiceProvider.php
This provider:
- Registers module auto-discovery
- Loads modules from both old (
app/Modules) and new (app-modules) directories - Handles route, view, translation, and migration registration
- Provides Filament 5 auto-discovery for resources, pages, and widgets
- Manages theme support for modules
File: app/Console/Commands/MakeModuleCommand.php
A new Artisan command that creates modules following the internachi/modular pattern:
php artisan make:module YourModuleCreates:
- Complete directory structure in
app-modules/YourModule - composer.json with proper autoloading
- Service provider with Laravel package discovery
- Example controller, model, migration, view, and test
- Configuration file
- Filament resource directories
File: app/Modules/ModuleManager.php
Extended to support:
- Loading modules from both old and new directory structures
- Creating wrapper classes for modular modules to work with existing ModuleInterface
- Maintaining backward compatibility with existing modules
File: app/Console/Commands/ModuleCommand.php
Modified to delegate module creation to the new make:module command while maintaining all other functionality (list, enable, disable, install, uninstall, info).
File: config/modular.php
Comprehensive configuration including:
- Module and theme directories
- Auto-discovery settings
- Filament 5 integration options
- Caching configuration
- Testing settings
File: config/app.php
- Registered
ModularServiceProviderin the providers array
app-modules/YourModule/
├── composer.json # Module as composer package
├── src/
│ ├── YourModuleModule.php # Main module class
│ ├── Providers/
│ │ └── YourModuleServiceProvider.php
│ ├── Http/Controllers/
│ ├── Models/
│ ├── Services/
│ └── Filament/ # Auto-discovered by Filament
│ ├── Resources/
│ ├── Pages/
│ └── Widgets/
├── routes/
│ ├── web.php
│ ├── api.php
│ └── admin.php
├── database/migrations/
├── resources/
│ ├── views/
│ ├── lang/
│ └── assets/
├── config/
└── tests/
The old app/Modules/ structure continues to work for backward compatibility.
Each module has its own composer.json with PSR-4 autoloading:
{
"autoload": {
"psr-4": {
"Modules\\YourModule\\": "src/"
}
}
}After creating modules, run:
composer dump-autoloadModules use Laravel's package auto-discovery:
{
"extra": {
"laravel": {
"providers": [
"Modules\\YourModule\\Providers\\YourModuleServiceProvider"
]
}
}
}Place Filament components in standard directories:
src/Filament/Resources/- Resource classessrc/Filament/Pages/- Custom pagessrc/Filament/Widgets/- Dashboard widgets
Components are automatically discovered and registered.
Modules can provide themes in resources/themes/ with:
- Custom layouts
- CSS stylesheets
- JavaScript files
- Theme metadata (
theme.json)
Themes integrate with the existing theme system using helpers:
set_theme(),active_theme()theme_asset(),theme_layout()@themeCss,@themeJsBlade directives
Commands remain the same:
# Create
php artisan make:module YourModule
php artisan module create YourModule
# Manage
php artisan module list
php artisan module enable YourModule
php artisan module disable YourModule
php artisan module install YourModule
php artisan module uninstall YourModule
php artisan module info YourModule- Better IDE Support: Full autocomplete and code navigation
- Standard Structure: Follows Laravel package conventions
- Isolated Dependencies: Each module can have its own dependencies
- Easy Testing: Module-specific test suites
- Reusability: Modules can be extracted as standalone packages
- Maintainability: Clear separation of concerns
- Flexibility: Easy to add, remove, or update modules
- Performance: Efficient autoloading and caching
- Scalability: Supports large applications with many modules
- Admin Panel: Seamless Filament 5 integration
- Theming: Module-specific themes and assets
Use the new structure:
php artisan make:module YourModule
cd app-modules/YourModule
# Develop your module
composer dump-autoloadExisting modules in app/Modules/ continue to work. To migrate:
-
Create new module structure:
php artisan make:module YourModule
-
Copy code from old module to new structure:
- Controllers →
src/Http/Controllers/ - Models →
src/Models/ - Views →
resources/views/ - Routes →
routes/ - Migrations →
database/migrations/
- Controllers →
-
Update namespaces from
App\Modules\YourModuletoModules\YourModule -
Run
composer dump-autoload -
Test thoroughly
-
Remove old module directory when satisfied
- README.md: Updated with new module system overview
- docs/MODULE_DEVELOPMENT.md: Comprehensive development guide
- docs/MODULE_QUICK_START.md: Quick start guide (existing)
- docs/EXTERNAL_MODULES.md: External module integration (existing)
- ✅ Old modules in
app/Modules/continue to work - ✅ Existing module commands work unchanged
- ✅ Module database records remain compatible
- ✅ Existing hooks and events still fire
- ✅ Theme system integration preserved
All syntax validation passed:
- ✅ ModularServiceProvider
- ✅ MakeModuleCommand
- ✅ ModuleManager
- ✅ ModuleCommand updates
Security check:
- ✅ No vulnerabilities detected by CodeQL
- Test module creation in running environment
- Create example module demonstrating all features
- Migrate BlogModule as reference implementation
- Add integration tests for new module system
- Create video/tutorial demonstrating usage
This refactoring provides a modern, standards-based module system that integrates seamlessly with Laravel's ecosystem, Filament 5, and the existing theme system. It maintains backward compatibility while providing a clear migration path for future development.