Hexagonal Architecture
ELI5 — The Vibe Check
Hexagonal Architecture (aka Ports and Adapters) treats your app like a USB hub. Your business logic sits in the middle, and everything else (databases, APIs, UIs) plugs in through standardized ports. Want to switch from MySQL to Postgres? Just swap the adapter — the core never changes.
Real Talk
Hexagonal Architecture (Alistair Cockburn) isolates the application core from external systems using Ports (interfaces defining how the core communicates) and Adapters (implementations that translate external systems to the core's ports). Enables testability and infrastructure independence.
Show Me The Code
// Port (interface)
interface UserRepository {
findById(id: string): Promise<User | null>;
save(user: User): Promise<User>;
}
// Adapter (implementation)
class PostgresUserRepository implements UserRepository {
async findById(id: string) { /* SQL query */ }
async save(user: User) { /* SQL insert */ }
}
When You'll Hear This
"Hexagonal Architecture made switching from REST to GraphQL painless." / "The port defines the contract, the adapter does the work."
Related Terms
Clean Architecture
Clean Architecture is like an onion with strict rules: the inner layers (your core business logic) have absolutely no idea the outer layers (databases, API...
Dependency Inversion
Dependency Inversion says high-level code shouldn't depend on low-level code — both should depend on abstractions.
Repository Pattern
Repository Pattern puts a layer between your business logic and your database, so your business code never writes SQL directly.
SOLID (SOLID)
SOLID is five rules for writing code that doesn't turn into a nightmare over time. Each letter stands for a different rule.