Skip to content

aheroglu/clean-architecture-starter

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Clean Architecture Starter Template

project-image

This is a starter template for easily starting to develop your projects.

Table Of Contents

Give a star! ⭐

Are you using or liking this project? Please give a star to support me!

Versions 📦

The project currently uses .NET version 9.

Technologies Used ⚙️

  • .NET 9
  • Entity Framework Core
  • MediatR
  • FluentValidation
  • Mapster
  • Bogus (For dummy data)
  • xUnit (Testing)
  • MailKit (For email functionality)

Architecture 🏗️

This project follows the Clean Architecture principles, ensuring a strict separation of concerns between different layers. The aim is to provide a maintainable and scalable structure adhering to SOLID principles.

Clean Architecture Layers

  • Domain: Contains business rules and entities.
  • Application: Contains application logic, services, CQRS, and validations.
  • Infrastructure: Manages database connections, external services, and other infrastructure concerns.
  • Presentation: Handles API and user interface logic (Controllers).
  • WebAPI: Orchestrates the presentation layer of the application.

Email Configuration 📧

This project includes email-sending functionality using the IEmailService interface and the MailKit library. To enable email sending, you need to configure your appsettings.json file with your email settings.

Step 1: Update appsettings.json

Add the following configuration to your appsettings.json file and customize the values according to your email provider:

"EmailSettings": {
  "SmtpServer": "smtp.gmail.com",
  "SmtpPort": 587,
  "SenderName": "Your Name",
  "SenderEmail": "[email protected]",
  "Username": "[email protected]",
  "Password": "your-email-password"
}

Layers 🗂️

Application Layers

Domain Layer

  • Abstractions (Base Entity)
  • Entities (Domain entities)
  • Repositories (Interfaces: IUnitOfWork, IRepository, IProductRepository)

Application Layer

  • Features (CQRS, Handlers using MediatR)
  • Behaviors (Custom Validation Behavior with MediatR)
  • Common (Generic Result Class)
  • Services (IJwtProvider, ICacheService, IEmailService, IFileService Interfaces)

Infrastructure Layer

  • Context (IdentityDbContext and UnitOfWork Implementation)
  • Repositories (Repository classes implementing Domain repositories)
  • Services (JWT, File Service, Email implementations)
  • Options (JwtOptions, JwtSetupOptions, EmailOptions)

Presentation Layer

  • Base API Controller
  • Controllers (handling API routes)

Test Layer

  • Unit tests using xUnit and Moq.

Packages 📦

  • MediatR
  • FluentValidation
  • AutoMapper
  • xUnit
  • Moq
  • Bogus
  • MailKit

Setup ⚙️

  1. Clone the repository:
git clone https://github.com/aheroglu/clean-architecture-starter.git
  1. Install the necessary NuGet dependencies:
dotnet restore
  1. Apply the database migrations:
dotnet ef database update
  1. Run the project:
dotnet run

Dummy Data 🤡

The Bogus library is used to generate dummy data through the Helper class. The application will populate the database with random data when it starts in development mode.

In Program.cs, the dummy data generation is triggered like this:

if (builder.Environment.IsDevelopment())
{
    Helper.GenerateData(app).Wait();
}

Testing ✔️

Unit tests are written using xUnit and Moq. Tests cover various CRUD operations and logic through mock repositories and services.

dotnet test

Development 🚀

You can continue developing the project by following the layered architecture. For new features, you can add CQRS handlers to the Application layer and define any necessary services in the Infrastructure layer.

Application Layers