# nuyonu/n-tier-architecture architecture

> Architecture diagram of the GitHub repository nuyonu/n-tier-architecture, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-04-04). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/nuyonu/n-tier-architecture
- Repository: https://github.com/nuyonu/n-tier-architecture

## Overview

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

## Diagram (Mermaid)

```mermaid
graph TD
    Client["External Client"]:::external

    subgraph "Presentation Layer"
        AAPI["API Layer (N-Tier.API)"]:::api
    end

    subgraph "Business/Application Layer"
        AAPP["Application Layer (N-Tier.Application)"]:::app
        ACORE["Domain Layer (N-Tier.Core)"]:::domain
    end

    subgraph "Data Layer"
        ADB["Data Access Layer (N-Tier.DataAccess)"]:::data
    end

    subgraph "Shared Services"
        SHARED["Shared Components (N-Tier.Shared)"]:::shared
    end

    subgraph "Testing Infrastructure"
        TEST["Supporting/Testing Infrastructure (tests)"]:::test
    end

    Client -->|"HTTPRequest"| AAPI
    AAPI -->|"InvokesServices"| AAPP
    AAPI -->|"UsesClaims"| SHARED
    AAPP -->|"ExecutesBusinessLogic"| ACORE
    AAPP -->|"DataOperations"| ADB
    AAPP -->|"UtilizesUtilities"| SHARED

    %% Optional: Testing arrows to indicate test coverage across layers
    TEST -->|"IntegrationTests"| AAPI
    TEST -->|"UnitTests"| AAPP
    TEST -->|"RepositoryTests"| ADB

    click AAPI "https://github.com/nuyonu/n-tier-architecture/blob/main/src/N-Tier.API"
    click AAPP "https://github.com/nuyonu/n-tier-architecture/blob/main/src/N-Tier.Application"
    click ACORE "https://github.com/nuyonu/n-tier-architecture/blob/main/src/N-Tier.Core"
    click ADB "https://github.com/nuyonu/n-tier-architecture/blob/main/src/N-Tier.DataAccess"
    click SHARED "https://github.com/nuyonu/n-tier-architecture/blob/main/src/N-Tier.Shared"
    click TEST "https://github.com/nuyonu/n-tier-architecture/tree/main/tests"

    classDef external fill:#FFECB3,stroke:#F57C00,stroke-width:2px;
    classDef api fill:#BBDEFB,stroke:#0D47A1,stroke-width:2px;
    classDef app fill:#C8E6C9,stroke:#1B5E20,stroke-width:2px;
    classDef domain fill:#FFCDD2,stroke:#B71C1C,stroke-width:2px;
    classDef data fill:#DCEDC8,stroke:#33691E,stroke-width:2px;
    classDef shared fill:#F3E5F5,stroke:#4A148C,stroke-width:2px;
    classDef test fill:#B3E5FC,stroke:#01579B,stroke-width:2px;
```
