A Laravel package to easily implement Clean Architecture in your projects. ๐
- ๐ฏ Domain-Driven Design - Organize your code with DDD principles
- โก Quick Setup - Get started with Clean Architecture in minutes
- ๐งฉ Auto-Generation - Generate complete domains with one command
- ๐๏ธ Layer Separation - Clear separation between Domain, Application, and Infrastructure
- ๐ง Customizable - Flexible configuration to fit your project needs
- ๐งช Test-Ready - Pre-built test templates for immediate testing
- ๐ Well-Documented - Comprehensive documentation and examples
- ๐จ Modern PHP - Built for PHP 8.3+ with latest Laravel features
- ๐ PHP 8.3+
- โก Laravel 12.x
composer require plin-code/laravel-clean-architecturePublish the configuration files and stubs:
php artisan vendor:publish --provider="PlinCode\LaravelCleanArchitecture\CleanArchitectureServiceProvider"php artisan clean-arch:installThis command will create:
- ๐ Folder structure for Domain, Application and Infrastructure layers
- ๐งฉ Base classes (BaseModel, BaseAction, BaseService, etc.)
- โ๏ธ Configuration file
- ๐ Documentation
php artisan clean-arch:make-domain UserThis command will generate:
- ๐๏ธ Domain model with events
- ๐ Status enums
- ๐ Domain events (Created, Updated, Deleted)
- โก Actions (Create, Update, Delete, GetById)
- ๐ง Service
- ๐ API Controller
- ๐ Form Requests (Create, Update)
- ๐ค API Resource
- ๐งช Feature tests
clean-arch:install- ๐๏ธ Install Clean Architecture structureclean-arch:make-domain {name}- ๐ Create a complete new domainclean-arch:make-action {name} {domain}- โก Create a new actionclean-arch:make-service {name}- ๐ง Create a new serviceclean-arch:make-controller {name}- ๐ Create a new controllerclean-arch:generate-package {name} {vendor}- ๐ฆ Generate a new package
app/
โโโ Application/
โ โโโ Actions/
โ โ โโโ Users/
โ โ โโโ CreateUserAction.php
โ โ โโโ UpdateUserAction.php
โ โ โโโ DeleteUserAction.php
โ โ โโโ GetByIdUserAction.php
โ โโโ Services/
โ โโโ UserService.php
โโโ Domain/
โ โโโ Users/
โ โโโ User.php
โ โโโ Enums/
โ โ โโโ UserStatus.php
โ โโโ Events/
โ โโโ UserCreated.php
โ โโโ UserUpdated.php
โ โโโ UserDeleted.php
โโโ Infrastructure/
โโโ API/
โโโ Controllers/
โ โโโ UsersController.php
โโโ Requests/
โ โโโ CreateUserRequest.php
โ โโโ UpdateUserRequest.php
โโโ Resources/
โโโ UserResource.php
This package implements Clean Architecture principles:
- ๐ฏ Domain Layer: Contains business logic and entities
- โก Application Layer: Contains use cases and application logic
- ๐๏ธ Infrastructure Layer: Contains implementation details (controllers, database, etc.)
- ๐ฏ Domain Layer: Does not depend on any other layer
- โก Application Layer: Depends only on Domain Layer
- ๐๏ธ Infrastructure Layer: Depends on Application and Domain Layers
php artisan clean-arch:make-domain Productclass ProductsController extends Controller
{
public function __construct(
private CreateProductAction $createProductAction,
private ProductService $productService
) {}
public function store(CreateProductRequest $request): JsonResponse
{
$product = $this->createProductAction->execute($request);
return response()->json([
'data' => new ProductResource($product),
'message' => 'Product created successfully'
], 201);
}
}The configuration file config/clean-architecture.php allows you to customize:
- ๐ท๏ธ Default namespace
- ๐ Directory paths
- โ Validation options
- ๐ Logging settings
This package uses several tools to maintain code quality:
- ๐จ Laravel Pint - Code formatting and style fixing
- ๐ PHPStan - Static analysis for finding bugs
- ๐งช PEST - Modern testing framework built on PHPUnit
- ๐ญ Orchestra Testbench - Laravel package testing
# ๐งช Run tests
composer test
# ๐ Run tests with coverage
composer test-coverage
# ๐จ Fix code style
composer format
# ๐ Check code style without fixing
composer format-test
# ๐ Run static analysis
composer analyse
# โจ Run all quality checks
composer quality- ๐ฅ Clone the repository
- ๐ฆ Install dependencies:
composer install - โจ Run quality checks:
composer quality
Pull requests are welcome! ๐ For major changes, please open an issue first to discuss what you would like to change.
Please make sure to update tests as appropriate and follow our Contributing Guidelines. ๐
MIT ๐