# ammaryasser88/smartstoreapi architecture

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

- Interactive diagram: https://gitdiagram.com/ammaryasser88/smartstoreapi
- Repository: https://github.com/ammaryasser88/smartstoreapi

## Overview

##### Main Components
- API Layer (SmartStoreAPi)
- Application Layer (SmartStore.Application)
- Domain Layer (SmartStore.Domain)
- Shared Library (SmartStore.Shared)
- Database (SQL Server)
- External Clients (Web/Mobile frontends, POS devices)
- External Services (JWT Authentication, Logging, Email/SMS via MessageService)

##### Relationships & Data Flows
- Clients → HTTP requests → API Layer
- API Controllers ←→ Application Services
- Services ←→ UnitOfWork → Generic Repositories
- Repositories ←→ EF Core DbContext (SmartStoreContext) ←→ SQL Server
- AutoMapper & FluentValidation operate within the Application Layer to map DTOs and validate incoming data.
- Shared Library provides pagination utilities to both API and Application layers.

##### Architectural Patterns & Principles
- Clean Architecture: strict layer boundaries, dependency inversion (inner layers know nothing of outer layers)
- Repository Pattern + Unit of Work for data access abstraction
- DTO mapping via AutoMapper profiles
- Validation via FluentValidation validators
- Layered .NET projects grouped by responsibility (Application, Domain, API, Shared)

##### Technologies
- ASP.NET Core 8 (Web API)
- Entity Framework Core (ORM)
- SQL Server (Relational Database)
- AutoMapper (Object–Object Mapping)
- FluentValidation (Request Validation)
- JWT (Authentication)

##### Elements
- API Layer: Controllers, ConfigureServicesExtension, Program.cs
- Application Layer:
- BusinessServices & ApplicationServices interfaces & implementations
- GenericRepository, UnitOfWork
- AutoMapper Profiles & Validators
- Domain Layer: Entities, Configurations, DbContext, Migrations, Request/Response DTOs
- Shared Library: PaginationHelper & PaginationObject
- Database: SQL Server instance
- External Clients & Services: Web/Mobile, JWT Auth, MessageService

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% External Clients and Services
    subgraph "External"
        direction TB
        WebMobile["Web/Mobile Clients"]:::external
        POS["POS Devices"]:::external
        JWTAuth["JWT Authentication"]:::external
        MessageExt["Email/SMS Service"]:::external
    end

    %% API Layer
    subgraph "API Layer" 
        direction TB
        Program["Program.cs"]:::api
        ConfigExt["ConfigureServicesExtension"]:::api
        Controllers["Controllers"]:::api
    end

    %% Application Layer
    subgraph "Application Layer"
        direction TB
        BS_Intf["BusinessServices Interfaces"]:::application
        BS_Impl["BusinessServices Implementations"]:::application
        Repo_Intf["IRepository"]:::application
        Repo_Impl["Repository"]:::application
        UoW_Intf["IUnitOfWork"]:::application
        UoW_Impl["UnitOfWork"]:::application
        MSG_Intf["IMessageService"]:::application
        MSG_Impl["MessageService"]:::application
        AutoMap["AutoMapper Profiles"]:::application
        Validators["FluentValidation Validators"]:::application
        SR_DTO["ServiceResult DTO"]:::application
    end

    %% Domain Layer
    subgraph "Domain Layer"
        direction TB
        Entities["Entities"]:::domain
        Configs["Configurations"]:::domain
        ReqDTOs["Request DTOs"]:::domain
        ResDTOs["Response DTOs"]:::domain
        DbContext["SmartStoreContext (DbContext)"]:::domain
        Migrations["Migrations"]:::domain
    end

    %% Shared Library
    subgraph "Shared Library"
        direction TB
        PaginationHelper["PaginationHelper"]:::shared
        PaginationObject["PaginationObject"]:::shared
    end

    %% Database
    SQLServer["SQL Server"]:::db

    %% Data Flows
    WebMobile -->|"HTTP request"| Controllers
    POS -->|"HTTP request"| Controllers
    Controllers -->|"calls Services"| BS_Intf
    BS_Intf -->|"invokes"| BS_Impl
    BS_Impl -->|"uses"| Repo_Intf
    Repo_Intf -->|"implemented by"| Repo_Impl
    BS_Impl -->|"uses"| UoW_Intf
    UoW_Intf -->|"implemented by"| UoW_Impl
    Repo_Impl -->|"calls"| DbContext
    DbContext -->|"executes SQL"| SQLServer
    BS_Impl -->|"maps/validates"| AutoMap
    BS_Impl -->|"maps/validates"| Validators
    BS_Impl -->|"returns ServiceResult"| SR_DTO
    Controllers -->|"returns JSON"| WebMobile
    Controllers -->|"returns JSON"| POS

    %% Extensions and Program
    Program -->|"configures services"| ConfigExt
    ConfigExt -->|"registers dependencies"| Controllers
    ConfigExt -->|"registers dependencies"| BS_Impl
    ConfigExt -->|"registers dependencies"| Repo_Impl

    %% Shared usage
    Controllers -->|"pagination utils"| PaginationHelper
    BS_Impl -->|"pagination utils"| PaginationObject

    %% External Services
    MSG_Impl -->|"sends messages"| MessageExt
    Controllers -->|"auth via"| JWTAuth

    %% Click Events
    click Controllers "https://github.com/ammaryasser88/smartstoreapi/tree/master/SmartStoreAPi/Controllers"
    click ConfigExt "https://github.com/ammaryasser88/smartstoreapi/blob/master/SmartStoreAPi/Extensions/ConfigureServicesExtension.cs"
    click Program "https://github.com/ammaryasser88/smartstoreapi/blob/master/SmartStoreAPi/Program.cs"
    click Repo_Intf "https://github.com/ammaryasser88/smartstoreapi/blob/master/SmartStore.Application/GenaricRepository/Abstraction/IRepository.cs"
    click Repo_Impl "https://github.com/ammaryasser88/smartstoreapi/blob/master/SmartStore.Application/GenaricRepository/Implementation/Repository.cs"
    click UoW_Intf "https://github.com/ammaryasser88/smartstoreapi/blob/master/SmartStore.Application/UnitOfWork/Abstraction/IUnitOfWork.cs"
    click UoW_Impl "https://github.com/ammaryasser88/smartstoreapi/blob/master/SmartStore.Application/UnitOfWork/Implementation/UnitOfWork.cs"
    click BS_Intf "https://github.com/ammaryasser88/smartstoreapi/tree/master/SmartStore.Application/Services/BusinessServices/Abstraction"
    click BS_Impl "https://github.com/ammaryasser88/smartstoreapi/tree/master/SmartStore.Application/Services/BusinessServices/Implementation"
    click MSG_Intf "https://github.com/ammaryasser88/smartstoreapi/blob/master/SmartStore.Application/Services/ApplicationServices/Abstraction/IMessageService.cs"
    click MSG_Impl "https://github.com/ammaryasser88/smartstoreapi/blob/master/SmartStore.Application/Services/ApplicationServices/Implementation/MessageService.cs"
    click AutoMap "https://github.com/ammaryasser88/smartstoreapi/tree/master/SmartStore.Application/MapperConfigurations"
    click Validators "https://github.com/ammaryasser88/smartstoreapi/tree/master/SmartStore.Application/Validators"
    click SR_DTO "https://github.com/ammaryasser88/smartstoreapi/blob/master/SmartStore.Application/Responses/ServiceResult.cs"
    click DbContext "https://github.com/ammaryasser88/smartstoreapi/blob/master/SmartStore.Domain/Context/SmartStoreContext.cs"
    click Configs "https://github.com/ammaryasser88/smartstoreapi/tree/master/SmartStore.Domain/Configurations"
    click Entities "https://github.com/ammaryasser88/smartstoreapi/tree/master/SmartStore.Domain/Entities"
    click ReqDTOs "https://github.com/ammaryasser88/smartstoreapi/tree/master/SmartStore.Domain/Dtos/Request"
    click ResDTOs "https://github.com/ammaryasser88/smartstoreapi/tree/master/SmartStore.Domain/Dtos/Response"
    click Migrations "https://github.com/ammaryasser88/smartstoreapi/tree/master/SmartStore.Domain/Migrations"
    click PaginationHelper "https://github.com/ammaryasser88/smartstoreapi/blob/master/SmartStore.Shared/Pagination/PaginationHelper.cs"
    click PaginationObject "https://github.com/ammaryasser88/smartstoreapi/blob/master/SmartStore.Shared/Pagination/PaginationObject.cs"

    %% Styles
    classDef external fill:#f9c,stroke:#333,stroke-width:1px
    classDef api fill:#bbdefb,stroke:#333,stroke-width:1px
    classDef application fill:#c8e6c9,stroke:#333,stroke-width:1px
    classDef domain fill:#ffe0b2,stroke:#333,stroke-width:1px
    classDef shared fill:#e0e0e0,stroke:#333,stroke-width:1px
    classDef db fill:#fff9c4,stroke:#333,stroke-width:1px
```
