Skip to content

Hexagonal Architecture

Spicy — senior dev territoryArchitecture

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."

Made with passive-aggressive love by manoga.digital. Powered by Claude.