A mini backend system for an e-commerce company that processes orders and sends notifications to users, built with .NET 9, RabbitMQ, Redis, and SQL Server.
The solution follows Clean Architecture principles with the following projects:
- ECommerce.Domain: Core business entities and enums
- ECommerce.Application: Business logic, interfaces, DTOs, and services
- ECommerce.Infrastructure: Data access, external service implementations (RabbitMQ, Redis, SQL Server)
- ECommerce.API: REST API with JWT authentication
- ECommerce.OrderProcessor: Background worker service that consumes RabbitMQ messages
- ✅ Create orders via REST API
- ✅ Input validation with FluentValidation
- ✅ Order queuing with RabbitMQ
- ✅ Background order processing
- ✅ Redis caching with 2-minute TTL
- ✅ JWT authentication
- ✅ Serilog logging with file and console sinks
- ✅ Correlation ID tracking
- ✅ Swagger UI documentation
- ✅ Docker Compose for infrastructure
- ✅ Unit tests for core business logic
- .NET 9 SDK
- Docker and Docker Compose
- Visual Studio 2022 or JetBrains Rider (optional)
git clone https://github.com/tahakocal/ECommerceOrderSystem.git
cd ECommerceOrderSystemdocker-compose up -dThis will start:
- SQL Server on port 1433
- RabbitMQ on port 5672 (Management UI on 15672)
- Redis on port 6379
Migration files are already included in the project. You just need to apply them:
# Install EF Core tools globally (if not already installed)
dotnet tool install --global dotnet-ef
# Apply existing migrations to create database schema
cd src/ECommerce.Infrastructure
dotnet ef database update --startup-project ../ECommerce.APIThis will create:
- ECommerceDB database
- Users table
- Orders table
- OrderLogs table
- OutboxMessages table
cd src/ECommerce.API
dotnet runThe API will be available at:
- HTTP: http://localhost:5079
- HTTPS: https://localhost:7219
- Swagger UI: https://localhost:7219/swagger or http://localhost:5079/swagger
- Health Check: https://localhost:7219/health or http://localhost:5079/health
In a new terminal:
cd src/ECommerce.OrderProcessor
dotnet runDetailed API documentation with request/response examples is available at: Swagger UI: https://localhost:7219/swagger or http://localhost:5079/swagger
GET /health- API health status
A test user is automatically created when the application starts with sample data:
{
"username": "tahakocal",
"password": "123456"
}Sample Orders (automatically seeded):
- Order 1: PROD-001, Quantity: 2, Status: Completed, Payment: CreditCard (5 days ago)
- Order 2: PROD-002, Quantity: 1, Status: Processing, Payment: BankTransfer (2 days ago)
- Order 3: PROD-003, Quantity: 3, Status: Pending, Payment: CreditCard (1 hour ago)
You can use these credentials to login and test the API endpoints, including retrieving the pre-seeded orders.
POST /api/auth/register- Register new userPOST /api/auth/login- Login with credentials
POST /api/orders- Create new orderGET /api/orders/{userId}- Get user's orders (cached)
- Client sends order request to API
- API validates input using FluentValidation
- Order is saved to SQL Server database
- Order event is saved to OutboxMessages table (for reliability)
- System attempts to publish to RabbitMQ
order-placedqueue- If successful, marks outbox message as processed
- If RabbitMQ is down, message remains in outbox for later processing
- Redis cache for user's orders is invalidated
- Background worker picks up the message from queue
- Worker processes the order (simulated with 5-second delay)
- Processing log is stored in Redis
- Notification is logged (can be extended to send actual notifications)
Serilog Configuration:
- Console Sink: Structured logging with timestamp and level
- File Sink: Daily rolling files with 7-day retention
- Correlation ID: Every request gets a unique correlation ID for tracing
Log Files:
- API:
logs/api-log-{Date}.txt - Worker:
logs/worker-log-{Date}.txt
Log Levels:
- Information: API calls, user actions, order processing
- Warning: Validation failures, failed login attempts
- Error: Exceptions, connection failures
- Clean Architecture: Separation of concerns with domain-centric design
- Repository Pattern: Data access abstraction
- Dependency Injection: Loose coupling and testability
- Outbox Pattern: Reliable message delivery with transactional guarantees
- Message Queue Pattern: Asynchronous processing with RabbitMQ
- JWT authentication for API endpoints
- Input validation on all requests
- Secure password storage with PBKDF2-SHA256 hashing
- HTTPS enforcement in production
- Correlation IDs for request tracking
URL: http://localhost:15672
Credentials: guest/guest
Monitor queues:
- Navigate to "Queues" tab
- Check
order-placedqueue for message count - View message rates and processing
Run unit tests with:
dotnet testTests cover:
- Order creation and validation
- Authentication (login/register)
- Caching operations
- Message queue publishing
- Error handling
if you have any questions, please feel free to ask. Note: Some comments were made with the help of AI. I hope it helps you.
Thanks for reading.