# youmnagbr/e-commerce-asp.net--web-api- architecture

> Architecture diagram of the GitHub repository youmnagbr/e-commerce-asp.net--web-api-, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-03-28). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/youmnagbr/e-commerce-asp.net--web-api-
- Repository: https://github.com/youmnagbr/e-commerce-asp.net--web-api-

## Overview

##### Main Components
- Domain Layer (Talabat.Core): This module contains the core entities such as BasketItem, CustomerBasket, Department, Employee, and Product-related classes. It also defines repository contracts (like IGenericRepository) and specifications used to drive query logic.
- Business Logic Layer (Talabat.Service): This layer abstracts the business operations and orchestrates calls to the repository.
- Presentation Layer (Talabat): Contains the Controllers (e.g., BasketController, ProductsController, EmployeeController), middleware (like the ExceptionMiddleware), DTOs, mapping profiles, and extensions. This is the Web API that handles HTTP requests from external clients.
- Frontend (Angular): Although not visible in the file tree, the README clearly describes an Angular application running separately. This component will communicate with the Web API for all e-commerce functionality.
- External Services:
- SQL Server: The database is implemented using SQL Server with code-first Entity Framework.
- JWT Authentication: For secure communications, the API uses JWT authentication to protect endpoints.

##### Relationships and Interactions
- The Angular Frontend interacts with the ASP.NET Web API by making HTTP requests to API endpoints (e.g., for products, basket actions, employee data).
- API Controllers (in the Talabat folder) receive requests from the frontend. They depend on the Business Logic Layer (Talabat.Service) to process the requests.
- The Service layer calls into the Repository layer (Talabat.Repository) which, in turn, uses the Domain Models and Specifications (from Talabat.Core) to query or persist data into the SQL Server database.
- Middleware, such as the ExceptionMiddleware, intercepts requests to handle errors and ensure proper API responses.
- The mapping profile and DTOs facilitate data transformation between the domain entities and the data exposed to the client.

##### Important Architectural Patterns and Principles
- Onion Architecture: Separates concerns by isolating the domain, application/service, infrastructure, and presentation layers.
- Repository and Unit of Work Patterns: Facilitate data abstraction and ensure cleaner database transaction management.
- Specification Pattern: Used to encapsulate complex query logic, making the repository queries more maintainable.
- JWT Authentication: Enables stateless and secure API requests.
- API Documentation and Middleware: The Swagger services extension aids in API documentation; middleware ensures proper error handling.

##### Relevant Technologies/Frameworks
- ASP.NET Core Web API (.NET 6) for backend development.
- Entity Framework Core for ORM.
- SQL Server for database.
- Angular for the frontend.
- JWT for authentication.
- Visual Studio for development and Git for version control.

##### Final Remarks
- Clarity by segmenting related areas together and using annotations that explain how each architectural choice (like the Onion pattern or the specification approach) adds value to the project.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Frontend
    AF["Angular Frontend"]:::frontend

    %% Presentation Layer
    subgraph "Presentation Layer (ASP.NET Core Web API)"
        API["API Controllers"]:::presentation
        EM["Exception Middleware"]:::presentation
        DTO["DTOs"]:::presentation
        MP["Mapping Profile"]:::presentation
    end

    %% Business Logic Layer
    BL["Business Logic - Talabat.Service"]:::service

    %% Data Access Layer
    DA["Data Access - Talabat.Repository"]:::repository

    %% Domain Layer
    D["Domain Layer - Talabat.Core"]:::domain
    SPEC["Specifications"]:::domain

    %% External Components
    JWT["JWT Authentication"]:::external
    DB["SQL Server"]:::db

    %% Relationships
    AF -->|"HTTPRequest"| API
    API -->|"invokes"| BL
    BL -->|"calls"| DA
    DA -->|"persistsTo"| DB
    DA -->|"utilizes"| D
    D -->|"defines"| SPEC
    API -->|"authCheck"| JWT
    API -->|"errorHandling"| EM

    %% Click Events
    click API "https://github.com/youmnagbr/e-commerce-asp.net--web-api-/tree/master/Talabat/Controllers"
    click EM "https://github.com/youmnagbr/e-commerce-asp.net--web-api-/blob/master/Talabat/Middlwares/ExcpetionMiddleware.cs"
    click DTO "https://github.com/youmnagbr/e-commerce-asp.net--web-api-/tree/master/Talabat/DTOs"
    click MP "https://github.com/youmnagbr/e-commerce-asp.net--web-api-/blob/master/Talabat/Helpers/MappingProfile.cs"
    click BL "https://github.com/youmnagbr/e-commerce-asp.net--web-api-/blob/master/Talabat.Service"
    click DA "https://github.com/youmnagbr/e-commerce-asp.net--web-api-/blob/master/Talabat.Repository"
    click D "https://github.com/youmnagbr/e-commerce-asp.net--web-api-/blob/master/Talabat.Core"
    click SPEC "https://github.com/youmnagbr/e-commerce-asp.net--web-api-/tree/master/Talabat.Core/Specfications"

    %% Styles
    classDef frontend fill:#cde,stroke:#333,stroke-width:2px
    classDef presentation fill:#f9c,stroke:#333,stroke-width:2px
    classDef service fill:#cff,stroke:#333,stroke-width:2px
    classDef repository fill:#fc9,stroke:#333,stroke-width:2px
    classDef domain fill:#dfd,stroke:#333,stroke-width:2px
    classDef db fill:#ffd,stroke:#333,stroke-width:2px
    classDef external fill:#ddf,stroke:#333,stroke-width:2px
```
