# essraaabdelrahman/productsapi architecture

> Architecture diagram of the GitHub repository essraaabdelrahman/productsapi, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-16). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/essraaabdelrahman/productsapi
- Repository: https://github.com/essraaabdelrahman/productsapi

## Overview

Products API is a Clean Architecture REST service for creating products and retrieving them individually or as a list. The principal flow is an HTTP request through the Products controller into MediatR command/query handling, then through the repository abstraction to EF Core and SQL Server; results are returned as DTOs. The map also preserves documented validation, exception handling, logging, and correlation-ID capabilities. Some infrastructure is documented but not sampled, so those relationships are shown only where the README supports them.

Main entry points: [`Products.Api/Controllers/ProductsController.cs`](https://github.com/essraaabdelrahman/productsapi/blob/master/Products.Api/Controllers/ProductsController.cs) (Products controller), [`ProductsApi.Application/Products/Queries/GetProductById/GetProductByIdQueryHandler.cs`](https://github.com/essraaabdelrahman/productsapi/blob/master/ProductsApi.Application/Products/Queries/GetProductById/GetProductByIdQueryHandler.cs) (Product handler), [`ProductsApi.Application/Products/Commands/CreateProduct/CreateProductCommand.cs`](https://github.com/essraaabdelrahman/productsapi/blob/master/ProductsApi.Application/Products/Commands/CreateProduct/CreateProductCommand.cs) (Create command), [`ProductsApi.Application/Abstractions/IProductRepository.cs`](https://github.com/essraaabdelrahman/productsapi/blob/master/ProductsApi.Application/Abstractions/IProductRepository.cs) (Product repository contract)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_api["HTTP API"]
  node_products_controller["Products controller"]
  node_create_request["Create request"]
  node_exception_handler["Problem details handler"]
  node_runtime_observability["Request tracing and logging<br/>[Program.cs]"]
  node_serilog["Serilog sinks<br/>[appsettings.json]"]
end

subgraph group_application["Application"]
  node_create_command["Create command"]
  node_create_handler["Create handler"]
  node_create_validator["Create validator"]
  node_get_all_query["List query"]
  node_get_all_handler["List handler"]
  node_get_one_query["Product query"]
  node_get_one_handler["Product handler"]
  node_validation_behavior["Validation behavior"]
  node_logging_behavior["Command/query logging<br/>[LoggingBehavior.cs]"]
  node_product_dto["Product DTO<br/>[ProductDto.cs]"]
  node_repository_contract["Product repository contract"]
  node_not_found["Not-found exception"]
end

subgraph group_domain["Domain"]
  node_product_entity["Product entity<br/>[Product.cs]"]
end

subgraph group_infrastructure["Infrastructure"]
  node_product_repository["Product repository"]
  node_db_context["EF Core context<br/>[AppDbContext.cs]"]
  node_sql_server[("SQL Server")]
  node_product_mapping["Product EF mapping"]
end

node_client(("API client"))

node_client -->|"sends HTTP"| node_products_controller
node_products_controller -->|"accepts body"| node_create_request
node_products_controller -->|"sends command"| node_create_command
node_products_controller -->|"sends query"| node_get_all_query
node_products_controller -->|"sends query"| node_get_one_query
node_create_command -.->|"dispatched to"| node_create_handler
node_get_all_query -.->|"dispatched to"| node_get_all_handler
node_get_one_query -.->|"dispatched to"| node_get_one_handler
node_create_handler -->|"calls"| node_repository_contract
node_get_all_handler -->|"calls"| node_repository_contract
node_get_one_handler -->|"calls"| node_repository_contract
node_create_handler -->|"creates"| node_product_entity
node_get_one_handler -->|"throws"| node_not_found
node_get_one_handler -->|"maps result"| node_product_dto
node_get_all_handler -->|"returns DTOs"| node_product_dto
node_create_validator -->|"validates"| node_create_command
node_validation_behavior -.->|"runs validators"| node_create_validator
node_logging_behavior -.->|"logs handling"| node_create_command
node_products_controller -->|"returns"| node_product_dto
node_exception_handler -->|"handles"| node_not_found
node_repository_contract -->|"implemented by"| node_product_repository
node_product_repository -->|"queries and saves"| node_db_context
node_db_context -->|"tracks"| node_product_entity
node_db_context -->|"loads configuration"| node_product_mapping
node_product_repository -.->|"persists through EF"| node_sql_server
node_runtime_observability -->|"registers"| node_exception_handler
node_runtime_observability -->|"configures logging"| node_serilog
node_runtime_observability -.->|"enables request tracing"| node_logging_behavior

click node_products_controller "https://github.com/essraaabdelrahman/productsapi/blob/master/Products.Api/Controllers/ProductsController.cs"
click node_create_request "https://github.com/essraaabdelrahman/productsapi/blob/master/Products.Api/Contracts/CreateProductRequest.cs"
click node_exception_handler "https://github.com/essraaabdelrahman/productsapi/blob/master/Products.Api/Middleware/GlobalExceptionHandler.cs"
click node_runtime_observability "https://github.com/essraaabdelrahman/productsapi/blob/master/Products.Api/Program.cs"
click node_create_command "https://github.com/essraaabdelrahman/productsapi/blob/master/ProductsApi.Application/Products/Commands/CreateProduct/CreateProductCommand.cs"
click node_create_handler "https://github.com/essraaabdelrahman/productsapi/blob/master/ProductsApi.Application/Products/Commands/CreateProduct/CreateProductCommandHandler.cs"
click node_create_validator "https://github.com/essraaabdelrahman/productsapi/blob/master/ProductsApi.Application/Products/Commands/CreateProduct/CreateProductCommandValidator%20.cs"
click node_get_all_query "https://github.com/essraaabdelrahman/productsapi/blob/master/ProductsApi.Application/Products/Queries/GetProducts/GetProductsQuery.cs"
click node_get_all_handler "https://github.com/essraaabdelrahman/productsapi/blob/master/ProductsApi.Application/Products/Queries/GetProducts/GetProductsQueryHandler.cs"
click node_get_one_query "https://github.com/essraaabdelrahman/productsapi/blob/master/ProductsApi.Application/Products/Queries/GetProductById/GetProductByIdQuery.cs"
click node_get_one_handler "https://github.com/essraaabdelrahman/productsapi/blob/master/ProductsApi.Application/Products/Queries/GetProductById/GetProductByIdQueryHandler.cs"
click node_validation_behavior "https://github.com/essraaabdelrahman/productsapi/blob/master/ProductsApi.Application/Behaviors/ValidationBehavior.cs"
click node_logging_behavior "https://github.com/essraaabdelrahman/productsapi/blob/master/ProductsApi.Application/Behaviors/LoggingBehavior.cs"
click node_product_dto "https://github.com/essraaabdelrahman/productsapi/blob/master/ProductsApi.Application/Products/ProductsDto/ProductDto.cs"
click node_repository_contract "https://github.com/essraaabdelrahman/productsapi/blob/master/ProductsApi.Application/Abstractions/IProductRepository.cs"
click node_not_found "https://github.com/essraaabdelrahman/productsapi/blob/master/ProductsApi.Application/Common/NotFoundException.cs"
click node_product_entity "https://github.com/essraaabdelrahman/productsapi/blob/master/ProductsApi.Domain/Entities/Product.cs"
click node_product_repository "https://github.com/essraaabdelrahman/productsapi/blob/master/ProductsApi.Infrastructure/Repositories/ProductRepository.cs"
click node_db_context "https://github.com/essraaabdelrahman/productsapi/blob/master/ProductsApi.Infrastructure/Persistence/AppDbContext.cs"
click node_product_mapping "https://github.com/essraaabdelrahman/productsapi/blob/master/ProductsApi.Infrastructure/Persistence/Configurations/ProductConfiguration.cs"
click node_serilog "https://github.com/essraaabdelrahman/productsapi/blob/master/Products.Api/appsettings.json"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_products_controller,node_create_request,node_exception_handler,node_runtime_observability,node_serilog,node_client toneBlue
class node_create_command,node_create_handler,node_create_validator,node_get_all_query,node_get_all_handler,node_get_one_query,node_get_one_handler,node_validation_behavior,node_logging_behavior,node_product_dto,node_repository_contract,node_not_found toneAmber
class node_product_entity toneMint
class node_product_repository,node_db_context,node_sql_server,node_product_mapping toneRose
```

## Components

### HTTP API

- [Products controller](https://github.com/essraaabdelrahman/productsapi/blob/master/Products.Api/Controllers/ProductsController.cs): `Products.Api/Controllers/ProductsController.cs`
- [Create request](https://github.com/essraaabdelrahman/productsapi/blob/master/Products.Api/Contracts/CreateProductRequest.cs): `Products.Api/Contracts/CreateProductRequest.cs`
- [Problem details handler](https://github.com/essraaabdelrahman/productsapi/blob/master/Products.Api/Middleware/GlobalExceptionHandler.cs): `Products.Api/Middleware/GlobalExceptionHandler.cs`
- [Request tracing and logging](https://github.com/essraaabdelrahman/productsapi/blob/master/Products.Api/Program.cs): `Products.Api/Program.cs`
- [Serilog sinks](https://github.com/essraaabdelrahman/productsapi/blob/master/Products.Api/appsettings.json): `Products.Api/appsettings.json`

### Application

- [Create command](https://github.com/essraaabdelrahman/productsapi/blob/master/ProductsApi.Application/Products/Commands/CreateProduct/CreateProductCommand.cs): `ProductsApi.Application/Products/Commands/CreateProduct/CreateProductCommand.cs`
- [Create handler](https://github.com/essraaabdelrahman/productsapi/blob/master/ProductsApi.Application/Products/Commands/CreateProduct/CreateProductCommandHandler.cs): `ProductsApi.Application/Products/Commands/CreateProduct/CreateProductCommandHandler.cs`
- [Create validator](https://github.com/essraaabdelrahman/productsapi/blob/master/ProductsApi.Application/Products/Commands/CreateProduct/CreateProductCommandValidator%20.cs): `ProductsApi.Application/Products/Commands/CreateProduct/CreateProductCommandValidator .cs`
- [List query](https://github.com/essraaabdelrahman/productsapi/blob/master/ProductsApi.Application/Products/Queries/GetProducts/GetProductsQuery.cs): `ProductsApi.Application/Products/Queries/GetProducts/GetProductsQuery.cs`
- [List handler](https://github.com/essraaabdelrahman/productsapi/blob/master/ProductsApi.Application/Products/Queries/GetProducts/GetProductsQueryHandler.cs): `ProductsApi.Application/Products/Queries/GetProducts/GetProductsQueryHandler.cs`
- [Product query](https://github.com/essraaabdelrahman/productsapi/blob/master/ProductsApi.Application/Products/Queries/GetProductById/GetProductByIdQuery.cs): `ProductsApi.Application/Products/Queries/GetProductById/GetProductByIdQuery.cs`
- [Product handler](https://github.com/essraaabdelrahman/productsapi/blob/master/ProductsApi.Application/Products/Queries/GetProductById/GetProductByIdQueryHandler.cs): `ProductsApi.Application/Products/Queries/GetProductById/GetProductByIdQueryHandler.cs`
- [Validation behavior](https://github.com/essraaabdelrahman/productsapi/blob/master/ProductsApi.Application/Behaviors/ValidationBehavior.cs): `ProductsApi.Application/Behaviors/ValidationBehavior.cs`
- [Command/query logging](https://github.com/essraaabdelrahman/productsapi/blob/master/ProductsApi.Application/Behaviors/LoggingBehavior.cs): `ProductsApi.Application/Behaviors/LoggingBehavior.cs`
- [Product DTO](https://github.com/essraaabdelrahman/productsapi/blob/master/ProductsApi.Application/Products/ProductsDto/ProductDto.cs): `ProductsApi.Application/Products/ProductsDto/ProductDto.cs`
- [Product repository contract](https://github.com/essraaabdelrahman/productsapi/blob/master/ProductsApi.Application/Abstractions/IProductRepository.cs): `ProductsApi.Application/Abstractions/IProductRepository.cs`
- [Not-found exception](https://github.com/essraaabdelrahman/productsapi/blob/master/ProductsApi.Application/Common/NotFoundException.cs): `ProductsApi.Application/Common/NotFoundException.cs`

### Domain

- [Product entity](https://github.com/essraaabdelrahman/productsapi/blob/master/ProductsApi.Domain/Entities/Product.cs): `ProductsApi.Domain/Entities/Product.cs`

### Infrastructure

- [Product repository](https://github.com/essraaabdelrahman/productsapi/blob/master/ProductsApi.Infrastructure/Repositories/ProductRepository.cs): `ProductsApi.Infrastructure/Repositories/ProductRepository.cs`
- [EF Core context](https://github.com/essraaabdelrahman/productsapi/blob/master/ProductsApi.Infrastructure/Persistence/AppDbContext.cs): `ProductsApi.Infrastructure/Persistence/AppDbContext.cs`
- **SQL Server**
- [Product EF mapping](https://github.com/essraaabdelrahman/productsapi/blob/master/ProductsApi.Infrastructure/Persistence/Configurations/ProductConfiguration.cs): `ProductsApi.Infrastructure/Persistence/Configurations/ProductConfiguration.cs`

### Other components

- **API client**

## Connections

- API client → Products controller: sends HTTP (evidence: `README.md`)
- Products controller → Create request: accepts body (evidence: `Products.Api/Controllers/ProductsController.cs`)
- Products controller → Create command: sends command (evidence: `Products.Api/Controllers/ProductsController.cs`)
- Products controller → List query: sends query (evidence: `Products.Api/Controllers/ProductsController.cs`)
- Products controller → Product query: sends query (evidence: `Products.Api/Controllers/ProductsController.cs`)
- Create command → Create handler: dispatched to (evidence: `ProductsApi.Application/Products/Commands/CreateProduct/CreateProductCommandHandler.cs`)
- List query → List handler: dispatched to (evidence: `ProductsApi.Application/Products/Queries/GetProducts/GetProductsQueryHandler.cs`)
- Product query → Product handler: dispatched to (evidence: `ProductsApi.Application/Products/Queries/GetProductById/GetProductByIdQueryHandler.cs`)
- Create handler → Product repository contract: calls (evidence: `ProductsApi.Application/Products/Commands/CreateProduct/CreateProductCommandHandler.cs`)
- List handler → Product repository contract: calls (evidence: `ProductsApi.Application/Products/Queries/GetProducts/GetProductsQueryHandler.cs`)
- Product handler → Product repository contract: calls (evidence: `ProductsApi.Application/Products/Queries/GetProductById/GetProductByIdQueryHandler.cs`)
- Create handler → Product entity: creates (evidence: `ProductsApi.Application/Products/Commands/CreateProduct/CreateProductCommandHandler.cs`)
- Product handler → Not-found exception: throws (evidence: `ProductsApi.Application/Products/Queries/GetProductById/GetProductByIdQueryHandler.cs`)
- Product handler → Product DTO: maps result (evidence: `ProductsApi.Application/Products/Queries/GetProductById/GetProductByIdQueryHandler.cs`)
- List handler → Product DTO: returns DTOs (evidence: `ProductsApi.Application/Products/Queries/GetProducts/GetProductsQueryHandler.cs`)
- Create validator → Create command: validates (evidence: `ProductsApi.Application/Products/Commands/CreateProduct/CreateProductCommandValidator .cs`)
- Validation behavior → Create validator: runs validators
- Command/query logging → Create command: logs handling
- Products controller → Product DTO: returns (evidence: `Products.Api/Controllers/ProductsController.cs`)
- Problem details handler → Not-found exception: handles (evidence: `Products.Api/Middleware/GlobalExceptionHandler.cs`)
- Product repository contract → Product repository: implemented by (evidence: `ProductsApi.Infrastructure/DependencyInjection.cs`)
- Product repository → EF Core context: queries and saves (evidence: `ProductsApi.Infrastructure/Repositories/ProductRepository.cs`)
- EF Core context → Product entity: tracks (evidence: `ProductsApi.Infrastructure/Persistence/AppDbContext.cs`)
- EF Core context → Product EF mapping: loads configuration (evidence: `ProductsApi.Infrastructure/Persistence/AppDbContext.cs`)
- Product repository → SQL Server: persists through EF
- Request tracing and logging → Problem details handler: registers (evidence: `Products.Api/Program.cs`)
- Request tracing and logging → Serilog sinks: configures logging (evidence: `README.md`)
- Request tracing and logging → Command/query logging: enables request tracing
