Skip to content

Advanced Hotel Booking Engine API built with .NET 8, Clean Architecture, and DDD. Features include CQRS, Optimistic Concurrency Control, and dynamic inventory management.

License

Notifications You must be signed in to change notification settings

mustafakurtt/CoreBooking

Repository files navigation

CoreBooking API

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

.NET 8 Architecture SQL Server CQRS


💻 About The Project

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.


🏗 Architecture & Patterns

1. Domain-Driven Design (DDD) & V2 Architecture

The project moved from Anemic Models (V1) to Rich Domain Models (V2).

  • Value Objects: Replaced primitive types with Money, Address, and DateRange to 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.

2. Optimistic Concurrency Control

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.

3. CQRS with Mediator

  • Commands (Write): Handle complex transaction scopes (Booking + Inventory + Payment).
  • Queries (Read): Optimized with EF Core Include and AutoMapper Flattening for rich DTOs.

🔍 Advanced Search Engine Logic

The GetAvailableRooms query is not a simple filter; it's a hybrid algorithm.

The Challenge: "Find a room for 5 nights." The Solution:

  1. Gap Analysis: The query scans the Inventory table. It groups records by RoomType and checks if every single day in the requested range has Quantity > 0. If even one day is sold out, the room is excluded.
  2. Dynamic Pricing: It aggregates (SUM) daily prices to calculate the total cost for the specific date range.
  3. Hybrid Filtering: Combines custom LINQ logic (Availability/Price) with Dynamic Querying (City, Hotel Name filtering).

🔄 Booking Lifecycle & Logic

The system manages the full lifecycle of a reservation:

  1. Create (Transaction):
    • Validates availability gap.
    • Calculates total price dynamically.
    • Decrements inventory stock.
    • Uses RowVersion to prevent race conditions.
  2. Cancel (Compensation):
    • Checks Domain Rule: "Is check-in within 3 days?"
    • Increments inventory stock (Restocking).
    • Updates Payment status to Refunded.
    • Invalidates Search Cache.

🛠️ Tech Stack

  • 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

🚀 Roadmap & Status

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

⚙️ Getting Started

  1. Clone the repository
    git clone [https://github.com/mustafakurtt/CoreBooking.git](https://github.com/mustafakurtt/CoreBooking.git)
  2. Update Connection String in appsettings.json.
  3. Run Migrations:
    dotnet ef database update --project src/coreBooking/Persistence --startup-project src/coreBooking/WebAPI
  4. Run API: dotnet run --project src/coreBooking/WebAPI

Made with 💻 by Mustafa Kurt

About

Advanced Hotel Booking Engine API built with .NET 8, Clean Architecture, and DDD. Features include CQRS, Optimistic Concurrency Control, and dynamic inventory management.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages