57ac80a66608d23b36f9e21259863680dcabd0a3
MyNewProjectName - Clean Architecture Template
A Clean Architecture template for .NET 9 applications.
📁 Project Structure
├── MyNewProjectName.Domain # Enterprise Business Rules (Entities, Value Objects, Domain Events)
├── MyNewProjectName.Application # Application Business Rules (Use Cases, CQRS, Validators)
├── MyNewProjectName.Contracts # DTOs for external communication (Requests, Responses)
├── MyNewProjectName.Infrastructure # External concerns (Database, Identity, Services)
├── MyNewProjectName.WebAPI # Web API presentation layer
├── MyNewProjectName.AdminAPI # Admin API presentation layer
└── MyNewProjectName.UnitTest # Unit tests
🏗️ Architecture
This template follows Clean Architecture principles:
┌─────────────────────────────────────────────────────────┐
│ Presentation Layer (WebAPI, AdminAPI) │
├─────────────────────────────────────────────────────────┤
│ Infrastructure Layer (EF Core, Identity, Services) │
├─────────────────────────────────────────────────────────┤
│ Application Layer (MediatR, AutoMapper, Validators) │
├─────────────────────────────────────────────────────────┤
│ Domain Layer (Entities, ValueObjects, Interfaces) │
└─────────────────────────────────────────────────────────┘
Dependency Rule
- Inner layers know nothing about outer layers
- Dependencies point inward
🚀 Getting Started
Prerequisites
- .NET 9 SDK
- SQL Server (or modify connection string for other databases)
Setup
-
Clone and rename the template
# Clone the repository git clone <repository-url> MyNewProject cd MyNewProject # Run the rename script ./rename-project.sh MyNewProject -
Update connection string
Edit
appsettings.jsonin WebAPI/AdminAPI projects:{ "ConnectionStrings": { "DefaultConnection": "Your-Connection-String" } } -
Run migrations
cd MyNewProjectName.Infrastructure dotnet ef migrations add InitialCreate --startup-project ../MyNewProjectName.WebAPI dotnet ef database update --startup-project ../MyNewProjectName.WebAPI -
Run the application
dotnet run --project MyNewProjectName.WebAPI
NuGet Packages
Application Layer
- MediatR - CQRS pattern implementation
- AutoMapper - Object-to-object mapping
- FluentValidation - Validation rules
Infrastructure Layer
- Entity Framework Core - ORM
- Microsoft.AspNetCore.Identity - Authentication/Authorization
🔧 Key Features
- Clean Architecture structure
- CQRS with MediatR
- Validation pipeline with FluentValidation
- Logging pipeline behavior
- Global exception handling
- Generic Repository pattern
- Unit of Work pattern
- AutoMapper integration
- Multi-API support (WebAPI + AdminAPI)
- Auditable entities
- Soft delete support
- Domain events support
📝 Usage Examples
Creating a new Feature
- Add Entity in
Domain/Entities/ - Add Repository Interface in
Domain/Interfaces/ - Add Command/Query in
Application/Features/{FeatureName}/ - Add DTO in
Contracts/DTOs/ - Add Controller in
WebAPI/Controllers/
Sample CQRS Structure
Application/Features/Sample/
├── Commands/
│ └── CreateSample/
│ ├── CreateSampleCommand.cs
│ ├── CreateSampleCommandHandler.cs
│ └── CreateSampleCommandValidator.cs
└── Queries/
└── GetSamples/
├── GetSamplesQuery.cs
├── GetSamplesQueryHandler.cs
└── SampleDto.cs
🔄 Renaming the Project
Use the provided script to rename all occurrences of MyNewProjectName:
./rename-project.sh NewProjectName
📄 License
MIT License
Description
Languages
Python
91.9%
C#
5.7%
JavaScript
1.3%
Shell
0.5%
TypeScript
0.3%
Other
0.2%