Development › Modules
Modules
Every business capability lives in app/Modules/{Name}.
#Creating a module
php artisan make:module OrdersThis scaffolds:
app/Modules/Orders/
├── Domain/{Entities,ValueObjects,Events,Exceptions,Contracts}/
├── Application/{Actions,Commands,Queries,DTOs,Services}/
├── Infrastructure/{Persistence,Repositories,Services,Consumers,Providers}/
└── Presentation/{Controllers,Requests,Resources,Routes}/It also creates:
Infrastructure/Providers/OrdersServiceProvider.phpPresentation/Routes/api.php(loaded underapi/v1)
Register the provider in bootstrap/providers.php:
use App\Modules\Orders\Infrastructure\Providers\OrdersServiceProvider;
return [
App\Providers\AppServiceProvider::class,
OrdersServiceProvider::class,
];#Generating module artifacts
php artisan make:action CreateOrder --module=Orders
php artisan make:dto CreateOrderData --module=Orders
php artisan make:domain-event OrderCreated --module=Orders
php artisan make:consumer OrderCreatedConsumer --module=Orders#Recommended request flow
POST /api/v1/orders
→ CreateOrderRequest (validation)
→ CreateOrderData (DTO)
→ CreateOrder Action
→ OrderRepository (contract)
→ Infrastructure repository
→ OrderCreated domain event
→ EventBus (local +/or Kafka)#Module communication
Allowed
- Inject another module’s public contract (bound in that module’s provider)
- Publish/subscribe domain or integration events
- Call a thin application service exposed for cross-module use
Not allowed
- Import another module’s Eloquent models
- Reach into
Infrastructure/Repositoriesof another module - Share database tables casually across module boundaries without an explicit ownership decision
#Isolation checklist
- Domain has no Laravel facades
- Controllers only call Actions
- Repository interfaces live in Domain; implementations in Infrastructure
- Provider binds contracts and loads routes
- Routes stay inside the module (not in
routes/api.php)
#Modules shipped in this starter
| Module | Purpose |
|---|---|
| Auth | Authentication boundaries (Sanctum) |
| Users | User identity / profile shell |
| Notifications | Outbound notification capability (LogNotifier) |
Add your domain modules with php artisan make:module {Name}. See architecture.md and development.md.