Diagnose and fix Deptrac architectural violations automatically...
make deptrac reports violationsDiagnose and fix Deptrac violations by refactoring code to respect hexagonal architecture boundaries.
Success Criteria: make deptrac outputs "โ
No violations found"
Fix the code, NEVER modify deptrac.yaml
The architecture is correct. The code must conform to it, not vice versa.
make deptrac
Domain must not depend on Symfony
src/Customer/Domain/Entity/Customer.php:8
uses Symfony\Component\Validator\Constraints as Assert
Extract:
src/Customer/Domain/Entity/Customer.php:8uses (import statement)| Domain Depends On | Fix Pattern | Example File |
|---|---|---|
| Symfony Validator | Move to YAML config | 01-domain-symfony-validation.php |
| Doctrine (ODM/ORM) | Use XML mapping | 02-domain-doctrine-annotations.php |
| API Platform | Move to YAML config | 03-domain-api-platform.php |
| Infrastructure โ Handler | Use Command Bus | 04-infrastructure-handler.php |
See: REFERENCE.md for complete fix patterns and advanced scenarios.
Follow the pattern from examples, then verify:
make deptrac
Repeat until: "โ No violations found"
Domain โโโโโโโโโโโโโโโโโ> (NO dependencies)
โ
โ
Application โโโโโโโโโโ> Domain + Infrastructure + Symfony + API Platform
โ
โ
Infrastructure โโโโโโโ> Domain + Application + Symfony + Doctrine
Allowed Dependencies:
| Layer | Can Depend On |
|---|---|
| Domain | โ Nothing (pure PHP only) |
| Application | โ Domain, Infrastructure, Symfony, API Platform |
| Infrastructure | โ Domain, Application, Symfony, Doctrine ORM |
Template examples use Doctrine ODM/MongoDB in places; apply the same patterns with Doctrine ORM and MySQL in this service.
See: CODELY-STRUCTURE.md for complete directory hierarchy.
โ Problem: Validation annotations in Domain entity
use Symfony\Component\Validator\Constraints as Assert;
class Customer {
#[Assert\NotBlank]
private string $name;
}
โ
Solution: Move validation to config/validator/{Entity}.yaml
โ Problem: Doctrine attributes in Domain entity
use Doctrine\ODM\MongoDB\Mapping\Annotations as ODM;
#[ODM\Document]
class Customer { }
โ
Solution: Create XML mapping in config/doctrine/{Entity}.mongodb.xml
โ Problem: API Platform attributes in Domain entity
use ApiPlatform\Metadata\ApiResource;
#[ApiResource]
class Customer { }
โ
Solution: Create YAML config in config/api_platform/resources/{entity}.yaml
โ Problem: Direct handler call from Infrastructure
class Repository {
public function __construct(
private SomeHandler $handler // โ Circular dependency
) {}
}
โ Solution: Use Command Bus pattern
class Repository {
public function __construct(
private CommandBusInterface $commandBus // โ
Interface
) {}
public function someMethod() {
$this->commandBus->dispatch(new SomeCommand());
}
}
See: examples/ directory for complete, runnable examples.
When facing multiple violations:
make deptrac > violations.txt
Group violations by layer pair:
# After each fix
make deptrac
Track progress: 15 violations โ 10 โ 5 โ 0 โ
deptrac.yaml to allow violations@SuppressWarnings, @psalm-suppress, @phpstan-ignore*, @infection-ignore*, phpcs:ignore)Generator classes under Factory)make deptrac after each changeDeptrac
Checking dependencies...
โ
No violations found
โ
CI checks successfully passed!
After fixing violations:
make deptrac shows 0 violationsconfig/validator/config/doctrine/config/api_platform/make all-tests)make ci passes completely# Run Deptrac analysis
make deptrac
# Check specific layer violations (if supported)
vendor/bin/deptrac analyze --report-uncovered
# Verify architecture after fixes
make deptrac && make ci
For detailed patterns, examples, and troubleshooting:
01-domain-symfony-validation.php - Fixing Symfony validation violations02-domain-doctrine-annotations.php - Removing Doctrine imports03-domain-api-platform.php - Moving API Platform config04-infrastructure-handler.php - Using Command Bus pattern# โ NEVER DO THIS
paths:
- { collector: layer_domain, exclude: '.*Annotation.*' } # Hiding violations
// โ BAD: Hiding framework dependency
class MyValidator {
private SymfonyValidator $validator; // Still violates!
}
// โ BAD: Moving Domain entity to Application to "fix" violation
// src/Application/Entity/Customer.php // WRONG LAYER!