Skip to content
IRC-Coding IRC-Coding
Hexagonal Architecture Ports and Adapters Dependency Inversion Clean Architecture Software Architecture

Hexagonal Architecture (Ports and Adapters) Explained

Hexagonal Architecture (Ports and Adapters) explained: domain core, ports, adapters, dependency inversion, examples, exam questions.

S

schutzgeist

2 min read

Hexagonal Architecture

This article is a definition of terms for Hexagonal Architecture (Ports and Adapters) – including typical exam questions, brief key points, and tags for review.

What is Hexagonal Architecture?

Hexagonal Architecture (also called Ports and Adapters) is an architectural approach that strictly separates the business core (domain / use cases) from external dependencies – such as:

  • UI (Web, Mobile, CLI)
  • Database
  • Message Broker
  • external APIs

The core idea: The core defines what it needs (ports/interfaces). The infrastructure provides interchangeable implementations (adapters).

The Building Blocks: Domain, Ports, Adapters

Domain Core

At the center lies the business logic:

  • Entities / Value Objects
  • Use Cases / Application Services
  • Business rules

Ports

Ports are interfaces that establish the direction of dependency:

  • Inbound Ports: What the application offers (use cases, commands)
  • Outbound Ports: What the application needs (repositories, payment, mail, logging)

Adapters

Adapters connect ports with concrete technology:

  • Inbound Adapter: REST Controller, GraphQL Resolver, CLI, Scheduler
  • Outbound Adapter: DB Repository, HTTP Client, Cache, Message Producer

Why Is This Helpful? (Advantages)

  • Testability: Core logic can be tested without DB/HTTP (mocks/fakes on ports)
  • Interchangeability: Technology changes affect adapters, not the core
  • Reduced Coupling: fewer framework dependencies in domain code
  • Clean Responsibilities: clear system boundaries

Typical Disadvantages / Trade-offs

  • More abstraction (ports/adapters) = more artifacts
  • Higher initial effort (wiring, DI, mapping)
  • Learning curve for teams used to “developing directly against frameworks”

Mini Practical Example (simplified)

Idea

A use case “pay order” only knows ports. A Stripe adapter or a DB adapter can be swapped out later.

// Inbound Port
export interface PayOrderUseCase {
  pay(orderId: string): Promise<string>;
}

// Outbound Ports
export interface OrderRepositoryPort {
  findById(orderId: string): Promise<any>;
  save(order: any): Promise<void>;
}

export interface PaymentProviderPort {
  charge(amountInCents: number, customerId: string): Promise<{ transactionId: string }>;
}

Typical Exam Questions (with Short Answers)

  1. What is the goal of hexagonal architecture? Decoupling business logic from technical details via ports and adapters.
  2. Inbound vs. Outbound Adapter – difference? Inbound brings requests into the core, outbound implements infrastructure access.
  3. How is Dependency Inversion implemented here? The core defines ports (interfaces), the infrastructure implements them.
  4. Why is this relevant for IHK? You can justify architectural decisions with testability, maintainability, and technology independence.

Conclusion

Hexagonal architecture is particularly suitable when you prioritize long-term maintainability, good tests, and technology independence.

Back to Blog
Share:

Related Posts