0PricingLogin
PHP Academy · Lesson

From Layered to Clean Architecture

Understand why dependencies should point inward.

Why Clean Architecture

You already know the classic three-layer PHP stack: Controller → Service → Repository → Database. It works, but the business logic ends up coupled to Eloquent, Doctrine, the HTTP request, and the framework lifecycle. Clean Architecture flips the dependency direction so your domain knows nothing about infrastructure. The reward: testable use cases, swappable adapters, and a codebase that survives framework upgrades.

The Dependency Rule

The single rule of Clean Architecture: source code dependencies point only inward. Inner circles (entities, use cases) must never reference outer circles (controllers, ORMs, frameworks). At runtime control flows outward via interfaces, but at compile/import time nothing inner imports anything outer.

  • Entities: enterprise rules
  • Use Cases: application rules
  • Adapters: controllers, presenters, gateways
  • Frameworks & Drivers: DB, HTTP, the web

All lessons in this course

  1. From Layered to Clean Architecture
  2. Ports and Adapters Explained
  3. Use Cases and Application Services
  4. Dependency Inversion in Practice
← Back to PHP Academy