CleanArchitectureTemplate is a modern, robust starting point for building scalable and maintainable .NET applications. It follows the principles of Clean Architecture to promote separation of concerns, testability, and ease of evolution over time.
- ποΈ Clean Architecture Implementation: Organized into distinct layersβPresentation, Application, Domain, Infrastructureβfor clear separation of concerns.
- π’ .NET 8 and C# 12: Leverages the latest .NET SDK features and performance improvements.
- π’οΈ Entity Framework Core with PostgreSQL: Simplifies database operations using EF Core with PostgreSQL provider.
- π CQRS with MediatR: Implements the Command Query Responsibility Segregation pattern using MediatR.
- β Fluent Validation: Ensures robust validation for input models.
- βοΈ AutoMapper: Simplifies object-to-object mapping.
- βοΈ Azure Blob Storage Integration: Supports file storage with Azure Storage Blobs.
- π JWT Authentication: Provides secure authentication using JWT bearer tokens.
- π ASP.NET Core Identity Mechanism: Offers a comprehensive identity management system for user authentication and role-based authorization.
- π Login with Facebook or Google: Provides seamless integration with external login providers to enhance user experience.
- π Logging with Serilog: Structured logging for easier debugging and tracking.
- π Visualization with Seq: Centralized logging visualization for enhanced observability.
- π Swagger UI: Includes interactive API documentation with Swashbuckle.AspNetCore.
- βοΈ Global Exception Handler: Ensures centralized and consistent error handling across the application.
Before setting up the project, ensure you have the following installed:
- βοΈ .NET 8 SDK
- π₯οΈ Visual Studio 2022
- π PostgreSQL
- βοΈ Azure account (optional, for Blob Storage integration)
- π Seq (optional, for log visualization)
Follow these steps to get the solution up and running:
-
Clone the Repository
git clone https://github.com/adarSonmez/CleanArchitectureTemplate.git
-
Navigate to the Solution Directory
cd CleanArchitectureTemplate
-
Restore NuGet Packages
dotnet restore
-
Configure the Database Connection
Update theConnectionStrings:DefaultConnection
inappsettings.json
located in
Presentation/CleanArchitectureTemplate.WebAPI
with your PostgreSQL details. -
Apply Migrations
dotnet ef database update --project Infrastructure/CleanArchitectureTemplate.Persistence
-
Set Up Serilog and Seq
- Ensure
appsettings.json
includes the Seq configuration underLogging
:"Logging": { "LogLevel": { "Default": "Information", "Microsoft.AspNetCore": "Warning" }, "Seq": { "ServerUrl": "http://localhost:5341" } }
- Start Seq locally or on a server and ensure the application is pointed to the correct URL.
- Ensure
-
Configure Azure, AWS, or Google Cloud Storage (Optional)
Update theStorage
section inappsettings.json
with your provider details. Example:"Storage": { "Azure": "<YourAzureBlobConnectionString>", "AWS": "<YourAWSStorageKey>", "Google": "<YourGoogleCloudStorageKey>" }
-
Set Up External Login Providers (Optional)
Update theOAuth:Google
andOAuth:Facebook
sections inappsettings.json
with the appropriate client ID and secret for Google and Facebook login. -
Configure JWT Authentication
Ensure theJwt
section inappsettings.json
contains the necessary values for your application's secret key, issuer, audience, and token expiration times. Example:"Jwt": { "SecretKey": "PANTA RHEI!", "Issuer": "<YourIssuer>", "Audience": "<YourAudience>", "AccessTokenExpiration": 360, "RefreshTokenExpiration": 60 }
-
Run the Application
dotnet run --project Presentation/CleanArchitectureTemplate.WebAPI
-
Open your browser and navigate to:
πhttp://localhost:5000/swagger
to access the Swagger UI for API documentation. -
View application logs in Seq by navigating to:
πhttp://localhost:5341
(or your configured Seq server URL).
The solution is organized into the following layers:
-
π¨ Presentation Layer
CleanArchitectureTemplate.WebAPI
: The ASP.NET Core Web API project serving as the entry point.
-
π§ Application Layer
CleanArchitectureTemplate.Application
: Contains business logic, DTOs, commands, queries, and validators.
-
π¦ Domain Layer
CleanArchitectureTemplate.Domain
: Defines domain entities, value objects, and interfaces.
-
π Infrastructure Layer
CleanArchitectureTemplate.Infrastructure
: Implements external services like file storage, email sending, and authentication.
-
πΎ Persistence Layer
CleanArchitectureTemplate.Persistence
: Manages data access with Entity Framework Core, including database contexts and repositories.
Contributions are welcome! To contribute:
-
Fork the repository.
-
Create a new branch for your feature:
git checkout -b feature/YourFeature
-
Commit your changes:
git commit -m "Add YourFeature"
-
Push to the branch:
git push origin feature/YourFeature
-
Open a pull request.
β Pro Tip: Ensure your code follows the project's coding standards and includes appropriate tests.
This project is licensed under the MIT License.
This template is inspired by the principles outlined in π Clean Architecture: A Craftsman's Guide to Software Structure and Design by Robert C. Martin.
- π GitHub Repository
- π οΈ Official .NET Documentation