How essraaabdelrahman/productsapi works
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: ProductsController.cs Products controller · GetProductByIdQueryHandler.cs Product handler · CreateProductCommand.cs Create command · IProductRepository.cs Product repository contract
Components 23
HTTP API
- Products controller
Products.Api/Controllers/ProductsController.cs - Create request
Products.Api/Contracts/CreateProductRequest.cs - Problem details handler
Products.Api/Middleware/GlobalExceptionHandler.cs - Request tracing and logging
Products.Api/Program.cs - Serilog sinks
Products.Api/appsettings.json
Application
- Create command
ProductsApi.Application/Products/Commands/CreateProduct/CreateProductCommand.cs - Create handler
ProductsApi.Application/Products/Commands/CreateProduct/CreateProductCommandHandler.cs - Create validator
ProductsApi.Application/Products/Commands/CreateProduct/CreateProductCommandValidator .cs - List query
ProductsApi.Application/Products/Queries/GetProducts/GetProductsQuery.cs - List handler
ProductsApi.Application/Products/Queries/GetProducts/GetProductsQueryHandler.cs - Product query
ProductsApi.Application/Products/Queries/GetProductById/GetProductByIdQuery.cs - Product handler
ProductsApi.Application/Products/Queries/GetProductById/GetProductByIdQueryHandler.cs - Validation behavior
ProductsApi.Application/Behaviors/ValidationBehavior.cs - Command/query logging
ProductsApi.Application/Behaviors/LoggingBehavior.cs - Product DTO
ProductsApi.Application/Products/ProductsDto/ProductDto.cs - Product repository contract
ProductsApi.Application/Abstractions/IProductRepository.cs - Not-found exception
ProductsApi.Application/Common/NotFoundException.cs
Domain
- Product entity
ProductsApi.Domain/Entities/Product.cs
Infrastructure
- Product repository
ProductsApi.Infrastructure/Repositories/ProductRepository.cs - EF Core context
ProductsApi.Infrastructure/Persistence/AppDbContext.cs - SQL Server
- Product EF mapping
ProductsApi.Infrastructure/Persistence/Configurations/ProductConfiguration.cs
Other components
- API client
Connections 28
- API client → Products controller: sends HTTP
README.md - Products controller → Create request: accepts body
Products.Api/Controllers/ProductsController.cs - Products controller → Create command: sends command
Products.Api/Controllers/ProductsController.cs - Products controller → List query: sends query
Products.Api/Controllers/ProductsController.cs - Products controller → Product query: sends query
Products.Api/Controllers/ProductsController.cs - Create command → Create handler: dispatched to
ProductsApi.Application/Products/Commands/CreateProduct/CreateProductCommandHandler.cs - List query → List handler: dispatched to
ProductsApi.Application/Products/Queries/GetProducts/GetProductsQueryHandler.cs - Product query → Product handler: dispatched to
ProductsApi.Application/Products/Queries/GetProductById/GetProductByIdQueryHandler.cs - Create handler → Product repository contract: calls
ProductsApi.Application/Products/Commands/CreateProduct/CreateProductCommandHandler.cs - List handler → Product repository contract: calls
ProductsApi.Application/Products/Queries/GetProducts/GetProductsQueryHandler.cs - Product handler → Product repository contract: calls
ProductsApi.Application/Products/Queries/GetProductById/GetProductByIdQueryHandler.cs - Create handler → Product entity: creates
ProductsApi.Application/Products/Commands/CreateProduct/CreateProductCommandHandler.cs - Product handler → Not-found exception: throws
ProductsApi.Application/Products/Queries/GetProductById/GetProductByIdQueryHandler.cs - Product handler → Product DTO: maps result
ProductsApi.Application/Products/Queries/GetProductById/GetProductByIdQueryHandler.cs - List handler → Product DTO: returns DTOs
ProductsApi.Application/Products/Queries/GetProducts/GetProductsQueryHandler.cs - Create validator → Create command: validates
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
Products.Api/Controllers/ProductsController.cs - Problem details handler → Not-found exception: handles
Products.Api/Middleware/GlobalExceptionHandler.cs - Product repository contract → Product repository: implemented by
ProductsApi.Infrastructure/DependencyInjection.cs - Product repository → EF Core context: queries and saves
ProductsApi.Infrastructure/Repositories/ProductRepository.cs - EF Core context → Product entity: tracks
ProductsApi.Infrastructure/Persistence/AppDbContext.cs - EF Core context → Product EF mapping: loads configuration
ProductsApi.Infrastructure/Persistence/AppDbContext.cs - Product repository → SQL Server: persists through EF
- Request tracing and logging → Problem details handler: registers
Products.Api/Program.cs - Request tracing and logging → Serilog sinks: configures logging
README.md - Request tracing and logging → Command/query logging: enables request tracing