<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Bengusu Akdurucak on Medium]]></title>
        <description><![CDATA[Stories by Bengusu Akdurucak on Medium]]></description>
        <link>https://medium.com/@bengusu.akdurucak?source=rss-1d835948de58------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*lCgeUiWPXqYFZcHy</url>
            <title>Stories by Bengusu Akdurucak on Medium</title>
            <link>https://medium.com/@bengusu.akdurucak?source=rss-1d835948de58------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 20 Nov 2026 12:46:39 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@bengusu.akdurucak/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Inside vs Outside: A Practical Guide to Hexagonal Architecture]]></title>
            <link>https://medium.com/tom-tech/inside-vs-outside-a-practical-guide-to-hexagonal-architecture-c0557f00a984?source=rss-1d835948de58------2</link>
            <guid isPermaLink="false">https://medium.com/p/c0557f00a984</guid>
            <category><![CDATA[microservices]]></category>
            <dc:creator><![CDATA[Bengusu Akdurucak]]></dc:creator>
            <pubDate>Wed, 01 Oct 2025 07:31:38 GMT</pubDate>
            <atom:updated>2025-10-01T10:52:54.732Z</atom:updated>
            <content:encoded><![CDATA[<p>In modern software development, one of the recurring challenges is keeping business logic clean and independent from external concerns like databases, frameworks, and user interfaces. Over time, these dependencies creep into the core of our systems, making them harder to test, maintain, and adapt to new technologies.</p><p>To solve this, <strong>Alistair Cockburn</strong> introduced <strong>Hexagonal Architecture</strong> in 2005, also known as the <strong>Ports and Adapters pattern</strong>. Its purpose is simple yet powerful:<br> 👉 Design your application so it can function without a UI or a database, ensuring testability, flexibility, and long-term maintainability.</p><h3>What is Hexagonal Architecture?</h3><p>The essence of Hexagonal Architecture lies in preventing <strong>business logic leakage</strong> into the UI or infrastructure layers.</p><p><strong>Why is this important?</strong></p><ul><li>Tests become hard to automate when logic is tied to UI details.</li><li>Switching between human-driven and batch-driven operations becomes complex.</li><li>Applications cannot easily be driven by other programs.</li></ul><p><strong>Root cause:</strong> The entanglement of <strong>business rules</strong> with <strong>external systems</strong>.<br><strong>Principle:</strong> Inside code must never leak into the outside world.</p><h3>Core Concepts</h3><h3>1. Application Core</h3><p>The <strong>Application Core</strong> is the heart of the architecture:</p><ul><li>Contains <strong>business rules</strong> and <strong>domain logic</strong>.</li><li>Independent of UI, databases, frameworks, or external services.</li><li>Defines <strong>use cases</strong> (application services) and <strong>domain models</strong>.</li><li>Talks to the outside world only via <strong>Ports</strong>.</li><li>Developed and tested <strong>in isolation</strong>.</li><li>Adapts to new technologies quickly.</li><li>Provides a <strong>cleaner, more flexible, and understandable structure</strong>.</li></ul><h3>2. Ports</h3><p>Ports define <strong>how the core communicates with the outside world</strong>.</p><ul><li>They separate <em>what</em> the core needs from <em>how</em> it’s implemented.</li><li>Act as a <strong>contract</strong> between the core and external systems.</li><li>Keep the core agnostic of frameworks, databases, or protocols.</li><li><strong>Inbound Ports (Primary/Driving):</strong> Define how the outside world drives the application (e.g., REST APIs, Message Queues).</li><li><strong>Outbound Ports (Secondary/Driven):</strong> Define how the core interacts with external services (e.g., Repositories, Messaging).</li></ul><h3>3. Adapters</h3><p>Adapters implement the ports and act as <strong>translators</strong> between the Application Core and external systems.</p><ul><li>Ensure the core remains technology-agnostic.</li><li><strong>Inbound Adapters (Primary/Driving):</strong> Translate external requests into core calls.</li><li><strong>Outbound Adapters (Secondary/Driven):</strong> Translate core outputs into external operations.</li></ul><h3>Architecture Structure and SOLID Alignment</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/906/1*3rqDST3hB7ol8UVIjXk6_A.png" /></figure><p>At a high level, Hexagonal Architecture can be visualized as a <strong>core surrounded by ports and adapters</strong>. The core is insulated from external changes, while adapters handle communication with databases, UIs, or third-party services.</p><p>It also aligns naturally with the <strong>SOLID principles</strong>:</p><ul><li><strong>Single Responsibility:</strong> Each adapter is responsible for only one concern.</li><li><strong>Open/Closed Principle:</strong> To add new technology, you don’t modify the core — you add a new adapter.</li><li><strong>Dependency Inversion:</strong> High-level modules (core) never depend on low-level modules (adapters). Both depend on abstractions (ports).</li></ul><h3>Traditional Layered Architecture</h3><p>Before diving into comparisons, let’s briefly recall the classic layered approach.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/472/1*Ax20Evm0N-cScyACGNsS2Q.png" /></figure><p>Traditional layered architecture typically has three main layers:</p><p>· <strong>Application Layer:</strong> Manages application flow, coordinates user requests, and triggers business operations.</p><p>· <strong>Business Logic Layer:</strong> Where rules are applied, data is processed, and transactions are controlled.</p><p>· <strong>Persistence Layer:</strong> Handles CRUD operations and interacts with data sources like SQL or NoSQL databases.</p><p>While this approach is simple and widely used, over time the layers often become tightly coupled, making business logic dependent on UI and database details. As the system grows, testing becomes harder and flexibility is lost.</p><h3>Example: Java Package Structure in Layered Architecture</h3><p>A common structure in Spring Boot projects looks like this:</p><pre>com.example.demo<br> ├── controller<br> │    └── UserController.java<br> ├── service<br> │    └── UserService.java<br> ├── repository<br> │    └── UserRepository.java<br> ├── model<br> │    └── User.java</pre><ul><li>Controllers depend on Services.</li><li>Services depend on Repositories.</li><li>Business logic often leaks into the Repository or even Controller layer.</li><li>Replacing a database or changing the UI usually ripples through all layers.</li></ul><h3>Hexagonal Architecture Package Structures</h3><p>Unlike layered architecture, Hexagonal focuses on <strong>separating the core (business logic + use cases) from external concerns</strong> (UI, DB, messaging). There are two common ways to organize packages:</p><h3>1. DDD-Oriented Package Structure</h3><p>This approach separates <strong>domain</strong> and <strong>application</strong> explicitly, closer to Domain-Driven Design (DDD):</p><pre>com.example.demo<br> ├── domain<br> │    ├── model<br> │    │    └── User.java<br> │    └── service<br> │         └── UserService.java<br> ├── application<br> │    └── port<br> │         ├── in<br> │         │    └── CreateUserUseCase.java<br> │         └── out<br> │              └── SaveUserPort.java<br> ├── adapter<br> │    ├── in<br> │    │    └── web<br> │    │         └── UserController.java<br> │    └── out<br> │         └── persistence<br> │              └── UserRepositoryAdapter.java</pre><ul><li><strong>domain</strong>: Models and pure business logic.</li><li><strong>application</strong>: Ports (use cases &amp; contracts).</li><li><strong>adapter</strong>: Implementations for web, DB, messaging, etc.</li><li>Pros: Clean separation, aligns with DDD.</li><li>Cons: Can feel heavy for smaller projects.</li></ul><h3>2. Pragmatic Package Structure</h3><p>A lighter approach often used in Spring Boot projects. Here <strong>domain and application logic live together</strong> under the application package:</p><pre>com.example.demo<br> ├── application<br> │    ├── model<br> │    │    └── User.java<br> │    ├── service<br> │    │    └── UserService.java<br> │    ├── port<br> │    │    ├── in<br> │    │    │    └── CreateUserUseCase.java<br> │    │    └── out<br> │    │         └── SaveUserPort.java<br> ├── adapter<br> │    ├── in<br> │    │    └── web<br> │    │         └── UserController.java<br> │    └── out<br> │         └── persistence<br> │              └── UserRepositoryAdapter.java</pre><ul><li><strong>application</strong>: Includes domain models, business services, and ports.</li><li><strong>adapter</strong>: Handle external technologies.</li><li>Pros: Simpler, easier adoption in Java/Spring projects.</li><li>Cons: Less explicit separation compared to strict DDD.</li></ul><h3>Comparison with Layered Architecture</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*BEt89xlKOYWYesueFV2niQ.png" /></figure><h3>Advantages and Challenges</h3><h3>✅ Advantages</h3><ul><li><strong>Separation of Concerns:</strong> Clear split between business logic and infrastructure.</li><li><strong>Core Independence:</strong> Application core developed &amp; tested in isolation.</li><li><strong>Testability:</strong> Easier unit/integration tests without UI/DB.</li><li><strong>Flexibility:</strong> Swap or add new adapters with minimal changes.</li><li><strong>Maintainability:</strong> Modular code; localized changes reduce bugs.</li><li><strong>Extensibility:</strong> Add new interfaces or integrations via ports/adapters.</li><li><strong>Parallel Development:</strong> Teams can work independently on the core vs adapters.</li></ul><h3>⚠️ Challenges</h3><ul><li><strong>Initial Complexity:</strong> More upfront design effort.</li><li><strong>Learning Curve:</strong> Requires shift to DDD / Clean Architecture mindset.</li><li><strong>Overhead for Simple Apps:</strong> Might feel like over-engineering.</li><li><strong>Extra Abstraction:</strong> Ports/adapters can add cognitive load.</li><li><strong>Adapter Management:</strong> Maintenance effort grows with integrations.</li><li><strong>Discipline:</strong> Strict boundaries must be enforced to keep logic pure.</li></ul><h3>Trade-offs</h3><p>Hexagonal Architecture is not without trade-offs. It requires upfront investment in design, a shift in mindset, and the discipline to keep business logic pure. For small or simple applications, it can feel like over-engineering.</p><p>However, in large, evolving systems, this investment pays off. The payoff comes in the form of <strong>flexibility</strong>, <strong>sustainability</strong>, and <strong>testability</strong> — qualities that are critical in today’s rapidly changing software landscape.</p><h3>Conclusion</h3><p>Hexagonal Architecture is more than a pattern — it’s a mindset. By separating the <strong>inside</strong> (business logic) from the <strong>outside</strong> (UI, databases, frameworks), it helps developers build systems that are <strong>flexible, testable, and maintainable over the long run</strong>.</p><p>In a world where frameworks and tools change rapidly, Hexagonal Architecture ensures that your application’s <strong>core value lives on — independent of technology trends.</strong></p><h3>Further Reading / Resources</h3><p>If you’d like to dive deeper into Hexagonal Architecture and related practices, here are some recommended resources:</p><ul><li><a href="https://alistair.cockburn.us/hexagonal-architecture">Alistair Cockburn’s Original Article on Hexagonal Architecture (2005)</a></li><li><a href="https://www.domainlanguage.com/ddd/">Domain-Driven Design by Eric Evans</a></li><li><a href="https://blog.cleancoder.com/">Clean Architecture by Robert C. Martin</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c0557f00a984" width="1" height="1" alt=""><hr><p><a href="https://medium.com/tom-tech/inside-vs-outside-a-practical-guide-to-hexagonal-architecture-c0557f00a984">Inside vs Outside: A Practical Guide to Hexagonal Architecture</a> was originally published in <a href="https://medium.com/tom-tech">TOM Tech</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>