Order Management System with Clean Architecture
A .NET solution implementing clean architecture with CQRS, domain events, RabbitMQ integration, and MongoDB synchronization.
Full Description
This project implements an order management system using .NET and follows the Clean Architecture pattern. It exposes three REST API endpoints: Get Orders, Get Order by ID, and Create Order. The Create Order endpoint triggers a CQRS command handler that performs business validations such as inventory checks, persists the order to a SQL Server database, and then publishes an OrderCreatedEvent domain event. An event handler listens for this event and publishes a message to a RabbitMQ queue. A separate Consumer worker application listens to this RabbitMQ queue, reads the order data from the SQL database, and synchronizes it to a MongoDB collection. Additionally, there is a Migration Runner console application that performs initial data seeding. The entire solution is containerized using Docker with separate Dockerfiles for the API, Consumer, and Migration Runner apps. MongoDB, SQL Server, and RabbitMQ services are orchestrated using Docker Compose.
Key Features
- Clean Architecture with separated layers (API, Application, Domain, Infrastructure)
- CQRS pattern with MediatR commands and queries
- Domain events for decoupled event-driven communication
- RabbitMQ integration for asynchronous messaging
- Worker service for syncing data from SQL Server to MongoDB
- Initial data seeding via Migration Runner console app
- Containerized with Docker and orchestrated using Docker Compose
Tech Stack
- 💻C#
- 🌐.NET 8
- 🗄️SQL Server
- 🍃MongoDB
- 🐇RabbitMQ
- 🐳Docker
- ⚙️Docker Compose
- 🔄CQRS
Architecture
- API
- Exposes REST endpoints and handles HTTP requests
- Application
- CQRS handlers and business logic for orders
- Domain
- Entities, value objects, domain events
- Infrastructure
- Database access, event handlers, RabbitMQ publisher
- Consumer Worker
- Listens to RabbitMQ, syncs SQL data to MongoDB
- Migration Runner
- Console app for initial database seeding
- Docker Compose
- Orchestrates MongoDB, SQL Server, RabbitMQ services
Installation
- Clone the repository
- Run docker-compose up to start MongoDB, SQL Server, and RabbitMQ
- Build and run the API, Consumer, and Migration Runner projects via Docker
- Use API endpoints to create and retrieve orders
Screenshots
DevOps & Deployment
- CI/CD: GitHub Actions pipeline builds Docker images and runs tests
- Hosting: Docker Compose setup suitable for local or cloud VM deployment
- Analytics: Basic logging with Serilog integrated in API and Consumer
Notes
- CQRS and domain events help maintain clean separation of concerns.
- RabbitMQ decouples the order creation from downstream data synchronization.
- Separate worker app allows scalable syncing to MongoDB without blocking API.
- Docker Compose simplifies local development environment setup.