DEV Community

Dabananda Mitra
Dabananda Mitra

Posted on

Stop Rewriting Auth! ๐Ÿ›‘ Kickstart Your Next .NET Web API with Clean Architecture & JWT

The Problem: "Boilerplate Hell"

Weโ€™ve all been there. You have a great idea for a new .NET API. You open Visual Studio, create a new project, and then... you spend the next two days setting up the same things you set up for your last five projects:

  • ๐Ÿ“‚ Setting up the folder structure.
  • ๐Ÿ” Configuring ASP.NET Core Identity.
  • ๐Ÿ”‘ Writing the JWT token generation logic.
  • ๐Ÿ“ง Figuring out email verification.
  • ๐Ÿ“œ configuring Serilog because the default logger isn't enough.
  • ๐Ÿ—๏ธ Implementing a standardized API response wrapper.

Itโ€™s tedious, repetitive, and kills your momentum.

The Solution: CleanAuthTemplate

I built CleanAuthTemplate to solve exactly this problem. It is a robust, production-ready starter kit built on Clean Architecture principles. It comes pre-loaded with everything you need to secure and structure an enterprise-level application, so you can start writing business logic on Day 1.

Whatโ€™s Inside?

This isn't just a "Hello World" app. Itโ€™s a fully structured solution containing:

  • Clean Architecture: Strict separation of concerns (Domain, Application, Infrastructure, API).
  • Security First: Pre-configured Identity and JWT Authentication (Access Tokens) with Role-Based Authorization (Admin/User).
  • Email Ready: Integrated MailKit with html templates for email verification flows.
  • Observability: Structured logging with Serilog (console & rolling file logs).
  • Best Practices: Global Exception Handling and standardized API responses.

How to Use It (The Easy Way)

You don't need to manually copy-paste files. Iโ€™ve designed this to work as a native .NET Project Template. Here is how you can install it and generate a new project in less than a minute:

  1. Install the Template Clone the repo and install it into your .NET CLI. This registers the template locally on your machine.
git clone https://github.com/dabananda/CleanAuthTemplate.git
cd CleanAuthTemplate
dotnet new install .
Enter fullscreen mode Exit fullscreen mode
  1. Generate Your New Project Now, you can create a new solution anywhere on your computer using the cleanauth command. The CLI will automatically rename all namespaces and files to match your new project name!
# Create a new project named "MySuperApp"
dotnet new cleanauth -n MySuperApp
Enter fullscreen mode Exit fullscreen mode
  1. Run & Go Update your connection strings in appsettings.json, run the migrations, and you are live.
dotnet ef database update
dotnet run
Enter fullscreen mode Exit fullscreen mode

๐Ÿค” Why Clean Architecture?

The template follows the dependency rule where dependencies flow inward. This ensures your core business logic (Domain and Application layers) remains independent of external frameworks and databases, making your app easier to test and maintain in the long run.

๐Ÿ”— Links & Resources

GitHub Repository: github.com/dabananda/CleanAuthTemplate

If this template saves you some time, please consider giving the repo a โญ star! Iโ€™m actively looking for feedback, so feel free to open an issue or drop a comment below.

Happy Coding! ๐Ÿ’ป

dotnet #csharp #cleanarchitecture #webapi #opensource #developer

Top comments (0)