PHPArchitectureGuardian is a powerful static analysis tool that helps you enforce architectural principles in your PHP projects. It ensures your code follows architectural patterns like Domain-Driven Design (DDD), Clean Architecture, or Hexagonal Architecture (Ports & Adapters).
-
🏛️ Verify adherence to various architectural patterns:
- Domain-Driven Design (DDD)
- Clean Architecture
- Hexagonal Architecture (Ports & Adapters)
- Custom architecture rules
-
🔍 Enforce architectural constraints:
- Prevent improper dependencies between layers
- Ensure correct implementation of interfaces
- Validate proper namespace usage
- Enforce naming conventions
-
🛠️ Highly customizable:
- Configure namespaces for different architecture layers
- Create custom rules with specific validation logic
- Define custom naming conventions
- Specify custom dependency constraints
-
📊 Comprehensive reporting:
- Clear violation descriptions
- Severity levels for different issues
- Configurable output formats
You can install the package via composer:
composer require --dev qdenka/php-architecture-guardianRun the tool in your project directory:
vendor/bin/php-architecture-guardianCreate a .architecture-guardian.php configuration file in your project root:
<?php
return [
'analyzers' => [
'ddd' => [
'enabled' => true,
'config' => [
'domain_namespaces' => ['Domain', 'App\\Domain'],
'application_namespaces' => ['Application', 'App\\Application'],
'infrastructure_namespaces' => ['Infrastructure', 'App\\Infrastructure'],
],
],
// Additional analyzers and configurations...
],
];See the example configuration for a complete example with all options.
PHPArchitectureGuardian - A tool for enforcing architectural principles in PHP projects
Usage:
php-architecture-guardian [options]
Options:
-c, --config Path to configuration file (default: .architecture-guardian.php)
-p, --path Path to analyze (default: current directory)
-h, --help Display this help message
Enforces the layered architecture of DDD:
- Domain Layer: Contains business logic, entities, value objects
- Application Layer: Contains application services, commands, queries
- Infrastructure Layer: Contains implementations of repositories, external services
Rules ensure:
- Domain layer does not depend on application or infrastructure
- Application layer does not depend on infrastructure (configurable)
- Infrastructure components implement domain interfaces
Enforces the concentric layers of Clean Architecture:
- Entities Layer: Core business objects
- Use Cases Layer: Application-specific business rules
- Interface Adapters Layer: Presenters, controllers, gateways
- Frameworks & Drivers Layer: Web, UI, DB, devices, external interfaces
Rules ensure:
- Entities do not depend on outer layers
- Use Cases depend only on Entities
- Interface Adapters depend only on Use Cases and Entities
- Frameworks & Drivers depend on inner layers
Enforces the separation of:
- Domain: Core business logic
- Ports: Interfaces defining how domain interacts with outside world
- Adapters: Implementations of ports that connect to external systems
Rules ensure:
- Domain does not depend on anything outside
- Ports are interfaces and depend only on domain
- Adapters implement ports and connect to external systems
Create your own architecture rules:
- Define custom naming conventions for different namespaces
- Specify allowed dependencies between namespaces
- Create custom rule classes for complex validation logic
Contributions are welcome! Please see CONTRIBUTING for details.
The MIT License (MIT). Please see License File for more information.