Generating Modules

The core of this package is the make:module Artisan command. It's a powerful tool that can generate a complete, test-ready module with a single command.

Basic Usage

To generate a new module, you simply need to provide a name for it:

bash
php artisan make:module Product

This will generate a Product module with the default components configured in config/module-generator.php.

Generated Files

Each module generates the following structure:

App/
├── Models/
│   └── Product.php
├── Services/
│   ├── ProductService.php
│   └── ProductServiceInterface.php
├── Repositories/
│   ├── Contracts/ProductRepositoryInterface.php
│   └── Eloquent/ProductRepository.php
├── DTOs/
│   └── ProductDTO.php
├── Http/
│   ├── Controllers/Api/V1/ProductController.php
│   ├── Requests/Product/
│   │   ├── StoreProductRequest.php
│   │   └── UpdateProductRequest.php
│   └── Resources/ProductResource.php
├── Actions/Product/
│   ├── CreateAction.php
│   ├── UpdateAction.php
│   ├── DeleteAction.php
│   └── ... (more actions)
└── Providers/ProductServiceProvider.php

tests/
└── Feature/ProductCrudTest.php

Command Options

OptionAliasDescription
--api-aGenerate API controller with form requests and actions
--requests-rGenerate Store/Update form requests
--tests-tGenerate feature test suite
--no-controller-ncSkip controller generation
--no-resource-nrSkip API Resource
--no-dto-ndSkip DTO
--no-test-ntSkip feature tests
--no-provider-npSkip service provider
--no-actionsSkip action layer
--controller=Subdir-cPlace controller in subfolder
--swagger-sgGenerate OpenAPI annotations
--no-swaggerDisable Swagger annotations
--from-migration=-fmInfer schema from migration
--fields=Inline schema definition
--force-fOverwrite existing files

Common Examples

API Module with Everything

bash
php artisan make:module Product \
  --api --requests --tests --swagger \
  --fields="name:string, price:decimal(10,2), is_active:boolean"

Web Module (Form-Based)

bash
php artisan make:module BlogPost \
  --requests --tests \
  --fields="title:string, content:text, published_at:timestamp"

Minimal Module (Services Only)

bash
php artisan make:module Calculator \
  --no-controller --no-resource --no-test