Skip to content

About

πŸ§… OnionApiTemplate – Clean Architecture ASP.NET Core Web API Template

Resources

Stars

2 stars

Watchers

0 watching

Forks

Β 
Β 

Repository files navigation

OnionApiTemplate# 🧱 Clean Architecture .NET Project

This is a modular .NET 8 Web API project following the principles of Clean Architecture. The architecture separates concerns into distinct layers: Presentation, API, Application, Domain, and Infrastructure.


πŸ“ Project Structure

πŸ“¦ Project.Root
β”œβ”€β”€ Api/                 --> Entry point, config, middleware, static files
β”‚   β”œβ”€β”€ Extensions/
β”‚   β”œβ”€β”€ Factories/
β”‚   β”œβ”€β”€ Middleware/
β”‚   β”œβ”€β”€ Models/
β”‚   β”‚   └── Errors/
β”‚   β”œβ”€β”€ wwwroot/
β”‚   β”œβ”€β”€ Program.cs
β”‚   └── appsettings.json
β”‚
β”œβ”€β”€ Presentation/        --> HTTP Controllers
β”‚   └── Controllers/
β”‚
β”œβ”€β”€ Application/         --> Application logic and services
β”‚   β”œβ”€β”€ Dtos/
β”‚   β”œβ”€β”€ Common/
β”‚   β”‚   └── Settings/     --> Includes JwtSettings
β”‚   β”œβ”€β”€ Interfaces/
β”‚   β”œβ”€β”€ Services/
β”‚   β”œβ”€β”€ MappingProfiles/
β”‚   └── Validations/
β”‚
β”œβ”€β”€ Domain/              --> Core business models and rules
β”‚   β”œβ”€β”€ Entities/
β”‚   β”œβ”€β”€ Errors/
β”‚   β”œβ”€β”€ Exceptions/
β”‚   β”œβ”€β”€ Interfaces/
β”‚   β”œβ”€β”€ Settings/
β”‚   └── Specifications/
β”‚
└── Infrastructure/      --> External integrations and implementations
    β”œβ”€β”€ Persistence/
    └── Services/

πŸ” Authentication

JWT Authentication is implemented using a strongly-typed JwtSettings class located in:

Application/Common/Settings/Jwt.cs

JWT tokens are generated and validated in the Application or Infrastructure layer and configured in Program.cs.


βœ… Validation

  • DTO validation using FluentValidation.
  • Business rules are handled in the Domain layer using entities, exceptions, or specifications.
  • Custom validation errors are returned using ProblemDetails and ValidationErrorResponse.

🧩 Middleware

Custom middleware (like global exception handler) is registered in the API layer under:

Api/Middleware/

πŸš€ Getting Started

  1. Clone the repo.
  2. Set your connection strings and JWT keys in appsettings.json.
  3. Run EF Core migrations if needed.
  4. Build & run the API.

πŸ“Œ Notes

  • Following Separation of Concerns and Dependency Inversion.
  • Use of AutoMapper for mapping between DTOs and Entities.
  • Ready to plug in external services like Stripe, Email, etc.

πŸ™Œ Author

Built by Mostafa ELshenawy – using Clean Architecture with love.

About

πŸ§… OnionApiTemplate – Clean Architecture ASP.NET Core Web API Template

Resources

Stars

2 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages