Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Laravel Modules Laravel Package

nwidart/laravel-modules

Modularize large Laravel apps with nwidart/laravel-modules. Create self-contained modules (controllers, models, views, routes, config) with Artisan generators, module discovery, enabling/disabling, and per-module resources—tested and maintained across modern Laravel versions.

View on GitHub
Deep Wiki
Context7

Technical Evaluation

Architecture Fit

  • Modular Monolith Advantage: The package excels in Laravel-based modular monoliths, where domain separation (e.g., AuthModule, BillingModule) aligns with business capabilities. It enforces cohesion (related logic grouped) and loose coupling (modules interact via contracts/APIs).
  • Microservices Misalignment: Not suited for true microservices (each module would still share Laravel’s core, defeating isolation). Better for large-scale monoliths needing maintainability.
  • Laravel-Centric: Deeply integrated with Laravel’s ecosystem (Service Providers, Artisan, Blade, etc.). Non-Laravel PHP apps would require significant adaptation.
  • Opinionated Structure: Enforces a standardized module skeleton (e.g., Http/Controllers, Database/Migrations), which may conflict with existing legacy codebases.

Integration Feasibility

  • Low Friction for Greenfield Projects: Ideal for new Laravel 11+ projects with no existing module structure. The module:make commands (controllers, models, etc.) reduce boilerplate.
  • Legacy Migration Challenges:
    • Namespace Collisions: Existing classes in App\Http\Controllers may clash with module-generated paths (e.g., Modules/Auth/Http/Controllers).
    • Route Conflicts: Shared routes (e.g., /login) require explicit namespace resolution (e.g., Route::module('Auth')->get(...)).
    • Service Provider Overrides: Custom providers must extend Nwidart\Modules\Module or use the ModuleServiceProvider wrapper.
  • Database Schema Management:
    • Migrations: Module-specific migrations are auto-discovered but require manual table prefixing (e.g., auth_users) to avoid conflicts.
    • Seeders: The --direction flag (e.g., module:seed --direction=down) helps with rollbacks, but shared seed data (e.g., roles) needs coordination.

Technical Risk

Risk Area Severity Mitigation
Performance Overhead Medium File-based module activation (module_statuses.json) scales poorly for >100 modules. Database activator (v6+) reduces this but adds complexity.
Dependency Spaghetti High Modules sharing Laravel core (e.g., Auth, Cache) risk circular dependencies. Use interfaces/contracts for module-to-module communication.
Asset Pipeline Fragments Medium Vite/Laravel Mix support is module-aware but requires manual config for shared assets (e.g., global CSS/JS).
Testing Isolation High Modules share Laravel’s kernel, making unit testing harder. Use --module flag in phpunit.xml to scope tests.
Upgrade Path Critical Breaking changes (e.g., v6’s File Activator) require migration scripts (php artisan module:v6:migrate).

Key Questions for TPM

  1. Architecture Goals:
    • Is the goal scalability (modular monolith) or decomposition (microservices)? If the latter, this package may not suffice.
    • How will modules communicate? (e.g., direct service calls, message queues, or APIs?)
  2. Team Maturity:
    • Does the team have experience with modular design? Lack of discipline leads to "anarchy of modules."
    • Are developers comfortable with Artisan commands and namespace conventions?
  3. Legacy Constraints:
    • How will existing routes, middleware, and service providers integrate without conflicts?
    • Is the database schema-first or module-first? (Prefixing strategies needed.)
  4. CI/CD Impact:
    • How will module-specific tests be isolated in pipelines? (e.g., parallel test execution.)
    • Will asset compilation (Vite/Mix) be module-scoped or global?
  5. Long-Term Maintenance:
    • Who will own module boundaries? (e.g., "Who decides if Billing and Payments are separate modules?")
    • How will shared dependencies (e.g., Laravel\Cashier) be managed across modules?

Integration Approach

Stack Fit

  • Laravel 11+: Native support with no PHP version constraints (PHP 8.1+).
  • Frontend: Works with Vite, Laravel Mix, or Inertia.js (via module-specific asset pipelines).
  • Testing: Compatible with Pest, PHPUnit, and Laravel Dusk (module-scoped test helpers available).
  • Database: Supports MySQL, PostgreSQL, SQLite, and SQL Server (via Laravel’s Eloquent).
  • Alternatives:
    • Lumen: Not supported (Lumen lacks Service Providers, Blade, etc.).
    • Symfony: Incompatible (requires custom integration).

Migration Path

Phase Steps Tools/Commands
Assessment Audit existing code for namespace conflicts, shared routes, and global service providers. composer why-not nwidart/laravel-modules
Scaffold Setup Initialize modules in a dedicated modules/ directory (or custom path). composer require nwidart/laravel-modules
Configuration Publish config and stubs; configure module namespace, asset paths, and database activator. php artisan vendor:publish --provider="Nwidart\Modules\LaravelModulesServiceProvider"
Module Extraction Refactor controllers, models, and routes into modules. Use --module flag for make:controller, make:model, etc. php artisan module:make Auth --controller --model --migration --resource
Route Isolation Replace routes/web.php with module-specific RouteServiceProvider or use Route::module('Auth')->.... php artisan module:route-provider Auth
Asset Pipeline Configure Vite/Mix per module or use a global build with module-specific entry points. Update vite.config.js or webpack.mix.js
Database Migration Prefix module tables (e.g., auth_users) and update seeders with --direction flags. php artisan module:seed Auth --class=AuthDatabaseSeeder --direction=up
Testing Scope tests to modules using --module in phpunit.xml or create module-specific test suites. php artisan make:test AuthTest --module=Auth
Deployment Use module activation (php artisan module:enable Auth) for feature flags or database activator for runtime control. php artisan module:enable Auth

Compatibility

  • Pros:
    • Zero-config for new modules: module:make handles scaffolding.
    • Laravel conventions: Works seamlessly with Eloquent, Blade, Queues, etc.
    • Artisan integration: Extends Laravel’s CLI with module-specific commands.
  • Cons:
    • Shared Laravel core: Modules cannot opt out of Laravel’s kernel (e.g., middleware, events).
    • Asset compilation: Requires manual Vite/Mix configuration for shared assets.
    • Legacy code: Existing global helpers, facades, or singletons may need refactoring.

Sequencing

  1. Start Small:
    • Begin with non-critical modules (e.g., Blog, Settings) before core domains (Auth, Payments).
  2. Isolate Dependencies:
    • Use interfaces for module-to-module communication (e.g., AuthContracts\Authenticator).
  3. Incremental Migration:
    • Move one feature per module (e.g., extract UserProfile from Auth).
  4. Test Early:
    • Validate module activation/deactivation doesn’t break core functionality.
  5. Monitor Performance:
    • Profile file I/O (module statuses) and autoloading with composer dump-autoload --optimize.

Operational Impact

Maintenance

  • Pros:
    • Decoupled development: Teams can work on modules in parallel.
    • Feature toggling: Enable/disable modules at runtime (php artisan module:disable Auth).
    • Versioning: Modules can be versioned independently (though Laravel’s core remains monolithic).
  • Cons:
    • Namespace Hell: Deeply nested paths (e.g., Modules\Auth\Http\Controllers\ProfileController) increase import complexity.
    • Shared State: Modules sharing **
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
hamzi/corewatch
minionfactory/raw-hydrator
hexters/coinpayment
rjcodes/rjcms
act-training/laravel-permissions-manager
alimarchal/laravel-chart-of-accounts
babenkoivan/elastic-scout-driver
mkwebdesign/filament-watchdog-v5
renatomarinho/laravel-page-speed
zedmagdy/filament-business-hours
renatovdemoura/blade-elements-ui
devgeek/beacon-admin
benjamin-rqt/data-watcher-bundle
atriumphp/atrium
sandermuller/package-boost-laravel
sandermuller/boost-skills
redaxo/core
yusufgenc/filament-api-forge
l3aro/rating-star-for-filament
leek/filament-subtenant-scope