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 Modular Laravel Package

alizharb/laravel-modular

View on GitHub
Deep Wiki
Context7

Technical Evaluation

Architecture Fit

  • Modular Monolith Advantage: Aligns perfectly with Laravel’s ecosystem while enforcing strict isolation between modules. Ideal for large-scale applications requiring domain-driven separation without microservices overhead.
  • Laravel 11/12 Optimization: Built for modern Laravel (PHP 8.2+), leveraging topological sorting for dependency resolution and zero-config autoloading via composer-merge-plugin.
  • Framework-Agnostic Design: While Laravel-specific, the architecture (e.g., module.json, composer.json per module) is adaptable to other PHP frameworks with minimal effort.

Integration Feasibility

  • Seamless Artisan Overrides: 29+ commands (e.g., make:model --module) integrate natively, reducing friction for developers accustomed to vanilla Laravel.
  • Vite/Asset Support: First-class dynamic asset loading via modular_vite() and module_asset() helpers, critical for modern SPAs.
  • Database Isolation: Modular migrations (modular:migrate) and seeders enable per-module database management, mitigating global schema conflicts.

Technical Risk

  • Dependency Management Complexity:
    • Pros: Topological sorting prevents circular dependencies; modular:sync merges dependencies into root composer.json for production.
    • Cons: Requires discipline to avoid implicit module coupling (e.g., direct class instantiation across modules). Risk of composer merge conflicts if not synced pre-deployment.
  • Performance Overhead:
    • Discovery Caching (modular:cache) mitigates runtime autoloading costs, but uncached environments may see latency spikes.
    • Vite Workspaces: NPM workspaces add complexity; modules must adhere to consistent JS build pipelines.
  • Migration Path:
    • Greenfield Projects: Ideal for new Laravel 11/12 apps.
    • Legacy Systems: Refactoring existing monoliths into modules requires incremental adoption (e.g., start with feature modules, avoid breaking core app/ structure).

Key Questions

  1. Module Granularity:
    • Should modules align with business domains (e.g., Blog, Payments) or technical layers (e.g., Auth, API)?
    • Impact: Overly fine-grained modules increase dependency management overhead.
  2. Dependency Isolation:
    • How will shared libraries (e.g., App\Services\Logger) be handled without violating the "Wall of Separation"?
    • Solution: Use contracts/interfaces or publish shared code to a composer package.
  3. CI/CD Pipeline:
    • Will modular:sync be automated in CI, or will teams manually merge dependencies?
    • Risk: Manual syncs introduce human error in production.
  4. Testing Strategy:
    • How will cross-module integration tests be managed (e.g., testing Blog module’s API calls to Auth module)?
    • Tooling: Leverage modular:test and Pest for isolated module tests.
  5. Asset Management:
    • Will modules use shared Vite config or isolated vite.config.js per module?
    • Tradeoff: Shared config simplifies HMR but may limit module autonomy.

Integration Approach

Stack Fit

  • Laravel 11/12: Native support; no polyfills required.
  • PHP 8.2+: Leverages strict typing, enums, and attributes for module metadata.
  • Frontend:
    • Vite: Required for asset management (supports workspaces).
    • Livewire/Filament: Official ecosystem packages (laravel-modular-livewire, laravel-modular-filament) enable seamless UI integration.
  • Databases:
    • MySQL/PostgreSQL: Modular migrations work with any PDO-supported DB.
    • Multi-DB: Not natively supported; requires custom module.json configuration.

Migration Path

  1. Assessment Phase:
    • Audit existing codebase for tight coupling (e.g., app/Http/Controllers referencing app/Models directly).
    • Identify core vs. modular components (e.g., Auth may stay in app/).
  2. Incremental Adoption:
    • Step 1: Install laravel-modular and generate a pilot module (e.g., Blog).
    • Step 2: Refactor one feature (e.g., PostsController) into the module.
    • Step 3: Gradually move domain-specific logic (models, policies, migrations) into modules.
  3. Dependency Management:
    • Use modular:sync pre-deployment to merge module composer.json into root.
    • Disable composer-merge-plugin in production for performance.
  4. Asset Transition:
    • Migrate module-specific JS/CSS to modules/{Module}/resources/js.
    • Update vite.config.js to include modularLoader.

Compatibility

  • Laravel Packages:
    • Most packages (e.g., Spatie, Laravel Nova) work if they support service providers and config publishing.
    • Risk: Packages with global hooks (e.g., Illuminate\Events) may require module-specific listeners.
  • Third-Party Auth:
    • Sanctum/Passport: Can be modularized, but session drivers must be configured per-module.
  • Queues/Jobs:
    • Jobs should be module-scoped (e.g., Modules\Blog\Jobs\PublishPost) to avoid namespace collisions.

Sequencing

Phase Tasks Tools/Commands
Setup Install package, configure composer.json, run modular:install. composer require, modular:install
Module Creation Generate first module (make:module Blog), define module.json. make:module, modular:list
Refactoring Move models/controllers to module, update routes/service providers. make:model --module, modular:check
Database Run modular:migrate, test module-specific seeds. modular:migrate, modular:seed
Assets Configure Vite workspaces, link assets (modular:link). modular:npm, modular_vite()
Testing Write module tests, verify isolation with modular:test. Pest, modular:test
Deployment Sync dependencies, cache discovery (modular:cache), disable merge-plugin. modular:sync, modular:cache

Operational Impact

Maintenance

  • Pros:
    • Isolated Dependencies: Module-specific composer.json reduces version conflict risks.
    • Atomic Updates: Deploy modules independently (e.g., update Blog without touching Auth).
    • Debugging: modular:debug and modular:doctor provide module-specific diagnostics.
  • Cons:
    • Stubs & Generators: Customizing make:module stubs requires global or per-module overrides.
    • Shared Config: Centralized config (e.g., .env) may need module-specific overrides (e.g., Blog::settings).

Support

  • Developer Onboarding:
    • Learning Curve: Developers must understand module boundaries, module.json, and topological dependencies.
    • Documentation: Official docs are comprehensive but assume familiarity with Laravel conventions.
  • Troubleshooting:
    • Common Issues:
      • Circular dependencies (modular:check detects these).
      • Missing autoloading (composer dump-autoload or modular:cache).
      • Asset loading failures (verify modular:link and Vite config).
    • Tooling: modular:doctor provides health scores and remediation steps.

Scaling

  • Performance:
    • Production: Discovery caching (modular:cache) reduces autoloading overhead.
    • Development: Topological sorting ensures modules load in correct order (e.g., Auth before Blog).
  • Horizontal Scaling:
    • Modules are stateless (assuming no in-memory caching across modules).
    • Database: Modular migrations enable sharding by module (e.g., Blog on DB1, Store on DB2).
  • Resource Usage:
    • Memory: Each module loads its own service providers, increasing memory usage linearly with module count.
    • Mitigation: Use Laravel’s config('app.load_modules') to lazy-load modules.

Failure Modes

Scenario Impact Mitigation Strategy
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.
nasirkhan/laravel-sharekit
directorytree/privacy-filter-classifier
directorytree/privacy-filter
datacore/hub-sdk
develia/commons
cuci/prototurk-sdk
cuci/prototurk-sdk-symfony
develia/geo-bundle
dreamzy/livewire-charts
touchestate-sdk/php-sdk
22h/doctrine-garbage-collection-bundle
agtp/agtp-php
agtp/mod-php
splash/sonata-admin
splash/metadata
splash/openapi
splash/scopes
splash/toolkit
testo/output-teamcity
testo/bridge-symfony