Laravel Modular is a professional, framework-agnostic modular system engineered for Laravel 11/12. It empowers you to build scalable, strictly typed, and decoupled applications with zero configuration overhead.
We override 29+ native Artisan commands to provide a seamless "first-class" modular experience, feeling exactly like standard Laravel but better.
make:model, make:controller, etc.) fully support --module.composer-merge-plugin integration for isolated module dependencies.modular:cache) for near-zero overhead in production.module:enable and module:disable.ModuleRegistry and traits for maximum stability.modules/Shop/stubs.modular_vite() and asset linking.Enhance your modular application with our official packages:
Install the package via Composer:
composer require alizharb/laravel-modular
Run the installation command to automatically configure your application:
php artisan modular:install
Note: This will automatically install and configure
wikimedia/composer-merge-pluginto handle your module dependencies.
If you prefer to configure things manually, follow these steps:
1. Composer Autoloading
Add the following to your root composer.json to ensure module namespaces are autoloaded:
"autoload": {
"psr-4": {
"App\\": "app/",
"Modules\\": "modules/"
}
},
"extra": {
"merge-plugin": {
"include": [
"modules/*/composer.json"
]
}
}
2. Vite Configuration
To enable hot-readling for module assets, create a vite.modular.js file in your root and update vite.config.js:
// vite.config.js
import { defineConfig } from "vite";
import laravel from "laravel-vite-plugin";
import { modularLoader } from "./vite.modular.js";
export default defineConfig({
plugins: [
laravel({
input: [
"resources/css/app.css",
"resources/js/app.js",
...modularLoader.inputs(), // Add this line
],
refresh: [
...modularLoader.refreshPaths(), // Add this line
],
}),
],
});
Generate a fully structured module in seconds:
php artisan make:module Blog
Every standard Laravel make: command acts as a modular command when you pass the --module flag:
# Create a Model with Migration, Controller, and Factory in 'Blog' module
php artisan make:model Post --module=Blog -mcf
# Create a resource controller
php artisan make:controller API/PostController --module=Blog --api
Run migrations and seeders specifically for your modules:
# Migrate all modules
php artisan modular:migrate
# Migrate a specific module
php artisan modular:migrate Blog --fresh --seed
# Rollback a module's migrations
php artisan modular:migrate Blog --rollback --step=2
# Run module seeders
php artisan modular:seed Blog
# List all modules and discovered resources
php artisan modular:list
# Visualize module dependencies in an ASCII tree
php artisan modular:list --tree
# Diagnose common configuration issues and view Health Scores
php artisan modular:doctor
# Sync module dependencies to root composer.json
php artisan modular:sync
# Export a module to a standalone Composer package
php artisan modular:export Blog --path=packages/blog
# Run npm commands for a module (Workspaces)
php artisan modular:npm Blog install
php artisan modular:npm Blog build
# Check for circular dependencies
php artisan modular:check
# Debug module configuration
php artisan modular:debug Blog
# Run module tests
php artisan modular:test Blog
Use our dedicated Blade directives to conditionally render UI based on module availability:
@moduleEnabled('Blog')
<a href="{{ route('blog.index') }}">Read the Blog</a>
@endmoduleEnabled
@moduleDisabled('Store')
<p>Our store is currently offline.</p>
@endmoduleDisabled
For maximum production performance, we recommended the following:
"Modules\\": "modules/" is in your root composer.json. modular:install handles this for you.php artisan modular:sync to merge module dependencies into your root composer.json and disable the merge-plugin.php artisan modular:cache in your deployment pipeline.Define middleware in your module.json:
"middleware": {
"web": ["Modules\\Blog\\Http\\Middleware\\TrackVisits"],
"blog.admin": "Modules\\Blog\\Http\\Middleware\\AdminGuard"
}
Access config case-insensitively:
// Both work!
config('Blog::settings.key');
config('blog::settings.key');
Access module information globally with strictly typed helpers:
// Get the registry or specific module config
$modules = module();
$blogConfig = module('Blog');
// Get absolute path to a resource
$viewPath = module_path('Blog', 'Resources/views');
// Get absolute path to a config file
$configPath = module_config_path('Blog', 'settings.php');
Link your module assets to public/modules for easy serving:
php artisan modular:link
Use the helper to generate asset URLs in your Blade views:
<link rel="stylesheet" href="{{ module_asset('Blog', 'css/app.css') }}">
<img src="{{ module_asset('Blog', 'images/logo.png') }}" alt="Blog Logo">
Publish the configuration file for advanced customization:
php artisan vendor:publish --tag="modular-config"
You can customize:
packages/ or any custom directory.vendor, author, license) for generated composer.json files.We strictly enforce testing. Use the provided test suite to verify your modules:
vendor/bin/pest
Extend your modular architecture with our official ecosystem packages:
| Package | Description |
|---|---|
| Laravel Themer | For advanced theme management support |
| Modular Livewire | Provides automatic Livewire component discovery and registration within modules. |
| Modular JS | Enables JS discovery within modular structures and provides zero-config autoloading for modules. |
| Modular Filament | Enables Filament v5 admin panel integration with automatic discovery in modules. |
| Filament Themer Launcher | Provides a comprehensive Filament v5 interface for managing and switching themes. |
| Filament Modular Launcher | A powerful Filament v5 manager for listing, toggling, and backing up system modules. |
| Laravel Hooks | Adds a universal extensibility and plugin system for Laravel applications. |
We provide first-class support for modern frontend tooling:
php artisan modular:npm to configure workspaces, allowing each module to manage its own package.json dependencies efficiently.modular_vite('ModuleName') helper to load module-specific assets with full Hot Module Replacement (HMR) support.php artisan modular:link.We would like to extend our thanks to the following sponsors for funding Laravel Modular development. If you are interested in becoming a sponsor, please visit the Laravel Modular GitHub Sponsors page.
We welcome contributions! Please see CONTRIBUTING for details.
git checkout -b feature/AmazingFeature)git commit -m 'Add some AmazingFeature')git push origin feature/AmazingFeature)If you discover any security-related issues, please email Ali Harb at harbzali@gmail.com.
The MIT License (MIT). Please see License File for more information.
How can I help you explore Laravel packages today?