You’re still concern about what is the at the moment? You’re searching around to the to apply for your project. Go deeply into this article, it’s going to help you answering by your own. Modern Software Architecture Best Software Architecture In term of software development, the architecture of project is really important for the sake of during many projects that I have worked. The software architecture ensures that the software that you build has a basis of the skeleton. It just likes the mainframe or the background of a house. Upon on that, we have a freedom to build anything we want. maintenance and re-usability The question always in my head these days is how can we ? I have done some of the experiments in the code, and finally, I decided to write it out in this article. The purpose is really straightforward for sharing what I have learned, and learn more what I get from feedback. This article is based on my experience in software development and how the modular approach gives the benefits and applies on it. combine the Clean Architecture and Modular pattern Clean Architecture concepts Modular patterns The modular approach for the architecture is also a topic that we have talked a lot in our company. Back to 5 years ago, I worked on the big project that has a lot of people involved, and in that time, we had organized the architecture to the modular approach. And by the time, we know that with the modular we can and because . Could anyone remember about the conflicted code in the big project? Could you spend the half of day (or more) just to merge the codes? It is really a nightmare, isn’t it. cut the large monolith software into many vertical smaller monoliths make the team works more easily each team only needs to focus on the module that they work So in the modular approach, we need to make sure that the modules should be independent enough so that it can be work by the sole developers in different teams. It should be in logical design style and gives us strong points as Help our software system is able to . extensible, reusable, maintainable, and adaptable into a flexible composite of collaborating modules (in monolith style). Break large monolith stack Help newcomers to (because it is small enough) easy to understand the business features and the functionalities of the system Open the door to (if need, but it is not easy to adopt it from my point of view) migrate into the Microservices Architecture Clean Architecture has coined since 2012 by Uncle Bob, and by the time, . We can see using it by combination with to build the software architecture for the mobile app. A couple of articles out there also proposed to use Clean Architecture for the web application. In early this year, Uncle Bob published the book named . If you have never read that book before I highly recommend you to take a look at it. This book mentions a lot of best practices when using , and some of as well. The Clean Architecture it becomes an important things in the software architecture world Android MVP pattern “ Clean Architecture: A Craftsman’s Guide to Software Structure and Design ” SOLID design patterns tips and tricks in deployment work A bit overview about the clean architecture, if you have already known, please skip this and jump over to the implementation section. According to Clean Architecture, we need to below ensure some of the important points 1. . The architecture does not depend on the existence of some library of feature laden software. This allows you to use such frameworks as tools, rather than having to cram your system into their limited constraints. Independent of Frameworks 2. . The business rules can be tested without the UI, Database, Web Server, or any other external element. Testable 3. . The UI can change easily, without changing the rest of the system. A Web UI could be replaced with a console UI, for example, without changing the business rules. Independent of UI 4. . You can swap out Oracle or SQL Server, for Mongo, BigTable, CouchDB, or something else. Your business rules are not bound to the database. Independent of Database 5. . In fact your business rules simply don’t know anything at all about the outside world. Independent of any external agency And it follows strictly the diagram Implementation “Talk is cheap. Show me the code.” — Linus Torvalds Let start off with the main story today, any project has to analyze and ask the customer about and . They will give us bunch of or (if there is an agile project). And the final step, we will have to draw the use case diagram. For those people that could not catch what I said so far, I would like to analyze an example in the blog engine domain. Let say we want to build the blog website that have some of the features like read the blog, see the posts of this blog, add some of the comments in the public interface. And we definitely have a way to CRUD actions on blogs, posts, and comments. Beside of that, we also need to login into the system before we can modify the blogs, posts, and comments. Based on the requirement of features for this application, we’re going to end up with the use case diagram below what they want to do for their system what they need for their system to act for use cases user stories Now is the time, I will show you how can I apply the modular pattern to this example. If you look at the diagram above, you will notice that we only have 3 main things for managing are authentication, blog, and post. Grab some ideas from Domain-Driven Design( and books are the good starting point from my point of view), in this case is , I separate my application domain out to the Access Control Context, Blog Context and Post Context (I divide it into 3 Bounded Contexts because my domain knowledge like that, it will be different from others due to different domain experts, but at least it needs to sort out the business needs). Let put them together, and we have a diagram like Tackling Complexity in the Heart of Software Implementing Domain-Driven Design Bounded Context pattern Lets explaining a bit about the diagram above, the Access Control Context with the red color is for authentication and authorization tasks. The Blog Context filled with green color is for blog management includes setting up the blog, status assignment, and theme… The third one is the Post Context which manages its own comments and tags. As you can see, the Post Context has the relationship with others. For more information of how can we design the ( ) please come to articles, you will learn the huge of useful things. You have my promise :) Bounded Context Root aggregate Effective Aggregate Design Too much for the theory, let now jump into the code. Due to the limitation of this article, I only can show you one Bounded Context code, and I would like to choose the Post Context because I think this is the most interested in. The rests, you can have a look at my GitHub codes — . So far, some of you will question that what the heck Clean Architecture involves into this? Don’t panic. Let me show you the project structure, then you have the rest. the link gives you at the end of this article Is it clean for structuring the project? By the time, I found out that the does not only it, but also the large code base. For those people want to run this example project, I use to implementation so that you need to install at least the . simple structure help new-comers easy to catch up and work on help code readers easy to figure out what we want to do and navigate through .NET Core 2.0 run-time environment Now I start to explain about the structure above. First, we have the in the diagram, that contains all the stuff related to necessary toolkit for the project. ( in OOP). The BlogCore.Core will not need to depend on any framework or library, but on .NET SDK definitely (some of the cases we call its vanilla code). Additionally, we have 3 projects: BlogCore.Infrastructure, BlogCore.Infrastructure.AspNetCore and BlogCore.Infrastructure.EfCore that will depend on EntityFrameworkCore, AspNetCore and others libraries like Autofac, AutoMapper, FluentValidation, MediatR… Framework folder Remember that we’re going to avoid using the abstraction in our code, but use the composition Composition over inheritance Second, in the middle of the diagram, We use it for putting the host projects there. You can see I have 2 hosts: one for the API (BlogCore.API) and another for the Single Page Application (BlogCore.App). Hosts folder Third, is used to do the migrating works, in this case, we migrate data for the Access Control Context, Blog Context and Post Context. We can choose to migrate using Entity Framework migration and seed data for them. Otherwise, you can also use the T-SQL scripts to do the migration. It is up to you, I don’t say which one is better than others. Migrations folder Finally, we have the that contains the heart of this application. We have divided it into Bounded Context folders here, and make our architecture more clearly. Each Bounded Context has 2 sub-projects, e.g. BlogCore.PostContext and BlogCore.PostContext.Core. BlogCore.PostContext.Core only contains domain objects, contracts, and interfaces which is really good for another projects references. The rule is if we have another module that wants to use some of the classes, objects so that it should reference the <Module name>.Core and to the interface inside this project( in another module. This will make loose-coupling for those modules. We will get a lot of benefits with this approach). Modules folder only depends on the interface Lets see the Post Bounded Context structure in the details I think we should deep dive into some of the code to understand more about how can we implement the Clean Architecture with the Modular pattern for this project. We have that acts like Root Aggregate in the Post Context as Post.cs entity Then, we have the PostGenericRepository.cs We need to create the DbContext for the as PostContext.cs In Clean Architecture, the use case is very important and should be designed very carefully. In my project, I named it as ListOutPostByBlogInteractor.cs After processing the business case for the Post Bounded Context, we need to aggregate some of the data related to the Access Control Bounded Context, and in this case, we get the Author information of it and use the IUserRepository interface to get the author’s details information. So that we introduce another class called ListOutPostByBlogPresenter.cs And we need to have a place to register these dependency objects. So the comes into play, and we use Autofac module in this project. The idea is the module will register all the dependency its own. Dependency Injection Yes, that’s enough, then we only need to introduce for what we did the API Recap Today, I have walked you through the journey of how can we make the modular works well in the Clean Architecture. We at least know what is modular, what it’s actually important. We run through some of the overviews of Clean Architecture, and some of the strong points of it as well. And the last but not least, we know how to implement it using .NET Core 2.0. What is not covered in this articles are the , , , for the Clean Architecture…I’m going to write more about them if you guys interested in, just drop the messages in the comment box below. Data flow Synchronized between Bounded Contexts Unit Testing Deployment The source code for this article can be found at https://github.com/thangchung/blog-core Thanks for reading! If you enjoyed this article, be sure to click 👏 symbol below so others will see it.