Skip to content

Latest commit

Β 

History

History
160 lines (135 loc) Β· 4.6 KB

File metadata and controls

160 lines (135 loc) Β· 4.6 KB

.NET Clean Architecture (Onion Architecture) Starter Template

Welcome to the .NET Clean Architecture Starter Template!
This repository serves as a well-structured boilerplate for building scalable .NET applications following clean architecture principles.

πŸ“Œ Overview

This template provides:

  • A modular and scalable project structure.
  • Clean Architecture principles (Domain-Driven Design).
  • Entity Framework Core setup for database management.
  • Repository & Service pattern for better code maintainability.
  • ASP.NET Identity for authentication & role-based authorization.
  • AutoMapper for DTO mapping.
  • Middleware setup for security & request handling.
  • Dependency Injection for better code organization.
  • Exception Handling Middleware (IHandlerException) to manage errors efficiently.
  • Scalar API documentation integration for improved OpenAPI documentation.

πŸ“‚ Project Structure

IdentityManagerAPI/
│── .gitignore
│── README.md
│── appsettings.json
│── Program.cs
│── IdentityManagerAPI.http
β”œβ”€β”€ Controllers/
β”‚   β”œβ”€β”€ AuthUserController.cs
β”‚   β”œβ”€β”€ UserController.cs
β”œβ”€β”€ Middlewares/
β”‚   β”œβ”€β”€ GlobalExceptionHandler.cs
│──BearerSecuritySchemeTransformer.cs
β”‚
β”œβ”€β”€ DataAcess/
β”‚   β”œβ”€β”€ Configuration/
β”‚   β”‚   β”œβ”€β”€ ApplicationUserConfiguration.cs
β”‚   β”‚   β”œβ”€β”€ RoleConfiguration.cs
β”‚   β”œβ”€β”€ Migrations/
β”‚   β”œβ”€β”€ Repos/
β”‚   β”‚   β”œβ”€β”€ IRepos/
β”‚   β”‚   β”‚   β”œβ”€β”€ IImageRepository.cs
β”‚   β”‚   β”‚   β”œβ”€β”€ IRepository.cs
β”‚   β”‚   β”‚   β”œβ”€β”€ IUserRepository.cs
β”‚   β”‚   β”œβ”€β”€ ImageRepository.cs
β”‚   β”‚   β”œβ”€β”€ Repository.cs
β”‚   β”‚   β”œβ”€β”€ UserRepository.cs
β”‚   β”œβ”€β”€ ApplicationDbContext.cs
β”‚
β”œβ”€β”€ IdentityManager.Services/
β”‚   β”œβ”€β”€ ControllerService/
β”‚   β”‚   β”œβ”€β”€ IControllerService/
β”‚   β”‚   β”‚   β”œβ”€β”€ IAuthService.cs
β”‚   β”‚   β”‚   β”œβ”€β”€ IUserService.cs
β”‚   β”‚   β”œβ”€β”€ AuthService.cs
β”‚   β”‚   β”œβ”€β”€ UserService.cs
β”‚
β”‚
β”œβ”€β”€ Models/
β”‚   β”œβ”€β”€ Domain/
β”‚   β”‚   β”œβ”€β”€ ApplicationUser.cs
β”‚   β”‚   β”œβ”€β”€ Image.cs
β”‚   β”œβ”€β”€ DTOs/
β”‚   β”‚   β”œβ”€β”€ Auth/
β”‚   β”‚   β”‚   β”œβ”€β”€ LoginRequestDTO.cs
β”‚   β”‚   β”‚   β”œβ”€β”€ LoginResponseDTO.cs
β”‚   β”‚   β”‚   β”œβ”€β”€ RegisterRequestDTO.cs
β”‚   β”‚   β”œβ”€β”€ Image/
β”‚   β”‚   β”‚   β”œβ”€β”€ ImageUploadRequestDto.cs
β”‚   β”‚   β”œβ”€β”€ Mapper/
β”‚   β”‚   β”‚   β”œβ”€β”€ MappingConfig.cs
β”‚   β”‚   β”œβ”€β”€ User/
β”‚   β”‚   β”‚   β”œβ”€β”€ UserDTO.cs
β”œβ”€β”€

πŸš€ Getting Started

1️⃣ Clone the Repository

git clone https://github.com/mrXrobot26/IdentityManagerAPI.git
cd IdentityManagerAPI

2️⃣ Setup Database & Migrations

  1. Update Connection String in appsettings.json:

    "ConnectionStrings": {
       "DefaultConnection": "your_database_connection_string_here"
    }
  2. Apply Migrations:

    dotnet ef database update

πŸ”§ Project Configuration

Authentication & Identity

  • Uses ASP.NET Core Identity for user authentication & role management.
  • Default roles: Admin, User.

Middleware

  • BearerSecuritySchemeTransformer.cs for authentication.
  • Custom middleware can be added for logging, security, etc.

DTOs & AutoMapper

  • Uses DTOs for API request/response models.
  • AutoMapper is configured in MappingConfig.cs to handle model transformations.

πŸ—οΈ Built With

Technology Description
.NET Core Framework for building APIs
Entity Framework Core ORM for database management
ASP.NET Identity Authentication & Authorization
AutoMapper Object-to-object mapping
Scalar API documentation
Middleware Custom request handlers
Dependency Injection Loosely coupled architecture

πŸ“– API Documentation (Scalar)

Once the application is running, access Scalar UI at:

http://localhost:5025/scalar/v1

πŸ› οΈ Development & Contribution

Running Locally

  1. Ensure you have .NET 9 SDK installed.
  2. Run:
    dotnet run

Contributing

  1. Fork the repo.
  2. Create a new branch (feature-branch).
  3. Commit your changes.
  4. Push to your fork and create a Pull Request.

πŸ”₯ Star the Repo & Contribute!

This template is open-source and constantly evolving.
If you find it useful, give it a star ⭐ and contribute! πŸš€