The Clean Architecture .NET 8 API is a structured and well-organized example of implementing Clean Architecture using .NET Core 8. This project serves as a learning reference for developers who want to understand and implement Clean Architecture using best practices and modern development patterns. π
This repository demonstrates:
π Separation of Concerns (SoC) through Clean Architecture π°
π Implementation of Code First with Migrations π
π Usage of Repository Pattern and Unit of Work π
π Automated Testing with xUnit π§ͺ
π Authentication and Authorization with JWT π
clean-architecture-dotnet.Api
βββ Config # Configuration files, such as AutoMapper settings
β βββ MappingConfig # Mapping profiles for AutoMapper
βββ Controllers # API controllers handling HTTP requests
β βββ V1 # Versioned API controllers
βββ Middlewares # Custom middleware components
βββ Properties # Metadata and project properties
clean-architecture-dotnet.Application
βββ Mappings # AutoMapper configuration for domain-to-view model mappings
βββ Models # Application-level data models
β βββ Http # HTTP request/response models
βββ Services # Business logic and service layer
β βββ Login # Authentication and authorization logic
β β βββ Interfaces # Interfaces for login services
β βββ Products # Product-related business logic
β β βββ Interfaces # Interfaces for product services
β βββ Sales # Sales-related business logic
β β βββ Interfaces # Interfaces for sales services
β βββ Users # User-related business logic
β β βββ Interfaces # Interfaces for user services
βββ ViewModels # View models for API responses
β βββ Products # Product-related view models
β βββ Sales # Sales-related view models
β βββ Users # User-related view models
clean-architecture-dotnet.Domain
βββ Entities # Core domain entities
β βββ Base # Base classes for domain entities
β βββ Products # Product entity definitions
β βββ Sales # Sales entity definitions
β βββ Users # User entity definitions
βββ Enums # Enumeration types for the domain layer
clean-architecture-dotnet.Infrastructure
βββ Authentication # Authentication implementation (JWT, token management)
βββ Context # Database context configuration (Entity Framework Core)
βββ EntitiesConfiguration # Database table configurations (EF Core Fluent API)
β βββ Products # Product table configurations
β βββ Sales # Sales table configurations
β βββ Users # User table configurations
βββ Repositories # Data access layer
β βββ Products # Product repository implementations
β β βββ Interfaces # Repository interfaces
β βββ Sales # Sales repository implementations
β β βββ Interfaces # Repository interfaces
β βββ Users # User repository implementations
β β βββ Interfaces # Repository interfaces
clean-architecture-dotnet.Tests
βββ Application # Application layer testing
β βββ Products # Product tests implementations
β βββ Sales # Sales tests implementations
β βββ Users # User tests implementations
Make sure you have the following installed:
- .NET Core 8 SDK
- SQL Server
- Postman (optional, for API testing)
# Clone the repository
git clone https://github.com/your-repo/clean-architecture-dotnet.git
cd clean-architecture-template-dotnet
Before running the application, configure the database connection string in:
appsettings.json
appsettings.Development.json
Example:
"ConnectionStrings": {
"DefaultConnection": "Data Source=localhost;Initial Catalog=clean-architecture-dotnet;Integrated Security=True;TrustServerCertificate=True"
}
# Start the API
dotnet run --project clean-architecture-dotnet.Api
The application will automatically check if the database and tables exist. If not, they will be created upon execution.
To generate an authentication token, use the following credentials in the login endpoint:
- Email:
[email protected]
This application includes:
π User Registration (With Address & Contact Info) π€
π Product Management (With Product Types) π
π Sales Registration (With Business Rules Applied) π°
- .NET Core 8 π
- Entity Framework Core (Code First + Migrations) π°
- SQL Server π
- AutoMapper π
- xUnit (Unit Testing) π§ͺ
- JWT Authentication π
- Repository & Service Layer Pattern π
This project is licensed under the GPL-2.0 License.