This project provides a clear implementation of Clean Architecture principles in PHP, ensuring a well-structured and maintainable codebase. It guides developers through creating clean, organized applications by defining architectural levels and checking dependencies. Perfect for PHP developers looking to enhance their architectural understanding.
Overview
The php-clean-architecture package provides a robust implementation of Clean Architecture for PHP projects, adhering to the architectural principles as outlined by Robert C. Martin (Uncle Bob). The goal is to create a well-structured and maintainable codebase by clearly defining architecture levels and their dependencies.
For a detailed explanation of Clean Architecture, refer to Clean Architecture.
Key Features
- Opinionated Design: This package offers a structured approach to building applications by enforcing architectural boundaries and dependencies.
- Deptrac Integration: The package utilizes deptrac to check whether the defined levels of architecture and their dependencies are respected, ensuring best practices in design.
Core Concepts
-
Architecture Levels: The architecture is divided into distinct levels:
- Entity: Represents the core entities in the application.
- Repository: Interfaces for data access.
- UseCase: Contains the business logic for the application's core functionality.
- Controller: Acts as the interface between user inputs and the use cases.
- Service: Used for third-party tools or libraries interaction.
-
Use Case Definition: Each use case should represent a specific action, such as login or registration, ensuring clear and focused functionality within the application.
Getting Started
Developers can easily start using the package by following these core commands, which require configuration through the provided YAML files after installation:
vendor/bin/php-clean-architecture make:entity EntityName
vendor/bin/php-clean-architecture make:repository RepositoryName
vendor/bin/php-clean-architecture make:usecase UseCaseName
vendor/bin/php-clean-architecture make:controller ControllerName
vendor/bin/php-clean-architecture make:service ServiceName
CI/CD Check
Integrating the architecture checks into Continuous Integration/Continuous Deployment (CI/CD) pipelines is straightforward. The following command verifies whether the architecture adheres to the defined structure before deployment:
vendor/bin/php-clean-architecture check
Examples
To create a new entity, repository, use case, controller, or service, execute:
vendor/bin/php-clean-architecture make:entity SomeEntity
vendor/bin/php-clean-architecture make:repository SomeRepository
vendor/bin/php-clean-architecture make:usecase SomeUseCase
vendor/bin/php-clean-architecture make:controller SomeController
vendor/bin/php-clean-architecture make:service SomeService
Conclusion
The php-clean-architecture package aids in building scalable and maintainable PHP applications by enforcing a clean architecture. It encourages developers to adhere to the rules of architecture, potentially enhancing the overall quality of the codebase. For more information, review the full documentation available in the repository.
No comments yet.
Sign in to be the first to comment.