# merttmetinn/smartsyncapi architecture

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

- Interactive diagram: https://gitdiagram.com/merttmetinn/smartsyncapi
- Repository: https://github.com/merttmetinn/smartsyncapi

## Overview

##### Main Components
- Presentation Layer (SmartSyncAPI.API):
- Contains the API controllers (AdminController, CartController, CustomerController, LogController, OrderController, ProductController) that expose HTTP endpoints.
- Includes middleware such as the TokenMiddleware for handling authentication issues.
- Holds configuration files (appsettings.json, launchSettings.json) which set up the runtime environment.

- Application Layer (SmartSyncAPI.Application):
- Implements use-case-specific features via Command and Query sub-folders (e.g., CreateAdmin, LoginAdmin, AddProduct, UpdateCart, etc.).
- Defines abstractions for repositories (read/write repository interfaces) and services (password hashing, token service) to ensure loose coupling.
- Centralizes business logic and mediates requests coming in from the API layer.

- Domain Layer (SmartSyncAPI.Domain):
- Contains core business entities (Admin, Cart, Customer, Log, Order, OrderProduct, Product) and DTOs.
- Defines common base classes and enumerations (e.g., BaseEntity, OrderStatus) that capture the domain’s rules and behaviour.
- Acts as the central point of the business logic without any dependencies on external components.

- Infrastructure/Persistence Layer (SmartSyncAPI.Persistance):
- Provides concrete implementations of the repository interfaces defined in the Application Layer.
- Manages data access through the SmartSyncDbContext (the Entity Framework Core context) along with corresponding migrations.
- Contains service registrations for integration (e.g., dependency injection configuration for repositories and services).

##### Relationships & Interactions
- The Presentation layer (API controllers) accepts HTTP requests, forwards them to the Application layer where the corresponding Command or Query handlers process the requests.
- The Application layer executes business logic and then interacts with the Infrastructure/Persistence layer through repository interfaces for data storage and retrieval.
- The Domain layer supplies the fundamental business models that are used across both Application and Infrastructure layers.
- Middleware (e.g., TokenMiddleware) and service implementations (TokenService, PasswordHasher) are cross-cutting concerns that ensure security and authentication.

##### Architectural Patterns and Design Principles
- Clean Architecture: The separation into Presentation, Application, Domain, and Infrastructure encourages a loosely coupled, easily maintainable structure.
- Repository Pattern: Both read and write repositories are abstracted in the Application layer and implemented concretely in the Infrastructure layer.
- Command-Query Responsibility Segregation (CQRS): Commands (for changes) and Queries (for data retrieval) are organized into distinct folders to separate mutating from querying operations.
- Dependency Injection: Evident in the service registrations for repositories and services, allowing easier testing and management of dependencies.

## Diagram (Mermaid)

```mermaid
graph TD
    %% Presentation Layer
    subgraph "Presentation Layer"
        P1("AdminController"):::presentation
        P2("CartController"):::presentation
        P3("CustomerController"):::presentation
        P4("LogController"):::presentation
        P5("OrderController"):::presentation
        P6("ProductController"):::presentation
        P7("TokenMiddleware"):::presentation
        P8("Config (appsettings.json)"):::presentation
        P9("Config (launchSettings.json)"):::presentation
    end

    %% Application Layer
    subgraph "Application Layer"
        A1("Command/Query Handlers"):::application
        A2("Repository & Service Abstractions"):::application
        A3("Service Registration"):::application
    end

    %% Domain Layer
    subgraph "Domain Layer"
        D1("Domain Entities"):::domain
        D2("DTOs"):::domain
        D3("Enums"):::domain
    end

    %% Infrastructure/Persistence Layer
    subgraph "Infrastructure/Persistence Layer"
        I1("DbContext & Factory"):::infrastructure
        I2("Migrations"):::infrastructure
        I3("Repository Implementations"):::infrastructure
        I4("Persistence Service Registration"):::infrastructure
        I5("Persistence Services"):::infrastructure
    end

    %% Connections
    %% Presentation to Application (HTTP requests from controllers)
    P1 -->|"HTTP_Request"| A1
    P2 -->|"HTTP_Request"| A1
    P3 -->|"HTTP_Request"| A1
    P4 -->|"HTTP_Request"| A1
    P5 -->|"HTTP_Request"| A1
    P6 -->|"HTTP_Request"| A1
    P8 -->|"Config"| A1
    P9 -->|"Config"| A1

    %% Application processing and dependency on Domain
    A1 -->|"Business_Logic"| D1
    A2 -->|"Uses_Domain"| D1

    %% Application invoking Persistence for data access
    A1 -->|"Data_Access"| I3
    A3 -->|"DI_Registration"| I4

    %% Infrastructure providing domain models back
    I1 -->|"Domain_Models"| D1

    %% Cross-cutting: Middleware to persistence-level services for authentication
    P7 -->|"Authentication"| I5

    %% Styling Classes
    classDef presentation fill:#cce5ff,stroke:#0056b3,stroke-width:2px;
    classDef application fill:#d4edda,stroke:#155724,stroke-width:2px;
    classDef domain fill:#e2e3e5,stroke:#6c757d,stroke-width:2px;
    classDef infrastructure fill:#ffeeba,stroke:#856404,stroke-width:2px;

    %% Click Events for Presentation Layer
    click P1 "https://github.com/merttmetinn/smartsyncapi/blob/master/SmartSyncAPI/Presentation/SmartSyncAPI.API/Controllers/AdminController.cs"
    click P2 "https://github.com/merttmetinn/smartsyncapi/blob/master/SmartSyncAPI/Presentation/SmartSyncAPI.API/Controllers/CartController.cs"
    click P3 "https://github.com/merttmetinn/smartsyncapi/blob/master/SmartSyncAPI/Presentation/SmartSyncAPI.API/Controllers/CustomerController.cs"
    click P4 "https://github.com/merttmetinn/smartsyncapi/blob/master/SmartSyncAPI/Presentation/SmartSyncAPI.API/Controllers/LogController.cs"
    click P5 "https://github.com/merttmetinn/smartsyncapi/blob/master/SmartSyncAPI/Presentation/SmartSyncAPI.API/Controllers/OrderController.cs"
    click P6 "https://github.com/merttmetinn/smartsyncapi/blob/master/SmartSyncAPI/Presentation/SmartSyncAPI.API/Controllers/ProductController.cs"
    click P7 "https://github.com/merttmetinn/smartsyncapi/blob/master/SmartSyncAPI/Presentation/SmartSyncAPI.API/Middlewares/TokenMiddleware.cs"
    click P8 "https://github.com/merttmetinn/smartsyncapi/blob/master/SmartSyncAPI/Presentation/SmartSyncAPI.API/appsettings.json"
    click P9 "https://github.com/merttmetinn/smartsyncapi/blob/master/SmartSyncAPI/Presentation/SmartSyncAPI.API/Properties/launchSettings.json"

    %% Click Events for Application Layer
    click A1 "https://github.com/merttmetinn/smartsyncapi/tree/master/SmartSyncAPI/Core/SmartSyncAPI.Application/Features"
    click A2 "https://github.com/merttmetinn/smartsyncapi/tree/master/SmartSyncAPI/Core/SmartSyncAPI.Application/Abstractions"
    click A3 "https://github.com/merttmetinn/smartsyncapi/blob/master/SmartSyncAPI/Core/SmartSyncAPI.Application/ServiceRegistirations.cs"

    %% Click Events for Domain Layer
    click D1 "https://github.com/merttmetinn/smartsyncapi/tree/master/SmartSyncAPI/Core/SmartSyncAPI.Domain/Entities"
    click D2 "https://github.com/merttmetinn/smartsyncapi/tree/master/SmartSyncAPI/Core/SmartSyncAPI.Domain/Dto"
    click D3 "https://github.com/merttmetinn/smartsyncapi/tree/master/SmartSyncAPI/Core/SmartSyncAPI.Domain/Enums"

    %% Click Events for Infrastructure/Persistence Layer
    click I1 "https://github.com/merttmetinn/smartsyncapi/tree/master/SmartSyncAPI/Infrastructure/SmartSyncAPI.Persistance/Contexts"
    click I2 "https://github.com/merttmetinn/smartsyncapi/tree/master/SmartSyncAPI/Infrastructure/SmartSyncAPI.Persistance/Migrations"
    click I3 "https://github.com/merttmetinn/smartsyncapi/tree/master/SmartSyncAPI/Infrastructure/SmartSyncAPI.Persistance/Abstractions/Repositories"
    click I4 "https://github.com/merttmetinn/smartsyncapi/blob/master/SmartSyncAPI/Infrastructure/SmartSyncAPI.Persistance/ServiceRegistiration.cs"
    click I5 "https://github.com/merttmetinn/smartsyncapi/tree/master/SmartSyncAPI/Infrastructure/SmartSyncAPI.Persistance/Abstractions/Services"
```
