# mhkarami97/divarapi architecture

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

- Interactive diagram: https://gitdiagram.com/mhkarami97/divarapi
- Repository: https://github.com/mhkarami97/divarapi

## Overview

##### Main Components
- API Layer – Represented by the “MyApi” project and its Controllers inside MyApi/Controllers/v1. This layer receives client requests and delegates them to other parts of the system.
- Web Framework – The “WebFramework” project houses cross-cutting concerns such as custom controllers, middleware, filters, swagger configuration, and mapping configurations (AutoMapper). This can be depicted as a supporting infrastructure used by the API layer.
- Service Layer – The “Services” project contains the business logic, including functionalities like JWT token handling, data initialization, identity-related operations, scheduling cron jobs for notifications, and security operations. Use this to show where the application’s core logic lives.
- Repository/Data Access Layer – The “Data” and “Repositories” projects implement repository patterns to abstract data access. The “Data” folder with its ApplicationDbContext, migrations, and repository contracts, plus the “Repositories” project’s concrete implementations, indicate your data persistence strategy (likely using Entity Framework Core).
- Domain/Entities – The “Entities” project encapsulates the domain models (such as User, Post, Contact, Banner, etc.). These are the core business objects that are mapped to the database.
- Data Transfer Objects (DTOs) – The “Models” project holds DTOs that serve as the contracts between your API and its consumers. They ensure separation between internal data representations and external communication.
- Common Library – The “Common” project contains shared functionality (exceptions, settings, utilities, etc.), which are likely used across all layers for consistency and reducing code duplication.
- External Integrations – Although not explicitly a separate module, external services are present in the “Services/Notification” (e.g., Email and SMS notifications), as well as scheduled tasks (CronJob) that indicate integration with external email/SMS gateways.
- Testing – The “XUnitTest” project represents your testing layer to validate various components like controllers and utilities.

##### Relationships and Data Flow
- A client sends an HTTP request to the API layer.
- The API controllers (in MyApi/Controllers/v1) process the request, using components provided by the WebFramework (middleware, filters, etc.) to handle cross-cutting concerns (such as exception handling and security).
- The controllers call into the Service Layer (from Services) to execute business logic.
- The Service Layer in turn communicates with the Repository/Data Access Layer (Repositories and Data projects) to perform CRUD operations on the Domain Entities.
- The Domain Entities (in Entities) represent the persistent state and are connected to the database through the ApplicationDbContext.
- DTOs (from Models) are utilized to format and sanitize data as it moves between the client and the API.
- Additionally, aspects like identity management, notifications, and scheduled jobs are integrated within the Services layer interacting with external components.
- The Common library supports all these layers by providing shared utilities (for example, error handling and string operations).

##### Important Architectural Patterns and Principles
- Layered (or Onion/Clean Architecture) – You see distinct boundaries between the API, Service, Repository, and Domain layers.
- Repository Pattern – Abstracts database operations for a cleaner separation and easier testing.
- Dependency Injection – Evident from the configuration files and the modular structure, ensuring components are loosely coupled.
- Modular Design – Each project (Common, Data, Entities, Models, etc.) encapsulates a specific area of concern, promoting maintainability and extensibility.

##### Relevant Technologies and Frameworks
- .NET Core 3.1 – The framework underpinning the application.
- Entity Framework Core – Likely used for data persistence through the ApplicationDbContext and migrations.
- AutoMapper – For object mapping, as set in the WebFramework/CustomMapping directory.
- Logging and Configuration Tools – (nlog.config, appsettings.json files).
- Testing Framework – XUnit for unit tests.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Presentation Layer
    subgraph "Presentation Layer"
        API_Controllers["API Controllers"]:::api
        Web_Framework["Web Framework"]:::framework
    end

    %% Business Layer
    subgraph "Business Layer"
        Business_Services["Business Services"]:::service
        subgraph "External Integrations"
            Notification_Services["Notification Services"]:::external
            Cron_Jobs["Cron Jobs"]:::external
        end
    end

    %% Data Layer
    subgraph "Data Layer"
        Repositories["Repository Implementations"]:::repository
        Data_EF["Data (EF Core)"]:::repository
        Domain_Entities["Domain Entities"]:::domain
        Database["Database"]:::database
    end

    %% Other Components
    DTOs["DTOs"]:::dto
    Common_Library["Common Library"]:::common
    Testing["Testing"]:::testing
    Client["Client"]:::client

    %% Connections
    Client -->|"sends"| API_Controllers
    API_Controllers -->|"uses"| Web_Framework
    API_Controllers -->|"transforms"| DTOs
    API_Controllers -->|"calls"| Business_Services
    Web_Framework -->|"supports"| API_Controllers

    Business_Services -->|"invokes"| Repositories
    Business_Services -->|"uses"| Common_Library
    Business_Services -->|"outputs"| DTOs
    Business_Services -->|"integrates"| Notification_Services
    Business_Services -->|"schedules"| Cron_Jobs

    Repositories -->|"accesses"| Data_EF
    Data_EF -->|"maps"| Domain_Entities
    Domain_Entities -->|"persists to"| Database

    Testing -->|"tests"| API_Controllers
    Testing -->|"tests"| Business_Services

    %% Styling
    classDef client fill:#e0bbff, stroke:#6a0dad, stroke-width:2px;
    classDef api fill:#f8d7da, stroke:#721c24, stroke-width:2px;
    classDef framework fill:#cfe2ff, stroke:#084298, stroke-width:2px;
    classDef service fill:#d1e7dd, stroke:#0f5132, stroke-width:2px;
    classDef repository fill:#cff4fc, stroke:#055160, stroke-width:2px;
    classDef domain fill:#fff3cd, stroke:#856404, stroke-width:2px;
    classDef dto fill:#e2e3e5, stroke:#6c757d, stroke-width:2px;
    classDef common fill:#d1d1e1, stroke:#333, stroke-width:2px;
    classDef external fill:#e2f0cb, stroke:#6a994e, stroke-width:2px;
    classDef testing fill:#fefbd8, stroke:#f4d03f, stroke-width:2px;
    classDef database fill:#d4edda, stroke:#155724, stroke-width:2px;

    %% Click Events
    click API_Controllers "https://github.com/mhkarami97/divarapi/tree/master/MyApi/Controllers/v1"
    click Web_Framework "https://github.com/mhkarami97/divarapi/tree/master/WebFramework"
    click Business_Services "https://github.com/mhkarami97/divarapi/tree/master/Services"
    click Data_EF "https://github.com/mhkarami97/divarapi/tree/master/Data"
    click Repositories "https://github.com/mhkarami97/divarapi/tree/master/Repositories"
    click Domain_Entities "https://github.com/mhkarami97/divarapi/tree/master/Entities"
    click DTOs "https://github.com/mhkarami97/divarapi/tree/master/Models"
    click Common_Library "https://github.com/mhkarami97/divarapi/tree/master/Common"
    click Notification_Services "https://github.com/mhkarami97/divarapi/tree/master/Services/Notification"
    click Cron_Jobs "https://github.com/mhkarami97/divarapi/tree/master/Services/CronJob"
    click Testing "https://github.com/mhkarami97/divarapi/tree/master/XUnitTest"
```
