Ports and Adapters
ELI5 — The Vibe Check
Ports and Adapters (aka Hexagonal Architecture) means your app defines 'ports' (interfaces) and the outside world connects through 'adapters.' Want to switch from PostgreSQL to MongoDB? Just swap the adapter. The app's core never changes.
Real Talk
An architectural pattern (by Alistair Cockburn) where the application core defines ports (interfaces) that adapters implement. Driving adapters (e.g., REST controllers, CLI) initiate actions, while driven adapters (e.g., database repositories, email services) are called by the core. This creates a technology-agnostic core that's easily testable.
When You'll Hear This
"The repository port is an interface — the PostgreSQL adapter implements it for production, the in-memory adapter for tests." / "Ports and adapters make your app testable without any infrastructure running."
Related Terms
Adapter Pattern
You're in Europe with a US charger. You need an adapter. In code, your app expects a PaymentProcessor with a .pay() method, but the new Stripe SDK uses .
Dependency Injection
Instead of your UserService creating its own DatabaseConnection (tight coupling), you pass the database in from outside: new UserService(db).
Hexagonal Architecture
Hexagonal Architecture (aka Ports and Adapters) treats your app like a USB hub.
Onion Architecture
Onion architecture arranges code in concentric layers like an onion. The core (domain) has no dependencies. Each outer layer depends inward, never outward.