PHP Version Laravel Version License
Super light-weight Modular approach with no overhead for Laravel. This package provides a clean, performant way to organize your Laravel application into modular components with intelligent discovery, caching, and management capabilities.
- β¨ Zero Configuration - Works out of the box with sensible defaults
- π High Performance - Intelligent caching with automatic invalidation
- π Auto Discovery - Automatically discovers modules from configured paths
- π¦ Multiple Module Types - Support for foundation, modules, plugins, themes, etc.
- ποΈ Enable/Disable - Runtime enable/disable of modules
- π± Database Seeders - Built-in seeder management for modules
- π¨ Beautiful CLI - Interactive commands with Laravel Prompts
- π Protected Modules - Prevent critical modules from being disabled
- π Module Information - Rich metadata and dependency management
- PHP >= 8.2
- Laravel >= 10.0
Install via Composer:
composer require panicdevs/modules
The package will automatically register its service provider via Laravel's auto-discovery.
Publish the configuration file (optional):
php artisan vendor:publish --provider="PanicDevs\Modules\Providers\ModulesServiceProvider" --tag="modules-config"
Configure where your modules are located in config/modules.php:
'paths' => [ 'foundation' => [ 'path' => 'foundation', // Path relative to project root 'namespace' => 'Foundation', // PSR-4 namespace prefix 'icon' => 'π’', // Icon for CLI display 'protected' => true, // Cannot be disabled ], 'modules' => [ 'path' => 'modules', 'namespace' => 'Modules', 'icon' => 'π¦', 'protected' => false, // Can be disabled ], // Add more module types as needed... ],
Enable or disable module manifest caching:
'cache' => env('MODULES_CACHE_ENABLED', true),
Each module must contain a module.json file in its root directory:
modules/
βββ User/
β βββ module.json # Required: Module configuration
β βββ Providers/
β β βββ UserServiceProvider.php
β βββ Database/
β β βββ Seeders/
β β βββ UserDatabaseSeeder.php
β βββ Routes/
β β βββ api.php
β βββ ...
βββ Auth/
βββ module.json
βββ ...
{
"id": "User",
"name": "User",
"alias": "user",
"title": "User Management Module",
"description": "User authentication and management functionality",
"version": "1.0.0",
"priority": 10,
"providers": [
"Modules\\User\\Providers\\UserServiceProvider"
],
"files": [
"Helpers/repositories.php"
],
"depends_on": ["auth", "shared"]
}- id/name: Unique module identifier
- alias: Short name for CLI commands (defaults to lowercase name)
- title: Human-readable module title
- description: Module description
- version: Module version
- priority: Loading priority (higher loads first, default: 0)
- providers: Array of service provider classes to register
- files: Array of files to include (relative to module root)
- depends_on: Array of module dependencies
Module enable/disable status is stored in modules_statuses.json in your project root:
{
"foundation": {
"Core": true,
"Base": true,
"Support": true
},
"modules": {
"User": true,
"Auth": true,
"Blog": false
}
}The package provides several Artisan commands for module management:
# List all modules php artisan modules:list # Show only enabled modules php artisan modules:list --enabled # Show only disabled modules php artisan modules:list --disabled
# Interactive module selection php artisan modules:enable # Enable specific module php artisan modules:enable User # Enable all modules of a type php artisan modules:enable --all --type=modules
# Interactive module selection php artisan modules:disable # Disable specific module php artisan modules:disable User # Disable all modules of a type php artisan modules:disable --all --type=modules
# Interactive seeder selection php artisan modules:seed # Seed specific modules php artisan modules:seed User Auth # Seed all modules with seeders php artisan modules:seed --all # Force seeding without confirmation php artisan modules:seed User --force
# Cache module manifest for better performance php artisan modules:cache # Clear module cache php artisan modules:clear # Test module loading performance php artisan modules:test
Inject the ModuleService to interact with modules in your code:
use PanicDevs\Modules\Services\ModuleService; class SomeController { public function __construct( private ModuleService $moduleService ) {} public function index() { // Get all enabled modules $enabledModules = $this->moduleService->allEnabled(); // Get specific module $userModule = $this->moduleService->find('User'); // Check if module is enabled if ($this->moduleService->isEnabled('User')) { // Module is enabled } // Get module path $path = $this->moduleService->getPath('User'); // Get module namespace $namespace = $this->moduleService->getNamespace('User'); } }
// Module retrieval $moduleService->all(); // Get all modules $moduleService->allEnabled(); // Get enabled modules only $moduleService->find('ModuleName'); // Get specific module $moduleService->findByAlias('alias'); // Find by alias // Module status $moduleService->isEnabled('ModuleName'); // Check if enabled // Module information $moduleService->getPath('ModuleName'); // Get module path $moduleService->getNamespace('ModuleName'); // Get PSR-4 namespace $moduleService->getAlias('ModuleName'); // Get module alias $moduleService->getTitle('ModuleName'); // Get module title $moduleService->getDescription('ModuleName'); // Get description $moduleService->getVersion('ModuleName'); // Get version $moduleService->getDependencies('ModuleName'); // Get dependencies // Module organization $moduleService->getByType('modules'); // Get modules by type $moduleService->getEnabledByType('modules'); // Get enabled modules by type $moduleService->getEnabledByPriority(); // Get modules ordered by priority // Statistics $moduleService->getStats(); // Get module statistics
The package includes intelligent caching:
- Automatic: Module manifest is cached automatically when
modules.cacheistrue - Cache Location:
bootstrap/cache/modules.php - Auto-Invalidation: Cache is invalidated when
modules_statuses.jsonchanges - Production Ready: Optimized for production environments
- Lazy Loading: Modules are only loaded when needed
- Priority-Based: Modules load in priority order (highest first)
- PSR-4 Integration: Seamless autoloading integration
- Minimal Overhead: Less than 1ms overhead in production
Each module can have its own database seeders:
modules/User/Database/Seeders/
βββ UserDatabaseSeeder.php # Main seeder (required)
βββ V1/
βββ UserTableSeeder.php
βββ RoleTableSeeder.php
The main seeder (ModuleNameDatabaseSeeder.php) coordinates all module seeders:
<?php namespace Modules\User\Database\Seeders; use Foundation\Base\Database\Seeders\V1\BaseDatabaseSeeder\BaseDatabaseSeeder; use Modules\User\Database\Seeders\V1\UserTableSeeder; class UserDatabaseSeeder extends BaseDatabaseSeeder { public function run(): void { parent::run(); $this->call([ UserTableSeeder::class, ]); } }
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -am 'Add some amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
If you discover any security-related issues, please email hunt@panicdevs.agency instead of using the issue tracker.
The MIT License (MIT).
- Armin Hooshmand - Lead Developer
- PanicDevs - Development Team
- Issues: GitHub Issues
- Documentation: GitHub README
- Security: Security Advisories
Made with β€οΈ by PanicDevs