A scalable, enterprise-grade E-commerce backend built with ASP.NET Core Web API following Clean Architecture principles.
- β¨ Features
- ποΈ Architecture & Design Patterns
- ποΈ Project Structure
- π οΈ Tech Stack
- π Getting Started
- π Authentication & Authorization
- π§ͺ API Endpoints Overview
- ποΈ Database & Migrations
- π€ Contributing
- π License
- π¨βπ» Author
| Feature | Description |
|---|---|
| πΉ Product Catalog | Full CRUD with advanced filtering by Brand, Type, Price & Search |
| πΉ Pagination & Sorting | Optimized queries for large datasets with configurable page size |
| πΉ Specification Pattern | Encapsulated query logic for clean, reusable filtering/sorting |
| πΉ Generic Repository + UoW | Abstracted data access with transactional consistency |
| πΉ DTO + AutoMapper | Decoupled API contracts with efficient object mapping |
| πΉ Global Error Handling | Consistent error responses with detailed diagnostics |
| πΉ JWT Authentication | Secure endpoints with role-based authorization |
| πΉ Swagger UI | Interactive API documentation with try-it-out support |
Store.G02.V2/ βββ Core/ # Domain Entities, Interfaces, Specifications β βββ Entities/ # Aggregates & Value Objects β βββ Interfaces/ # Repository & Service contracts β βββ Specifications/ # Query specification implementations β βββ Infrastructure/ # External Implementations β βββ Data/ # EF Core DbContext & Migrations β βββ Repositories/ # Concrete Repository implementations β βββ Services/ # Email, File Storage, Auth services β βββ Shared/ # Cross-cutting Concerns β βββ DTOs/ # Request/Response models β βββ Exceptions/ # Custom exception types β βββ Helpers/ # Utilities & Extensions β βββ Store.G02.V2/ # Presentation Layer (API) βββ Controllers/ # REST API endpoints βββ Middleware/ # Global error handling, logging βββ Properties/ # appsettings, launchSettings
Patterns Implemented:
- β Clean Architecture β Separation of concerns, dependency inversion
- β Repository + Unit of Work β Testable, transactional data access
- β Specification Pattern β Reusable, composable query logic
- β Generic Repository β DRY CRUD operations across entities
- β DTO Pattern β Secure, versioned API contracts
- β Dependency Injection β Built-in .NET Core DI container
π¦ Store.G02.V2.sln βββ π Core/ β βββ π Product.cs, Brand.cs, Type.cs β βββ π IRepository.cs, IUnitOfWork.cs β βββ π BaseSpecification.cs, ISpecification β βββ π Infrastructure/ β βββ π StoreContext.cs (EF Core) β βββ π ProductRepository.cs β βββ π AuthService.cs (JWT Implementation) β βββ π Shared/ β βββ π ProductDto.cs, PaginationDto.cs β βββ π ApiException.cs, ApiResponse β βββ π MappingProfiles.cs (AutoMapper) β βββ π Store.G02.V2/ (API Project) βββ π Program.cs, appsettings.json βββ π ProductsController.cs, AuthController.cs βββ π SwaggerConfig.cs
| Layer | Technology |
|---|---|
| Framework | ASP.NET Core 7/8 Web API |
| Language | C# 12 with modern features |
| ORM | Entity Framework Core |
| Database | SQL Server (LocalDB/Production) |
| Mapping | AutoMapper |
| Auth | JWT Bearer Tokens, ASP.NET Core Identity |
| Docs | Swagger/OpenAPI 3.0 |
| Testing | xUnit/MSTest ready structure |
| Tools | Postman, Bruno, Swagger UI |
- .NET 7/8 SDK
- SQL Server or LocalDB
- Visual Studio 2022 or VS Code + C# Dev Kit
- Postman or Bruno for API testing
# 1. Clone the repository
git clone https://github.com/Mariomedhat899/Store.G02.V2.git
cd Store.G02.V2
# 2. Restore NuGet packages
dotnet restore
# 3. Configure connection string
# Edit: Store.G02.V2/appsettings.json
"ConnectionStrings": {
"DefaultConnection": "Server=(localdb)\\mssqllocaldb;Database=StoreG02V2;Trusted_Connection=True;"
}
# 4. Apply Entity Framework migrations
Update-Database
# OR via CLI:
dotnet ef database update
# 5. Run the API
dotnet run --project Store.G02.V2
# Or press F5 in Visual Studio
---
π Authentication & Authorization
This API supports JWT-based authentication for protected endpoints:
POST /api/auth/login
Content-Type: application/json
{
"email": "user@example.com",
"password": "yourPassword123"
}
Response:
{
"token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...",
"expiresIn": 3600,
"user": { "id": "guid", "email": "user@example.com", "roles": ["Customer"] }
}
Use the token in subsequent requests:
Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...
---
ποΈ Database & Migrations
# Add a new migration
Add-Migration AddProductImageUrl -Context StoreContext
# Update database
Update-Database -Context StoreContext
# Script migration for deployment
Script-Migration -Context StoreContext
# Remove last migration (if needed)
Remove-Migration -Context StoreContext
Seed Data: Initial Brands, Types, and sample Products are seeded on first run.
π ASP.NET Core E-commerce API | Clean Architecture + Repository + Specification Pattern | JWT Auth | EF Core + SQL Server | Swagger Docs