DotNet-Architecture-Patterns is a comprehensive reference repository demonstrating the evolution of ASP.NET Core software architecture.
It provides production-ready templates ranging from simple Monolithic structures to complex, enterprise-grade Clean Architecture solutions. This project serves as a practical guide to understanding Dependency Injection, SoC (Separation of Concerns), and SOLID principles in real-world scenarios.
This repository is structured to show the progression from tightly coupled code to highly decoupled, maintainable systems.
| Module / Architecture | Complexity | Scalability | Testability | Ideal Use Case |
|---|---|---|---|---|
| 01-SingleLayer-MVC | ⭐ | ⭐ | ⭐ | Quick prototypes, internal tools, learning basics. |
| 02-SingleLayer-API | ⭐⭐ | ⭐⭐ | ⭐⭐ | Simple backends for mobile/web apps without complex logic. |
| 03-MultiLayer-Shared | ⭐⭐⭐ | ⭐⭐⭐ | ⭐⭐⭐ | Standard business applications with distinct logic layers. |
| 04-Clean-N-Layer | ⭐⭐⭐⭐⭐ | ⭐⭐⭐⭐⭐ | ⭐⭐⭐⭐⭐ | Enterprise systems, high-traffic apps, long-term maintenance. |
The Monolith.
- Structure: Controllers, Models, and Views are strictly coupled in a single project.
- Focus: Understanding the basics of MVC routing and Razor Views.
- Limitation: Hard to unit test; UI and Business Logic are intertwined.
The Decoupling of UI.
- Structure: A standalone RESTful API.
- Focus: Returning JSON data, HTTP Status Codes, and Swagger documentation.
- Improvement: The frontend can now be React, Angular, or a Mobile App (separated from backend).
Introduction to N-Tier.
- Structure: Breaks the app into
API,Business (BLL), andDataAccess (DAL)layers using a shared class library. - Focus: Separation of Concerns. The API strictly handles requests; it knows nothing about the database.
- Key Concept: Introduction of simple Dependency Injection.
The Enterprise Standard (Best Practice).
- Structure: Strictly implements Clean Architecture principles involving
Core,Data,Service, andAPIlayers. - Key Features:
- Core Layer: Holds Entities, Interfaces, and DTOs (No external dependencies).
- Repository Pattern & Unit of Work: Abstracts database access completely.
- Service Layer: Contains pure business logic and mapping (AutoMapper).
- Dependency Injection: Heavy use of DI to decouple layers.
- Custom Response Wrapper: Standardized API responses (Success/Fail/Data).
This is the architecture I recommend and use for production-level applications like MelesAI.
- Framework: .NET 8 (ASP.NET Core)
- Language: C# 12
- Database: MS SQL Server / Entity Framework Core (Code-First)
- Mapping: AutoMapper
- Documentation: Swagger / OpenAPI
- Tools: Visual Studio 2022, Postman
This repository is designed as a Multi-Project Solution. You can run any architecture pattern from a single interface.
-
Clone the repository:
git clone [https://github.com/enesimo16/DotNet-Architecture-Patterns.git](https://github.com/enesimo16/DotNet-Architecture-Patterns.git)
-
Open the Solution:
- Double-click
ArchitecturePatterns.slnto open all projects in Visual Studio.
- Double-click
-
Configure Database:
- Each project (specifically
03and04) has its ownappsettings.json. - Update the
ConnectionStringsto match your local SQL Server instance (LocalDB or Docker).
- Each project (specifically
-
Run Migrations:
- Open Package Manager Console.
- Select the target Data project (e.g.,
04-Clean-N-Layer-Architecture.Data). - Run:
update-database
-
Run the App:
- Set your desired project (e.g.,
04-Clean-N-Layer-Architecture.API) as the Startup Project. - Press
F5.
- Set your desired project (e.g.,
Enes Yel(https://github.com/enesimo16)