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.cache
istrue
- Cache Location:
bootstrap/cache/modules.php
- Auto-Invalidation: Cache is invalidated when
modules_statuses.json
changes - 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 [email protected] 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