!(https://hackernoon.com/hn-images/1*qLH9BLF-7Xm9xa9r_Tf52Q.jpeg)\n\n[Source](https://pixabay.com/en/water-lily-aquatic-plant-nature-3504363/)\n\n### Key takeaways\n\n* [Domain-Driven Design](https://www.amazon.com/Domain-Driven-Design-Tackling-Complexity-Software/dp/0321125215) (DDD) works with [Clean Architecture](https://8thlight.com/blog/uncle-bob/2012/08/13/the-clean-architecture.html) (CA)\n* Clean DDD in a practical way ([microservices](https://www.martinfowler.com/microservices/))\n* Clean DDD on the [cloud-native way](https://landscape.cncf.io/)\n\nI wrote about CA topic last year and today I’m going to write out another part of it. CA is good to make the software architecture more succinctly and manageable, but the boilerplate codes are also huge (if you used to implement it you will get my point — a lot of requests, responses, interactors or use cases, interfaces, and classes need to be created, see my implementation at [https://github.com/thangchung/blog-core](https://github.com/thangchung/blog-core)). Back in the time, when we implement [Command Query Responsibility Segregation](https://martinfowler.com/bliki/CQRS.html) ([CQRS](https://cqrs.files.wordpress.com/2010/11/cqrs_documents.pdf)) and [Event Sourcing](http://codebetter.com/gregyoung/2010/02/20/why-use-event-sourcing/) (ES)patterns that will make many people feel unhappy with those of boilerplate codes. That’s a reason I research and write out what I know and learn about make CA more practical and maintainable ways.\n\nFor those people aren’t familiar with CA, please see my previous article at [https://hackernoon.com/applying-clean-architecture-on-web-application-with-modular-pattern-7b11f1b89011](https://hackernoon.com/applying-clean-architecture-on-web-application-with-modular-pattern-7b11f1b89011)\n\nLet’s start with the whole picture in the application I have worked in a way of CA as following\n\n!(https://hackernoon.com/hn-images/1*YVxaXqiIYskqPauNKZ2OSA.png)\n\n1. Domain code that doesn’t depend on any framework or libraries. It makes these core components can re-use in the future\n2. A bit outer layer of domain code that acts like adaptors, we use it to implement Unit of Work (UOW), Generic Repository (GR), Event Bus, Dependency Injection and a lot of more stuff\n3. Partial CA patterns with request and response DTOs and handlers for them. We utilize [MediatR](https://github.com/jbogard/MediatR) and [AutoMapper](https://github.com/AutoMapper/AutoMapper) libs for simplifying this kind of work, and another reason that it’s cool 😍 Thank you [Jimmy](https://github.com/jbogard)!\n4. Partial presenter for Web API\n\nAfter implemented, it will end up with the structure of code as below\n\n!(https://hackernoon.com/hn-images/1*nyO3sQkhzTX6eqROzmCAdg.png)\n\nNothing hyper to talk here, it quite simple and clean, right? Lets diving into the details so that we will understand more about it. I’m going to show you the Cart Service ([miniservices](https://thenewstack.io/miniservices-a-realistic-alternative-to-microservices) pattern actually) with the business like add a new product to a cart, add more product to that cart, get the current cart with products, update that cart, delete product out of the current cart, and final action is to check out the cart.\n\n!(https://hackernoon.com/hn-images/1*uz9yzs0cZp6JyaAdihIsNg.png)\n\n[https://www.gartner.com/webinar/3437517](https://www.gartner.com/webinar/3437517)\n\nThat’s it. Then we have the use cases like\n\n!(https://hackernoon.com/hn-images/1*N5Ki5xVklljDHXp3J8SRnA.png)\n\nIf you like API first approach, then we should have the OpenAPI as\n\n!(https://hackernoon.com/hn-images/1*1VXuRcayTTDXXDZ3QcMBag.png)\n\nLet's narrow down to the code because I know that all we are developers so that the code should be easier to understand, right?\n\n### Domain components (mainly DDD patterns)\n\n!(https://hackernoon.com/hn-images/1*VOnHX-ofuZiBxih_WM7uGg.png)\n\nCart.cs\n\nCartItem.cs\n\nProduct.cs\n\n### Infrastructure components\n\nUnit of Work, Generic Repository, Event Bus, ClientRequest, Dependency Injection… components are in NetCoreKit — A set of cloud-native tools and utilities for .NET Core — which is developed by myself ([https://github.com/cloudnative-netcore/netcorekit](https://github.com/cloudnative-netcore/netcorekit)).\n\n### Request/Response handlers\n\n* Get Cart with Products\n\n* Add Product to a Cart\n\n* Update Product in the Cart\n\n* Delete Product in the Cart\n\n* Checkout\n\n### Web API Presenter\n\n### Cloud-Native parts\n\nThis is the cloud-native apps so that we can package it to a container and host it Kubernetes if we want. The work to do that as below\n\n!(https://hackernoon.com/hn-images/1*9GcwL0w4nm_vZFcXu10Dhw.png)\n\nDockerfile\n\nKubernetes manifests\n\nThat’s it for today. Hopefully with a ton of code that doesn’t make you dizzy 🙏.\n\n### Recap\n\nThe world has changed a lot from years recently so that we need to learn and flow with it. In this article, I showed you how can we combine CA with DDD, and host it to the cloud-native platform( Kubernetes in this case). That knowledge is my own, you can think of it in another way or create another stack for your own.\n\n> _The source code for this article can be found at_ [https://github.com/vietnam-devs/coolstore-microservices](https://github.com/vietnam-devs/coolstore-microservices)\n\nThanks for reading! If you enjoyed this article, be sure to click 👏 symbol below so others will see it.