Clean Architecture — A Practical .NET Starter


Built for clarity: Clean Architecture in .NET

I built a small, opinionated Clean Architecture starter to make APIs easier to read, test and extend. If you care about clear boundaries and predictable code paths, this layout will save you time as the project grows.

Diagrams & Schemas

Below are a couple of simple diagrams that illustrate the Clean Architecture layers and a typical request flow. The images are static SVGs embedded here for clarity.

Clean Architecture Layers

Presentation at the top accepts requests, Application contains use cases and orchestrates domain logic, Domain holds entities and core business rules, Infrastructure contains persistence and external integrations.

Clean Architecture Flow

Below is the folder structure I find most helpful — clear, copyable, and ready for features.

Src/
  API/
    App.API/
      Program.cs
      appsettings.json
      Controllers/
        ProductsController.cs
        CategoriesController.cs
        CustomBaseController.cs
      Filters/
      Extensions/
  Core/
    App.Application/
      ServiceResult.cs
      ServiceExtensions.cs
      Features/
        Products/
        Categories/
    App.Domain/
      Entities/
        Product.cs
        Category.cs
  Infrastructure/
    App.Persistence/
      AppDbContext.cs
      GenericRepository.cs
      UnitOfWork.cs
    App.Caching/
    App.ServiceBus/
Test/

Why this structure?

  • Thin controllers: the controllers in App.API only route requests and delegate to services. That keeps HTTP concerns separated from business rules.
  • Application layer: App.Application houses service contracts and the ServiceResult<T> pattern that standardizes responses across the API.
  • Infrastructure: persistence, caching, and external integrations are implemented here so they can be swapped or mocked in tests.

Key files (quick tour)

  • Src/API/App.API/Controllers/ProductsController.cs — endpoint surface; reads requests and calls IProductService.
  • Src/Core/App.Application/ServiceResult.cs — single pattern for success/failure and HTTP status mapping.
  • Src/Infrastructure/App.Persistence/GenericRepository.cs — a generic repository for CRUD operations.

How to try it locally

Want the repo? 👉 GitHub Repo

Clone and run:

git clone https://github.com/emirbuckun/NLayerArchitecture.git
cd NLayerArchitecture
dotnet restore
dotnet build Src/API/App.API/App.API.csproj
dotnet run --project Src/API/App.API/App.API.csproj

Visit the API endpoints under /api/products and /api/categories (see Src/API/App.API/App.API.http for request examples).