Skip to content

This repository has a Clean Architecture template using .NET Core 8. It applies the Code First pattern with Migrations to create a SQL Server database. The goal is to guide developers in learning and applying Clean Architecture principles in .NET applications. πŸš€

License

Notifications You must be signed in to change notification settings

omatheusribeiro/clean-architecture-template-dotnet

Repository files navigation

πŸ“Œ Clean Architecture .NET 8 API

πŸ“š Overview

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 πŸ”‘

🏰 Project Structure

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

🎼 Screenshots

Screenshot 1

Architecture Diagram

Screenshot 2

πŸš€ Getting Started

πŸ“ Prerequisites

Make sure you have the following installed:

πŸ”§ Installation

# Clone the repository
git clone https://github.com/your-repo/clean-architecture-dotnet.git
cd clean-architecture-template-dotnet

βš™οΈ Configuration

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"
}

▢️ Running the Application

# 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.

πŸ”‘ Authentication & Initial Token Usage

To generate an authentication token, use the following credentials in the login endpoint:

πŸ› οΈ Features & Modules

This application includes:

πŸ‘‰ User Registration (With Address & Contact Info) πŸ‘€
πŸ‘‰ Product Management (With Product Types) πŸ›‚
πŸ‘‰ Sales Registration (With Business Rules Applied) πŸ’°

πŸ› οΈ Technologies Used

  • .NET Core 8 πŸš€
  • Entity Framework Core (Code First + Migrations) 🏰
  • SQL Server πŸ“‚
  • AutoMapper πŸ”„
  • xUnit (Unit Testing) πŸ§ͺ
  • JWT Authentication πŸ”‘
  • Repository & Service Layer Pattern πŸ“š

πŸ“„ License

This project is licensed under the GPL-2.0 License.

About

This repository has a Clean Architecture template using .NET Core 8. It applies the Code First pattern with Migrations to create a SQL Server database. The goal is to guide developers in learning and applying Clean Architecture principles in .NET applications. πŸš€

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages