.NET 8 Clean Architecture Project Generator
This skill guides the creation of a new .NET 8 Web API solution using Clean Architecture. IMPORTANT: Do NOT generate code files manually. Use the CLI commands provided below to scaffold the solution and projects.
Prerequisite
- .NET 8 SDK installed (dotnet --version )
Directory Structure
The final structure will look like this:
SolutionName/ ├── src/ │ ├── SolutionName.Domain/ # Core business logic, entities, interfaces (No dependencies) │ ├── SolutionName.Application/ # Use cases, DTOs, interfaces (Depends on Domain) │ ├── SolutionName.Infrastructure/ # External concerns, DB, file system (Depends on Application) │ └── SolutionName.Api/ # Presentation layer (Depends on Application, Infrastructure) ├── tests/ # Unit and Integration tests └── SolutionName.sln
Step-by-Step Instructions
- Create Solution
Run these commands in the terminal:
Create solution file
dotnet new sln -n SOLUTION_NAME
- Create Projects (Clean Architecture Layers)
Create src directory
mkdir src
DOMAIN Layer (Class Library)
dotnet new classlib -n SOLUTION_NAME.Domain -o src/SOLUTION_NAME.Domain
APPLICATION Layer (Class Library)
dotnet new classlib -n SOLUTION_NAME.Application -o src/SOLUTION_NAME.Application
INFRASTRUCTURE Layer (Class Library)
dotnet new classlib -n SOLUTION_NAME.Infrastructure -o src/SOLUTION_NAME.Infrastructure
API Layer (Web API)
dotnet new webapi -n SOLUTION_NAME.Api -o src/SOLUTION_NAME.Api --use-controllers
- Establish Dependencies
Application -> Domain
dotnet add src/SOLUTION_NAME.Application reference src/SOLUTION_NAME.Domain
Infrastructure -> Application
dotnet add src/SOLUTION_NAME.Infrastructure reference src/SOLUTION_NAME.Application
Api -> Application
dotnet add src/SOLUTION_NAME.Api reference src/SOLUTION_NAME.Application
Api -> Infrastructure
dotnet add src/SOLUTION_NAME.Api reference src/SOLUTION_NAME.Infrastructure
- Add Projects to Solution
dotnet sln add src/SOLUTION_NAME.Domain dotnet sln add src/SOLUTION_NAME.Application dotnet sln add src/SOLUTION_NAME.Infrastructure dotnet sln add src/SOLUTION_NAME.Api
- Cleanup
- Remove default Class1.cs and WeatherForecast.cs files from all projects.
Verification
Run dotnet build to ensure the solution builds correctly.
Parent Hub
- _backend-mastery
Part of Workflow
This skill is utilized in the following sequential workflows:
- _workflow-feature-lifecycle