Ports and Adapters Explained
Isolate the core with ports and pluggable adapters.
The Hexagon Idea
Ports & Adapters — Alistair Cockburn's Hexagonal Architecture — draws your application as a hexagon. Inside is pure business logic. Every interaction with the outside world (HTTP, DB, queue, clock, email) crosses a port, and each port is satisfied by one or more adapters. The shape has no privileged top or bottom: the UI and the database are symmetric, both just adapters.
Ports Are Interfaces
A port is an interface owned by the application core that expresses a need or capability in domain terms. It must not leak infrastructure vocabulary — no PDOStatement, no GuzzleResponse, no Eloquent.
<?php
// Driven (outbound) port: the core needs to persist users
interface UserRepository
{
public function byId(UserId $id): ?User;
public function save(User $user): void;
}All lessons in this course
- From Layered to Clean Architecture
- Ports and Adapters Explained
- Use Cases and Application Services
- Dependency Inversion in Practice