Skip to content

Introduction

Laravel Modules splits one Laravel application into modules. Each module lives in its own folder and holds its own routes, controllers, models, views, migrations, config and translations. The application stays one deployable Laravel app.

A module is a small Laravel package inside your application. By default it lives in Modules/<Name>/ at the application root. A module has:

  • a module.json file that names the module and lists its service providers and files;
  • a composer.json file that maps the module namespace (Modules\<Name>\) to the folder of its classes;
  • a main service provider, usually with a route provider, that registers its routes, views, config, translations and migrations;
  • its own routes/, resources/views/, database/migrations/, config/ and tests/ folders.

module:make generates this structure. Anatomy of a module explains why each part is there. Module code is plain Laravel: controllers, Eloquent models, Blade views, and migrations.

The package scans the module folder for module.json files when the application boots. It registers the service providers of every enabled module in priority order. Composer autoloads module classes through wikimedia/composer-merge-plugin. See How modules boot for the full sequence.

A module is enabled or disabled. Enabled modules register their providers, routes, views, and migrations. Disabled modules stay on disk without registering providers or routes.

The package stores status outside module.json in an activator (by default, modules_statuses.json at the application root). New modules are enabled unless you pass --disabled. See Module status and activators.

The package adds Artisan commands in five groups (see Artisan commands):

  • Module management: list, enable, disable, install, update, and delete modules (module:list, module:enable, module:disable).
  • Generators: scaffold modules and the classes inside them (module:make, module:make-controller, module:make-model).
  • Database: run migrations and seeders for one or all modules (module:migrate, module:seed).
  • Publish: copy module configs, migrations, translations, assets, or Inertia entry files to the application (module:publish-config).
  • Utility: setup, autoload migration, and PHPUnit coverage updates (module:setup, module:update-phpunit-coverage).
  • The application has grown and several features, teams, or domains share one app/ folder. A module gives each a folder to own.
  • You want to turn a feature off without deleting it, for example per customer or per environment.
  • You want a feature structured like a package so you can copy, move, or extract it to Composer later.
  • The application is small. One app/ folder is easier to navigate than several modules.
  • You need strict isolation. A module is a folder convention that shares the container, database, config, and autoloader with the rest of the app. The package does not prevent one module from using another module’s classes.
  • You need separate deployments. Modules deploy together with the application. Build separate applications when you need independent deploys.
  • It does not isolate modules or declare dependencies between them. module.json has no required-module field.
  • It does not version modules or load them from a database. Modules are folders found on disk.
  • It does not provide an admin interface, an end-user installer, or a theme system. It provides generators and a module registry.
  • It does not change how Laravel works inside a module.