Introduction to the Modular Project
The internachi/modular
project aims to improve the structure and organization of Laravel applications by introducing a modular system. This system uses established Laravel conventions and is designed to be lightweight and easy to integrate into existing projects.
What is Modular?
internachi/modular
is a module system specifically created for Laravel applications. It uses Composer's path repositories for autoloading and leverages Laravel package discovery for module initialization. This allows developers to create modules within a dedicated app-modules/
directory, helping to keep large projects organized and maintainable.
Key Features
- Composer Integration: Uses Composer path repositories for seamless module autoloading.
- Laravel Auto-Discovery: Utilizes Laravel's package discovery to set up modules automatically.
- Lightweight Tooling: Provides minimal yet powerful tools to bridge any gaps in module management.
Getting Started
To start using internachi/modular
, the installation process is straightforward:
-
Install the Package: Use Composer to require the
internachi/modular
.composer require internachi/modular
Laravel will automatically recognize and set up the package for you.
-
Configure Namespace: Customize your default module namespace by publishing the package config. It's recommended to use an organizational namespace for easier module extraction.
php artisan vendor:publish --tag=modular-config
-
Create Modules: Use the Artisan command to scaffold new modules.
php artisan make:module my-module
This creates a new module with a standard structure including directories for source code, tests, routes, and resources.
-
Update Composer: After module creation, perform a Composer update to ensure everything is current.
composer update modules/my-module
-
Optional Sync: Run a sync command to update project configurations if necessary.
php artisan modules:sync
Usage
Modules created with internachi/modular
follow existing Laravel conventions and should integrate smoothly with:
- Artisan Commands: Commands are auto-registered.
- Migrations: Automatically run by the Migrator.
- Factories, Policies, Blade Components, and Event Listeners: All auto-discovered and managed efficiently.
Commands
The package includes several useful commands for module creation and management:
- Create new modules, cache, and clear module settings, sync configurations, and list available modules through a set of customized Artisan commands.
- Extend existing Laravel
make:
commands with a--module=
option to specify module contexts. - Support for third-party package commands like those from Livewire.
Blade Component Registration
Automatically register Laravel Blade components with a designated namespace, simplifying component usage in views.
Customizable Module Structure
Developers can customize the module scaffolding by publishing config files and adjusting pre-defined stubs to fit specific project needs.
Comparison with Other Solutions
internachi/modular
is designed for developers who prefer to adhere closely to Laravel conventions and seek a lightweight module solution. It differs from other options like nwidart/laravel-modules
, which might be better suited for applications needing dynamic third-party module management.
In summary, internachi/modular
offers a convention-oriented, lightweight modular approach that enhances the organization of Laravel projects, making it an ideal choice for developers focused on efficient project structuring.