A practice-focused e-commerce API built with .NET 8 following Clean Architecture principles. This project is for learning and showcasing best practices for building scalable, maintainable, and testable applications.
This is a complete e-commerce backend API featuring product catalog management, shopping basket functionality, order processing, and a comprehensive identity/authentication system. The project follows Domain-Driven Design (DDD) patterns with CQRS implemented via MediatR.
- Product Management - Full CRUD operations with pagination
- Category Management - Organize products by categories
- Shopping Basket - Add/remove items, clear basket, checkout
- Order Processing - Order creation and history tracking
- User Authentication - JWT-based authentication with refresh tokens
- Role-Based Authorization - Permission-based access control
- User Management - Registration, email confirmation, password reset
- Email Notifications - Email confirmation and password reset emails
- Background Jobs - Outbox pattern with Hangfire
- API Versioning - Versioned API endpoints (V1)
- Real-time Communication - SignalR support with optional Redis backplane
- Distributed Caching - Redis support for caching
| Category | Technologies |
|---|---|
| Framework | .NET 8, ASP.NET Core |
| Architecture | Clean Architecture, CQRS, DDD |
| ORM | Entity Framework Core 8, Dapper |
| Database | SQL Server |
| Authentication | ASP.NET Core Identity, JWT Bearer |
| Validation | FluentValidation |
| Mapping | Mapster |
| Mediator | MediatR 12 |
| Background Jobs | Hangfire |
| Caching | Redis (StackExchange.Redis) |
| MailKit, MimeKit | |
| Logging | Serilog (Console + File sinks) |
| API Docs | Swagger/OpenAPI (Swashbuckle) |
| Testing | xUnit, FluentAssertions, NetArchTest |
| CI/CD | GitHub Actions, Azure App Service |
CleanArchitecture.sln
├── src/
│ ├── Core/
│ │ ├── CleanArchitecture.Domain # Entities, Value Objects, Domain Events
│ │ └── CleanArchitecture.Application # Use Cases, Commands, Queries, Interfaces
│ │
│ ├── Infrastructure/
│ │ ├── CleanArchitecture.Persistence # EF Core DbContext, Repositories
│ │ ├── CleanArchitecture.Identity # ASP.NET Identity, JWT Auth
│ │ └── CleanArchitecture.Infrastructure # Email, Caching, Background Jobs
│ │
│ └── API/
│ └── CleanArchitecture.Api # Controllers, Middlewares, Configs
│
└── tests/
├── CleanArchitecture.Application.Tests.Unit # Unit Tests
└── CleanArchitecture.ArchitectureTests # Architecture Tests
┌─────────────────────────────────────────────────────────────────┐
│ API Layer │
│ (Controllers, Middlewares, Swagger) │
├─────────────────────────────────────────────────────────────────┤
│ Application Layer │
│ (Commands, Queries, Handlers, Validators, DTOs) │
├─────────────────────────────────────────────────────────────────┤
│ Domain Layer │
│ (Entities, Aggregates, Value Objects, Domain Events) │
├─────────────────────────────────────────────────────────────────┤
│ Infrastructure Layer │
│ ┌──────────────┐ ┌──────────────┐ ┌──────────────────────┐ │
│ │ Persistence │ │ Identity │ │ Infrastructure │ │
│ │ (EF Core) │ │ (JWT Auth) │ │ (Email, Cache, Jobs) │ │
│ └──────────────┘ └──────────────┘ └──────────────────────┘ │
└─────────────────────────────────────────────────────────────────┘
- .NET 8 SDK or later
- SQL Server (LocalDB, SQL Server, or Azure SQL)
- Redis (optional, for distributed caching and SignalR backplane)
- Visual Studio 2022 / VS Code / Rider
git clone <repository-url>
cd eshop-clean-architecturedotnet restoreUpdate the connection string in src/API/CleanArchitecture.Api/Configurations/database.json:
{
"ConnectionStrings": {
"DefaultConnection": "Data Source=localhost,1433;Initial Catalog=eshop;User id=sa;Password=YourPassword@;TrustServerCertificate=True"
}
}dotnet builddotnet run --project src/API/CleanArchitecture.ApiThe API will be available at:
- HTTPS:
https://localhost:7047 - HTTP:
http://localhost:5016 - Swagger UI:
https://localhost:7047/swagger
Note: The application automatically applies migrations and seeds the database on startup.
Configuration files are located in src/API/CleanArchitecture.Api/Configurations/:
| File | Description |
|---|---|
database.json |
SQL Server connection string |
security.json |
JWT settings & admin credentials |
cache.json |
Redis caching configuration |
mail.json |
SMTP email settings |
hangfire.json |
Background job dashboard settings |
logger.json |
Serilog logging configuration |
signalr.json |
SignalR backplane settings |
outbox.json |
Outbox pattern settings |
The application uses EF Core with SQL Server. Migrations are automatically applied on startup.
To manually create a new migration:
dotnet ef migrations add <MigrationName> --project src/Infrastructure/CleanArchitecture.Persistence --startup-project src/API/CleanArchitecture.ApiTo update the database manually:
dotnet ef database update --project src/Infrastructure/CleanArchitecture.Persistence --startup-project src/API/CleanArchitecture.ApiThe application seeds an admin user on startup with the following credentials (configured in security.json):
- Username:
admin - Email: (See
security.json) - Password: (See
security.json)
⚠️ Important: Change these credentials for production environments!
The solution includes two test projects:
dotnet test tests/CleanArchitecture.Application.UnitTestsValidates Clean Architecture dependency rules:
dotnet test tests/CleanArchitecture.ArchitectureTestsdotnet testA Dockerfile is provided for containerization.
docker build -t cleanarchitecture-api -f src/Presentations/BackEnds/CleanArchitecture.Api/Dockerfile .docker run -d -p 8080:8080 -p 8081:8081 cleanarchitecture-apiExposed Ports:
8080- HTTP8081- HTTPS
The project includes a GitHub Actions workflow (.github/workflows/main.yml) that:
- Triggers on push to
mainbranch or manual dispatch - Restores, builds, and publishes the application
- Deploys to Azure App Service (
eshop-clean-architecture)
Required Secrets:
API_PUBLISH_SECRET- Azure Web App publish profile
dotnet publish src/API/CleanArchitecture.Api -c Release -o ./publishHangfire is used for background job processing with the Outbox Pattern.
- Dashboard URL:
https://localhost:7047/jobs - Dashboard Credentials: (See
hangfire.json)- User:
Admin - Password:
Admin@Jobs
- User:
- Verify SQL Server is running
- Check connection string in
database.json - Ensure
TrustServerCertificate=Truefor local development
- If not using Redis, set
UseDistributedCacheandPreferRedistofalseincache.json - If using Redis, ensure Redis is running on the configured port
- Verify SMTP settings in
mail.json - For Gmail, use an App Password instead of your account password
- Ensure less secure app access or use OAuth2
- Ensure the JWT key in
security.jsonis at least 32 characters - Verify token expiration settings
- Check the Authorization header format:
Bearer <token>
Built with ❤️ using .NET 8 and Clean Architecture