A production-ready ASP.NET Core Web API template built with Clean Architecture principles. This starter kit comes pre-configured with Identity Authentication, JWT Security, Role Management, Email Verification, Serilog Logging, and Global Exception Handling.
It is designed to be a robust starting point for enterprise-level applications, ensuring scalability, maintainability, and standard coding practices.
- Clean Architecture: Strict separation of concerns (Domain, Application, Infrastructure, API).
- Authentication & Authorization:
- ASP.NET Core Identity.
- JWT Token Authentication (Access Tokens).
- Role-Based Authorization (Admin, User, Manager).
- Security:
- Standardized API Responses (
Succeeded,Data,Message). - Global Exception Handling Middleware (hides stack traces in production).
- CORS Policy Configuration.
- Standardized API Responses (
- Logging:
- Serilog integrated for structured logging.
- Logs to Console (colored) and File (rolling daily intervals).
- Request Logging (logs HTTP method, path, and duration).
- Email System:
- MailKit integration for sending emails.
- HTML Email Template support.
- Email Verification flow.
- Database:
- Entity Framework Core.
- Automated Database Seeding (Admin User & Default Roles).
- Framework: .NET 10
- Language: C#
- Database: Microsoft SQL Server
- ORM: Entity Framework Core
- Auth: ASP.NET Core Identity & JWT Bearer
- Logging: Serilog
- Email: MailKit
- Documentation: OpenAPI (Built-in)
The solution follows the Clean Architecture dependency rule (dependencies flow inward):
CleanAuthTemplate.Domain:- Enterprise logic and entities (e.g.,
ApplicationUser). - No dependencies on other projects.
- Enterprise logic and entities (e.g.,
CleanAuthTemplate.Application:- Business logic, Interfaces (
IEmailService,IJwtTokenGenerator), and DTOs. - Depends on Domain.
- Business logic, Interfaces (
CleanAuthTemplate.Infrastructure:- External concerns (DbContext, Email Implementation, Identity, JWT generation).
- Depends on Application.
CleanAuthTemplate.API:- Presentation layer (Controllers, Middleware, Program.cs).
- Depends on Application and Infrastructure.
You can install this project as a local .NET template to generate new solutions with a single command.
Clone the repository and install it into your .NET CLI:
# Clone the repository
git clone https://github.com/dabananda/CleanAuthTemplate.git
cd CleanAuthTemplate
# Install the template locally
dotnet new install .Once installed, you can create a new solution anywhere on your machine. The template will automatically rename all files and namespaces (e.g., CleanAuthTemplate β MyNewApp).
# Create a directory for your new project
mkdir MyNewApp
cd MyNewApp
# Generate the solution (Replace 'MyNewApp' with your desired name)
dotnet new cleanauth -n MyNewAppAfter generating your project, follow these steps to get it running:
-
Configure Settings: Open
MyNewApp.API/appsettings.jsonand update:- ConnectionStrings: Point to your local SQL Server.
- EmailSettings: Add your SMTP credentials.
- JwtSettings: Set a secure Secret key.
-
Initialize Database:
dotnet ef database update -s MyNewApp.API -p MyNewApp.Infrastructure- Run the API:
dotnet run --project MyNewApp.APIIf you want to contribute to this template or run the source code directly without installing it:
- .NET SDK
- SQL Server (LocalDB or Docker)
git clone https://github.com/dabananda/CleanAuthTemplate.git
cd CleanAuthTemplateUpdate CleanAuthTemplate.API/appsettings.json with your settings:
{
"ConnectionStrings": {
"DefaultConnection": "Server=(localdb)\\mssqllocaldb;Database=CleanAuthTemplateDb;Trusted_Connection=True;TrustServerCertificate=Yes;MultipleActiveResultSets=true"
},
"EmailSettings": {
"SmtpServer": "smtp.gmail.com",
"SmtpPort": 587,
"Username": "your-email@gmail.com",
"Password": "your-app-password",
"From": "your-email@gmail.com"
},
"JwtSettings": {
"Secret": "your-very-secure-secret-key-minimum-32-chars",
"Issuer": "CleanAuthTemplateAPI",
"Audience": "CleanAuthTemplateClient",
"DurationInMinutes": "60"
},
"AdminUser": {
"Email": "admin@email.com",
"Password": "Pass@123"
},
"DefaultUser": {
"Email": "user@email.com",
"Password": "Pass@123"
},
"Serilog": {
"Using": [ "Serilog.Sinks.Console", "Serilog.Sinks.File" ],
"MinimumLevel": {
"Default": "Information",
"Override": {
"Microsoft": "Warning",
"System": "Warning"
}
},
"WriteTo": [
{
"Name": "Console",
"Args": {
"theme": "Serilog.Sinks.SystemConsole.Themes.AnsiConsoleTheme::Code, Serilog.Sinks.Console",
"outputTemplate": "[{Timestamp:HH:mm:ss} {Level:u3}] {Message:lj}{NewLine}{Exception}"
}
},
{
"Name": "File",
"Args": {
"path": "Logs/log-.txt",
"rollingInterval": "Day",
"retainedFileCountLimit": 7,
"outputTemplate": "{Timestamp:yyyy-MM-dd HH:mm:ss.fff zzz} [{Level:u3}] {Message:lj}{NewLine}{Exception}"
}
}
]
},
"AllowedHosts": "*"
}Apply migrations and seed the database (creates default Roles and Admin user):
dotnet ef database update -s CleanAuthTemplate.API -p CleanAuthTemplate.Infrastructuredotnet run --project CleanAuthTemplate.APIThe API will start at https://localhost:7078 (or similar).
- POST
/api/auth/register: Register a new user (sends verification email). - POST
/api/auth/login: Login to receive a JWT Token. - GET
/api/auth/verify-email: Verify email using the token sent.
- Email: admin@email.com
- Password: Admin@123
(Note: These are created automatically by the DbSeeder on first run).
All API responses follow this standard wrapper:
{
"succeeded": true,
"message": "Operation Successful",
"errors": null,
"data": { ... }
}Dabananda Mitra
- Portfolio: dmitra.netlify.app
- LinkedIn: linkedin.com/in/dabananda
- Email: dabananda.dev@gmail.com
- WhatsApp: +8801304080014
This project is licensed under the MIT License - see the LICENSE.txt file for details.