plin-code / laravel-clean-architecture
Laravel package for generating Clean Architecture structure
Package info
github.com/plin-code/laravel-clean-architecture
pkg:composer/plin-code/laravel-clean-architecture
Requires
- php: ^8.3
- illuminate/console: ^12.0 || ^13.0
- illuminate/filesystem: ^12.0 || ^13.0
- illuminate/support: ^12.0 || ^13.0
Requires (Dev)
- larastan/larastan: ^3.9
- laravel/pint: ^1.13
- mockery/mockery: ^1.6
- orchestra/testbench: ^10.0 || ^11.0
- pestphp/pest: ^3.0 || ^4.0
- pestphp/pest-plugin-laravel: ^3.0 || ^4.0
This package is not auto-updated.
Last update: 2026-03-31 10:47:36 UTC
README
A Laravel package to easily implement Clean Architecture in your projects. ๐
โจ Features
- ๐ฏ 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
๐ Requirements
- ๐ PHP 8.3+
- โก Laravel 12.x / 13.x
๐ฆ Installation
composer require plin-code/laravel-clean-architecture
โ๏ธ Configuration
Publish the configuration files and stubs:
php artisan vendor:publish --provider="PlinCode\LaravelCleanArchitecture\CleanArchitectureServiceProvider"
๐ฏ Usage
๐๏ธ Installing Clean Architecture structure
php artisan clean-arch:install
This command will create:
- ๐ Folder structure for Domain, Application and Infrastructure layers
- ๐งฉ Base classes (BaseModel, BaseAction, BaseService, etc.)
- โ๏ธ Configuration file
- ๐ Documentation
๐ Creating a new domain
php artisan clean-arch:make-domain User
This 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
- ๐๏ธ Database migration
- ๐งช Feature tests
After generating the core files, make-domain prompts interactively for optional components. You can choose to also generate an Observer, Listener, Job, Mail, Notification, and Export for the domain. Each prompt can be answered independently, so you only generate what your domain needs.
โ Architecture validation
php artisan clean-arch:validate
This command checks your codebase for layer dependency violations (for example, Domain code importing from Infrastructure). It returns exit code 1 when violations are found, making it suitable for use in CI pipelines.
Clean Architecture Validation
=============================
โ Domain has no Application imports
โ Domain has no Infrastructure imports
โ Application has no Infrastructure imports
โ No Observers in Domain
โ No Jobs in Infrastructure
โ No Commands in Infrastructure
โ No duplicate Services directory
No violations found.
๐ ๏ธ Available commands
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:make-observer {name} {domain}- ๐๏ธ Create a new observerclean-arch:make-listener {name}- ๐ Create a new listenerclean-arch:make-job {name}- โณ Create a new jobclean-arch:make-mail {name}- ๐ง Create a new mailableclean-arch:make-notification {name}- ๐ Create a new notificationclean-arch:make-export {name}- ๐ค Create a new exportclean-arch:validate- โ Validate architecture dependency rulesclean-arch:generate-package {name} {vendor}- ๐ฆ Generate a new package
๐ Project structure after clean-arch:install
app/
โโโ Domain/ # Pure business logic
โโโ Application/ # Use cases and orchestration
โ โโโ Actions/
โ โโโ Services/
โ โโโ Jobs/
โ โโโ Listeners/
โ โโโ Console/Commands/
โโโ Infrastructure/ # Framework adapters
โโโ Http/
โ โโโ Controllers/Api/
โ โโโ Middleware/
โ โโโ Requests/
โ โโโ Resources/
โโโ UI/
โโโ Mail/
โโโ Notifications/
โโโ Observers/
โโโ Exports/
โโโ Validation/
โโโ Exceptions/
๐ Generated structure after clean-arch:make-domain User
app/
โโโ Domain/
โ โโโ Users/
โ โโโ Models/
โ โ โโโ User.php
โ โโโ Enums/
โ โ โโโ UserStatus.php
โ โโโ Events/
โ โโโ UserCreated.php
โ โโโ UserUpdated.php
โ โโโ UserDeleted.php
โโโ Application/
โ โโโ Actions/
โ โ โโโ Users/
โ โ โโโ CreateUserAction.php
โ โ โโโ UpdateUserAction.php
โ โ โโโ DeleteUserAction.php
โ โ โโโ GetByIdUserAction.php
โ โโโ Services/
โ โโโ UserService.php
โโโ Infrastructure/
โโโ Http/
โโโ Controllers/
โ โโโ Api/
โ โโโ UsersController.php
โโโ Requests/
โ โโโ CreateUserRequest.php
โ โโโ UpdateUserRequest.php
โโโ Resources/
โโโ UserResource.php
๐๏ธ Clean Architecture Principles
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.)
๐ Dependencies
- ๐ฏ Domain Layer: Does not depend on any other layer
- โก Application Layer: Depends only on Domain Layer
- ๐๏ธ Infrastructure Layer: Depends on Application and Domain Layers
๐ก Examples
๐๏ธ Creating a Product domain
php artisan clean-arch:make-domain Product
๐ฎ Using in controller
class 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); } }
โ๏ธ Configuration
The configuration file config/clean-architecture.php allows you to customize:
- ๐ท๏ธ Default namespace
- ๐ Directory paths
- โ Validation options
- ๐ Logging settings
๐ ๏ธ Development
This package uses several tools to maintain code quality:
๐ง Code Quality Tools
- ๐จ 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
๐ Available Scripts
# ๐งช 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
๐ Development Setup
- ๐ฅ Clone the repository
- ๐ฆ Install dependencies:
composer install - โจ Run quality checks:
composer quality
๐ค Contributing
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. ๐
๐ License
MIT ๐