# serkanyasr/webapi-ntier-architecture architecture

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

- Interactive diagram: https://gitdiagram.com/serkanyasr/webapi-ntier-architecture
- Repository: https://github.com/serkanyasr/webapi-ntier-architecture

## Overview

##### Main Architecture Overview

- Presentation Layer (API Controllers)
- Service Layer
- Repository Layer
- Data Layer (Entities)

##### Component Breakdown

a) Main components:

PRESENTATION TIER:
- Routing and HTTP method handlers

SERVICE TIER:
- IServiceManager and ServiceManager
- BookManager and LoggerManager services

REPOSITORY TIER:
- Repository pattern implementation
- IRepositoryManager and RepositoryManager
- BookRepository and its interface
- RepositoryBase for generic operations

DATA TIER:
- Entity models (Book)
- DbContext (RepositoryContext)
- Database connection

##### Relationships and Dependencies

- Dependency flow (top to bottom)
- Data flow between layers
- Database interactions

##### Special Components

- Configuration components (BookConfig)
- Logging infrastructure (NLog)
- Dependency Injection container
- Extension methods (ServicesExtensions)

##### Specific Implementation Details

- Generic repository pattern implementation
- Service manager pattern
- Entity Framework Core integration
- Logging infrastructure
- Dependency injection setup

##### Technical Elements

Technical aspects:
- EF Core DbContext configuration
- Repository pattern abstractions
- Service layer business logic separation
- Controller endpoint definitions

##### Design Patterns to Highlight

Patterns:
- Repository Pattern
- Dependency Injection
- Factory Pattern (RepositoryContextFactory)
- Manager Pattern (ServiceManager, RepositoryManager)

##### Flow Representation

Typical request flow:
##### Response path back through the layers

Remember to:
- Clear boundaries between layers
- Cross-cutting concerns like logging
- Document the dependency injection setup

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph Client
        HTTP[HTTP Requests]
    end

    subgraph "API Layer"
        BC["BooksController"]:::controller
    end

    subgraph "Service Layer"
        ISM["IServiceManager"]:::interface
        SM["ServiceManager"]:::service
        BM["BookManager"]:::service
        LM["LoggerManager"]:::service
    end

    subgraph "Repository Layer"
        IRM["IRepositoryManager"]:::interface
        RM["RepositoryManager"]:::repository
        IRB["IRepositoryBase<T>"]:::interface
        RB["RepositoryBase<T>"]:::repository
        IBR["IBookRepository"]:::interface
        BR["BookRepository"]:::repository
    end

    subgraph "Data Layer"
        BE["Book Entity"]:::entity
        RC["RepositoryContext"]:::dbcontext
        BC2["BookConfig"]:::config
        DB[(Database)]:::database
    end

    subgraph "Infrastructure"
        RCF["RepositoryContextFactory"]:::infrastructure
        SE["ServicesExtensions"]:::infrastructure
        NL["NLog Config"]:::infrastructure
    end

    %% Relationships
    HTTP --> BC
    BC --> ISM
    ISM --> SM
    SM --> BM
    SM --> LM
    BM --> IRM
    IRM --> RM
    RM --> IBR
    IBR --> BR
    BR --> IRB
    BR --> RC
    RB --> RC
    RC --> DB
    RC --> BC2
    BC2 --> BE
    RCF --> RC
    SE --> SM
    LM --> NL

    %% Click Events
    click BC "https://github.com/serkanyasr/WebAPI-NTier-Architecture/blob/master/Presentations/Controllers/BooksController.cs"
    click ISM "https://github.com/serkanyasr/WebAPI-NTier-Architecture/blob/master/Services/Contracts/IServiceManager.cs"
    click SM "https://github.com/serkanyasr/WebAPI-NTier-Architecture/blob/master/Services/ServiceManager.cs"
    click BM "https://github.com/serkanyasr/WebAPI-NTier-Architecture/blob/master/Services/BookManager.cs"
    click LM "https://github.com/serkanyasr/WebAPI-NTier-Architecture/blob/master/Services/LoggerManager.cs"
    click IRM "https://github.com/serkanyasr/WebAPI-NTier-Architecture/blob/master/Repositories/Contracts/IRepositoryManager.cs"
    click RM "https://github.com/serkanyasr/WebAPI-NTier-Architecture/blob/master/Repositories/EFCore/RepositoryManager.cs"
    click IRB "https://github.com/serkanyasr/WebAPI-NTier-Architecture/blob/master/Repositories/Contracts/IRepositoryBase.cs"
    click RB "https://github.com/serkanyasr/WebAPI-NTier-Architecture/blob/master/Repositories/EFCore/RepositoryBase.cs"
    click IBR "https://github.com/serkanyasr/WebAPI-NTier-Architecture/blob/master/Repositories/Contracts/IBookRepository.cs"
    click BR "https://github.com/serkanyasr/WebAPI-NTier-Architecture/blob/master/Repositories/EFCore/BookRepository.cs"
    click BE "https://github.com/serkanyasr/WebAPI-NTier-Architecture/blob/master/Entities/Models/Book.cs"
    click RC "https://github.com/serkanyasr/WebAPI-NTier-Architecture/blob/master/Repositories/EFCore/RepositoryContext.cs"
    click BC2 "https://github.com/serkanyasr/WebAPI-NTier-Architecture/blob/master/Repositories/EFCore/config/BookConfig.cs"
    click RCF "https://github.com/serkanyasr/WebAPI-NTier-Architecture/blob/master/webAPI/ContextFactory/RepositoryContextFactory.cs"
    click SE "https://github.com/serkanyasr/WebAPI-NTier-Architecture/blob/master/webAPI/Extensions/ServicesExtensions.cs"
    click NL "https://github.com/serkanyasr/WebAPI-NTier-Architecture/blob/master/webAPI/nlog.config"

    %% Styling
    classDef controller fill:#2196F3,stroke:#1565C0,color:white
    classDef service fill:#4CAF50,stroke:#2E7D32,color:white
    classDef repository fill:#FFC107,stroke:#FFA000,color:black
    classDef entity fill:#F44336,stroke:#C62828,color:white
    classDef interface fill:#90CAF9,stroke:#64B5F6,color:black
    classDef infrastructure fill:#9E9E9E,stroke:#616161,color:white
    classDef dbcontext fill:#E91E63,stroke:#C2185B,color:white
    classDef database fill:#7E57C2,stroke:#5E35B1,color:white
    classDef config fill:#FF9800,stroke:#F57C00,color:black
```
