Tech Flow
04.06.2025

Hexagonal Architecture: Why Every Dev Should Befriend It

Hexagonal architecture (or Ports and Adapters) is an approach that aims to make your software more maintainable, scalable, and independent of technical details. In this article find out why it is more relevant than ever, how it applies (including in the frontend), and when it is best left aside.

Written by:
William Virtuani

William Virtuani

Frontend Senior
Article cover image

SHARE

Benefits and challenges of hexagonal architecture

Let's talk about architecture. Not the one with bricks, but a software pattern that makes the eyes of anyone who's ever had to maintain a serious app sparkle — and avoid switching careers after three painful deploys: hexagonal architecture.

If you're a frontend dev thinking "meh, backend stuff," hold up: hexagonal architecture concerns you more than you think. Why? Because it's a way of designing software that doesn't fall apart every time something around it changes — like APIs, databases, frameworks, or even the whims of your product owner.

What Is Hexagonal Architecture?

Spoiler: it's got nothing to do with beehives. Also known as Ports and Adapters, hexagonal architecture is a pattern introduced by Alistair Cockburn with one clear goal: separate the core of your application (the part that does things) from the outside world (the part that breaks things). The app is drawn as a hexagon — though it could be a circle — where the core logic is isolated and communicates outward only through "ports" (interfaces) and "adapters" (concrete implementations).

In simple terms: your business logic shouldn’t care if you're using Postgres or Mongo, if calls come through REST or GraphQL, or if the frontend is written in React or Svelte.

hexagonal architecture

So is this something new?

Not at all. The original paper dates back to 2005, but its roots go even deeper, tied to Domain-Driven Design (DDD) and the idea that business logic should be protected like an endangered panda.

The truth? In many places (US, UK, Germany) it’s been standard practice for years. In Italy, as often happens, we tend to catch on when something becomes a trend on LinkedIn. Suddenly everyone talks about "hexagonal," "clean," and "onion" as if it were the latest JavaScript hype library. Better late than never. But fair warning: adopting hexagonal architecture isn’t just about adding fancy file names. It’s a mindset shift.

The Three Core Principles
  1. Independence from infrastructure
    The application logic lives blissfully unaware of the database, external APIs, or web frameworks. Zero coupling, maximum peace of mind.

  2. Directional dependencies
    Dependencies always point toward the core. Never the other way around. This means the domain doesn't care about the tech you're using outside — and that’s a beautiful thing.

  3. Extreme testability
    Clear separation of concerns means you can test your domain logic without spinning up a server, connecting to a DB, or mocking another fetch call.

Benefits (Even If You Just Do CSS™)

Maintainability

When the domain is isolated, every change doesn't turn into an earthquake. Change the database? Write a new adapter. Change the communication channel? Add a new port.

Reusability

Good hexagonal architecture lets you reuse your domain logic across different interfaces: web app, mobile, CLI, API. One brain, many bodies.

Simpler testing

Tests on the domain have no side effects. No HTTP, no database, just pure logic. It’s like training at the gym without risking a dislocated shoulder.

Team scalability

Frontend, backend, DevOps: everyone can work on different layers without stepping on each other. And the domain becomes the shared contract.

Does It Work in Frontend?

Yes — especially in serious projects. Separating business logic, presentation, and infrastructure is the healthiest way to scale a SPA (or even just keep your sanity across two sprints). With a bit of discipline, you can apply hexagonal-inspired patterns to the frontend too: think about how you structure your hooks, services, models, and components.

When Not to Use It

Let’s stay humble. Hexagonal architecture is powerful, but it's not a silver bullet.

Here are some cases where it might be overkill:

  • Short-lived or small projects: If you're spinning up an MVP in 3 days or building a form with two APIs, adding extra abstraction just creates noise.

  • Inexperienced teams: A bad implementation of hexagonal can create more confusion than clarity. If you can't tell an adapter from a gateway, maybe start simpler.

  • Performance-critical systems: Every layer adds cost. In systems where latency is measured in milliseconds (game engines, real-time microservices), a leaner approach might work better.

Bottom line: not using hexagonal architecture doesn’t make you a barbarian. You just need to know what you’re doing, and why.

A Quick Example

Let’s say you have an app that calculates quotes. The core is a module that receives input and returns a result. It doesn't care whether data comes from a form, API, or CSV file. Those are adapters. The core module is tested on its own, like a Greek god untouched by human chaos.

Conclusion

Hexagonal architecture isn’t some shiny new trend. It’s a mature, reliable pattern that helps you write software that won’t betray you at the first sign of change. It’s not a religion — it’s a mindset. One that puts your business logic at the center and everything else at the edge. And if you ever find yourself working on serious projects, you’ll realize it’s one of the best architectural decisions you can make.

If your domain knows what an HTTP request is, you're doing it wrong.

GET IN
TOUCH

Our mission is to turn your needs into solutions.

Contact us to collaborate on crafting the one that fits you best.