Dev.to
7/3/2026

The original title is "The src/ Layout for Hexagonal PHP: Layers and Import Rules"
Original: The src/ Layout for Hexagonal PHP: Layers and Import Rules
Short summary
Hexagonal architecture in PHP requires organizing code into three distinct layers (Domain, Application, Infrastructure) with strictly enforced import rules: inward imports only. Domain imports nothing but itself; Application imports Domain; Infrastructure imports everything and connects to vendors. Use CI tools like Deptrac to enforce these boundaries automatically, preventing framework and vendor concerns from leaking into domain logic.
- •Three-layer namespace structure (Domain, Application, Infrastructure) enforces clean architecture via PSR-4 autoloading
- •Import rules point inward only—Domain isolated, Application bridges to ports, Infrastructure handles adapters and vendors
- •Deptrac and CI checks prevent architectural violations at build time, not just code review
Generated with AI, which can make mistakes.
Is this a good recommendation for you?


