How does the Hexagonal Architecture (Ports and Adapters) apply DIP?

Answer

Hexagonal Architecture (also called Ports and Adapters, coined by Alistair Cockburn) is DIP applied at the architectural level. The domain (core business logic) sits at the center and defines ports — interfaces describing what it needs from the outside world (persistence, messaging, external services). Adapters are concrete implementations of those ports — a MySQL adapter, a SendGrid adapter, a REST adapter. The direction of dependency is always inward: adapters depend on port interfaces; the domain depends on nothing outside itself. This means the domain is fully testable without any infrastructure, can be driven by multiple adapters simultaneously (REST API + CLI + message queue), and infrastructure can be swapped without changing domain logic. Laravel's repository pattern partially implements this; clean architecture frameworks go further.