plin-code/laravel-clean-architecture

Laravel package for generating Clean Architecture structure

Maintainers

Package info

github.com/plin-code/laravel-clean-architecture

pkg:composer/plin-code/laravel-clean-architecture

Statistics

Installs: 3 980

Dependents: 0

Suggesters: 0

Stars: 4

Open Issues: 0

v2.0.1 2026-03-31 10:37 UTC

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. ๐Ÿš€

Latest Version on Packagist GitHub Tests Action Status GitHub Code Style Action Status Total Downloads

โœจ 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 structure
  • clean-arch:make-domain {name} - ๐Ÿ†• Create a complete new domain
  • clean-arch:make-action {name} {domain} - โšก Create a new action
  • clean-arch:make-service {name} - ๐Ÿ”ง Create a new service
  • clean-arch:make-controller {name} - ๐ŸŒ Create a new controller
  • clean-arch:make-observer {name} {domain} - ๐Ÿ‘๏ธ Create a new observer
  • clean-arch:make-listener {name} - ๐Ÿ‘‚ Create a new listener
  • clean-arch:make-job {name} - โณ Create a new job
  • clean-arch:make-mail {name} - ๐Ÿ“ง Create a new mailable
  • clean-arch:make-notification {name} - ๐Ÿ”” Create a new notification
  • clean-arch:make-export {name} - ๐Ÿ“ค Create a new export
  • clean-arch:validate - โœ… Validate architecture dependency rules
  • clean-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:

  1. ๐ŸŽฏ Domain Layer: Contains business logic and entities
  2. โšก Application Layer: Contains use cases and application logic
  3. ๐Ÿ—๏ธ 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

  1. ๐Ÿ“ฅ Clone the repository
  2. ๐Ÿ“ฆ Install dependencies: composer install
  3. โœจ 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 ๐Ÿ“œ