How nuyonu/n-tier-architecture works
Main Components
• API Layer (Presentation): Represented by the N-Tier.API project. This contains controllers, middleware (for exception handling, performance, and transactions), and the overall web server components.
• Application Layer: Found in the N-Tier.Application project. This layer encapsulates business logic, application services, models, and validators (using FluentValidation). It also handles mapping profiles for translating between domain entities and DTOs.
• Domain/Core Layer: The N-Tier.Core project contains entities, common functionalities, and domain-level exceptions. This layer defines the business model and contracts.
• Data Access Layer: The N-Tier.DataAccess project manages database contexts, migrations, repository implementations (such as TodoList and TodoItem repositories), and persistence configurations. This layer implements Entity Framework Core for SQL Server operations.
• Shared Components: The N-Tier.Shared project provides utility services like claim handling that can be used across different layers.
• Supporting/Testing Infrastructure: The tests folder contains both integration and unit tests (using NUnit, XUnit, and FluentAssertions) for different layers of the application.
Relationships and Data Flow
• The API Layer acts as the entry point where HTTP requests are received and routed to controllers.
• Controllers invoke services in the Application Layer, which contain the business logic and coordination.
• The Application Layer interacts with the Data Access Layer (via repository interfaces) to perform database operations and applies mapping via AutoMapper.
• The Domain Layer (Core) provides the basic entities and validations that underpin the business logic.
• Shared services support common functionalities like identity claims, and this service might be used across both the API and Application Layers.
• External tools and frameworks (e.g., ASP.NET Identity, FluentValidation, AutoMapper) integrate into these layers to fortify the design.
Important Architectural Patterns and Design Principles
• Separation of Concerns: Each layer (API, Application, Core, DataAccess, Shared) has clear responsibilities.
• Dependency Injection: Each project/layer (especially API and Application) is set up for DI via dependency injection classes (e.g., ApiDependencyInjection.cs, ApplicationDependencyInjection.cs, DataAccessDependencyInjection.cs).
• Repository Pattern: Abstracts data operations to encapsulate the persistence logic.
• Middleware Pipelines: Custom middleware (exception handling, performance measurement, transaction management) suggests the use of a configurable, plug-in pipeline for request processing.
• Testing Driven Design: The presence of both unit and integration tests ensures that the layers are loosely coupled and testable.