<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: David Pereira</title>
    <description>The latest articles on DEV Community by David Pereira (@pereiren).</description>
    <link>https://dev.to/pereiren</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F354766%2Fad5e51fb-955f-49ac-80bc-cb2b57dbe3c9.png</url>
      <title>DEV Community: David Pereira</title>
      <link>https://dev.to/pereiren</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/pereiren"/>
    <language>en</language>
    <item>
      <title>A simple template for Onion Architecture with .NET 5</title>
      <dc:creator>David Pereira</dc:creator>
      <pubDate>Thu, 04 Feb 2021 11:00:31 +0000</pubDate>
      <link>https://dev.to/pereiren/a-simple-template-for-onion-architecture-with-net-5-3gll</link>
      <guid>https://dev.to/pereiren/a-simple-template-for-onion-architecture-with-net-5-3gll</guid>
      <description>&lt;p&gt;Just wanted to share a simple approach for Onion Architecture that has saved me a lot of time engaging productivity for everyone on my team.&lt;/p&gt;

&lt;h2&gt;
  
  
  Quick Reminder
&lt;/h2&gt;

&lt;p&gt;If you couldn’t check my series about Clean Architecture feel free to take a look at them (sorry for the spam):&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://dev.to/pereiren/clean-architecture-series-part-1-m64"&gt;Clean architecture series— Part 1&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://dev.to/pereiren/clean-architecture-series-part-2-49db"&gt;Clean architecture series — Part 2&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://dev.to/pereiren/clean-architecture-series-part-3-2795"&gt;Clean architecture series— Part 3&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  My simple template for Onion Architecture with .NET 5
&lt;/h2&gt;

&lt;p&gt;Clean architectures are awesome, I don’t have any doubt about that. Highly scalable, fully testable, easy to evolve, easy to adapt to new requirements, etc etc etc.&lt;/p&gt;

&lt;p&gt;But unfortunately, I must say that they are not for everyone. If you start adding Input Ports, Use Cases, Output Ports, Presenters, and also adding a DDD approach together with CQRS and Event Sourcing you are adding a kind of steep learning curve for newcomers or people without deep knowledge about good practices, clean code, and related stuff.&lt;/p&gt;

&lt;p&gt;And that’s completely fine when you work in a team you need to work as a team, understanding everyone’s point of view and trying to grow all together.&lt;/p&gt;

&lt;h3&gt;
  
  
  So, how did I try to solve this? How did I promote the usage of good practices in terms of architecture especially when building microservices or serverless functions without overwhelming with a ton of new concepts?
&lt;/h3&gt;

&lt;p&gt;I created this template:&lt;br&gt;
&lt;/p&gt;
&lt;div class="ltag-github-readme-tag"&gt;
  &lt;div class="readme-overview"&gt;
    &lt;h2&gt;
      &lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev.to%2Fassets%2Fgithub-logo-5a155e1f9a670af7944dd5e12375bc76ed542ea80224905ecaf878b9157cdefc.svg" alt="GitHub logo"&gt;
      &lt;a href="https://github.com/pereiren" rel="noopener noreferrer"&gt;
        pereiren
      &lt;/a&gt; / &lt;a href="https://github.com/pereiren/dotnet-template-onion" rel="noopener noreferrer"&gt;
        dotnet-template-onion
      &lt;/a&gt;
    &lt;/h2&gt;
    &lt;h3&gt;
      Onion Architecture with .NET 6/.NET Core and CQRS/Event Sourcing following a DDD approach
    &lt;/h3&gt;
  &lt;/div&gt;
  &lt;div class="ltag-github-body"&gt;
    
&lt;div id="readme" class="md"&gt;
&lt;div class="markdown-heading"&gt;
&lt;h1 class="heading-element"&gt;dotnet-template-onion&lt;/h1&gt;
&lt;/div&gt;
&lt;p&gt;
  &lt;a rel="noopener noreferrer" href="https://github.com/pereiren/dotnet-template-onionimages/logo.jpg"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fgithub.com%2Fpereiren%2Fdotnet-template-onionimages%2Flogo.jpg" alt="dotnet-template-onion logo" width="400"&gt;&lt;/a&gt;
&lt;/p&gt;

&lt;p&gt;A .NET/.NET Core template to use Onion Architecture and DDD (Domain Driven Design) with CQRS and ES with a simple example on how to use all this architecture together from the Controller until the Repository class using Domain objects and different patterns.&lt;/p&gt;

&lt;div class="markdown-heading"&gt;
&lt;h3 class="heading-element"&gt;Documentation&lt;/h3&gt;
&lt;/div&gt;

&lt;p&gt;You can find information about this template in:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://github.com/pereiren/dotnet-template-oniondocs/ARCHITECTURE.md" rel="noopener noreferrer"&gt;Main Architecture&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://github.com/pereiren/dotnet-template-oniondocs/HEXAGONAL.md" rel="noopener noreferrer"&gt;Hexagonal Architecture&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://github.com/pereiren/dotnet-template-oniondocs/DDD.md" rel="noopener noreferrer"&gt;DDD&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://github.com/pereiren/dotnet-template-oniondocs/CQRS-ES.md" rel="noopener noreferrer"&gt;CQRS AND ES&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://github.com/pereiren/dotnet-template-oniondocs/SOLID.md" rel="noopener noreferrer"&gt;SOLID&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="markdown-heading"&gt;
&lt;h3 class="heading-element"&gt;Prerequisites&lt;/h3&gt;
&lt;/div&gt;

&lt;div class="markdown-heading"&gt;
&lt;h4 class="heading-element"&gt;.NET 6&lt;/h4&gt;

&lt;/div&gt;

&lt;p&gt;Ensure you have the correct dotnet-core SDK installed for your system:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://dotnet.microsoft.com/download/dotnet/6.0" rel="nofollow noopener noreferrer"&gt;https://dotnet.microsoft.com/download/dotnet/6.0&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This is just the version used by the template, if you need to use a newer or older one, you can do it manually after.&lt;/p&gt;

&lt;div class="markdown-heading"&gt;
&lt;h3 class="heading-element"&gt;Usage&lt;/h3&gt;

&lt;/div&gt;

&lt;ol&gt;
&lt;li&gt;Clone this repository&lt;/li&gt;
&lt;li&gt;To allow the api to be created you will need to install the template from nuget:&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="snippet-clipboard-content notranslate position-relative overflow-auto"&gt;&lt;pre class="notranslate"&gt;&lt;code&gt;dotnet new -i {{Path_where_you_cloned_the_repository}}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;ul&gt;
&lt;li&gt;Example:&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="snippet-clipboard-content notranslate position-relative overflow-auto"&gt;&lt;pre class="notranslate"&gt;&lt;code&gt;dotnet new -i C:\GitLocal\dotnet-template-onion
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;ol start="3"&gt;
&lt;li&gt;To check that the template has been installed successfully:&lt;/li&gt;
&lt;/ol&gt;
&lt;div class="snippet-clipboard-content notranslate position-relative overflow-auto"&gt;&lt;pre class="notranslate"&gt;&lt;code&gt;dotnet new -l
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;ul&gt;
&lt;li&gt;There should now be a new template &lt;strong&gt;dotnet_template_onion&lt;/strong&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="snippet-clipboard-content notranslate position-relative overflow-auto"&gt;…&lt;/div&gt;
&lt;/div&gt;
  &lt;/div&gt;
  &lt;div class="gh-btn-container"&gt;&lt;a class="gh-btn" href="https://github.com/pereiren/dotnet-template-onion" rel="noopener noreferrer"&gt;View on GitHub&lt;/a&gt;&lt;/div&gt;
&lt;/div&gt;



&lt;p&gt;It’s just a simple Onion Architecture with CQRS and Event Sourcing. You can use it as you want, you can create a GitHub repository using the template from there or just doing a fork/clone and creating the template from the dotnet CLI.&lt;/p&gt;

&lt;p&gt;Just to understand it better I created this diagram which tries to explain everything that can happen in the code:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F3108%2F1%2Ali_AWJUzt1i4dxjYfbwSjg.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F3108%2F1%2Ali_AWJUzt1i4dxjYfbwSjg.jpeg" alt="High Res: [https://raw.githubusercontent.com/pereiren/dotnet-template-onion/master/images/dotnet-onion-ddd-cqrs-es.jpg](https://raw.githubusercontent.com/pereiren/dotnet-template-onion/master/images/dotnet-onion-ddd-cqrs-es.jpg)"&gt;&lt;/a&gt;&lt;em&gt;High Res: &lt;a href="https://raw.githubusercontent.com/pereiren/dotnet-template-onion/master/images/dotnet-onion-ddd-cqrs-es.jpg" rel="noopener noreferrer"&gt;https://raw.githubusercontent.com/pereiren/dotnet-template-onion/master/images/dotnet-onion-ddd-cqrs-es.jpg&lt;/a&gt;&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;This is the structure tree of the repository:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;C:.
│   .gitignore
│   Dotnet.Onion.Template.sln
│   README.md
│
├───docs
│       ARCHITECTURE.md
│       CQRS-ES.md
│       DDD.md
│       HEXAGONAL.md
│       SOLID.md
│
├───images
│       dotnet-onion-ddd-cqrs-es.jpg
│
├───src
│   ├───Dotnet.Onion.Template.API
│   │   │   .dockerignore
│   │   │   Dockerfile
│   │   │   Dotnet.Onion.Template.API.csproj
│   │   │   Program.cs
│   │   │   Startup.cs
│   │   │
│   │   ├───Bindings
│   │   ├───Config
│   │   │       appsettings-dev.json
│   │   │       appsettings-int.json
│   │   │       appsettings-prod.json
│   │   │       appsettings-stag.json
│   │   │
│   │   ├───Controllers
│   │   │       TasksController.cs
│   │   │
│   │   ├───Extensions
│   │   │   └───Middleware
│   │   │           ErrorDetails.cs
│   │   │           ExceptionMiddleware.cs
│   │   │
│   │   └───Properties
│   │           launchSettings.json
│   │
│   ├───Dotnet.Onion.Template.Application
│   │   │   Dotnet.Onion.Template.Application.csproj
│   │   │
│   │   ├───Handlers
│   │   │       TaskCommandHandler.cs
│   │   │       TaskEventHandler.cs
│   │   │
│   │   ├───Mappers
│   │   │       TaskViewModelMapper.cs
│   │   │
│   │   ├───Services
│   │   │       ITaskService.cs
│   │   │       TaskService.cs
│   │   │
│   │   └───ViewModels
│   │           TaskViewModel.cs
│   │
│   ├───Dotnet.Onion.Template.Domain
│   │   │   Dotnet.Onion.Template.Domain.csproj
│   │   │   IAggregateRoot.cs
│   │   │   IRepository.cs
│   │   │
│   │   └───Tasks
│   │       │   ITaskFactory.cs
│   │       │   ITaskRepository.cs
│   │       │   Task.cs
│   │       │
│   │       ├───Commands
│   │       │       CreateNewTaskCommand.cs
│   │       │       DeleteTaskCommand.cs
│   │       │       TaskCommand.cs
│   │       │
│   │       ├───Events
│   │       │       TaskCreatedEvent.cs
│   │       │       TaskDeletedEvent.cs
│   │       │       TaskEvent.cs
│   │       │
│   │       └───ValueObjects
│   │               Description.cs
│   │               Summary.cs
│   │               TaskId.cs
│   │
│   └───Dotnet.Onion.Template.Infrastructure
│       │   Dotnet.Onion.Template.Infrastructure.csproj
│       │
│       ├───Factories
│       │       EntityFactory.cs
│       │       TaskFactory.cs
│       │
│       └───Repositories
│               TaskRepository.cs
│
└───tests
    └───Dotnet.Onion.Template.Tests
        │   Dotnet.Onion.Template.Tests.csproj
        │
        └───UnitTests
            ├───Application
            │   └───Services
            │           TaskServiceTests.cs
            │
            └───Helpers
                    HttpContextHelper.cs
                    TaskHelper.cs
                    TaskViewModelHelper.cs
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;p&gt;As you can see, it has the shape of an onion and it has three common layers:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Application layer:&lt;/strong&gt; where all the business logic is implemented&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Domain layer:&lt;/strong&gt; where our domain is modeled (Task aggregate domain model for example) and some patterns about DDD are there like Repository Pattern (only interfaces, not implementation)&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Infrastructure layer:&lt;/strong&gt; where we implement the code that needs to go outside our application, like for example data access implementation&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;There can be external layers which are called presentation layers or testing layers. For example, in a common API, the external layer is RestAPI which has the dependencies to handle APIs with ASP.NET Core but in a Cron Job we don’t have APIs, so this external layer is a Console application layer that handles all that we need to start the application and the definition of the workflow to process some data.&lt;/p&gt;

&lt;p&gt;I didn’t add any library like AutoMapper or similar because I wanted to remain agnostic about that. If you want to use AutoMapper or any similar NuGet package feel free. The same thing with FluentMediator, I find it really useful and I wanted to handle my Mediator Bus with that package but if you would like to use MediatR you can do it without any problem, you just need to modify the code related to IMediator implementations and definitions.&lt;/p&gt;

&lt;p&gt;Going back to the diagram, if you did read my previous articles you will be familiar with The Dependency Rule. It is the most important thing when building a Clean Architecture and summarizing this rule says that the concentric circles represent different areas of software. In general, the further in you go, the higher level the software becomes. &lt;strong&gt;&lt;em&gt;The outer circles are mechanisms. The inner circles are policies.&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  What does that mean?
&lt;/h3&gt;

&lt;p&gt;Nothing in an inner circle can know anything at all about something in an outer circle. In particular, the name of something declared in an outer circle must not be mentioned by the code in an inner circle. That includes functions, classes. variables, or any other named software entity.&lt;/p&gt;
&lt;h2&gt;
  
  
  CQRS and Event Sourcing
&lt;/h2&gt;

&lt;p&gt;This is another thing I wanted to promote with my team (and also more teams). When designing a distributed architecture I think that CQRS (Command Query Responsibility Segregation) and ES (Event Sourcing) can help a lot. Of course, they are not a Silver Bullet, they are just patterns that you can follow if your microservice needs it or not.&lt;/p&gt;

&lt;p&gt;And that’s why I included it inside my template because it can be useful for anyone. Also, I didn’t want to introduce CQRS and Event Sourcing with difficult examples with different databases and propagating changes from the Write DB to the Read DB. It is just a simple “DataBase” (there is no database access, just creating mocked data inside the Repository implementation).&lt;/p&gt;

&lt;p&gt;If you are a little bit familiar with CQRS you know that there are two flows (models):&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Reading (Queries):&lt;/strong&gt; It is going to use Dependency Injection to the Repository class that it needs to go to the Database or any kind of data source system. The definition of that repository class is an interface, a contract, inside our Domain Layer (you can see that in the upper right corner of the diagram which is an image from the original post about Onion Architecture in 2008). The implementation as I mentioned before, should be outside the Domain Layer, in fact, it is inside the Infrastructure Layer. Why? Because if you are building the Repository implementation in the domain you are coupling the domain to the data source access and also you are breaking &lt;strong&gt;The Dependency Rule&lt;/strong&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Writing (Commands)&lt;/strong&gt;: If you are &lt;strong&gt;modifying the Aggregate state **(for example Tasks Aggregate) you need to specify that **creating a Domain Command **in the code to use CQRS properly. So from this point, if you want to use Domain Commands and CQRS in a way to get the best performance you just need to use a message bus. **In our case, we chose to use the Mediator pattern which creates an internal bus and it is the one managing or handling the Domain Commands to use Handlers.&lt;/strong&gt; These handlers are going to be called by a different thread any time, and if the thread pool is locked, the Domain Command is going to be in the Mediator bus waiting for a thread to be released and execute the rest of the code. This is everything C# magic and we just need to use the Mediator library to use this pattern. Once the code arrives at the specific Handler for any Command with a different thread, it is going to perform the changes in the data source (can be a database, API, etc) using the Repository pattern. But as I mentioned before using Dependency Injection to get a fully testable code following the dependency rule and SOLID principles applied in the architecture.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;And in that way, if you need it, once the Handler calls the Repository to perform the changes, you may raise an event that can go to any event store (a queue) and propagate the data to other microservices consuming information from that event store. For example, a Notification microservice that sends an email or something like that.&lt;/p&gt;

&lt;p&gt;And that’s it! I tried to keep it simple as much as I could but providing a nice starting point for everyone as I mentioned at the beginning. If you and your team have the skills to implement more complete architectures definitely you should go that way. If not, you can try with simpler solutions and start understanding all concepts, seeing the benefits and the cons of everything, and grow as a software engineer.&lt;/p&gt;

&lt;p&gt;If you have any question, feel free to send me a message on &lt;a href="https://www.linkedin.com/in/davidpereirac/" rel="noopener noreferrer"&gt;LinkedIn&lt;/a&gt;, here or my email, I will happily reply.&lt;/p&gt;

&lt;p&gt;And last but not least, feel free to check the documentation in the repository, fork it, debug it, and if you like it, clicking on the star!&lt;br&gt;
&lt;/p&gt;
&lt;div class="ltag-github-readme-tag"&gt;
  &lt;div class="readme-overview"&gt;
    &lt;h2&gt;
      &lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev.to%2Fassets%2Fgithub-logo-5a155e1f9a670af7944dd5e12375bc76ed542ea80224905ecaf878b9157cdefc.svg" alt="GitHub logo"&gt;
      &lt;a href="https://github.com/pereiren" rel="noopener noreferrer"&gt;
        pereiren
      &lt;/a&gt; / &lt;a href="https://github.com/pereiren/dotnet-template-onion" rel="noopener noreferrer"&gt;
        dotnet-template-onion
      &lt;/a&gt;
    &lt;/h2&gt;
    &lt;h3&gt;
      Onion Architecture with .NET 6/.NET Core and CQRS/Event Sourcing following a DDD approach
    &lt;/h3&gt;
  &lt;/div&gt;
  &lt;div class="ltag-github-body"&gt;
    
&lt;div id="readme" class="md"&gt;
&lt;div class="markdown-heading"&gt;
&lt;h1 class="heading-element"&gt;dotnet-template-onion&lt;/h1&gt;
&lt;/div&gt;

&lt;p&gt;
  &lt;a rel="noopener noreferrer" href="https://github.com/pereiren/dotnet-template-onionimages/logo.jpg"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fgithub.com%2Fpereiren%2Fdotnet-template-onionimages%2Flogo.jpg" alt="dotnet-template-onion logo" width="400"&gt;&lt;/a&gt;
&lt;/p&gt;

&lt;p&gt;A .NET/.NET Core template to use Onion Architecture and DDD (Domain Driven Design) with CQRS and ES with a simple example on how to use all this architecture together from the Controller until the Repository class using Domain objects and different patterns.&lt;/p&gt;

&lt;div class="markdown-heading"&gt;
&lt;h3 class="heading-element"&gt;Documentation&lt;/h3&gt;
&lt;/div&gt;

&lt;p&gt;You can find information about this template in:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://github.com/pereiren/dotnet-template-oniondocs/ARCHITECTURE.md" rel="noopener noreferrer"&gt;Main Architecture&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://github.com/pereiren/dotnet-template-oniondocs/HEXAGONAL.md" rel="noopener noreferrer"&gt;Hexagonal Architecture&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://github.com/pereiren/dotnet-template-oniondocs/DDD.md" rel="noopener noreferrer"&gt;DDD&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://github.com/pereiren/dotnet-template-oniondocs/CQRS-ES.md" rel="noopener noreferrer"&gt;CQRS AND ES&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://github.com/pereiren/dotnet-template-oniondocs/SOLID.md" rel="noopener noreferrer"&gt;SOLID&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="markdown-heading"&gt;
&lt;h3 class="heading-element"&gt;Prerequisites&lt;/h3&gt;
&lt;/div&gt;

&lt;div class="markdown-heading"&gt;
&lt;h4 class="heading-element"&gt;.NET 6&lt;/h4&gt;

&lt;/div&gt;

&lt;p&gt;Ensure you have the correct dotnet-core SDK installed for your system:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://dotnet.microsoft.com/download/dotnet/6.0" rel="nofollow noopener noreferrer"&gt;https://dotnet.microsoft.com/download/dotnet/6.0&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This is just the version used by the template, if you need to use a newer or older one, you can do it manually after.&lt;/p&gt;

&lt;div class="markdown-heading"&gt;
&lt;h3 class="heading-element"&gt;Usage&lt;/h3&gt;

&lt;/div&gt;

&lt;ol&gt;
&lt;li&gt;Clone this repository&lt;/li&gt;
&lt;li&gt;To allow the api to be created you will need to install the template from nuget:&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="snippet-clipboard-content notranslate position-relative overflow-auto"&gt;&lt;pre class="notranslate"&gt;&lt;code&gt;dotnet new -i {{Path_where_you_cloned_the_repository}}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;ul&gt;
&lt;li&gt;Example:&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="snippet-clipboard-content notranslate position-relative overflow-auto"&gt;&lt;pre class="notranslate"&gt;&lt;code&gt;dotnet new -i C:\GitLocal\dotnet-template-onion
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;ol start="3"&gt;
&lt;li&gt;To check that the template has been installed successfully:&lt;/li&gt;
&lt;/ol&gt;
&lt;div class="snippet-clipboard-content notranslate position-relative overflow-auto"&gt;&lt;pre class="notranslate"&gt;&lt;code&gt;dotnet new -l
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;ul&gt;
&lt;li&gt;There should now be a new template &lt;strong&gt;dotnet_template_onion&lt;/strong&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="snippet-clipboard-content notranslate position-relative overflow-auto"&gt;…&lt;/div&gt;
&lt;/div&gt;
  &lt;/div&gt;
  &lt;div class="gh-btn-container"&gt;&lt;a class="gh-btn" href="https://github.com/pereiren/dotnet-template-onion" rel="noopener noreferrer"&gt;View on GitHub&lt;/a&gt;&lt;/div&gt;
&lt;/div&gt;



&lt;p&gt;I hope you enjoyed it and it was clear what I wanted to do.&lt;/p&gt;

&lt;p&gt;Thanks for reading!&lt;/p&gt;

</description>
      <category>dotnet</category>
      <category>architecture</category>
      <category>productivity</category>
      <category>microservices</category>
    </item>
    <item>
      <title>Clean architecture series — Part 3</title>
      <dc:creator>David Pereira</dc:creator>
      <pubDate>Mon, 20 Apr 2020 07:11:40 +0000</pubDate>
      <link>https://dev.to/pereiren/clean-architecture-series-part-3-2795</link>
      <guid>https://dev.to/pereiren/clean-architecture-series-part-3-2795</guid>
      <description>&lt;p&gt;“ Anxiety arises from not being able to see the whole picture. If you feel anxious but you are not sure why, try putting your things in order.” — Marie Kondo&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--UI1wMaUO--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/1024/1%2A9_xIZvlpZ2ZrMp-LdrrUkA.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--UI1wMaUO--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/1024/1%2A9_xIZvlpZ2ZrMp-LdrrUkA.png" alt=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  The Clean Architecture 🧹
&lt;/h3&gt;

&lt;p&gt;We &lt;strong&gt;have seen what Hexagonal and Onion Architectures are&lt;/strong&gt; , so the &lt;strong&gt;next step&lt;/strong&gt; is to review what &lt;strong&gt;Clean Architecture means&lt;/strong&gt;.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;You can check the first two articles about Hexagonal and Onion architectures here:&lt;/p&gt;
&lt;/blockquote&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://dev.to/pereiren/clean-architecture-series-part-1-m64"&gt;Clean architecture series— Part 1&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://dev.to/pereiren/clean-architecture-series-part-2-49db"&gt;Clean architecture series — Part 2&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  What is Clean Architecture?
&lt;/h3&gt;

&lt;p&gt;Architecture pattern &lt;a href="https://blog.cleancoder.com/uncle-bob/2012/08/13/the-clean-architecture.html"&gt;promoted by Robert C. Martin (Uncle Bob) in 2012&lt;/a&gt; trying to do one more step in architecture patterns when thinking about isolated, maintainable, testable, scalable, evolutive and well-written code. Following similar principles to Hexagonal and Onion, Uncle Bob presented his architecture together with this diagram:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--GaptGMnZ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/772/0%2A4SYfkCc1p5Z62psJ.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--GaptGMnZ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/772/0%2A4SYfkCc1p5Z62psJ.jpg" alt=""&gt;&lt;/a&gt;&lt;a href="https://blog.cleancoder.com/uncle-bob/images/2012-08-13-the-clean-architecture/CleanArchitecture.jpg"&gt;&lt;/a&gt;&lt;a href="https://blog.cleancoder.com/uncle-bob/images/2012-08-13-the-clean-architecture/CleanArchitecture.jpg"&gt;https://blog.cleancoder.com/uncle-bob/images/2012-08-13-the-clean-architecture/CleanArchitecture.jpg&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The &lt;strong&gt;main goal of this architecture is the separation of concerns&lt;/strong&gt;. Uncle Bob mentioned that &lt;strong&gt;he didn’t want to create another new and totally different architecture from Hexagonal and Onion&lt;/strong&gt;. In fact, he did want to integrate &lt;strong&gt;all of these great architectures into a single actionable idea&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;The key principles of this architecture are:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;It’s really about the &lt;strong&gt;Separation of Concerns&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;Should be &lt;strong&gt;independent of frameworks&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;They should be  &lt;strong&gt;testable&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;They should be &lt;strong&gt;independent of a UI&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;They should be &lt;strong&gt;independent of a database&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;The &lt;strong&gt;Clean Architecture Diagram&lt;/strong&gt;
 —  &lt;strong&gt;Innermost&lt;/strong&gt; : “Enterprise / Critical Business Rules” ( &lt;strong&gt;Entities&lt;/strong&gt; )
 —  &lt;strong&gt;Next out&lt;/strong&gt; : “Application business rules” ( &lt;strong&gt;Use Cases&lt;/strong&gt; )
 —  &lt;strong&gt;Next out&lt;/strong&gt; : “Interface adapters” ( &lt;strong&gt;Gateways, Controllers, Presenters&lt;/strong&gt; )
 —  &lt;strong&gt;Outer&lt;/strong&gt; : “Frameworks and drivers” ( &lt;strong&gt;Devices, Web, UI, External Interfaces, DB&lt;/strong&gt; )&lt;/li&gt;
&lt;li&gt;The &lt;strong&gt;innermost circle&lt;/strong&gt; is the most general/ &lt;strong&gt;highest level&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Inner circles are policies&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Outer circles are mechanisms&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Inner circles cannot depend on outer circles&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Outer circles cannot influence inner circles&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;So yes, these principles are coming from Hexagonal and Onion architectures as you must be wondering right now.&lt;/p&gt;

&lt;p&gt;Also, all of these principles are following the same rule, which is…&lt;/p&gt;

&lt;h3&gt;
  
  
  The Dependency Rule
&lt;/h3&gt;

&lt;p&gt;The concentric circles represent different areas of software. In general, &lt;strong&gt;the further in you go, the higher level the software becomes. The outer circles are mechanisms. The inner circles are policies.&lt;/strong&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  What does that mean?
&lt;/h4&gt;

&lt;p&gt;&lt;strong&gt;Nothing in an inner circle can know anything at all about something in an outer circle&lt;/strong&gt;. In particular, the &lt;strong&gt;name of something declared in an outer circle must not be mentioned by the code in an inner circle&lt;/strong&gt;. That includes functions, classes. variables, or any other named software entity.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;For example:&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Elements located in the Entities circle&lt;/strong&gt; (the enterprise business rules) &lt;strong&gt;should not refer to any elements outside of it&lt;/strong&gt; (such as application business rules, interface adapters, frameworks, and drivers).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Data formats used in an outer circle should never be used by an inner circle&lt;/strong&gt; , especially if they are generated by a framework in an outer circle. The Clean Architecture prevents anything in an outer circle to impact the inner circles as shown in the following diagram:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--ZWFmFCmh--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/1024/0%2A00xx3fNwcNgsI1eV.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--ZWFmFCmh--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/1024/0%2A00xx3fNwcNgsI1eV.png" alt=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;With that in mind already, let’s take a look at the defined circles in the diagram&lt;/p&gt;

&lt;h3&gt;
  
  
  Circles of the Clean Architecture
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--0n-0ojqq--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/772/0%2AbQfITslYN44TZOGz.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--0n-0ojqq--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/772/0%2AbQfITslYN44TZOGz.jpg" alt=""&gt;&lt;/a&gt;&lt;a href="https://www.codingblocks.net/wp-content/uploads/2018/02/The-Clean-Architecture-Cone.jpg"&gt;&lt;/a&gt;&lt;a href="https://www.codingblocks.net/wp-content/uploads/2018/02/The-Clean-Architecture-Cone.jpg"&gt;https://www.codingblocks.net/wp-content/uploads/2018/02/The-Clean-Architecture-Cone.jpg&lt;/a&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  Entities
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;Entities encapsulate &lt;em&gt;Enterprise-wide&lt;/em&gt; business rules.&lt;/li&gt;
&lt;li&gt;An entity can be an object with methods, or it can be a set of data structures and functions. It doesn’t matter so long as the entities could be used by many different applications in the enterprise.&lt;/li&gt;
&lt;li&gt;If you don’t have an enterprise and are just writing a single application, then these entities are the business objects of the application. They encapsulate the most general and high-level rules.&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  Use Cases
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;Use cases are application-specific business rules. Changes should not impact the Entities. Changes should not be impacted by infrastructure such as a database&lt;/li&gt;
&lt;li&gt;The use cases orchestrate the flow of data in/out of the Entities and direct the Entities to use their Critical Business Rules to achieve the use case.&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  Interface Adapters
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;Converts data from data layers to use case or entity layers. Presenters, views, and controllers belong here.&lt;/li&gt;
&lt;li&gt;No code further in (use cases, entities) should have any knowledge of the database.&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  Frameworks and Drivers
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;These are the glue that hooks the various layers up.&lt;/li&gt;
&lt;li&gt;The infrastructure details live here.&lt;/li&gt;
&lt;li&gt;You’re not writing much of this code, i.e. we use SQL Server driver, but we don’t write it.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;You can add as many circles as you need. These are schematic.&lt;/strong&gt; As Uncle Bob mentioned, you can have all the circles/layers you need &lt;strong&gt;but following always The Dependency Rule&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;So the thing is, we have these circles and we follow The Dependency Rule, &lt;strong&gt;but how am I supposed to cross these circles boundaries?&lt;/strong&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;How to cross Circle Boundaries?&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--hzkiudrS--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/229/0%2AeujwXuAal-vhAHPT.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--hzkiudrS--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/229/0%2AeujwXuAal-vhAHPT.png" alt=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;This little screenshot which is part of the original diagram&lt;/strong&gt; proposed by Uncle Bob &lt;strong&gt;shows an example of how the Controllers and Presenters communicate with the Use Case in the next circle/layer.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The flow of control begins at the controller, moves through the use case, and then winds up executing the presenter.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;So if you remember well, &lt;strong&gt;The Dependency Rule says that no name in an outer circle can be mentioned by an inner circle.&lt;/strong&gt; And following the Flow of Control, the Use Case needs to call the presenter. &lt;strong&gt;And how do we solve that without violating The Dependency Rule? Two ways to handle it&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;By using the Dependency Inversion Principle from SOLID principles&lt;/strong&gt; , where we can define a port (an interface) in the inner circle and implement it in the outer circle.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;By using a great design pattern, Mediator.&lt;/strong&gt; By using it we can define an object that encapsulates how a set of objects interact.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;From my point of view, &lt;strong&gt;I prefer to use the Mediator pattern&lt;/strong&gt;. It has &lt;strong&gt;two great benefits&lt;/strong&gt; that fit really well with the Clean Architecture:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Objects delegate their interaction to a mediator object&lt;/strong&gt; instead of interacting with each other directly.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;It should be possible to change the interaction between a set of objects independently.&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--zWl-d5Rw--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/1024/0%2AG5S6qta2TmZHDRcG.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--zWl-d5Rw--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/1024/0%2AG5S6qta2TmZHDRcG.png" alt=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  Presenters
&lt;/h4&gt;

&lt;p&gt;This is another concept we can see in the Flow of Control diagram. &lt;strong&gt;The purpose of the presenter is to decouple the use cases from the format of the UI.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;They were created to decouple the interactor and the view, so if we use them we can follow the Dependency Rule.&lt;/strong&gt; If we were returning the response model for the API from the interactor we would be coupling an inner layer to the outer one and we wouldn’t be following the Dependency Rule.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Clean + Hexagonal + Onion Architecture&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;In the &lt;strong&gt;previous example on how to handle communication between Controllers and Use Cases we have seen how the Clean Architecture uses Ports and Adapters pattern&lt;/strong&gt;. Also remembering &lt;strong&gt;if we bring back the key principles of the Onion Architecture we must remember that it is an architecture driven by use cases.&lt;/strong&gt; So with these &lt;strong&gt;Use Cases we are introducing the usage of Onion Architecture principles&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;This is double confirming what I mentioned at the beginning of this article. &lt;strong&gt;Clean, Hexagonal and Onion architectures are not competing with each other to see which one is cooler or better.&lt;/strong&gt;  &lt;strong&gt;All&lt;/strong&gt; of them &lt;strong&gt;try to find a way to separate concerns&lt;/strong&gt; , and &lt;strong&gt;Clean Architecture is focused on combining principles from previous architectures patterns and&lt;/strong&gt; more principles (like &lt;strong&gt;the&lt;/strong&gt; &lt;a href="https://ericbackhage.net/clean-code/the-stable-dependencies-principle/"&gt;&lt;strong&gt;Stable Dependencies Principe&lt;/strong&gt;&lt;/a&gt; &lt;strong&gt;,&lt;/strong&gt; &lt;a href="https://ericbackhage.net/clean-code/the-stable-abstractions-principle/"&gt;&lt;strong&gt;Stable Abstractions Principle&lt;/strong&gt;&lt;/a&gt; &lt;strong&gt;, SOLID, etc&lt;/strong&gt; )&lt;/p&gt;

&lt;h4&gt;
  
  
  So, how should I structure my code following all of this?
&lt;/h4&gt;

&lt;p&gt;First of all, &lt;strong&gt;this is not a dogma&lt;/strong&gt;. Benefits are known and it should be a 100% fit for a lot of enterprise projects where business rules change continuously and also we are adding more and more features. But maybe you don’t need to do this for a simple background process service or serverless function. It’s up to you.&lt;/p&gt;

&lt;p&gt;But if you definitely want to try it, go for it. &lt;strong&gt;Try to put everything in place understanding all the concepts and why you should put something in that circle/layer. And once you’ve tried it, compare your boilerplate with other clean architectures projects out there on GitHub&lt;/strong&gt; or wherever.&lt;/p&gt;

&lt;p&gt;Next chapter will be focused on building an API following this architecture, but right now I would like to share the boilerplate of that API:&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;This a simple version of the layers and folders structure for an API, &lt;strong&gt;sometimes you need to use more architecture patterns, sometimes less. The important thing about this kind of stuff is understanding the rules and growing every day learning new things.&lt;/strong&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Conclusion
&lt;/h3&gt;

&lt;p&gt;I think that &lt;strong&gt;every day more and more developers try to understand how to create quality code following best practices&lt;/strong&gt; to add more features, to get good code coverage in the tests, to scale it up easily and &lt;strong&gt;to maintain the code free of bugs and bad spaghetti code smells.&lt;/strong&gt;&lt;br&gt;&lt;br&gt;
I have seen dozens of &lt;strong&gt;legacy projects almost impossible to maintain, with a lot of bugs and bad practices generating performance issues, never-ending feature developments, and developers burnouts&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--GKbL-Kkj--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/670/0%2AGf_by7SlV2VEYfq_.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--GKbL-Kkj--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/670/0%2AGf_by7SlV2VEYfq_.jpg" alt=""&gt;&lt;/a&gt;&lt;a href="https://static.makeuseof.com/wp-content/uploads/2015/02/programming-burnout-670x335.jpg"&gt;&lt;/a&gt;&lt;a href="https://static.makeuseof.com/wp-content/uploads/2015/02/programming-burnout-670x335.jpg"&gt;https://static.makeuseof.com/wp-content/uploads/2015/02/programming-burnout-670x335.jpg&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Clean Architecture pattern has become more popular in Android development during the past few years and I do really wish that it become more popular in backend architectures or even in the frontend.&lt;/p&gt;

&lt;p&gt;Imagine the &lt;strong&gt;satisfaction&lt;/strong&gt; of building something great each day, &lt;strong&gt;creating well-engineered solutions for complex business scenarios&lt;/strong&gt; and making sure that you can add new features &lt;strong&gt;without losing huge amounts of time and mental health.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Of course, &lt;strong&gt;some developers won’t like this thinking of creating clean code/architectures or they will say something like &lt;em&gt;“meh this looks over-engineered”.&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;I don’t like to reply to that&lt;/strong&gt; kind of comment. &lt;strong&gt;But Marie Kondo does:&lt;/strong&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;There are two reasons we can’t let go: an attachment to the past or a fear for the future.&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--1ZkyJ0fn--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/635/0%2A1JSUjnOfPJSQJ7Fd.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--1ZkyJ0fn--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/635/0%2A1JSUjnOfPJSQJ7Fd.jpg" alt=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Remember to tidy up your code, she is watching you.&lt;/p&gt;

&lt;h3&gt;
  
  
  The next article in the series will be more practical, building a simple API with .NET Core and accessing real data.
&lt;/h3&gt;

&lt;p&gt;Also, if you enjoyed this article, &lt;strong&gt;feel free to share it and to give some love!&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;If you have read all of this, thank you very much. &lt;a href="https://www.linkedin.com/in/davidpereirac/"&gt;Feel free to connect with me on Linkedin!&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Repositories&lt;/strong&gt; following the Clean Architecture
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://github.com/android/architecture-samples/tree/todo-mvp-clean"&gt;https://github.com/android/architecture-samples/tree/todo-mvp-clean&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://github.com/ivanpaulovich/clean-architecture-manga"&gt;https://github.com/ivanpaulovich/clean-architecture-manga&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://github.com/bufferapp/android-clean-architecture-boilerplate"&gt;https://github.com/bufferapp/android-clean-architecture-boilerplate&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://github.com/eduardomoroni/react-clean-architecture"&gt;https://github.com/eduardomoroni/react-clean-architecture&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://github.com/jasontaylordev/CleanArchitecture"&gt;https://github.com/jasontaylordev/CleanArchitecture&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://github.com/ardalis/CleanArchitecture"&gt;https://github.com/ardalis/CleanArchitecture&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://github.com/carlphilipp/clean-architecture-example"&gt;https://github.com/carlphilipp/clean-architecture-example&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  References
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://blog.cleancoder.com/uncle-bob/2012/08/13/the-clean-architecture.html"&gt;https://blog.cleancoder.com/uncle-bob/2012/08/13/the-clean-architecture.html&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://xurxodev.com/por-que-utilizo-clean-architecture-en-mis-proyectos/"&gt;http://xurxodev.com/por-que-utilizo-clean-architecture-en-mis-proyectos/&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://jmperezramos.net/desarrollo-en-android/visteme-con-clean-architecture-que-tengo-prisas/"&gt;http://jmperezramos.net/desarrollo-en-android/visteme-con-clean-architecture-que-tengo-prisas/&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://github.com/ivanpaulovich/clean-architecture-manga/wiki/Flow-of-Control"&gt;https://github.com/ivanpaulovich/clean-architecture-manga/wiki/Flow-of-Control&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://herbertograca.com/2017/11/16/explicit-architecture-01-ddd-hexagonal-onion-clean-cqrs-how-i-put-it-all-together/"&gt;https://herbertograca.com/2017/11/16/explicit-architecture-01-ddd-hexagonal-onion-clean-cqrs-how-i-put-it-all-together/&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://groups.google.com/forum/#!topic/clean-code-discussion/Ehwo7yIHUPQ"&gt;https://groups.google.com/forum/#!topic/clean-code-discussion/Ehwo7yIHUPQ&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://vrgsoft.net/blog/clean-architecture-for-android/"&gt;https://vrgsoft.net/blog/clean-architecture-for-android/&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>architecture</category>
      <category>career</category>
      <category>design</category>
      <category>productivity</category>
    </item>
    <item>
      <title>UrbanNoise, my open source project</title>
      <dc:creator>David Pereira</dc:creator>
      <pubDate>Sat, 18 Apr 2020 09:48:41 +0000</pubDate>
      <link>https://dev.to/urbannoise/urbannoise-my-open-source-project-2c6p</link>
      <guid>https://dev.to/urbannoise/urbannoise-my-open-source-project-2c6p</guid>
      <description>&lt;p&gt;I have been thinking about this during a while, and I finally decided to go &lt;strong&gt;open source for this personal project&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;I would love to start this project as open source in order to keep growing with latest technologies. Also I want to start it because I’d enjoy how this application could get our life easier when looking for an apartment.&lt;/p&gt;

&lt;p&gt;Imagine yourself after having an appointment to check if you like that apartment you saw on Internet. You probably liked it, but now you have a big question:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;“Will it be quiet during the night?”&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;So, if you can draw yourself in this situation I hope you support this project as much as I do!&lt;/p&gt;

&lt;p&gt;To resolve this circumstance an application will be built where &lt;strong&gt;you will be able to check the noise history for any area in your city&lt;/strong&gt; using classified and analyzed data, showing you something similar like the traffic map from Google similar to this (no final UI design yet on my mind, I am a back-end guy :) )&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F1024%2F1%2AuJMDmFgMtPwfRDhOW-DNbg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F1024%2F1%2AuJMDmFgMtPwfRDhOW-DNbg.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F560%2F1%2AG127b2XtrHI_a-va_h5ilg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F560%2F1%2AG127b2XtrHI_a-va_h5ilg.png"&gt;&lt;/a&gt;Heat map for Google Maps and Google Earth&lt;/p&gt;

&lt;p&gt;And also you could use this app not only for checking data, &lt;strong&gt;you could collaborate providing data through your mobile phone and microphone&lt;/strong&gt; , covering areas where there aren’t noise-meters! And don’t worry at all, I won’t listen anything you say like Alexa or Instagram do to sell you the best offer gadgets (I swear). I only want people to measure the noise level after calibrating your device!&lt;/p&gt;

&lt;p&gt;And if you are still hungry for more, in the future the application could predict the noise is going to be in any area you want after analyzing the acquired data, weather, events, traffic, etc (yeesss AI)&lt;/p&gt;

&lt;p&gt;This project will start collecting data from Barcelona city and if everything goes as expected it would grow acquired data from another cities around the world!&lt;/p&gt;

&lt;p&gt;And now, leaving behind the product definition let’s move to the techie section. Because you will be reading this asking yourself how I am planning to do this (I do really hope you are asking yourself that right now).&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Project name&lt;/strong&gt; : UrbanNoise (decided with the best girlfriend of the world like 3 years ago)&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Technologies stack&lt;/strong&gt; : .NET Core 3.0, Azure, CosmosDB, Serverless, DDD, hexagonal architectures, SOLID, DRY, KISS principles, xUnit, Selenium, etc. And trust me, this is for real. Every commit will be analyzed by SonarQube and during the code review process opening Pull Requests. Of course, testing and code coverage will be mandatory.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Data import process&lt;/strong&gt; from the noise-meter devices from Barcelona SmartCity webapp (please do not tell this to Ada Colau, it is for a good cause): Azure Functions with Time Triggers (15 minutes cron jobs), saving all the data in CosmosDB.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;API&lt;/strong&gt; : Using CQRS and Mediator patterns to split the data from be read or written when an user interacts with the application. And also using serverless Azure Functions with HTTP Triggers (it would be cheaper for me for a first phase of this open source project). We could use Azure API Management as a gateway as well.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Predictor&lt;/strong&gt; : To be decided, but I would enjoy using ML.NET together with Spark loading the CosmosDB data. The reason I didn’t decided totally this part of the project is my wallet. I am not sure if I could use the cloud services without spending too much money.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;GIT repositories:&lt;/strong&gt; All code will be located here &lt;a href="https://github.com/urbannoise" rel="noopener noreferrer"&gt;https://github.com/urbannoise&lt;/a&gt; (avoid current repositories as they were created when I was thinking to create everything with microservices and Kubernetes). I am owner of that open source organization.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;CI/CD:&lt;/strong&gt; Azure Dev Ops Pipelines. I still have to set up everything here, but at least I created the space to start with here: &lt;a href="https://dev.azure.com/davidpereiracostoya/UrbanNoise" rel="noopener noreferrer"&gt;https://dev.azure.com/davidpereiracostoya/UrbanNoise&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;UI/Mobile&lt;/strong&gt; : Wow, this my weak pain point. I would like to discuss this wieh someone, I was thinking about something like VueJS and Flutter, but I am interested in listening more experienced people.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Planning/Documentation&lt;/strong&gt; : Azure Dev Ops will be use mainly for this to have only one place where everything can be checked, but of course some Medium articles will be written to share the effort and possible challenges during the development of the project.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;And after reading all this text, maybe you are asking yourself, &lt;strong&gt;Why Open-Source?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Well, after thinking about it during a long time I have decided to do it in this way because:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;em&gt;It is a great opportunity to learn from the community.&lt;/em&gt;&lt;/li&gt;
&lt;li&gt;&lt;em&gt;I couldn’t do it alone (you know, office hours drain my energy battery)&lt;/em&gt;&lt;/li&gt;
&lt;li&gt;&lt;em&gt;But overall, to share our knowledge and our beautiful work.&lt;/em&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;And that’s all. So if you like the idea and you want to collaborate feel free to leave a comment here or send me a message to &lt;a href="https://linkedin.com/in/davidpereirac/" rel="noopener noreferrer"&gt;my LinkedIn&lt;/a&gt;. And if you can share this article I owe you a coffee!&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;EXTRA BONUS: We are looking for someone with UX experience in Mobile. If you like the idea and you want to collaborate, feel free to leave a comment or send me a message! Thanks!&lt;/strong&gt;&lt;/p&gt;




</description>
      <category>opensource</category>
      <category>dotnet</category>
      <category>motivation</category>
    </item>
    <item>
      <title>Clean architecture series — Part 2</title>
      <dc:creator>David Pereira</dc:creator>
      <pubDate>Mon, 30 Mar 2020 11:59:05 +0000</pubDate>
      <link>https://dev.to/pereiren/clean-architecture-series-part-2-49db</link>
      <guid>https://dev.to/pereiren/clean-architecture-series-part-2-49db</guid>
      <description>&lt;p&gt;Everyone has tasted onions. In pizzas, hamburgers, salads, etc. But have you ever tasted Onion architecture in your code?&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--96--3t3J--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/1024/0%2A9_CC4Fjbzo32BUDh.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--96--3t3J--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/1024/0%2A9_CC4Fjbzo32BUDh.jpg" alt=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  The Onion Architecture 🧅
&lt;/h3&gt;

&lt;p&gt;After the Hexagonal Architecture article, now it’s time to talk about Onion Architecture.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;You can check the first article of this series here about Hexagonal architectures&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;a href="https://dev.to/pereiren/clean-architecture-series-part-1-m64"&gt;Clean architecture series— Part 1&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  What is the Onion Architecture?
&lt;/h3&gt;

&lt;p&gt;So, this architecture pattern &lt;a href="https://jeffreypalermo.com/2008/07/the-onion-architecture-part-1/"&gt;was promoted by Jeffrey Palermo in 2008&lt;/a&gt; &lt;strong&gt;trying to solve common problems when maintaining applications&lt;/strong&gt; and also emphasizing the separation of concerns throughout the system. It was presented as an &lt;strong&gt;alternative to the well known Tradition Architecture&lt;/strong&gt; :&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--7QNxMf1q--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/357/0%2A1pnINs9XtZaTdet0" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--7QNxMf1q--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/357/0%2A1pnINs9XtZaTdet0" alt=""&gt;&lt;/a&gt;&lt;a href="https://i0.wp.com/jeffreypalermo.com/wp-content/uploads/2018/06/image257b0257d255b61255d1.png?resize=357%2C253&amp;amp;ssl=1"&gt;&lt;/a&gt;&lt;a href="https://i0.wp.com/jeffreypalermo.com/wp-content/uploads/2018/06/image257b0257d255b61255d1.png?resize=357%2C253&amp;amp;ssl=1"&gt;https://i0.wp.com/jeffreypalermo.com/wp-content/uploads/2018/06/image257b0257d255b61255d1.png?resize=357%2C253&amp;amp;amp;ssl=1&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The problems with this kind of architecture are all over the place but as Jeffrey Palermo says it starts wrong when &lt;strong&gt;each subsequent layer depends on the layers beneath it, and then every layer normally will depend on some common infrastructure and utility services&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;That problem would be represented in something like this:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--OWDryCE0--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/proxy/1%2AeSS5PEGJ6BCWjKOLo6oPvw.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--OWDryCE0--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/proxy/1%2AeSS5PEGJ6BCWjKOLo6oPvw.png" alt="UML class diagram with 2 classes at different layers."&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;So what Jeffrey Palermo proposed is a new approach to architecture.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--DMCw8aba--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/proxy/1%2AEmndhaXK7k11HwnY7MfUQQ.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--DMCw8aba--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/proxy/1%2AEmndhaXK7k11HwnY7MfUQQ.png" alt="Original ‘top’ view without infrastructure vs an alternative ‘side’ view."&gt;&lt;/a&gt;&lt;a href="https://cdn-images-1.medium.com/max/1200/1*EmndhaXK7k11HwnY7MfUQQ.png"&gt;&lt;/a&gt;&lt;a href="https://cdn-images-1.medium.com/max/1200/1*EmndhaXK7k11HwnY7MfUQQ.png"&gt;https://cdn-images-1.medium.com/max/1200/1*EmndhaXK7k11HwnY7MfUQQ.png&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;He mentioned:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Honestly, it’s not completely new, but I’m proposing it as a named, architectural pattern. Patterns are useful because it gives software professionals a common vocabulary with which to communicate. There are a lot of aspects to the Onion Architecture, and if we have a common term to describe this approach, we can communicate more effectively.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;The main premise of this architecture is that it controls coupling. The fundamental rule is that all code can depend on layers more central, but code cannot depend on layers further out from the core. In other words, all coupling is toward the center.&lt;/p&gt;

&lt;p&gt;So imagine the prior diagram example where Foo and Bar classes were coupled to each other even they are living in different layers. Following that main premise, you would need to control coupling in a similar way to this:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--VckxOmm1--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/proxy/1%2Atmx3ULMnFSyUtoNWWsD_JQ.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--VckxOmm1--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/proxy/1%2Atmx3ULMnFSyUtoNWWsD_JQ.png" alt="UML class diagram with introduced abstraction."&gt;&lt;/a&gt;&lt;a href="https://cdn-images-1.medium.com/max/1200/1*tmx3ULMnFSyUtoNWWsD_JQ.png"&gt;&lt;/a&gt;&lt;a href="https://cdn-images-1.medium.com/max/1200/1*tmx3ULMnFSyUtoNWWsD_JQ.png"&gt;https://cdn-images-1.medium.com/max/1200/1*tmx3ULMnFSyUtoNWWsD_JQ.png&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Remember that main rule when talking about Onion Architecture.&lt;/p&gt;

&lt;h3&gt;
  
  
  Benefits of Onion Architecture
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Sustainability / Timelessness:&lt;/strong&gt; by decoupling our application-business code from the tools we are using (i.e. the libraries and frameworks), we make it less vulnerable to the erosion of time and IT fads&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Testability:&lt;/strong&gt; We are decoupling everything between different layers, so everything can be tested.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Adaptability / Time to market:&lt;/strong&gt; adding a new way to interact with your application is very easy.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Understandability:&lt;/strong&gt; Rather than having a solution where use cases are completely lost or mixed within all the technical stuff, this architecture style states the emergence of an applicative-use-case-layer&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Use case driven:&lt;/strong&gt; Indeed, with this architecture style, we design our applications with our use cases in mind; not the number of persistence technologies or binding types we will need to support&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Disadvantages of Onion Architecture
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Interface soup&lt;/strong&gt; : lots of interfaces for interaction with the core which can make navigating a project tougher.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Core heavy:&lt;/strong&gt; lots of logic and movement in the core, any changes made inside the core could affect behavior outwards. But if this didn’t happen it would be a miracle.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Let’s take a look now at the layers of our onions 🧅🧅🧅&lt;/p&gt;

&lt;h3&gt;
  
  
  Layers of the Onion Architecture following DDD
&lt;/h3&gt;

&lt;p&gt;In the very &lt;strong&gt;center&lt;/strong&gt; , we see the &lt;strong&gt;Domain Model&lt;/strong&gt; , which &lt;strong&gt;represents the state and behavior combination that models truth for the organization&lt;/strong&gt;. Around the Domain Model, there are other layers with more behavior. The &lt;strong&gt;number of layers in the application core will vary&lt;/strong&gt; , but remember that the &lt;strong&gt;Domain Model is the very center&lt;/strong&gt; , and since all coupling is toward the center, the &lt;strong&gt;Domain Model is only coupled to itself&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;The &lt;strong&gt;first layer around the Domain Model&lt;/strong&gt; is typically where we would find &lt;strong&gt;interfaces&lt;/strong&gt; that provide object saving and retrieving behavior, called &lt;strong&gt;Repository Interfaces&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;If &lt;strong&gt;you are thinking about DDD&lt;/strong&gt; after reading that &lt;strong&gt;you are right&lt;/strong&gt;. &lt;strong&gt;Repository Pattern&lt;/strong&gt; belongs to Domain Driven Design and &lt;strong&gt;can be described as&lt;/strong&gt; :&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Pattern that mediates between the domain (aggregate roots) and data mapping layers using a collection-like interface for accessing domain objects.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;You may think &lt;strong&gt;where the implementation of that Repository Interface may reside&lt;/strong&gt;. Jeffrey Palermo mentioned that out on the edges we see UI, Infrastructure, and Tests. The outer layer is reserved for things that change often. These things should be intentionally isolated from the application core.&lt;/p&gt;

&lt;p&gt;So our &lt;strong&gt;implementation of that repository interface should live in the infrastructure layer&lt;/strong&gt; , isolating everything from the core. If one day we need to use MongoDB instead of MySQL when accessing data we don’t need to worry about the application core or business logic. We only need to focus our effort on the implementations of the Infrastructure layer. Because those as far as you are not changing anything about in the business rules, you don’t need to modify the Repository Interfaces or the Domain Model.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;A couple of pictures are worth than thousand words.&lt;/strong&gt; So here you can find the places where the Repository Interfaces and Implementations reside in the Onion Diagram and as well in the UML diagram.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--KTkSc-dI--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/proxy/1%2AW5JIMKJ5T_05J1VhZCZJUw.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--KTkSc-dI--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/proxy/1%2AW5JIMKJ5T_05J1VhZCZJUw.png" alt="Implementation detail of the Onion Architecture."&gt;&lt;/a&gt;&lt;a href="https://cdn-images-1.medium.com/max/1200/1*W5JIMKJ5T_05J1VhZCZJUw.png"&gt;&lt;/a&gt;&lt;a href="https://cdn-images-1.medium.com/max/1200/1*W5JIMKJ5T_05J1VhZCZJUw.png"&gt;https://cdn-images-1.medium.com/max/1200/1*W5JIMKJ5T_05J1VhZCZJUw.png&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--2hO7AdPX--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/436/1%2ARwCrCnRZjXi6C2xW2IHNkg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--2hO7AdPX--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/436/1%2ARwCrCnRZjXi6C2xW2IHNkg.png" alt=""&gt;&lt;/a&gt;&lt;a href="https://cdn-images-1.medium.com/max/1200/1*vAKOPgFeEmlMlW_Q6hygZA.png"&gt;&lt;/a&gt;&lt;a href="https://cdn-images-1.medium.com/max/1200/1*vAKOPgFeEmlMlW_Q6hygZA.png"&gt;https://cdn-images-1.medium.com/max/1200/1*vAKOPgFeEmlMlW_Q6hygZA.png&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;At this point, someone may be asking if the very center is the Domain Model or the Database&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;I just want to emphasize that the database is external. &lt;strong&gt;Some people are used to think applications where the center is a database&lt;/strong&gt; running triggers, stored procedures or jobs. If you follow this &lt;strong&gt;Onion Architecture there are no possible database applications&lt;/strong&gt;. Most of the applications might use a database as a storage service but only though some external infrastructure code that implements an interface that makes sense to the application core. Decoupling the application from the database, file system, etc, lowers the cost of maintenance for the life of the application.&lt;/p&gt;

&lt;h4&gt;
  
  
  So… where the hell is my business logic?
&lt;/h4&gt;

&lt;p&gt;Let’s get this straight.&lt;/p&gt;

&lt;p&gt;Around the Domain Model, we can see two layers. &lt;strong&gt;Domain Services and Application Services&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--P2FAm9-N--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/173/1%2ABxDcMW7R5SXYo1eSpQjyWQ.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--P2FAm9-N--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/173/1%2ABxDcMW7R5SXYo1eSpQjyWQ.png" alt=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Application Services:&lt;/strong&gt; Typically used to orchestrate how the outside world interacts with your application. For example, AuthenticationService would be an Application Service that co-ordinates how a user should be authenticated. In other words, they are like the use cases of our application.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Domain Services:&lt;/strong&gt; When a significant process or transformation in the domain is not a natural responsibility of an ENTITY or VALUE OBJECT, add an operation to the model as a standalone interface declared as a SERVICE. Define the interface in terms of the language of the model and make sure the operation name is part of the UBIQUITOUS LANGUAGE. Make the SERVICE stateless. For example, you might have a RegisterUserService that co-ordinates how a user is registered within your application.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;To &lt;strong&gt;explain the difference between these two concepts&lt;/strong&gt; and understand when and how to use them I am going to take &lt;strong&gt;an example from this great repository about DDD&lt;/strong&gt; : &lt;a href="https://github.com/zkavtaskin/Domain-Driven-Design-Example"&gt;https://github.com/zkavtaskin/Domain-Driven-Design-Example&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This code created by &lt;strong&gt;Zan Kavtaskin&lt;/strong&gt; ( &lt;a href="http://www.zankavtaskin.com/"&gt;http://www.zankavtaskin.com/&lt;/a&gt;) is a great example of how to &lt;strong&gt;apply DDD within an Onion Architecture&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;The &lt;strong&gt;entry point&lt;/strong&gt; of the application is an &lt;strong&gt;API (Presentation layer)&lt;/strong&gt;, and after that reaches an &lt;strong&gt;application service&lt;/strong&gt; to go deeper to the center, the &lt;strong&gt;domain model&lt;/strong&gt; , like following below diagram (just imagine a Presentation Layer outside the Application Layer)&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--7asn3KZx--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/907/0%2AUl732M2iiXVS7dtE.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--7asn3KZx--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/907/0%2AUl732M2iiXVS7dtE.png" alt=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;So, let’s take a look at the &lt;a href="https://github.com/zkavtaskin/Domain-Driven-Design-Example/blob/master/eCommerce.WebService/Controllers/CartController.cs"&gt;CartController.cs&lt;/a&gt;
&lt;/li&gt;
&lt;/ol&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;ol&gt;
&lt;li&gt;When the &lt;strong&gt;API reaches this route in this controller we are using the CartService&lt;/strong&gt; which allows users to interact with the Cart in this e-commerce application ( &lt;strong&gt;Application Service living in the Application Layer&lt;/strong&gt; )&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Here is the code for &lt;a href="https://github.com/zkavtaskin/Domain-Driven-Design-Example/blob/master/eCommerce/ApplicationLayer/Carts/CartService.cs"&gt;CartService.cs&lt;/a&gt;Application Service:&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;In that &lt;strong&gt;CheckOut function&lt;/strong&gt; , it is easy to see how this &lt;strong&gt;Application Service&lt;/strong&gt; is being used to interact with external users and coordinate the use cases of our business rules ( &lt;strong&gt;business logic&lt;/strong&gt; ). Like trying to verify if a customer has already created a cart and verifying that that cart is linked to the same customer, if they can do a checkout or not and whether they can create a purchase or not.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;And in some cases, &lt;strong&gt;that CheckOut function is making use of the CheckOut Domain Service&lt;/strong&gt; (&lt;a href="https://github.com/zkavtaskin/Domain-Driven-Design-Example/blob/master/eCommerce/DomainModelLayer/Services/CheckoutService.cs"&gt;checkOutDomainService&lt;/a&gt;) to add the checkout operation to the model and create a Purchase. Let’s take a look at this specific Domain Service:&lt;/li&gt;
&lt;/ol&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;&lt;strong&gt;First of all, let’s review the definition of Domain Service again:&lt;/strong&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;When a significant process or transformation in the domain is not a natural responsibility of an ENTITY or VALUE OBJECT&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;We can understand how this is being used in the application to follow DDD. &lt;strong&gt;This Domain Service is a process&lt;/strong&gt; (checkout) &lt;strong&gt;which is not the responsibility of the domain model itself and it is adding an operation to the model&lt;/strong&gt; (Purchase Aggregate Root).&lt;br&gt;&lt;br&gt;
In other words, we are handling the &lt;strong&gt;domain logic&lt;/strong&gt;  here.&lt;/p&gt;

&lt;p&gt;And that’s how you manage the business logic and the domain logic using Application Services and Domain Services in Onion Architectures and DDD.&lt;br&gt;&lt;br&gt;
If it’s the first time you are reading something like this, I know how you feel right now&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--kINuMqcM--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://cdn-images-1.medium.com/max/668/0%2AaMqsEghFSWBI3VWx.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--kINuMqcM--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://cdn-images-1.medium.com/max/668/0%2AaMqsEghFSWBI3VWx.gif" alt=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;But everything will be in place once you just try to use these concepts in your code. The practice is always the key to master 🔨🔨🔨&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--WcHhj4TA--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://cdn-images-1.medium.com/max/560/0%2AlxP4R-H_VJsoUMR5.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--WcHhj4TA--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://cdn-images-1.medium.com/max/560/0%2AlxP4R-H_VJsoUMR5.gif" alt=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Let’s get a &lt;strong&gt;summary&lt;/strong&gt; of what was covered &lt;strong&gt;until this point&lt;/strong&gt; (I know it’s a heavy and long article):&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;What is the Onion Architecture?&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Benefits&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Disadvantages&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Layers&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Domain Services and Application Services&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  &lt;strong&gt;So there is only one thing left, and that is….&lt;/strong&gt;
&lt;/h4&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--lvItf10V--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://cdn-images-1.medium.com/max/500/0%2AtPYNDfjyROVTFD4y.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--lvItf10V--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://cdn-images-1.medium.com/max/500/0%2AtPYNDfjyROVTFD4y.gif" alt=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Onion Architectures vs Hexagonal Architectures
&lt;/h3&gt;

&lt;p&gt;I have seen a lot of &lt;strong&gt;people talking about this like a new Marvel movie&lt;/strong&gt; , they tell you to choose, &lt;strong&gt;Onion team or Hexagonal team&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;I try to&lt;/strong&gt; be a guy that does &lt;strong&gt;not see everything in black and white&lt;/strong&gt;. I like to learn, explore and understand but &lt;strong&gt;always taking into account the benefits of any new trend, principle or whatever.&lt;/strong&gt; That’s the reason why I am not going to explain software architectures as a war, trying to convince you which one is the best and why you should use it alone. I am not going to do that.&lt;br&gt;&lt;br&gt;
Instead, &lt;strong&gt;I am going to focus this on how to use different architectures in a combined way, trying to show the benefits of it and when I would use them&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--dUq9IrB1--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/508/1%2A1Mg0Hru08t6ZQR6UQ3Bl5Q.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--dUq9IrB1--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/508/1%2A1Mg0Hru08t6ZQR6UQ3Bl5Q.png" alt=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Remember to read Part 1 of this series where I collected a lot of information about Hexagonal (Ports and Adapters) Architecture&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://dev.to/pereiren/clean-architecture-series-part-1-m64"&gt;Clean architecture series— Part 1&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;To summarize Hexagonal Architecture, let’s bring back quickly a self-explanatory diagram:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--IuGmfmOD--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/660/0%2AsHbljEPCW7cx1nw9" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--IuGmfmOD--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/660/0%2AsHbljEPCW7cx1nw9" alt=""&gt;&lt;/a&gt;Ports and Adapters in the diagram ( &lt;a href="https://softwarecampament.wordpress.com/portsadapters/#tc1"&gt;&lt;/a&gt;&lt;a href="https://softwarecampament.wordpress.com/portsadapters/#tc1"&gt;https://softwarecampament.wordpress.com/portsadapters/#tc1&lt;/a&gt;)&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;The Hexagon — &lt;/strong&gt; the application&lt;/li&gt;
&lt;li&gt;Driver Port — API offered by the application&lt;/li&gt;
&lt;li&gt;Driven Ports — required by the application&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Actors&lt;/strong&gt;  — environment devices that interact with the application&lt;/li&gt;
&lt;li&gt;Drivers — application users (either humans or hardware/software devices)&lt;/li&gt;
&lt;li&gt;Driven Actors — provide services required by the application&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Adapters — &lt;/strong&gt; to adapt specific technology to the application&lt;/li&gt;
&lt;li&gt;Driver Adapters — use the drivers’ ports&lt;/li&gt;
&lt;li&gt;Driven Adapters — implement the driven ports&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;So, &lt;strong&gt;Hexagonal Architecture talks about Primary and Secondary Actors, Ports, Adapters and the Application&lt;/strong&gt;. As I mentioned in Part 1, Alistair Cockburn didn’t mention anything about how you should do your code. Let’s quote this again:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;The Ports and Adapters original article doesn’t mention anything at all and how code must be structured inside the Hexagon/Application ( &lt;a href="http://web.archive.org/web/20180422210157/http://alistair.cockburn.us/Hexagonal+Architecture"&gt;http://web.archive.org/web/20180422210157/http://alistair.cockburn.us/Hexagonal+Architecture&lt;/a&gt;). I have seen a lot of articles talking about DDD or application layers but Alistair Cockburn didn’t write on how you should do your code, he only promoted the idea of ports and adapters&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;In other words, &lt;strong&gt;we can architect our application code with anything we want to&lt;/strong&gt;. And given that this is the Onion Architecture + DDD article this is how I want to draw my architecture diagram at this point:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--lroyt_LN--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/626/0%2AjN8rYL5ZlrjyvBE7.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--lroyt_LN--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/626/0%2AjN8rYL5ZlrjyvBE7.PNG" alt=""&gt;&lt;/a&gt;&lt;a href="https://josecuellar.net/wp-content/uploads/hexagonalarchitecture.PNG"&gt;&lt;/a&gt;&lt;a href="https://josecuellar.net/wp-content/uploads/hexagonalarchitecture.PNG"&gt;https://josecuellar.net/wp-content/uploads/hexagonalarchitecture.PNG&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;We now have ports, adapters and the Onion Architecture. &lt;a href="https://jeffreypalermo.com/2008/08/the-onion-architecture-part-3/"&gt;&lt;strong&gt;And the key tenets are clear as well&lt;/strong&gt; :&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The application is built around an independent object model.&lt;/li&gt;
&lt;li&gt;Inner layers define interfaces. Outer layers implement interfaces.&lt;/li&gt;
&lt;li&gt;The direction of coupling is toward the center.&lt;/li&gt;
&lt;li&gt;All application core code can be compiled and run separately from infrastructure.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Also, &lt;strong&gt;Hexagonal and Onion look for the same goal&lt;/strong&gt; as Jeffrey Palermo mentioned in his &lt;a href="https://jeffreypalermo.com/2008/07/the-onion-architecture-part-1/"&gt;first article about Onion Architecture&lt;/a&gt;:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Hexagonal architecture and Onion Architecture share the following premise: Externalize infrastructure and write adapter code so that the infrastructure does not become tightly coupled.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;And I like to see it in this way. In tons of StackOverflow answers, tech blogs or even GitHub code samples a lot of people &lt;strong&gt;try to stick to one of these architecture patterns without having in mind that these patterns can work together.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;And personally &lt;strong&gt;I would use them together for every application I need to be scalable, maintainable, highly covered by tests, evolvable and understandable.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Here some repositories with great examples of what I mentioned in this short article:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://github.com/josecuellar/Onion-DDD-Tooling-DotNET"&gt;https://github.com/josecuellar/Onion-DDD-Tooling-DotNET&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://github.com/zkavtaskin/Domain-Driven-Design-Example"&gt;https://github.com/zkavtaskin/Domain-Driven-Design-Example&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://github.com/ivanpaulovich/clean-architecture-manga"&gt;https://github.com/ivanpaulovich/clean-architecture-manga&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://github.com/mhadaily/flutter-architecture-ddd"&gt;https://github.com/mhadaily/flutter-architecture-ddd&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  And…
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--3ZxKcMWr--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/590/0%2AQGjwmCghYE0R4mvZ.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--3ZxKcMWr--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/590/0%2AQGjwmCghYE0R4mvZ.jpg" alt=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;In the next article, we are going to see how this Hexagonal+Onion Architecture works with the Clean Architecture pattern promoted by Uncle Bob.&lt;/strong&gt;
&lt;/h3&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Because…&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--sOUD6Tmm--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/800/0%2Ae8UOgNSPeBILr0L6.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--sOUD6Tmm--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/800/0%2Ae8UOgNSPeBILr0L6.jpg" alt=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If you have read all of this, thank you very much. &lt;a href="https://www.linkedin.com/in/davidpereirac/"&gt;Feel free to connect with me on Linkedin!&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  References
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://jeffreypalermo.com/2008/07/the-onion-architecture-part-1/"&gt;https://jeffreypalermo.com/2008/07/the-onion-architecture-part-1/&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://jeffreypalermo.com/2008/07/the-onion-architecture-part-2/"&gt;https://jeffreypalermo.com/2008/07/the-onion-architecture-part-2/&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://jeffreypalermo.com/2008/08/the-onion-architecture-part-3/"&gt;https://jeffreypalermo.com/2008/08/the-onion-architecture-part-3/&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://jeffreypalermo.com/2008/08/the-onion-architecture-part-3/"&gt;https://jeffreypalermo.com/2008/08/the-onion-architecture-part-3/&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://lorifpeterson.com/?p=64"&gt;http://lorifpeterson.com/?p=64&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://medium.com/@alinepaulucci/ddd-for-dummies-sqn-44ba83a6f6d8"&gt;https://medium.com/@alinepaulucci/ddd-for-dummies-sqn-44ba83a6f6d8&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://ajlopez.wordpress.com/2008/09/12/layered-architecture-in-domain-driven-design/"&gt;https://ajlopez.wordpress.com/2008/09/12/layered-architecture-in-domain-driven-design/&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://josecuellar.net/domain-driven-design-episodio-iii-arquitectura/"&gt;https://josecuellar.net/domain-driven-design-episodio-iii-arquitectura/&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://dzone.com/articles/onion-architecture-is-interesting"&gt;https://dzone.com/articles/onion-architecture-is-interesting&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.infoq.com/news/2014/10/ddd-onion-architecture/"&gt;https://www.infoq.com/news/2014/10/ddd-onion-architecture/&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.adictosaltrabajo.com/2019/07/02/capas-cebollas-y-colmenas-arquitecturas-en-el-backend/"&gt;https://www.adictosaltrabajo.com/2019/07/02/capas-cebollas-y-colmenas-arquitecturas-en-el-backend/&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://enterprisecraftsmanship.com/posts/domain-vs-application-services/"&gt;https://enterprisecraftsmanship.com/posts/domain-vs-application-services/&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://tpierrain.blogspot.com/2013/08/a-zoom-on-hexagonalcleanonion.html"&gt;http://tpierrain.blogspot.com/2013/08/a-zoom-on-hexagonalcleanonion.html&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.codeguru.com/csharp/csharp/cs_misc/designtechniques/understanding-onion-architecture.html"&gt;https://www.codeguru.com/csharp/csharp/cs_misc/designtechniques/understanding-onion-architecture.html&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>architecture</category>
      <category>career</category>
      <category>productivity</category>
      <category>design</category>
    </item>
    <item>
      <title>Clean architecture series - Part 1</title>
      <dc:creator>David Pereira</dc:creator>
      <pubDate>Thu, 26 Mar 2020 08:21:18 +0000</pubDate>
      <link>https://dev.to/pereiren/clean-architecture-series-part-1-m64</link>
      <guid>https://dev.to/pereiren/clean-architecture-series-part-1-m64</guid>
      <description>&lt;p&gt;I have been hearing this too long and I always wondered what hexagonal, onion and clean architectures really mean. I learnt a lot these last months and I want to share it.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Nc1P4Q0Z--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/1024/1%2Akmx7ojVIYniVpiyMx5svnQ.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Nc1P4Q0Z--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/1024/1%2Akmx7ojVIYniVpiyMx5svnQ.png" alt=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I am sure that most of the software developers know the words of clean code, SOLID, clean architecture, hexagonal architectures, onion architectures, etc; but I suspect that most of them don’t know the truth about these amazing topics in software development. If you know them or you want to know more, please feel free to be at my side for this article series about &lt;strong&gt;everything I learnt on Clean Architecture&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;I will try to explain what I learnt in &lt;strong&gt;different articles&lt;/strong&gt; , following more or less this structure:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Hexagonal Architecture (Alistair Cockburn)&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Onion Architecture + DDD (Jeffrey Palermo)&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Clean Architecture (Uncle Bob)&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;What, Why, When&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;How to follow a Clean Architecture in .NET Core APIs&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Bonus track: Clean Architecture + GraphQL in .NET Core (HotChocolate)&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Hexagonal Architecture
&lt;/h3&gt;

&lt;p&gt;So &lt;strong&gt;let get’s started with Hexagonal Architecture&lt;/strong&gt; , also known as Port and Adapters pattern (which I prefer). Even you didn’t know what this pattern means you probably used in your code.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--mGSornPJ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/1024/1%2AwGUc9E7RHspQyDi_Z9ZMxw.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--mGSornPJ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/1024/1%2AwGUc9E7RHspQyDi_Z9ZMxw.png" alt=""&gt;&lt;/a&gt;&lt;a href="https://pixabay.com/illustrations/network-control-block-chain-hexagon-4478145/"&gt;&lt;/a&gt;&lt;a href="https://pixabay.com/illustrations/network-control-block-chain-hexagon-4478145/"&gt;https://pixabay.com/illustrations/network-control-block-chain-hexagon-4478145/&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Promoted by Alistair Cockburn in 2005 in &lt;a href="http://alistair.cockburn.us/Hexagonal+Architecture"&gt;one of his article&lt;/a&gt;s. Regarding the age of this pattern I would like to quote &lt;strong&gt;Juan Manuel Garrido de Paz&lt;/strong&gt; , who mentions this in his awesome&lt;a href="https://softwarecampament.wordpress.com/portsadapters/#tc1"&gt;article about Ports and Adapters&lt;/a&gt;:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;If you are thinking… “Isn’t the article too old? How is it that it is still worth it nowadays, being software development a discipline in continous evolution where new technologies and frameworks arise every day and kill the one we used yesterday?” Well the answer is in the question. Ports &amp;amp; Adapters is a pattern that promotes &lt;strong&gt;decoupling from technology&lt;/strong&gt; and frameworks. So no, it isn’t too old. Good things are timeless. They are like wine, they get better as time passes by.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;After this brief introduction, let’s move forward and take a look at the famous hexagonal diagram:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Yu93Wj64--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/660/0%2A7tQRDsEymDftd4Ab" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Yu93Wj64--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/660/0%2A7tQRDsEymDftd4Ab" alt=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Following this diagram, we can see three important elements for the Ports and Adapters Pattern&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Application&lt;/strong&gt; : Represented as a hexagon (it has this shape because it is easier to draw elements around it), it contains all the business logic that our application needs to execute the business rules defined in the requirements. The Ports and Adapters original article doesn’t mention anything at all and how code must be structured inside the Hexagon/Application ( &lt;a href="http://web.archive.org/web/20180422210157/http://alistair.cockburn.us/Hexagonal+Architecture"&gt;http://web.archive.org/web/20180422210157/http://alistair.cockburn.us/Hexagonal+Architecture&lt;/a&gt;). I have seen a lot of articles talking about DDD or application layers but Alistair Cockburn didn’t write on how you should do your code, he only promoted the idea of ports and adapters which I am going to try to explain later on.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Drivers&lt;/strong&gt; (Primary Actors): External actors that interact with the application to get a response or to execute commands. In other words, the users of our application.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Driven Actors&lt;/strong&gt; (Secondary Actors): These actors are being triggered by our application. &lt;strong&gt;There are two types of driven actors: repositories&lt;/strong&gt; (the application may obtain data from it, for example, a database) &lt;strong&gt;and recipients&lt;/strong&gt; (the application only sends information to it, like an SMTP server)&lt;/li&gt;
&lt;/ul&gt;

&lt;blockquote&gt;
&lt;p&gt;The difference between a primary and secondary actor lies only in who &lt;em&gt;initiates&lt;/em&gt; the conversation&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;So... where the hell are those ports and adapters?&lt;/p&gt;

&lt;h3&gt;
  
  
  Ports
&lt;/h3&gt;

&lt;p&gt;Ports live between the actors and the application core. They are part of the application, living on the edge of the hexagon and they handle the interactions with a given purpose. They are the application boundaries, or in other words, they are the &lt;strong&gt;interfaces&lt;/strong&gt; that the application needs to communicate with external actors.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Driver Ports&lt;/strong&gt; are the &lt;strong&gt;API&lt;/strong&gt; of the application. This means that they provide the programmatic way of accessing a service to achieve a certain behaviour or output. Imagine in APIs, an interface type which is being called from the controller; that could be a driver port.&lt;/p&gt;

&lt;p&gt;In the other hand, &lt;strong&gt;Driven Ports&lt;/strong&gt; are the &lt;strong&gt;SPI&lt;/strong&gt; (Service Provider Interface) of the application. SPI is the description of classes, interfaces, methods, etc that you extend and implement to achieve a goal. It is the way to extend or alter the behaviour of a software application. Trying to explain it with other words, imagine that one of our APIs sends notifications, the Driven Port is the interface type we created with that method to send the notifications.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--ICHfOYN9--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/846/0%2ANAOQ7gFVGZMQu-TR" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--ICHfOYN9--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/846/0%2ANAOQ7gFVGZMQu-TR" alt=""&gt;&lt;/a&gt;Diagram showing API and SPI in Ports and Adapters patter ( &lt;a href="https://dev.to/julientopcu/hexagonal-architecture-decoupling-your-technical-code-from-your-business-logic-hexarch-1f3l"&gt;&lt;/a&gt;&lt;a href="https://beyondxscratch.com/2017/08/19/decoupling-your-technical-code-from-your-business-logic-with-the-hexagonal-architecture-hexarch/"&gt;https://beyondxscratch.com/2017/08/19/decoupling-your-technical-code-from-your-business-logic-with-the-hexagonal-architecture-hexarch/&lt;/a&gt;)&lt;/p&gt;

&lt;p&gt;Remember, ports are technology agnostic, they don’t know if for example this notification is being sent correctly or you are spamming your boss. The driven adapter will implement this driven port and will take care of this.&lt;/p&gt;

&lt;h3&gt;
  
  
  Adapters
&lt;/h3&gt;

&lt;p&gt;An adapter is a software component that allows a particular technology to interact with a port of the hexagon. Adapters are outside ports level. Some people say they are outside, others say that they are like in an upper parent hexagon outside the ports so I would say they are outside ports. That’s it.&lt;/p&gt;

&lt;p&gt;A Driver Adapter uses a Driver Port Interface, converting a specific technology request into a technology-agnostic request to a driver port. In an API, the controller is a driver adapter, receiving requests from the UI and calling methods of the driver port.&lt;/p&gt;

&lt;p&gt;A Driven Adapter implements a Driven Port Interface, converting technology-agnostic methods of the port into specific technology methods. For example, remembering our driven port to send notifications, our Driven Adapter would implement it and using email libraries depending on our programming language will send the email.&lt;/p&gt;

&lt;p&gt;This pattern gives you the flexibility of mocking everything and even more important, you can switch from one technology to another. For example, if you are using as a Database Driven Adapter the SQL Server libraries and you need to switch to Mongo, it shouldn’t be too hard. Ports and Adapters pattern will force you in some way to follow SOLID principles in your architecture and code, with all the benefits of using them.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--6Oy8gF98--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/660/0%2AaiNEwjIAKGx1xiK0" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--6Oy8gF98--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/660/0%2AaiNEwjIAKGx1xiK0" alt=""&gt;&lt;/a&gt;Ports and Adapters in the diagram ( &lt;a href="https://softwarecampament.wordpress.com/portsadapters/#tc1"&gt;&lt;/a&gt;&lt;a href="https://softwarecampament.wordpress.com/portsadapters/#tc1"&gt;https://softwarecampament.wordpress.com/portsadapters/#tc1&lt;/a&gt;)&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Summary&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;I am going to quote everything from &lt;strong&gt;Juan Manuel Garrido de Paz&lt;/strong&gt; article about Ports and Adapters because it is just perfect.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;The Hexagon — &lt;/strong&gt; the application&lt;/li&gt;
&lt;li&gt;Driver Port — API offered by the application&lt;/li&gt;
&lt;li&gt;Driven Ports — required by the application&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Actors&lt;/strong&gt;  — environment devices that interact with the application&lt;/li&gt;
&lt;li&gt;Drivers — application users (either humans or hardware/software devices)&lt;/li&gt;
&lt;li&gt;Driven Actors — provide services required by the application&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Adapters —&lt;/strong&gt;  to adapt specific technology to the application&lt;/li&gt;
&lt;li&gt;Driver Adapters — use the drivers' ports&lt;/li&gt;
&lt;li&gt;Driven Adapters — implement the driven ports&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Also, I want to clarify one thing about the hexagon itself. Some people in other articles mentioned it and some misunderstood what Alistair Cockburn did with the Hexagon shape.&lt;/p&gt;

&lt;p&gt;In the original article, Alistair says that the hexagon is just as it is because it is easy to highlight the inside-outside asymmetry and the nature of the ports. The term Hexagonal Architecture comes from this visual effect and it is not related to any kind of shape.&lt;/p&gt;

&lt;h3&gt;
  
  
  Benefits
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Testability&lt;/strong&gt;. All code must be isolated if you are following correctly this pattern, so everything can be mocked.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Maintainability&lt;/strong&gt;. We talked about it before, but if you need to extend an adapter it can be easily done because of all that great isolation we achieve the following Ports and Adapters. Same if we require to switch an adapter implementation to use another technology (aka database, SMTP or queues)&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Identify Tech Debt&lt;/strong&gt;. Tech debt will be there, but following this approach, you will be able to identify code smells and measure the tech debt in terms of effort and time.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Cons
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Complexity&lt;/strong&gt;. For me, it is the only real issue here. Everyone in a team needs to be aligned to make this kind of architecture work. If that doesn’t happen the code and the architecture will become a mess without the possibility of getting any of the previously mentioned benefits.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Example repositories
&lt;/h3&gt;

&lt;p&gt;With this article series I am trying to get a clean architecture and I will provide code samples once we review all this boring theory, but if you want to check how some people use Hexagonal Architecture here you have some Github repositories:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;.NET Core: &lt;a href="https://github.com/ivanpaulovich/hexagonal-architecture-acerola"&gt;https://github.com/ivanpaulovich/hexagonal-architecture-acerola&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Java: &lt;a href="https://github.com/iluwatar/java-design-patterns/tree/master/hexagonal"&gt;https://github.com/iluwatar/java-design-patterns/tree/master/hexagonal&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;NodeJS: &lt;a href="https://github.com/jbuget/nodejs-clean-architecture-app"&gt;https://github.com/jbuget/nodejs-clean-architecture-app&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Go: &lt;a href="https://github.com/Holmes89/hex-example"&gt;https://github.com/Holmes89/hex-example&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;I hope that &lt;strong&gt;I explained myself good enough&lt;/strong&gt; to understand what hexagonal architectures are and I wish &lt;strong&gt;you are not reacting to this article like this right now&lt;/strong&gt; :&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--8kxXtu-i--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://cdn-images-1.medium.com/max/460/0%2AYbjtuq23Ih0VWkea.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--8kxXtu-i--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://cdn-images-1.medium.com/max/460/0%2AYbjtuq23Ih0VWkea.gif" alt=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  See you soon in the next article about Onion Architecture and DDD!
&lt;/h3&gt;

&lt;p&gt;And if you enjoyed this article, feel free to share it and to give some likes!&lt;/p&gt;

&lt;h3&gt;
  
  
  References
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;a href="http://alistair.cockburn.us/Hexagonal+architecture"&gt;http://alistair.cockburn.us/Hexagonal+architecture&lt;/a&gt; (Must)&lt;/li&gt;
&lt;li&gt;&lt;a href="http://web.archive.org/web/20180528132445/http://alistair.cockburn.us/Hexagonal+Architecture"&gt;http://web.archive.org/web/20180528132445/http://alistair.cockburn.us/Hexagonal+Architecture&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://wiki.c2.com/?HexagonalArchitecture"&gt;http://wiki.c2.com/?HexagonalArchitecture&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://wiki.c2.com/?PortsAndAdaptersArchitecture"&gt;http://wiki.c2.com/?PortsAndAdaptersArchitecture&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://our-academy.org/posts/arquitectura-hexagonal"&gt;https://our-academy.org/posts/arquitectura-hexagonal&lt;/a&gt; (Spanish)&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://softwarecampament.wordpress.com/portsadapters/#tc1"&gt;https://softwarecampament.wordpress.com/portsadapters&lt;/a&gt; (Must)&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://www.youtube.com/watch?v=fGaJHEgonKg"&gt;https://www.youtube.com/watch?v=fGaJHEgonKg&lt;/a&gt; (Video from Marcus Biel)&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://www.youtube.com/watch?v=th4AgBcrEHA"&gt;https://www.youtube.com/watch?v=th4AgBcrEHA&lt;/a&gt; (Video)&lt;/li&gt;
&lt;li&gt;&lt;a href="https://dev.to/julientopcu/hexagonal-architecture-decoupling-your-technical-code-from-your-business-logic-hexarch-1f3l"&gt;https://beyondxscratch.com/2017/08/19/decoupling-your-technical-code-from-your-business-logic-with-the-hexagonal-architecture-hexarch/&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://codely.tv/blog/screencasts/arquitectura-hexagonal-ddd/"&gt;https://codely.tv/blog/screencasts/arquitectura-hexagonal-ddd/&lt;/a&gt; (Spanish)&lt;/li&gt;
&lt;li&gt;&lt;a href="http://mussabsharif.blogspot.com/2011/08/api-vs-spi.html"&gt;http://mussabsharif.blogspot.com/2011/08/api-vs-spi.html&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://blog.ndepend.com/hexagonal-architecture/"&gt;https://blog.ndepend.com/hexagonal-architecture/&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://www.dossier-andreas.net/software_architecture/ports_and_adapters.html"&gt;http://www.dossier-andreas.net/software_architecture/ports_and_adapters.html&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://hackernoon.com/hexagonal-architecture-with-kotlin-ktor-and-guice-f1b68fbdf2d9"&gt;https://hackernoon.com/hexagonal-architecture-with-kotlin-ktor-and-guice-f1b68fbdf2d9&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://stackoverflow.com/questions/2954372/difference-between-spi-and-api"&gt;https://stackoverflow.com/questions/2954372/difference-between-spi-and-api&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://thinkmicroservices.com/blog/2018/hexagonal-architecture.html"&gt;http://thinkmicroservices.com/blog/2018/hexagonal-architecture.html&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>design</category>
      <category>productivity</category>
      <category>career</category>
      <category>architecture</category>
    </item>
  </channel>
</rss>
