Enterprise-grade Hotel Booking Engine built with .NET 8, Clean Architecture, and DDD.
Features CQRS, Optimistic Concurrency, Hybrid Search Engine, and Dynamic Inventory Management.
About ·
Architecture ·
Search Engine ·
Lifecycle
CoreBooking is a robust backend API designed to simulate the core engine of OTAs (Online Travel Agencies) like Booking.com or Expedia. It solves complex distributed system problems such as inventory management, dynamic pricing aggregation, and the critical "double booking" (overbooking) problem in high-concurrency environments.
Unlike simple CRUD applications, this project enforces Rich Domain Models and strict Business Invariants within a scalable infrastructure.
The project moved from Anemic Models (V1) to Rich Domain Models (V2).
- Value Objects: Replaced primitive types with
Money,Address, andDateRangeto ensure type safety and logic encapsulation. - Shared Kernel: Centralized Constants and Enums for maintainability.
- Invariants: Business rules (e.g., "Cannot cancel within 3 days") are enforced inside Entities.
Solved the "Last Room" problem using RowVersion (Timestamp) at the database level.
- Scenario: Two users try to book the last room at the exact same millisecond.
- Solution: The database rejects the second transaction with a
DbUpdateConcurrencyException, ensuring data consistency.
- Commands (Write): Handle complex transaction scopes (Booking + Inventory + Payment).
- Queries (Read): Optimized with EF Core
Includeand AutoMapperFlatteningfor rich DTOs.
The GetAvailableRooms query is not a simple filter; it's a hybrid algorithm.
The Challenge: "Find a room for 5 nights." The Solution:
- Gap Analysis: The query scans the
Inventorytable. It groups records by RoomType and checks if every single day in the requested range hasQuantity > 0. If even one day is sold out, the room is excluded. - Dynamic Pricing: It aggregates (SUM) daily prices to calculate the total cost for the specific date range.
- Hybrid Filtering: Combines custom LINQ logic (Availability/Price) with Dynamic Querying (City, Hotel Name filtering).
The system manages the full lifecycle of a reservation:
- Create (Transaction):
- Validates availability gap.
- Calculates total price dynamically.
- Decrements inventory stock.
- Uses RowVersion to prevent race conditions.
- Cancel (Compensation):
- Checks Domain Rule: "Is check-in within 3 days?"
- Increments inventory stock (Restocking).
- Updates Payment status to
Refunded. - Invalidates Search Cache.
- Framework: .NET 8 Web API
- Data Access: Entity Framework Core 8
- Database: Microsoft SQL Server
- Mediator: MediatR
- Validation: FluentValidation
- Mapping: AutoMapper
- Caching: Redis (Ready) / InMemory
- Boilerplate: nArchitecture
| Module | Status | Features |
|---|---|---|
| Hotel | ✅ Done | Address Value Object, Name Uniqueness Rule |
| RoomType | ✅ Done | Enriched Queries, Hotel Relation |
| Inventory | ✅ Done | Daily Stock, Money Value Object, Concurrency |
| Booking | ✅ Done | Core Engine, DateRange Logic, Lifecycle Management |
| Payment | ✅ Done | Financial Safety Rules, TransactionId Check |
| Guest | ✅ Done | Capacity Control, EntityLengths Validation |
| Search | ✅ Done | Hybrid Search Algorithm |
- Clone the repository
git clone [https://github.com/mustafakurtt/CoreBooking.git](https://github.com/mustafakurtt/CoreBooking.git)
- Update Connection String in
appsettings.json. - Run Migrations:
dotnet ef database update --project src/coreBooking/Persistence --startup-project src/coreBooking/WebAPI
- Run API:
dotnet run --project src/coreBooking/WebAPI
Made with 💻 by Mustafa Kurt