{"id":"6b08bd3880884893657cc98c","slug":"hexagonal-architecture","title":"Pierogi in the Hexagon","summary":"Hexagonal architecture in .NET explained over a beer — so that even your aunt gets it at a family party","servedLang":"en","availableLangs":["pl","en"],"topics":["hexagonal-architecture","clean-architecture","onion-architecture","microservices"],"techs":["dotnet"],"tags":["ports-and-adapters","aspnet-core","mediatr","mapster","ef-core","kafka","testing","netarchtest"],"level":"intermediate","kind":"tutorial","access":"members","status":"published","cover":"/api/files/6b08bd3880884893657cc988","author":{"id":"6b08bd2e80884893657cc8cf","name":"Redakcja Art of Devs","avatar":null,"handle":"redakcja","community":false},"readingMinutes":62,"stats":{"views":9,"likes":0,"bookmarks":0,"comments":0},"publishedAt":"2026-11-26T23:14:00.666Z","updatedAt":"2026-11-27T13:08:37.572Z","requestedLang":"en","theme":{"hero":"split","heroMedia":{"kind":"image","fileId":"6b08bd3880884893657cc988","url":"/api/files/6b08bd3880884893657cc988"},"accent":"teal","background":"hex","weaveResources":true,"toc":"right"},"seoDescription":"A 13-lesson course on hexagonal architecture (ports and adapters) in .NET 10: Halina's pierogi place, ASP.NET Core, MediatR, Mapster, EF Core, Kafka, tests and microservices.","wordCount":12376,"doc":{"type":"doc","content":[{"type":"heading","attrs":{"level":2,"id":"warm-up-what-is-this-all-about"},"content":[{"type":"text","text":"Warm-up: what is this all about"}]},{"type":"paragraph","content":[{"type":"text","text":"Hexagonal architecture is a way of arranging code in which the heart of the application, the business logic, has no idea about the database, the framework, emails, text messages and the whole external circus.","marks":[{"type":"bold"}]},{"type":"text","text":" That's it. The rest of the course just unpacks this one sentence using pierogi."}]},{"type":"paragraph","content":[{"type":"text","text":"The scene goes like this: Friday, 7:30 p.m., a pub, second beer. A friend sighs: \"Listen, on the new project they want me to do some hexagon. Ports, adapters... I feel like I'm back in primary school geometry.\" So I grab a napkin and a pen and start drawing."}]},{"type":"heading","attrs":{"level":3,"id":"who-this-is-for"},"content":[{"type":"text","text":"Who this is for"}]},{"type":"bulletList","content":[{"type":"listItem","content":[{"type":"paragraph","content":[{"type":"text","text":"For the junior who heard \"hexagonal\" in a job interview and nodded wisely."}]}]},{"type":"listItem","content":[{"type":"paragraph","content":[{"type":"text","text":"For the mid who does it on a project but feels it's just \"more folders\"."}]}]},{"type":"listItem","content":[{"type":"paragraph","content":[{"type":"text","text":"For the senior who gets the topic but can't explain it to newcomers on the team."}]}]},{"type":"listItem","content":[{"type":"paragraph","content":[{"type":"text","text":"For the PM who finally wants to understand why \"changing the SMS provider\" took three sprints."}]}]}]},{"type":"heading","attrs":{"level":3,"id":"what-you-need-to-know"},"content":[{"type":"text","text":"What you need to know"}]},{"type":"paragraph","content":[{"type":"text","text":"C# basics: a class, an interface, "},{"type":"text","text":"async/await","marks":[{"type":"code"}]},{"type":"text","text":". You don't need to know DDD, SOLID by heart or any patterns from thick books. The examples target .NET 10 and a real-life stack: ASP.NET Core with Swagger, MediatR, Mapster, EF Core with SQL Server, and Kafka. The code is in English, just like in real projects. Beer optional, but it helps."}]},{"type":"heading","attrs":{"level":3,"id":"the-party-plan"},"content":[{"type":"text","text":"The party plan"}]},{"type":"table","content":[{"type":"tableRow","content":[{"type":"tableHeader","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"Lesson"}]}]},{"type":"tableHeader","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"What it's about"}]}]},{"type":"tableHeader","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"Metaphor"}]}]}]},{"type":"tableRow","content":[{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"1"},{"type":"text","text":"."},{"type":"text","text":" The problem"}]}]},{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"Why spaghetti code hurts"}]}]},{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"A flat with the fridge welded to the sofa"}]}]}]},{"type":"tableRow","content":[{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"2"},{"type":"text","text":"."},{"type":"text","text":" The big idea"}]}]},{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"The heart of the application and the world around it"}]}]},{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"Halina's pierogi place"}]}]}]},{"type":"tableRow","content":[{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"3"},{"type":"text","text":"."},{"type":"text","text":" Ports and adapters"}]}]},{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"Contract versus implementation"}]}]},{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"A socket and a travel adapter"}]}]}]},{"type":"tableRow","content":[{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"4"},{"type":"text","text":"."},{"type":"text","text":" Glossary"}]}]},{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"The words people throw around in code review"}]}]},{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"A cheat sheet from the menu"}]}]}]},{"type":"tableRow","content":[{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"5"},{"type":"text","text":"."},{"type":"text","text":" The golden rule"}]}]},{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"Dependencies point inwards"}]}]},{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"Halina doesn't know the wholesaler's number"}]}]}]},{"type":"tableRow","content":[{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"6"},{"type":"text","text":"."},{"type":"text","text":" Solution structure"}]}]},{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"How to split it into .NET projects"}]}]},{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"The kitchen floor plan"}]}]}]},{"type":"tableRow","content":[{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"7"},{"type":"text","text":"."},{"type":"text","text":" Code"}]}]},{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"From the domain to the controller and "},{"type":"text","text":"Program.cs","marks":[{"type":"code"}]}]}]},{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"Making pierogi step by step"}]}]}]},{"type":"tableRow","content":[{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"8"},{"type":"text","text":"."},{"type":"text","text":" Swapping an adapter"}]}]},{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"Adding Kafka without touching the logic"}]}]},{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"A new waitress"}]}]}]},{"type":"tableRow","content":[{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"9"},{"type":"text","text":"."},{"type":"text","text":" Tests"}]}]},{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"Tests without a database and without Docker"}]}]},{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"A taste test before opening"}]}]}]},{"type":"tableRow","content":[{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"10"},{"type":"text","text":"."},{"type":"text","text":" Deadly sins"}]}]},{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"Typical blunders"}]}]},{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"Halina in an apron with the wholesaler's logo"}]}]}]},{"type":"tableRow","content":[{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"11"},{"type":"text","text":"."},{"type":"text","text":" When NOT to"}]}]},{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"Form over substance"}]}]},{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"Skyscraper foundations for a hot-dog stand"}]}]}]},{"type":"tableRow","content":[{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"12"},{"type":"text","text":"."},{"type":"text","text":" Hex vs Onion vs Clean"}]}]},{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"How they differ"}]}]},{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"Same party, different T-shirts"}]}]}]},{"type":"tableRow","content":[{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"13"},{"type":"text","text":"."},{"type":"text","text":" Hexagons and microservices"}]}]},{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"Three services, three controllers and Kafka between them"}]}]},{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"The pierogi place opens a chain"}]}]}]}]},{"type":"paragraph","content":[{"type":"text","text":"At the end there's a fridge cheat sheet and a mini-quiz. Every lesson stands on its own, so you can read them separately, for example one a day on the tram."}]},{"type":"paragraph","content":[{"type":"text","text":"The course also comes with the "},{"type":"text","text":"Pierogi place simulator","marks":[{"type":"link","attrs":{"href":"/interactive/symulator-pierogarni.html"}}]},{"type":"text","text":" with three interactive simulations: an order slip travelling through the hexagon with switchable adapters, three microservices talking over Kafka (with services you can switch off and consumer lag), and a clickable architecture test."}]},{"type":"embed","attrs":{"provider":"interactive","url":"/interactive/symulator-pierogarni.html","embedUrl":"/interactive/symulator-pierogarni.html","caption":"Pierogi place simulator (interface in Polish): hexagon in action, microservices on Kafka and the architecture guard","height":900,"width":"wide"}},{"type":"heading","attrs":{"level":2,"id":"lesson-1-the-problem-a-flat-with-the-fridge-welded-to-the-sofa"},"content":[{"type":"text","text":"Lesson 1. The problem: a flat with the fridge welded to the sofa"}]},{"type":"paragraph","content":[{"type":"text","text":"Code without architecture works great until the first change. After that, every small fix means renovating the whole flat.","marks":[{"type":"bold"}]}]},{"type":"paragraph","content":[{"type":"text","text":"Imagine a flat where the fridge is welded to the sofa, the TV is bricked into the bathroom wall and the washing machine is plugged into the radiator. Everything works. Until you want to replace the fridge. Then you grab an angle grinder and cut through the sofa."}]},{"type":"image","attrs":{"src":"/api/files/6b08bd3480884893657cc972","alt":"Spaghetti code: OrdersController welded with noodles to SQL Server, an SMS gateway, a webhook and a business rule"}},{"type":"paragraph","content":[{"type":"text","text":"This is what a typical controller looks like in a project that \"was supposed to be quick\". A real example from life, just with pierogi:"}]},{"type":"codeBlock","attrs":{"language":"csharp","filename":"Spaghetti/OrdersController.cs"},"content":[{"type":"text","text":"[ApiController]\n[Route(\"api/orders\")]\npublic class OrdersController : ControllerBase\n{\n    [HttpPost]\n    public async Task<IActionResult> Place(OrderRequest req)\n    {\n        // 1. A business rule crammed into the controller\n        if (req.Quantity > 100)\n            return BadRequest(\"More than 100 pieces? Weddings only!\");\n\n        // 2. Hard-wired database (Dapper + connection string in code, a classic)\n        using var conn = new SqlConnection(\"Server=prod;Database=Pierogi;...\");\n        await conn.ExecuteAsync(\"INSERT INTO Orders (Phone, Quantity) VALUES (@Phone, @Quantity)\", req);\n\n        // 3. Hard-wired SMS, new HttpClient() right inside the method\n        var http = new HttpClient();\n        await http.PostAsJsonAsync(\"https://api.sms-provider.example/send\",\n            new { to = req.Phone, text = \"Halina is cooking!\" });\n\n        return Ok();\n    }\n}"}]},{"type":"paragraph","content":[{"type":"text","text":"At first glance: 20 lines, it works, what more could you want. Now watch what happens when life knocks on the door."}]},{"type":"heading","attrs":{"level":3,"id":"four-scenes-from-life"},"content":[{"type":"text","text":"Four scenes from life"}]},{"type":"orderedList","attrs":{"start":1},"content":[{"type":"listItem","content":[{"type":"paragraph","content":[{"type":"text","text":"\"Write a test for the 100-pierogi rule.\"","marks":[{"type":"bold"}]},{"type":"text","text":" To check a single "},{"type":"text","text":"if","marks":[{"type":"code"}]},{"type":"text","text":", you have to spin up SQL Server and send a real text message. Preferably to yourself, at three in the morning, from CI."}]}]},{"type":"listItem","content":[{"type":"paragraph","content":[{"type":"text","text":"\"We're moving to Postgres.\"","marks":[{"type":"bold"}]},{"type":"text","text":" The SQL is scattered across 40 controllers. You search the whole repo for "},{"type":"text","text":"SqlConnection","marks":[{"type":"code"}]},{"type":"text","text":" and pray nothing slips through."}]}]},{"type":"listItem","content":[{"type":"paragraph","content":[{"type":"text","text":"\"Text messages are too expensive, we're doing WhatsApp.\"","marks":[{"type":"bold"}]},{"type":"text","text":" Same story, just with "},{"type":"text","text":"HttpClient","marks":[{"type":"code"}]},{"type":"text","text":". Someone copied the sending code into three places and each version is slightly different."}]}]},{"type":"listItem","content":[{"type":"paragraph","content":[{"type":"text","text":"\"Pyszne.pl will send us orders through a webhook.\"","marks":[{"type":"bold"}]},{"type":"text","text":" You copy the controller because it's faster. Now the \"max 100 pieces\" rule lives in two places. In six months someone will change it to 120 in only one of them."}]}]}]},{"type":"heading","attrs":{"level":3,"id":"where-the-real-problem-lies"},"content":[{"type":"text","text":"Where the real problem lies"}]},{"type":"paragraph","content":[{"type":"text","text":"Not in someone using Dapper or "},{"type":"text","text":"HttpClient","marks":[{"type":"code"}]},{"type":"text","text":". The problem is that "},{"type":"text","text":"business rules and technical details are welded together","marks":[{"type":"bold"}]},{"type":"text","text":". The most valuable part of the application, \"how our pierogi place works\", is swimming in a noodle soup of connection strings and URLs."}]},{"type":"paragraph","content":[{"type":"text","text":"Hexagonal architecture simply means mounting all these appliances on plugs instead of welds. The fridge goes into a socket, the sofa stands on its own, and you replace each thing without an angle grinder."}]},{"type":"heading","attrs":{"level":2,"id":"lesson-2-the-big-idea-halina-s-pierogi-place"},"content":[{"type":"text","text":"Lesson 2. The big idea: Halina's pierogi place"}]},{"type":"paragraph","content":[{"type":"text","text":"All of hexagonal architecture fits into one small restaurant: the kitchen in the middle doesn't know where the order came from or who delivered the flour. And that's a very good thing.","marks":[{"type":"bold"}]}]},{"type":"paragraph","content":[{"type":"text","text":"Meet Mrs Halina. For 30 years she has been making pierogi in a small place in Oliwa, Gdańsk. Her rules are sacred: at least one pierogi per order, at most a hundred without advance notice, and every order must have a phone number so it's clear whom to call."}]},{"type":"paragraph","content":[{"type":"text","text":"These rules are the "},{"type":"text","text":"domain","marks":[{"type":"bold"}]},{"type":"text","text":". They are the entire value of this business. If the place closed tomorrow and reopened in another building, with other waitresses and another wholesaler, Halina's pierogi would taste exactly the same."}]},{"type":"heading","attrs":{"level":3,"id":"the-left-side-who-wants-something-from-the-kitchen"},"content":[{"type":"text","text":"The left side: who wants something from the kitchen"}]},{"type":"paragraph","content":[{"type":"text","text":"Orders arrive by different routes, and each one speaks a different language:"}]},{"type":"bulletList","content":[{"type":"listItem","content":[{"type":"paragraph","content":[{"type":"text","text":"Jola the waitress","marks":[{"type":"bold"}]},{"type":"text","text":" shouts across the dining room: \"Two ruskie, one with meat!\""}]}]},{"type":"listItem","content":[{"type":"paragraph","content":[{"type":"text","text":"The phone","marks":[{"type":"bold"}]},{"type":"text","text":": Mr Zdzisio mumbles something about \"the cabbage ones, the usual\"."}]}]},{"type":"listItem","content":[{"type":"paragraph","content":[{"type":"text","text":"The Pyszne.pl app","marks":[{"type":"bold"}]},{"type":"text","text":" (a Polish food delivery platform) sends JSON with English field names."}]}]}]},{"type":"paragraph","content":[{"type":"text","text":"But everything reaches the kitchen through "},{"type":"text","text":"a single hatch","marks":[{"type":"bold"}]},{"type":"text","text":", always in the same format: an order slip saying \"Ruskie x20, tel. 600 100 200\". Halina doesn't read JSON and doesn't decode Zdzisio. That's the job of Jola, the phone operator and the tablet by the till."}]},{"type":"heading","attrs":{"level":3,"id":"the-right-side-what-the-kitchen-needs-from-the-world"},"content":[{"type":"text","text":"The right side: what the kitchen needs from the world"}]},{"type":"paragraph","content":[{"type":"text","text":"The kitchen wants things from its surroundings, too:"}]},{"type":"bulletList","content":[{"type":"listItem","content":[{"type":"paragraph","content":[{"type":"text","text":"Record the order.","marks":[{"type":"bold"}]},{"type":"text","text":" Today in a notebook, tomorrow on a tablet, a year from now in the cloud."}]}]},{"type":"listItem","content":[{"type":"paragraph","content":[{"type":"text","text":"Let the customer know it's ready.","marks":[{"type":"bold"}]},{"type":"text","text":" A bell, a text message, WhatsApp, a shout through the window."}]}]},{"type":"listItem","content":[{"type":"paragraph","content":[{"type":"text","text":"Order flour.","marks":[{"type":"bold"}]},{"type":"text","text":" From the wholesaler, from the mill or from the discount store around the corner."}]}]}]},{"type":"paragraph","content":[{"type":"text","text":"Halina only says: \"I need 25 kg of flour in the back room by 7 a.m.\" Where the flour comes from and whose van brings it is no longer her concern."}]},{"type":"heading","attrs":{"level":3,"id":"why-a-hexagon-of-all-shapes"},"content":[{"type":"text","text":"Why a hexagon, of all shapes?"}]},{"type":"paragraph","content":[{"type":"text","text":"The name was coined by Alistair Cockburn, who described the idea around 2005. Its official, more boring name is "},{"type":"text","text":"Ports and Adapters","marks":[{"type":"bold"}]},{"type":"text","text":". The six sides mean nothing. The point was a shape with many sides on which ports are easy to draw, and a break from drawing layers stacked one on top of another."}]},{"type":"paragraph","content":[{"type":"text","text":"In short: it could have been an octagon, but then the diagram would look like a STOP sign and nobody would ever adopt it."}]},{"type":"heading","attrs":{"level":3,"id":"remember-this-picture"},"content":[{"type":"text","text":"Remember this picture"}]},{"type":"image","attrs":{"src":"/api/files/6b08bd3580884893657cc974","alt":"Halina's pierogi place as a hexagon: the kitchen in the middle, a waitress, a phone and a delivery app on the left, a notebook, a bell and a wholesaler on the right","width":"wide"}},{"type":"bulletList","content":[{"type":"listItem","content":[{"type":"paragraph","content":[{"type":"text","text":"The middle","marks":[{"type":"bold"}]},{"type":"text","text":" is Halina's kitchen, that is, the business logic."}]}]},{"type":"listItem","content":[{"type":"paragraph","content":[{"type":"text","text":"The edges of the hexagon","marks":[{"type":"bold"}]},{"type":"text","text":" are the hatches and doors, that is, the ports."}]}]},{"type":"listItem","content":[{"type":"paragraph","content":[{"type":"text","text":"Outside","marks":[{"type":"bold"}]},{"type":"text","text":" stand Jola, the courier, the phone, the notebook and the wholesaler, that is, the adapters and all the technology."}]}]}]},{"type":"paragraph","content":[{"type":"text","text":"Everything that follows is just an elaboration of this picture."}]},{"type":"heading","attrs":{"level":2,"id":"lesson-3-ports-and-adapters-or-a-usb-c-socket-and-everything-you-plug-into-it"},"content":[{"type":"text","text":"Lesson 3. Ports and adapters, or a USB-C socket and everything you plug into it"}]},{"type":"paragraph","content":[{"type":"text","text":"A port is the shape of the socket, an adapter is the plug. In code: a port is an interface, an adapter is a class that implements that interface.","marks":[{"type":"bold"}]}]},{"type":"paragraph","content":[{"type":"text","text":"Pick up a laptop. It has a USB-C socket on the side. You can plug a wall charger into that socket, a power bank, a docking station at the office or a cable from the car's cigarette lighter. The laptop hasn't the faintest idea where its power comes from. It only knows that something supplies it through USB-C."}]},{"type":"paragraph","content":[{"type":"text","text":"Now the most important part: "},{"type":"text","text":"it was the laptop that decided what socket it has","marks":[{"type":"bold"}]},{"type":"text","text":". The power bank manufacturer has to adapt, not the other way round. Nobody sensible rebuilds a laptop for a particular power bank."}]},{"type":"paragraph","content":[{"type":"text","text":"And when you fly to London, where the wall sockets come from another planet? You don't solder anything inside the laptop. You buy a travel adapter at the airport for a few quid. The laptop won't even notice it's in England."}]},{"type":"image","attrs":{"src":"/api/files/6b08bd3580884893657cc976","alt":"A laptop with a USB-C socket as the ICustomerNotifier port and three plugs as adapters: SMS, console and a test fake"}},{"type":"heading","attrs":{"level":3,"id":"the-same-thing-in-c"},"content":[{"type":"text","text":"The same thing in C#"}]},{"type":"codeBlock","attrs":{"language":"csharp","filename":"CustomerNotifier.cs"},"content":[{"type":"text","text":"// PORT: \"the socket in the laptop\". It says WHAT is needed, not HOW.\npublic interface ICustomerNotifier\n{\n    Task Notify(string phone, string message, CancellationToken ct);\n}\n\n// ADAPTER #1: \"the wall charger\", real text messages in production\npublic sealed class SmsCustomerNotifier(HttpClient http) : ICustomerNotifier\n{\n    public async Task Notify(string phone, string message, CancellationToken ct)\n    {\n        var response = await http.PostAsJsonAsync(\"send\", new { to = phone, text = message }, ct);\n        response.EnsureSuccessStatusCode();\n    }\n}\n\n// ADAPTER #2: \"the power bank\", for local development, costs nothing\npublic sealed class ConsoleCustomerNotifier : ICustomerNotifier\n{\n    public Task Notify(string phone, string message, CancellationToken ct)\n    {\n        Console.WriteLine($\"[HALINA SHOUTS THROUGH THE WINDOW at {phone}]: {message}\");\n        return Task.CompletedTask;\n    }\n}"}]},{"type":"paragraph","content":[{"type":"text","text":"Code that needs to notify a customer gets an "},{"type":"text","text":"ICustomerNotifier","marks":[{"type":"code"}]},{"type":"text","text":" in its constructor, and that's all. It doesn't know whether there's an SMS gateway on the other end or "},{"type":"text","text":"Console.WriteLine","marks":[{"type":"code"}]},{"type":"text","text":". Exactly like a laptop with a power bank."}]},{"type":"heading","attrs":{"level":3,"id":"the-real-port-test"},"content":[{"type":"text","text":"The real-port test"}]},{"type":"paragraph","content":[{"type":"text","text":"A port names a "},{"type":"text","text":"business need","marks":[{"type":"bold"}]},{"type":"text","text":", not a technology. A simple rule of thumb:"}]},{"type":"bulletList","content":[{"type":"listItem","content":[{"type":"paragraph","content":[{"type":"text","text":"ICustomerNotifier","marks":[{"type":"code"}]},{"type":"text","text":", "},{"type":"text","text":"IOrderBook","marks":[{"type":"code"}]},{"type":"text","text":", "},{"type":"text","text":"IFlourSupply","marks":[{"type":"code"}]},{"type":"text","text":" are ports. They speak the language of the business: notify the customer, record the order, deliver the flour."}]}]},{"type":"listItem","content":[{"type":"paragraph","content":[{"type":"text","text":"ISmsSender","marks":[{"type":"code"}]},{"type":"text","text":", "},{"type":"text","text":"ISqlOrderRepository","marks":[{"type":"code"}]},{"type":"text","text":", "},{"type":"text","text":"IKafkaPublisher","marks":[{"type":"code"}]},{"type":"text","text":" are adapters dressed up as ports. The technology sits right in the name."}]}]}]},{"type":"paragraph","content":[{"type":"text","text":"If the interface name contains Sql, Sms, Http, Kafka or Redis, the socket has almost certainly been cut for one specific plug. Like a USB-C port that fits only one power bank from one company."}]},{"type":"heading","attrs":{"level":2,"id":"lesson-4-a-no-nonsense-glossary"},"content":[{"type":"text","text":"Lesson 4. A no-nonsense glossary"}]},{"type":"paragraph","content":[{"type":"text","text":"In code review you'll hear six words: domain, application, inbound port, outbound port, driving adapter and driven adapter. You already know all of them from the pierogi place.","marks":[{"type":"bold"}]}]},{"type":"table","content":[{"type":"tableRow","content":[{"type":"tableHeader","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"Word from a clever book"}]}]},{"type":"tableHeader","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"In plain words"}]}]},{"type":"tableHeader","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"In the pierogi place"}]}]},{"type":"tableHeader","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"In our code"}]}]}]},{"type":"tableRow","content":[{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"Domain"}]}]},{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"Business rules that would be true even without a computer"}]}]},{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"Halina's recipe and rules"}]}]},{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"The "},{"type":"text","text":"Order","marks":[{"type":"code"}]},{"type":"text","text":" class, the "},{"type":"text","text":"HalinaSaysNoException","marks":[{"type":"code"}]},{"type":"text","text":" exception"}]}]}]},{"type":"tableRow","content":[{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"Application, use case"}]}]},{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"The scenario \"what happens when...\""}]}]},{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"\"Someone places an order\": accept it, record it, let people know"}]}]},{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"The MediatR handler "},{"type":"text","text":"PlaceOrderHandler","marks":[{"type":"code"}]}]}]}]},{"type":"tableRow","content":[{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"Inbound port (driving / primary port)"}]}]},{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"What the world can ask the application to do"}]}]},{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"The hatch for order slips"}]}]},{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"The command "},{"type":"text","text":"PlaceOrder : IRequest<OrderConfirmation>","marks":[{"type":"code"}]}]}]}]},{"type":"tableRow","content":[{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"Outbound port (driven / secondary port)"}]}]},{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"What the application needs from the world"}]}]},{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"The back door for suppliers"}]}]},{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"The interfaces "},{"type":"text","text":"IOrderBook","marks":[{"type":"code"}]},{"type":"text","text":", "},{"type":"text","text":"IOrderAnnouncer","marks":[{"type":"code"}]}]}]}]},{"type":"tableRow","content":[{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"Driving adapter (primary adapter)"}]}]},{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"Someone who calls the application and translates a foreign language into ours"}]}]},{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"Jola the waitress, the Pyszne.pl tablet"}]}]},{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"OrdersController","marks":[{"type":"code"}]},{"type":"text","text":" (HTTP), a Kafka consumer"}]}]}]},{"type":"tableRow","content":[{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"Driven adapter (secondary adapter)"}]}]},{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"Someone the application calls, who knows the technology"}]}]},{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"The wholesaler, the bell, the notebook"}]}]},{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"EfOrderBook","marks":[{"type":"code"}]},{"type":"text","text":" (EF Core), "},{"type":"text","text":"KafkaOrderAnnouncer","marks":[{"type":"code"}]},{"type":"text","text":", the SMS gateway"}]}]}]}]},{"type":"heading","attrs":{"level":3,"id":"how-not-to-mix-up-the-left-and-right-sides"},"content":[{"type":"text","text":"How not to mix up the left and right sides"}]},{"type":"paragraph","content":[{"type":"text","text":"Ask one question: "},{"type":"text","text":"who starts the conversation?","marks":[{"type":"bold"}]}]},{"type":"bulletList","content":[{"type":"listItem","content":[{"type":"paragraph","content":[{"type":"text","text":"If the world starts it (a customer clicks in Swagger, a message arrives from Kafka, a cron job fires), it's the "},{"type":"text","text":"left side","marks":[{"type":"bold"}]},{"type":"text","text":". The adapter drives the application, hence the name \"driving\"."}]}]},{"type":"listItem","content":[{"type":"paragraph","content":[{"type":"text","text":"If the application starts it (\"save this\", \"send a text\", \"publish an event\"), it's the "},{"type":"text","text":"right side","marks":[{"type":"bold"}]},{"type":"text","text":". The application drives the adapter, so the adapter is \"driven\"."}]}]}]},{"type":"paragraph","content":[{"type":"text","text":"Careful: Kafka can stand on both sides at once. A consumer that reads orders from a topic is a driving adapter. A producer that publishes the \"order placed\" event is a driven adapter. Same technology, two different roles, like a waitress who takes orders in the morning and receives a delivery in the afternoon."}]},{"type":"heading","attrs":{"level":3,"id":"and-where-does-mediatr-fit"},"content":[{"type":"text","text":"And where does MediatR fit?"}]},{"type":"paragraph","content":[{"type":"text","text":"MediatR is the postman inside the building. The adapter drops a slip (a command) into the mailbox, and MediatR carries it to the right cook (the handler). Command plus handler together form the inbound port and the use case. MediatR is not an architecture, just a convenient way of wiring one up."}]},{"type":"heading","attrs":{"level":2,"id":"lesson-5-the-golden-rule-all-arrows-point-inwards"},"content":[{"type":"text","text":"Lesson 5. The golden rule: all arrows point inwards"}]},{"type":"paragraph","content":[{"type":"text","text":"The kitchen doesn't know anyone outside. It's the outsiders who know the kitchen and adapt to it. If you remember one thing from this course, let it be this.","marks":[{"type":"bold"}]}]},{"type":"paragraph","content":[{"type":"text","text":"Halina doesn't have the wholesaler's number in her phone. Instead, she pins a note on the back-room door: \"Flour: 25 kg, paper sacks, delivery by 7:00.\" Whoever wants to supply her reads the note and adapts. Changing wholesalers? Halina doesn't even look up from her pastry board."}]},{"type":"heading","attrs":{"level":3,"id":"normally-the-arrow-points-the-wrong-way"},"content":[{"type":"text","text":"Normally the arrow points the wrong way"}]},{"type":"paragraph","content":[{"type":"text","text":"In spaghetti code, the business logic calls the database directly. That means the logic "},{"type":"text","text":"depends","marks":[{"type":"bold"}]},{"type":"text","text":" on EF Core and SQL Server. Change the database and you touch the logic."}]},{"type":"paragraph","content":[{"type":"text","text":"In the hexagon we pull a dependency inversion trick (that's the \"D\" in SOLID):"}]},{"type":"orderedList","attrs":{"start":1},"content":[{"type":"listItem","content":[{"type":"paragraph","content":[{"type":"text","text":"The kitchen (the "},{"type":"text","text":"Application","marks":[{"type":"code"}]},{"type":"text","text":" project) defines the "},{"type":"text","text":"IOrderBook","marks":[{"type":"code"}]},{"type":"text","text":" interface itself. That's the note on the door."}]}]},{"type":"listItem","content":[{"type":"paragraph","content":[{"type":"text","text":"The adapter (the "},{"type":"text","text":"Adapters.SqlServer","marks":[{"type":"code"}]},{"type":"text","text":" project) implements this interface with the "},{"type":"text","text":"EfOrderBook","marks":[{"type":"code"}]},{"type":"text","text":" class, using EF Core."}]}]},{"type":"listItem","content":[{"type":"paragraph","content":[{"type":"text","text":"So the dependency arrow goes from the adapter "},{"type":"text","text":"to","marks":[{"type":"bold"}]},{"type":"text","text":" the kitchen, not the other way round."}]}]}]},{"type":"image","attrs":{"src":"/api/files/6b08bd3580884893657cc978","alt":"Before and after: in spaghetti the logic depends on the database, in the hexagon EfOrderBook implements IOrderBook defined by the kitchen"}},{"type":"paragraph","content":[{"type":"text","text":"In practice you can check this in one second. Open "},{"type":"text","text":"Pierogarnia.Domain.csproj","marks":[{"type":"code"}]},{"type":"text","text":" and there isn't a single "},{"type":"text","text":"PackageReference","marks":[{"type":"code"}]},{"type":"text","text":" in it. Zero EF, zero Kafka, zero ASP.NET. The "},{"type":"text","text":"Application","marks":[{"type":"code"}]},{"type":"text","text":" project only references "},{"type":"text","text":"Domain","marks":[{"type":"code"}]},{"type":"text","text":" and the MediatR package."}]},{"type":"heading","attrs":{"level":3,"id":"so-who-introduces-everyone-to-everyone"},"content":[{"type":"text","text":"So who introduces everyone to everyone?"}]},{"type":"paragraph","content":[{"type":"text","text":"The floor manager, that is, "},{"type":"text","text":"Program.cs","marks":[{"type":"code"}]},{"type":"text","text":". It's the only place in the entire application where everybody knows each other. The floor manager hires the waitress, signs the contract with the wholesaler and says: \"Jola handles the hatch, we keep the notebook in SQL Server, and the bell is Kafka.\""}]},{"type":"paragraph","content":[{"type":"text","text":"The technical name for this is the "},{"type":"text","text":"composition root","marks":[{"type":"bold"}]},{"type":"text","text":". In .NET it's simply registration in the DI container, the "},{"type":"text","text":"builder.Services.Add...","marks":[{"type":"code"}]},{"type":"text","text":" lines. The kitchen receives ready-made helpers in its constructor and doesn't ask where they came from."}]},{"type":"heading","attrs":{"level":3,"id":"three-check-questions"},"content":[{"type":"text","text":"Three check questions"}]},{"type":"bulletList","content":[{"type":"listItem","content":[{"type":"paragraph","content":[{"type":"text","text":"Is there any "},{"type":"text","text":"using Microsoft.EntityFrameworkCore","marks":[{"type":"code"}]},{"type":"text","text":" in the "},{"type":"text","text":"Domain","marks":[{"type":"code"}]},{"type":"text","text":" project? If so, Halina has a wholesaler's sales rep in her kitchen."}]}]},{"type":"listItem","content":[{"type":"paragraph","content":[{"type":"text","text":"Is there a "},{"type":"text","text":"using Confluent.Kafka","marks":[{"type":"code"}]},{"type":"text","text":" in "},{"type":"text","text":"Application","marks":[{"type":"code"}]},{"type":"text","text":"? If so, the kitchen calls the courier itself."}]}]},{"type":"listItem","content":[{"type":"paragraph","content":[{"type":"text","text":"Does an endpoint or a Kafka consumer contain an "},{"type":"text","text":"if","marks":[{"type":"code"}]},{"type":"text","text":" with a business rule? If so, the waitress is making pierogi in the back room."}]}]}]},{"type":"paragraph","content":[{"type":"text","text":"In lesson 9 I'll show you how to turn these questions into an automated test that fails the build when someone breaks the rule."}]},{"type":"heading","attrs":{"level":2,"id":"lesson-6-building-the-pierogi-place-in-net-10-the-solution-structure"},"content":[{"type":"text","text":"Lesson 6. Building the pierogi place in .NET 10: the solution structure"}]},{"type":"paragraph","content":[{"type":"text","text":"Five projects plus tests. Every NuGet package lives exactly where it belongs, and not one floor higher.","marks":[{"type":"bold"}]}]},{"type":"codeBlock","attrs":{"language":"plaintext","filename":"Pierogarnia/solution-structure.txt"},"content":[{"type":"text","text":"Pierogarnia/\n├── src/\n│   ├── Pierogarnia.Domain/             ← Halina's kitchen: entities and rules. ZERO packages.\n│   ├── Pierogarnia.Application/        ← ports + use cases (MediatR)\n│   ├── Pierogarnia.Adapters.SqlServer/ ← the pantry: EF Core + SQL Server\n│   ├── Pierogarnia.Adapters.Kafka/     ← the bell and the door for Pyszne.pl: Confluent.Kafka + Mapster\n│   └── Pierogarnia.Api/                ← HTTP window (controllers) + Swagger + the floor manager (Program.cs)\n└── tests/\n    └── Pierogarnia.Tests/              ← the taste test, without opening the restaurant"}]},{"type":"heading","attrs":{"level":3,"id":"who-knows-whom"},"content":[{"type":"text","text":"Who knows whom"}]},{"type":"table","content":[{"type":"tableRow","content":[{"type":"tableHeader","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"Project"}]}]},{"type":"tableHeader","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"Role in the hexagon"}]}]},{"type":"tableHeader","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"Project references"}]}]},{"type":"tableHeader","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"NuGet packages"}]}]}]},{"type":"tableRow","content":[{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"Domain","marks":[{"type":"code"}]}]}]},{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"The middle, business rules"}]}]},{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"none"}]}]},{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"none"}]}]}]},{"type":"tableRow","content":[{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"Application","marks":[{"type":"code"}]}]}]},{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"Ports and use cases"}]}]},{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"Domain","marks":[{"type":"code"}]}]}]},{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"MediatR"}]}]}]},{"type":"tableRow","content":[{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"Adapters.SqlServer","marks":[{"type":"code"}]}]}]},{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"Driven adapter (persistence)"}]}]},{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"Application","marks":[{"type":"code"}]}]}]},{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"Microsoft.EntityFrameworkCore.SqlServer"}]}]}]},{"type":"tableRow","content":[{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"Adapters.Kafka","marks":[{"type":"code"}]}]}]},{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"Driven adapter (publishing events) and driving adapter (the Pyszne.pl consumer)"}]}]},{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"Application","marks":[{"type":"code"}]}]}]},{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"Confluent.Kafka, Mapster, Microsoft.Extensions.Hosting.Abstractions, Microsoft.Extensions.Options.ConfigurationExtensions"}]}]}]},{"type":"tableRow","content":[{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"Api","marks":[{"type":"code"}]}]}]},{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"Driving adapter (HTTP) and composition root"}]}]},{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"all of the above"}]}]},{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"Microsoft.AspNetCore.OpenApi, Swashbuckle.AspNetCore.SwaggerUI, Mapster, Microsoft.EntityFrameworkCore.Design"}]}]}]},{"type":"tableRow","content":[{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"Tests","marks":[{"type":"code"}]}]}]},{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"Tests of the kitchen and of the architecture"}]}]},{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"Application","marks":[{"type":"code"}]}]}]},{"type":"tableCell","attrs":{"colspan":1,"rowspan":1},"content":[{"type":"paragraph","content":[{"type":"text","text":"xUnit (from the template), NetArchTest.Rules"}]}]}]}]},{"type":"image","attrs":{"src":"/api/files/6b08bd3680884893657cc97a","alt":".NET 10 solution map: Domain in the middle, Application around it, Api, Kafka and SqlServer adapters outside, references pointing inward","width":"wide"}},{"type":"paragraph","content":[{"type":"text","text":"Notice one thing: "},{"type":"text","text":"the adapters don't know each other","marks":[{"type":"bold"}]},{"type":"text","text":". Kafka doesn't know about SQL Server, and SQL Server doesn't know about Kafka. Each one only knows the kitchen. They're introduced to each other only by the floor manager in the "},{"type":"text","text":"Api","marks":[{"type":"code"}]},{"type":"text","text":" project."}]},{"type":"heading","attrs":{"level":3,"id":"setting-it-up-from-the-terminal"},"content":[{"type":"text","text":"Setting it up from the terminal"}]},{"type":"codeBlock","attrs":{"language":"bash","filename":"create-solution.sh"},"content":[{"type":"text","text":"mkdir Pierogarnia && cd Pierogarnia\ndotnet new sln -n Pierogarnia\n\ndotnet new classlib -n Pierogarnia.Domain             -o src/Pierogarnia.Domain\ndotnet new classlib -n Pierogarnia.Application        -o src/Pierogarnia.Application\ndotnet new classlib -n Pierogarnia.Adapters.SqlServer -o src/Pierogarnia.Adapters.SqlServer\ndotnet new classlib -n Pierogarnia.Adapters.Kafka     -o src/Pierogarnia.Adapters.Kafka\ndotnet new web      -n Pierogarnia.Api                -o src/Pierogarnia.Api\ndotnet new xunit    -n Pierogarnia.Tests              -o tests/Pierogarnia.Tests\ndotnet sln add src/*/*.csproj tests/*/*.csproj\n\n# Arrows point inwards\ndotnet add src/Pierogarnia.Application reference src/Pierogarnia.Domain\ndotnet add src/Pierogarnia.Adapters.SqlServer reference src/Pierogarnia.Application\ndotnet add src/Pierogarnia.Adapters.Kafka reference src/Pierogarnia.Application\ndotnet add src/Pierogarnia.Api reference src/Pierogarnia.Application src/Pierogarnia.Adapters.SqlServer src/Pierogarnia.Adapters.Kafka\ndotnet add tests/Pierogarnia.Tests reference src/Pierogarnia.Application\n\n# Packages only where they belong\ndotnet add src/Pierogarnia.Application package MediatR\ndotnet add src/Pierogarnia.Adapters.SqlServer package Microsoft.EntityFrameworkCore.SqlServer\ndotnet add src/Pierogarnia.Adapters.Kafka package Confluent.Kafka\ndotnet add src/Pierogarnia.Adapters.Kafka package Mapster\ndotnet add src/Pierogarnia.Adapters.Kafka package Microsoft.Extensions.Hosting.Abstractions\ndotnet add src/Pierogarnia.Adapters.Kafka package Microsoft.Extensions.Options.ConfigurationExtensions\ndotnet add src/Pierogarnia.Api package Microsoft.AspNetCore.OpenApi\ndotnet add src/Pierogarnia.Api package Swashbuckle.AspNetCore.SwaggerUI\ndotnet add src/Pierogarnia.Api package Mapster\ndotnet add src/Pierogarnia.Api package Microsoft.EntityFrameworkCore.Design\ndotnet add tests/Pierogarnia.Tests package NetArchTest.Rules"}]},{"type":"heading","attrs":{"level":3,"id":"two-things-worth-knowing-before-you-start"},"content":[{"type":"text","text":"Two things worth knowing before you start"}]},{"type":"paragraph","content":[{"type":"text","text":"Swagger in .NET 10 works a bit differently than it used to.","marks":[{"type":"bold"}]},{"type":"text","text":" Since .NET 9 the template no longer adds Swashbuckle, and the OpenAPI document is generated by the built-in Microsoft.AspNetCore.OpenApi package ("},{"type":"text","text":"Microsoft Learn","marks":[{"type":"link","attrs":{"href":"https://learn.microsoft.com/aspnet/core/fundamentals/openapi/using-openapi-documents"}}]},{"type":"text","text":"). We add the Swagger UI itself separately, with the Swashbuckle.AspNetCore.SwaggerUI package, and point it at "},{"type":"text","text":"/openapi/v1.json","marks":[{"type":"code"}]},{"type":"text","text":"."}]},{"type":"paragraph","content":[{"type":"text","text":"MediatR has been dual-licensed since version 13.","marks":[{"type":"bold"}]},{"type":"text","text":" New versions are released under the RPL-1.5 licence or a commercial one. The free Community edition covers companies with less than USD 5 million in annual revenue, non-profits and education ("},{"type":"text","text":"Jimmy Bogard","marks":[{"type":"link","attrs":{"href":"https://www.jimmybogard.com/automapper-and-mediatr-commercial-editions-launch-today/"}}]},{"type":"text","text":"). In a large company, check the licence first. The alternative is a plain handler class injected through DI, and the hexagon works with it exactly the same way."}]},{"type":"heading","attrs":{"level":2,"id":"lesson-7-code-step-by-step-we-work-from-the-inside-out"},"content":[{"type":"text","text":"Lesson 7. Code step by step: we work from the inside out"}]},{"type":"paragraph","content":[{"type":"text","text":"We start with the kitchen and finish at the doors. First the rules, then the ports, then the use case, and only at the very end the database, Kafka, the controller and Swagger.","marks":[{"type":"bold"}]},{"type":"text","text":" That's the opposite of most tutorials, which start with "},{"type":"text","text":"dotnet ef migrations add","marks":[{"type":"code"}]},{"type":"text","text":". And that's the whole secret."}]},{"type":"heading","attrs":{"level":3,"id":"step-1-the-domain-or-halina-s-recipe"},"content":[{"type":"text","text":"Step 1. The domain, or Halina's recipe"}]},{"type":"paragraph","content":[{"type":"text","text":"The file "},{"type":"text","text":"Pierogarnia.Domain/Order.cs","marks":[{"type":"code"}]},{"type":"text","text":". Notice that there isn't a single "},{"type":"text","text":"using","marks":[{"type":"code"}]},{"type":"text","text":" for anything outside .NET."}]},{"type":"codeBlock","attrs":{"language":"csharp","filename":"Pierogarnia.Domain/Order.cs"},"content":[{"type":"text","text":"namespace Pierogarnia.Domain;\n\npublic enum DumplingType { PotatoCheese, Meat, Cabbage, Blueberry }\n\npublic enum OrderStatus { Placed, Ready, Delivered }\n\npublic sealed class HalinaSaysNoException(string message) : Exception(message);\n\npublic sealed record OrderLine(DumplingType Type, int Quantity)\n{\n    public decimal UnitPrice => Type switch\n    {\n        DumplingType.PotatoCheese => 2.50m,\n        DumplingType.Cabbage      => 2.50m,\n        DumplingType.Meat         => 3.00m,\n        DumplingType.Blueberry    => 3.50m,\n        _ => throw new HalinaSaysNoException(\"Halina doesn't make that kind of pierogi.\")\n    };\n\n    public decimal Value => UnitPrice * Quantity;\n}\n\npublic sealed class Order\n{\n    public const int MaxWithoutNotice = 100;\n\n    private readonly List<OrderLine> _lines = [];\n\n    public Guid Id { get; private set; }\n    public string Phone { get; private set; } = default!;\n    public OrderStatus Status { get; private set; }\n    public IReadOnlyList<OrderLine> Lines => _lines;\n\n    public int Pieces => _lines.Sum(l => l.Quantity);\n    public decimal Total => _lines.Sum(l => l.Value);\n\n    private Order() { } // for EF Core. Halina pretends she didn't see this.\n\n    public static Order Place(string phone, IEnumerable<OrderLine> lines)\n    {\n        if (string.IsNullOrWhiteSpace(phone))\n            throw new HalinaSaysNoException(\"No phone number? Who am I supposed to call?\");\n\n        var order = new Order\n        {\n            Id = Guid.NewGuid(),\n            Phone = phone,\n            Status = OrderStatus.Placed\n        };\n\n        foreach (var line in lines)\n            order.Add(line);\n\n        if (order._lines.Count == 0)\n            throw new HalinaSaysNoException(\"An empty order slip? Halina doesn't cook air.\");\n\n        return order;\n    }\n\n    private void Add(OrderLine line)\n    {\n        if (line.Quantity <= 0)\n            throw new HalinaSaysNoException(\"Zero pierogi is not an order, it's an insult.\");\n\n        if (Pieces + line.Quantity > MaxWithoutNotice)\n            throw new HalinaSaysNoException(\"More than 100 pieces is wedding territory. Call a week ahead.\");\n\n        _lines.Add(line);\n    }\n}"}]},{"type":"paragraph","content":[{"type":"text","text":"What matters here, one by one:"}]},{"type":"bulletList","content":[{"type":"listItem","content":[{"type":"paragraph","content":[{"type":"text","text":"You can't create a bad order.","marks":[{"type":"bold"}]},{"type":"text","text":" The constructor is private, and the only door is "},{"type":"text","text":"Order.Place(...)","marks":[{"type":"code"}]},{"type":"text","text":", which guards all the rules. Nobody will write "},{"type":"text","text":"new Order { Phone = null }","marks":[{"type":"code"}]},{"type":"text","text":"."}]}]},{"type":"listItem","content":[{"type":"paragraph","content":[{"type":"text","text":"There are no public setters.","marks":[{"type":"bold"}]},{"type":"text","text":" The list of lines is read-only, so nobody can sneak in 500 pierogi through a side door."}]}]},{"type":"listItem","content":[{"type":"paragraph","content":[{"type":"text","text":"One exception for all of Halina's \"no\"s.","marks":[{"type":"bold"}]},{"type":"text","text":" "},{"type":"text","text":"HalinaSaysNoException","marks":[{"type":"code"}]},{"type":"text","text":" is the language of the domain. The HTTP adapter will turn it into a 422, and the Kafka consumer into a log entry."}]}]},{"type":"listItem","content":[{"type":"paragraph","content":[{"type":"text","text":"The only compromise is the empty constructor for EF Core.","marks":[{"type":"bold"}]},{"type":"text","text":" It's private and contains no logic. A purist will create a separate persistence model and map between them, a pragmatist will leave it as it is here. Both paths are fine."}]}]}]},{"type":"heading","attrs":{"level":3,"id":"step-2-ports-or-notes-on-the-doors"},"content":[{"type":"text","text":"Step 2. Ports, or notes on the doors"}]},{"type":"paragraph","content":[{"type":"text","text":"The file "},{"type":"text","text":"Pierogarnia.Application/Ports.cs","marks":[{"type":"code"}]},{"type":"text","text":". The hatch at the entrance and two notes on the back-room door."}]},{"type":"codeBlock","attrs":{"language":"csharp","filename":"Pierogarnia.Application/Ports.cs"},"content":[{"type":"text","text":"using MediatR;\nusing Pierogarnia.Domain;\n\nnamespace Pierogarnia.Application;\n\n// ===== INPUT PORT: the order slip you pass through the window =====\npublic sealed record PlaceOrder(string Phone, IReadOnlyList<OrderLineDto> Lines)\n    : IRequest<OrderConfirmation>;\n\npublic sealed record OrderLineDto(DumplingType Type, int Quantity);\n\npublic sealed record OrderConfirmation(Guid OrderId, int Pieces, decimal Total);\n\n// ===== OUTPUT PORTS: notes pinned to the back door =====\npublic interface IOrderBook\n{\n    Task Add(Order order, CancellationToken ct);\n}\n\npublic interface IOrderAnnouncer\n{\n    Task Announce(OrderPlaced orderPlaced, CancellationToken ct);\n}\n\npublic sealed record OrderPlaced(\n    Guid OrderId, string Phone, IReadOnlyList<OrderLineDto> Lines, decimal Total, DateTimeOffset PlacedAt);"}]},{"type":"paragraph","content":[{"type":"text","text":"The names speak the language of the business: "},{"type":"text","text":"IOrderBook","marks":[{"type":"code"}]},{"type":"text","text":" is the order notebook, and "},{"type":"text","text":"IOrderAnnouncer","marks":[{"type":"code"}]},{"type":"text","text":" is whoever announces the news. The words \"SQL\" and \"Kafka\" appear nowhere. The "},{"type":"text","text":"OrderPlaced","marks":[{"type":"code"}]},{"type":"text","text":" event already carries the phone number and the lines, because in lesson 13 the kitchen and the couriers will need them."}]},{"type":"paragraph","content":[{"type":"text","text":"And why is there no port for text messages here? Because the text message to the customer will be sent by a separate service that listens to events from Kafka (you'll see it in lesson 13). The kitchen only announces: \"order placed\". Who notifies the customer, and how, is none of its business."}]},{"type":"heading","attrs":{"level":3,"id":"step-3-the-use-case-or-halina-at-work"},"content":[{"type":"text","text":"Step 3. The use case, or Halina at work"}]},{"type":"paragraph","content":[{"type":"text","text":"The file "},{"type":"text","text":"Pierogarnia.Application/PlaceOrderHandler.cs","marks":[{"type":"code"}]},{"type":"text","text":". A MediatR handler is the scenario \"what we do when an order slip comes in\"."}]},{"type":"codeBlock","attrs":{"language":"csharp","filename":"Pierogarnia.Application/PlaceOrderHandler.cs"},"content":[{"type":"text","text":"using MediatR;\nusing Pierogarnia.Domain;\n\nnamespace Pierogarnia.Application;\n\npublic sealed class PlaceOrderHandler(\n    IOrderBook orderBook,\n    IOrderAnnouncer announcer,\n    TimeProvider clock) : IRequestHandler<PlaceOrder, OrderConfirmation>\n{\n    public async Task<OrderConfirmation> Handle(PlaceOrder command, CancellationToken ct)\n    {\n        // 1. Halina cooks (the domain guards every rule)\n        var order = Order.Place(\n            command.Phone,\n            command.Lines.Select(l => new OrderLine(l.Type, l.Quantity)));\n\n        // 2. Write it in the order book (the kitchen doesn't know it's SQL Server)\n        await orderBook.Add(order, ct);\n\n        // 3. Ring the bell (the kitchen doesn't know it's Kafka)\n        await announcer.Announce(\n            new OrderPlaced(order.Id, order.Phone, command.Lines, order.Total, clock.GetUtcNow()),\n            ct);\n\n        return new OrderConfirmation(order.Id, order.Pieces, order.Total);\n    }\n}"}]},{"type":"paragraph","content":[{"type":"text","text":"Read it out loud. It sounds like a description of Halina's work, not like code: make them, write it in the notebook, ring the bell. "},{"type":"text","text":"This is what a use case should look like: short, boring and business-focused.","marks":[{"type":"bold"}]}]},{"type":"paragraph","content":[{"type":"text","text":"Notice the "},{"type":"text","text":"TimeProvider","marks":[{"type":"code"}]},{"type":"text","text":", too. Even the clock is the outside world! If we wrote "},{"type":"text","text":"DateTimeOffset.UtcNow","marks":[{"type":"code"}]},{"type":"text","text":", a test checking the event date would be a lottery. "},{"type":"text","text":"TimeProvider","marks":[{"type":"code"}]},{"type":"text","text":" has been built into .NET since version 8, so it's a port you don't even have to write."}]},{"type":"paragraph","content":[{"type":"text","text":"Finally, registering the kitchen in DI, the file "},{"type":"text","text":"Pierogarnia.Application/KitchenRegistration.cs","marks":[{"type":"code"}]},{"type":"text","text":":"}]},{"type":"codeBlock","attrs":{"language":"csharp","filename":"Pierogarnia.Application/KitchenRegistration.cs"},"content":[{"type":"text","text":"using Microsoft.Extensions.DependencyInjection;\n\nnamespace Pierogarnia.Application;\n\npublic static class KitchenRegistration\n{\n    public static IServiceCollection AddKitchen(this IServiceCollection services, string? mediatRLicenseKey)\n    {\n        services.AddMediatR(cfg =>\n        {\n            cfg.LicenseKey = mediatRLicenseKey; // MediatR 13+: license key (Community edition has one too)\n            cfg.RegisterServicesFromAssembly(typeof(KitchenRegistration).Assembly);\n        });\n        return services;\n    }\n}"}]}]},"toc":[{"id":"warm-up-what-is-this-all-about","text":"Warm-up: what is this all about","level":2,"locked":false},{"id":"who-this-is-for","text":"Who this is for","level":3,"locked":false},{"id":"what-you-need-to-know","text":"What you need to know","level":3,"locked":false},{"id":"the-party-plan","text":"The party plan","level":3,"locked":false},{"id":"lesson-1-the-problem-a-flat-with-the-fridge-welded-to-the-sofa","text":"Lesson 1. The problem: a flat with the fridge welded to the sofa","level":2,"locked":false},{"id":"four-scenes-from-life","text":"Four scenes from life","level":3,"locked":false},{"id":"where-the-real-problem-lies","text":"Where the real problem lies","level":3,"locked":false},{"id":"lesson-2-the-big-idea-halina-s-pierogi-place","text":"Lesson 2. The big idea: Halina's pierogi place","level":2,"locked":false},{"id":"the-left-side-who-wants-something-from-the-kitchen","text":"The left side: who wants something from the kitchen","level":3,"locked":false},{"id":"the-right-side-what-the-kitchen-needs-from-the-world","text":"The right side: what the kitchen needs from the world","level":3,"locked":false},{"id":"why-a-hexagon-of-all-shapes","text":"Why a hexagon, of all shapes?","level":3,"locked":false},{"id":"remember-this-picture","text":"Remember this picture","level":3,"locked":false},{"id":"lesson-3-ports-and-adapters-or-a-usb-c-socket-and-everything-you-plug-into-it","text":"Lesson 3. Ports and adapters, or a USB-C socket and everything you plug into it","level":2,"locked":false},{"id":"the-same-thing-in-c","text":"The same thing in C#","level":3,"locked":false},{"id":"the-real-port-test","text":"The real-port test","level":3,"locked":false},{"id":"lesson-4-a-no-nonsense-glossary","text":"Lesson 4. A no-nonsense glossary","level":2,"locked":false},{"id":"how-not-to-mix-up-the-left-and-right-sides","text":"How not to mix up the left and right sides","level":3,"locked":false},{"id":"and-where-does-mediatr-fit","text":"And where does MediatR fit?","level":3,"locked":false},{"id":"lesson-5-the-golden-rule-all-arrows-point-inwards","text":"Lesson 5. The golden rule: all arrows point inwards","level":2,"locked":false},{"id":"normally-the-arrow-points-the-wrong-way","text":"Normally the arrow points the wrong way","level":3,"locked":false},{"id":"so-who-introduces-everyone-to-everyone","text":"So who introduces everyone to everyone?","level":3,"locked":false},{"id":"three-check-questions","text":"Three check questions","level":3,"locked":false},{"id":"lesson-6-building-the-pierogi-place-in-net-10-the-solution-structure","text":"Lesson 6. Building the pierogi place in .NET 10: the solution structure","level":2,"locked":false},{"id":"who-knows-whom","text":"Who knows whom","level":3,"locked":false},{"id":"setting-it-up-from-the-terminal","text":"Setting it up from the terminal","level":3,"locked":false},{"id":"two-things-worth-knowing-before-you-start","text":"Two things worth knowing before you start","level":3,"locked":false},{"id":"lesson-7-code-step-by-step-we-work-from-the-inside-out","text":"Lesson 7. Code step by step: we work from the inside out","level":2,"locked":false},{"id":"step-1-the-domain-or-halina-s-recipe","text":"Step 1. The domain, or Halina's recipe","level":3,"locked":false},{"id":"step-2-ports-or-notes-on-the-doors","text":"Step 2. Ports, or notes on the doors","level":3,"locked":false},{"id":"step-3-the-use-case-or-halina-at-work","text":"Step 3. The use case, or Halina at work","level":3,"locked":false},{"id":"step-4-the-inbound-adapter-an-http-controller-with-swagger-and-mapster","text":"Step 4. The inbound adapter: an HTTP controller with Swagger and Mapster","level":3,"locked":true},{"id":"step-5-the-outbound-adapter-a-pantry-on-ef-core-and-sql-server","text":"Step 5. The outbound adapter: a pantry on EF Core and SQL Server","level":3,"locked":true},{"id":"step-6-the-outbound-adapter-a-bell-on-kafka","text":"Step 6. The outbound adapter: a bell on Kafka","level":3,"locked":true},{"id":"step-7-the-floor-manager-or-program-cs","text":"Step 7. The floor manager, or Program.cs","level":3,"locked":true},{"id":"fire-it-up-and-order","text":"Fire it up and order","level":3,"locked":true},{"id":"lesson-8-adding-kafka-a-new-door-to-the-kitchen-without-a-renovation","text":"Lesson 8. Adding Kafka: a new door to the kitchen without a renovation","level":2,"locked":true},{"id":"step-1-their-language-and-our-dictionary","text":"Step 1. Their language and our dictionary","level":3,"locked":true},{"id":"step-2-the-consumer-or-the-new-waitress","text":"Step 2. The consumer, or the new waitress","level":3,"locked":true},{"id":"step-3-two-lines-in-the-registration","text":"Step 3. Two lines in the registration","level":3,"locked":true},{"id":"the-renovation-bill","text":"The renovation bill","level":3,"locked":true},{"id":"bonus-swapping-an-adapter-on-your-local-machine","text":"Bonus: swapping an adapter on your local machine","level":3,"locked":true},{"id":"lesson-9-tests-without-opening-the-restaurant","text":"Lesson 9. Tests without opening the restaurant","level":2,"locked":true},{"id":"fake-adapters","text":"Fake adapters","level":3,"locked":true},{"id":"use-case-tests","text":"Use case tests","level":3,"locked":true},{"id":"a-test-that-guards-the-architecture","text":"A test that guards the architecture","level":3,"locked":true},{"id":"and-the-adapters","text":"And the adapters?","level":3,"locked":true},{"id":"lesson-10-the-seven-deadly-sins-of-the-hexagon-plus-a-bonus-one","text":"Lesson 10. The seven deadly sins of the hexagon (plus a bonus one)","level":2,"locked":true},{"id":"1-halina-in-an-apron-with-the-wholesaler-s-logo","text":"1. Halina in an apron with the wholesaler's logo","level":3,"locked":true},{"id":"2-a-socket-cut-for-a-single-plug","text":"2. A socket cut for a single plug","level":3,"locked":true},{"id":"3-the-waitress-who-makes-pierogi-in-the-back-room","text":"3. The waitress who makes pierogi in the back room","level":3,"locked":true},{"id":"4-halina-who-just-signs-off-on-someone-else-s-work","text":"4. Halina who just signs off on someone else's work","level":3,"locked":true},{"id":"5-mapster-shoves-pierogi-into-the-pot-without-halina","text":"5. Mapster shoves pierogi into the pot without Halina","level":3,"locked":true},{"id":"6-mediatr-as-a-gps-instead-of-a-postman","text":"6. MediatR as a GPS instead of a postman","level":3,"locked":true},{"id":"7-an-interface-for-every-teaspoon","text":"7. An interface for every teaspoon","level":3,"locked":true},{"id":"8-bonus-writing-to-the-database-and-to-kafka-on-your-word-of-honour","text":"8. Bonus: writing to the database and to Kafka \"on your word of honour\"","level":3,"locked":true},{"id":"lesson-11-when-not-to-build-a-hexagon","text":"Lesson 11. When NOT to build a hexagon","level":2,"locked":true},{"id":"hexagon-light","text":"Hexagon light","level":3,"locked":true},{"id":"lesson-12-hex-vs-onion-vs-clean-same-party-different-t-shirts","text":"Lesson 12. Hex vs Onion vs Clean: same party, different T-shirts","level":2,"locked":true},{"id":"where-does-vertical-slice-fit-in-all-this","text":"Where does Vertical Slice fit in all this?","level":3,"locked":true},{"id":"lesson-13-hexagons-and-microservices-the-pierogi-place-opens-a-chain","text":"Lesson 13. Hexagons and microservices: the pierogi place opens a chain","level":2,"locked":true},{"id":"the-rules-of-the-game","text":"The rules of the game","level":3,"locked":true},{"id":"the-solution-structure","text":"The solution structure","level":3,"locked":true},{"id":"who-publishes-what-and-who-listens","text":"Who publishes what, and who listens","level":3,"locked":true},{"id":"step-1-contracts-or-the-menu-on-the-wall","text":"Step 1. Contracts, or the menu on the wall","level":3,"locked":true},{"id":"step-2-shared-plumbing-one-consumer-for-everyone","text":"Step 2. Shared plumbing: one consumer for everyone","level":3,"locked":true},{"id":"step-3-the-orders-service-and-orderscontroller","text":"Step 3. The Orders service and OrdersController","level":3,"locked":true},{"id":"step-4-the-kitchen-service-and-kitchencontroller","text":"Step 4. The Kitchen service and KitchenController","level":3,"locked":true},{"id":"step-5-the-delivery-service-and-deliveriescontroller","text":"Step 5. The Delivery service and DeliveriesController","level":3,"locked":true},{"id":"step-6-firing-up-the-whole-chain","text":"Step 6. Firing up the whole chain","level":3,"locked":true},{"id":"the-flow-of-one-order-through-three-controllers","text":"The flow of one order through three controllers","level":3,"locked":true},{"id":"what-to-watch-out-for-when-hexagons-talk-through-kafka","text":"What to watch out for when hexagons talk through Kafka","level":3,"locked":true},{"id":"fridge-cheat-sheet-and-mini-quiz","text":"Fridge cheat sheet and mini-quiz","level":2,"locked":true},{"id":"mini-quiz","text":"Mini-quiz","level":3,"locked":true}],"locked":true,"paywall":null,"previewRatio":0.3,"totalBlocks":297,"visibleBlocks":111,"resources":[{"id":"6b0857a63c96f2d34d0b322b","type":"article","provider":"web","url":"https://alistair.cockburn.us/hexagonal-architecture/","embedUrl":null,"title":"Hexagonal Architecture","description":"The original description of the Ports and Adapters pattern by its author.","author":"Alistair Cockburn","thumbnailUrl":null,"durationSec":null,"lang":"en","topics":["hexagonal-architecture"],"techs":["general"],"tags":[],"price":"free","featured":false,"featuredOrder":0,"packageName":null,"source":"seed","publishedAt":null,"popularity":0,"verifiedAt":"2026-11-26T00:00:00.000Z","curated":true,"addedBy":"6b0857a15a2625e44ecaabe6","createdAt":"2026-11-26T16:00:38.912Z","updatedAt":"2026-11-26T16:00:38.912Z"},{"id":"6b0857c43c96f2d34d0b46ed","type":"book","provider":"openlibrary","url":"https://openlibrary.org/works/OL38388131W","embedUrl":null,"title":"Hexagonal Architecture Explained","description":"","author":"Alistair Cockburn, Juan Manuel Garrido de Paz","thumbnailUrl":"https://covers.openlibrary.org/b/id/14748279-L.jpg","durationSec":null,"lang":"en","topics":["hexagonal-architecture"],"techs":["general"],"tags":["book","software-architecture"],"price":"paid","featured":false,"featuredOrder":0,"packageName":null,"source":"openlibrary","publishedAt":"2024-01-01T00:00:00.000Z","popularity":39,"verifiedAt":"2026-11-26T11:00:08.000Z","curated":false,"addedBy":"6b0857a15a2625e44ecaabe6","createdAt":"2026-11-26T16:01:07.480Z","updatedAt":"2026-11-26T16:01:07.480Z"},{"id":"6b0857c13c96f2d34d0b4462","type":"article","provider":"web","url":"https://www.thoughtworks.com/insights/blog/architecture/hexagonal-architecture-explained-practical-example","embedUrl":null,"title":"Hexagonal architecture explained through a practical example","description":"Learn how to implement a hexagonal architecture for a simple application.","author":"Thoughtworks","thumbnailUrl":"https://www.thoughtworks.com/content/dam/thoughtworks/images/photography/meta/insights/in_meta_blogs.jpg","durationSec":null,"lang":"en","topics":["hexagonal-architecture"],"techs":["general"],"tags":["software-architecture"],"price":"free","featured":false,"featuredOrder":0,"packageName":null,"source":"manual","publishedAt":null,"popularity":50,"verifiedAt":"2026-11-26T11:30:12.000Z","curated":false,"addedBy":"6b0857a15a2625e44ecaabe6","createdAt":"2026-11-26T16:01:04.995Z","updatedAt":"2026-11-26T16:01:04.995Z"},{"id":"6b0857b93c96f2d34d0b3d9c","type":"podcast","provider":"apple-podcasts","url":"https://podcasts.apple.com/us/podcast/hexagonal-architecture-with-valentina-cupa%C4%87/id1536194837?i=1000633966279","embedUrl":"https://embed.podcasts.apple.com/us/podcast/id1536194837?i=1000633966279","title":"Hexagonal Architecture - with Valentina Cupać","description":"In this episode, I was joined by Valentina Cupać to chat about Hexagonal Architecture. We discussed what Hexagonal Architecture is, how it can help us build better software, and the difference between it and other similar architectures, such as Clean and Onion Architecture. Valentina is a…","author":"The Unhandled Exception Podcast","thumbnailUrl":"https://is1-ssl.mzstatic.com/image/thumb/Podcasts221/v4/c2/5b/2b/c25b2b09-016e-baa9-ccd5-76f8137263d4/mza_624080646818949005.jpg/600x600bb.jpg","durationSec":3445,"lang":"en","topics":["hexagonal-architecture","clean-architecture","onion-architecture"],"techs":["dotnet"],"tags":["podcast","software-architecture","testing"],"price":"free","featured":false,"featuredOrder":0,"packageName":null,"source":"itunes","publishedAt":"2023-11-07T05:00:00.000Z","popularity":56,"verifiedAt":"2026-11-26T10:58:33.000Z","curated":false,"addedBy":"6b0857a15a2625e44ecaabe6","createdAt":"2026-11-26T16:00:55.661Z","updatedAt":"2026-11-26T16:00:55.661Z"},{"id":"6b0857ca3c96f2d34d0b4b4d","type":"video","provider":"youtube","url":"https://www.youtube.com/watch?v=ET_Otfuy3os","embedUrl":"https://www.youtube-nocookie.com/embed/ET_Otfuy3os","title":"2023 - Piotr Suwała - Clean & Hexagonal Architecture - it really works!","description":"In IT industry we have a repeatable problem of code debt, which steals happiness from our work, inducing horrible stress and frustration. On the other hand frameworks, architectural approaches, tests cost us supposedly wasted time and they seem not to deliver their promises. In the presentation…","author":"confiturapl","thumbnailUrl":"https://i.ytimg.com/vi/ET_Otfuy3os/hqdefault.jpg","durationSec":null,"lang":"pl","topics":["hexagonal-architecture","clean-architecture","ddd-strategic-design"],"techs":["general"],"tags":["software-architecture","testing"],"price":"free","featured":false,"featuredOrder":0,"packageName":null,"source":"youtube-rss","publishedAt":"2023-10-25T15:00:07.000Z","popularity":50,"verifiedAt":"2026-11-26T11:01:20.000Z","curated":false,"addedBy":"6b0857a15a2625e44ecaabe6","createdAt":"2026-11-26T16:01:12.872Z","updatedAt":"2026-11-26T16:01:12.872Z"},{"id":"6b0857b23c96f2d34d0b359a","type":"repo","provider":"github","url":"https://github.com/thombergs/buckpal","embedUrl":null,"title":"thombergs/buckpal","description":"An example approach for implementing a Clean/Hexagonal Architecture","author":"thombergs","thumbnailUrl":"https://opengraph.githubassets.com/1/thombergs/buckpal","durationSec":null,"lang":"en","topics":["hexagonal-architecture"],"techs":["java"],"tags":["software-architecture"],"price":"free","featured":false,"featuredOrder":0,"packageName":null,"source":"github","publishedAt":"2019-05-08T21:29:43.000Z","popularity":66,"verifiedAt":"2026-11-26T10:55:56.000Z","curated":false,"addedBy":"6b0857a15a2625e44ecaabe6","createdAt":"2026-11-26T16:00:50.215Z","updatedAt":"2026-11-26T16:00:50.215Z"}],"challenges":[{"id":"6b093dc291bd8fbaf2a0c8d8","slug":"payment-circuit-breaker","title":"Circuit breaker for a payment gateway","summary":"A circuit breaker with closed, open and half-open states, an injected clock, a trial-success threshold and a business-error filter – so a payment gateway outage does not take the whole shop down.","servedLang":"en","availableLangs":["pl","en"],"kind":"code","category":"architecture","status":"published","difficulty":"hard","topics":["circuit-breaker","microservices"],"techs":["typescript","javascript","python","dotnet","java","go"],"tags":["circuit-breaker","resilience","fault-tolerance","state-machine","payments"],"languages":["typescript","javascript","python","csharp","java","go"],"questionCount":null,"xp":40,"stats":{"attempts":0,"solves":0,"solutions":0,"comments":0},"solveRate":null,"publishedAt":"2026-11-27T08:22:26.251Z"}],"attachments":[],"hasCode":true,"repoUrl":null,"series":[{"slug":"architecture-path","title":"From monolith to microservices","items":[{"slug":"monolith","title":"The Monolith: one application, one deployment, and why it is often the right start","current":false},{"slug":"modular-monolith","title":"The Modular Monolith: hard boundaries without the cost of the network","current":false},{"slug":"layered-architecture","title":"Layered architecture: presentation, logic, data – and where it breaks","current":false},{"slug":"hexagonal-architecture","title":"Pierogi in the Hexagon","current":true},{"slug":"clean-architecture","title":"Clean Architecture: the dependency rule and use cases at the centre","current":false},{"slug":"onion-architecture","title":"Onion architecture: the domain model in the middle, infrastructure outside","current":false},{"slug":"vertical-slice-architecture","title":"Vertical slice architecture: code by feature, not by layer","current":false},{"slug":"cqrs","title":"CQRS: one model for changing, another for reading","current":false},{"slug":"event-sourcing","title":"Event sourcing: store the facts, not just the latest state","current":false},{"slug":"event-driven-architecture","title":"Event-driven architecture: who publishes, who listens and what can go wrong","current":false},{"slug":"microservices","title":"Microservices: independent deployments, real costs and when it pays off","current":false},{"slug":"ddd-strategic-design","title":"DDD strategic design: subdomains, bounded contexts and context maps","current":false}]}],"prev":{"slug":"layered-architecture","title":"Layered architecture: presentation, logic, data – and where it breaks"},"next":{"slug":"clean-architecture","title":"Clean Architecture: the dependency rule and use cases at the centre"},"featured":false,"authorCard":{"id":"6b08bd2e80884893657cc8cf","name":"Redakcja Art of Devs","avatar":null,"handle":"redakcja","headline":"Wzorce projektowe · Architektura · AI i LLM","community":false,"reputation":{"points":3900,"level":{"key":"mentor","label":"Mentor"}},"articles":68,"skills":[{"key":"typescript","title":"TypeScript","level":5,"levelLabel":"Authority","articles":63},{"key":"dotnet","title":".NET","level":5,"levelLabel":"Authority","articles":53},{"key":"python","title":"Python","level":5,"levelLabel":"Authority","articles":52},{"key":"java","title":"Java","level":5,"levelLabel":"Authority","articles":38}]}}