A modern, full-featured RESTful e-commerce API built with .NET 9 and Clean Architecture principles. This repository demonstrates industry-standard patterns and best practices for building scalable, maintainable systems.
- Overview
- Key Features
- Architecture & Patterns
- Tech Stack
- Getting Started
- Configuration
- Advanced Features
- API Endpoints
- Project Structure
- License
This eCommerce API is a learning-focused project that implements product and category management, JWT authentication, and payment gateway integrations (Stripe & Fawaterek). The solution includes validation, global error handling, and structured logging to illustrate production-ready practices.
Authentication & Authorization
- User registration and login with JWT tokens
- Token refresh mechanism
Product & Category Management
- Full CRUD operations for products and categories
- Product categorization and basic inventory tracking
Payment Processing
- Stripe integration (credit/debit cards)
- Fawaterek integration (regional/local payments)
Enterprise Features
- Centralized validation via MediatR pipeline behavior
- Global exception handling middleware
- Structured logging with Serilog (console and rolling files)
- Docker images
- Swagger documentation
Domain ↔ Application
↑ ↑
└─── Infrastructure ↔ ── Host
- Domain — Core business entities
- Application — Use cases, DTOs, validation, MediatR handlers
- Infrastructure — Data access, external services, authentication
- Host — API entry point and controllers
| Pattern | Purpose |
|---|---|
| Repository Pattern | Abstracts data access layer |
| Unit of Work | Manages transactions across repositories |
| CQRS | Separates read (queries) and write (commands) operations |
| Mediator | Routes requests to handlers via MediatR |
| Pipeline Behavior | Automatic validation before handler execution |
| Middleware | Global exception handling and logging |
| Dependency Injection | Centralized service registration |
| Data Transfer Objects | Decouples API contracts from domain models |
| Factory | Dynamic payment service instantiation |
| Category | Technology |
|---|---|
| Framework | .NET 9 / ASP.NET Core 9.0 |
| Language | C# (nullable reference types) |
| ORM | Entity Framework Core 9 |
| Database | SQL Server 2019+ |
| CQRS & Mediation | MediatR |
| Validation | FluentValidation |
| Mapping | AutoMapper |
| Logging | Serilog |
| Payment | Stripe.net, RestSharp |
| Documentation | Swagger / Swashbuckle |
- .NET 9 SDK or later
- SQL Server 2019 or later
- Visual Studio 2022 / VS Code
- Docker (optional)
# Clone repository
git clone <repository-url>
cd eCommerce API
# Restore NuGet packages
dotnet restore
# Apply database migrations
dotnet ef database update --project eCommerce.Infrastruction --startup-project eCommerce.Host
# Run the application
dotnet run --project eCommerce.HostAPI: https://localhost:<port>
Swagger UI: https://localhost:<port>/swagger
Update appsettings.json with your settings. Sensitive values should be stored in environment variables or a secrets manager in production.
{
"Stripe": {
"PublishableKey": "pk_test_YOUR_KEY",
"SecretKey": "sk_test_YOUR_KEY",
"WebhookSecret": "webhook_secret_key"
},
"Fawaterek": {
"ApiKey": "YOUR_API_KEY",
"MerchantId": "YOUR_MERCHANT_ID",
"BaseUrl": "https://api.fawaterek.com"
}
}Important: Never commit API keys to version control. Use environment variables or Azure Key Vault in production.
Automatic validation through MediatR pipeline behavior. Create validators using FluentValidation:
public class CreateUserValidator : AbstractValidator<CreateUserDto>
{
public CreateUserValidator()
{
RuleFor(x => x.FullName).NotEmpty();
RuleFor(x => x.Email).EmailAddress();
}
}Invalid requests return HTTP 400 with error details automatically.
Unhandled exceptions are caught by middleware, logged via Serilog, and returned as consistent JSON responses:
{
"statusCode": 500,
"message": "An error occurred"
}Serilog logs all application events to console and daily rolling files in the logs/ directory.
Multi-stage Docker build creates optimized production images:
docker build -t ecommerce-api:latest .
docker run -d -p 8080:8080 ecommerce-api:latest| Method | Endpoint | Description |
|---|---|---|
| POST | /api/auth/register |
Register new user |
| POST | /api/auth/login |
Login and receive JWT token |
| POST | /api/auth/refresh |
Refresh expired token |
| Method | Endpoint | Description |
|---|---|---|
| GET | /api/products |
Get all products |
| GET | /api/products/{id} |
Get product by ID |
| POST | /api/products |
Create new product |
| PUT | /api/products/{id} |
Update product |
| DELETE | /api/products/{id} |
Delete product |
| Method | Endpoint | Description |
|---|---|---|
| GET | /api/categories |
Get all categories |
| GET | /api/categories/{id} |
Get category by ID |
| POST | /api/categories |
Create new category |
| PUT | /api/categories/{id} |
Update category |
| DELETE | /api/categories/{id} |
Delete category |
| Method | Endpoint | Description |
|---|---|---|
| POST | /api/payment/checkout |
Process checkout |
| POST | /api/payment/process |
Process payment |
eCommerce.Domain/
├── Entities/
└── ...
eCommerce.Application/
├── DTOs/
├── Features/
│ ├── Commands/
│ └── Queries/
├── Validation/
├── Services/
├── Common/
│ └── Behaviors/
└── Exceptions/
eCommerce.Infrastruction/
├── Context/
├── Repositories/
├── Services/
├── Middleware/
└── Authentication/
eCommerce.Host/
├── Controllers/
├── Program.cs
└── appsettings.json
MIT License - See LICENSE file for details.