plin-code/laravel-clean-architecture
Composer 安装命令:
composer require plin-code/laravel-clean-architecture
包简介
Laravel package for generating Clean Architecture structure
README 文档
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 📜
plin-code/laravel-clean-architecture 适用场景与选型建议
plin-code/laravel-clean-architecture 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 4.02k 次下载、GitHub Stars 达 5, 最近一次更新时间为 2025 年 05 月 29 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「package」 「php」 「laravel」 「ddd」 「clean-architecture」 「domain-driven-design」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 plin-code/laravel-clean-architecture 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 plin-code/laravel-clean-architecture 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 plin-code/laravel-clean-architecture 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Simple ASCII output of array data
Alfabank REST API integration
Package for view storage in laravel
User Approval Laravel Package
PHPUnit Pretty Result Printer
统计信息
- 总下载量: 4.02k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 6
- 点击次数: 18
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-05-29