A simple hotel booking API designed for developer interviews. This project demonstrates clean architecture patterns, Domain-Driven Design (DDD) principles, and includes deliberate issues for discussion during technical interviews.
This API manages guests and their hotel bookings with the following features:
- Guest management (CRUD operations)
- Booking management with business logic
- Entity Framework Core with In-Memory database
- RESTful API with Swagger documentation
- Unit tests with xUnit
- Guest: Represents hotel guests with personal information and address
- Booking: Represents room bookings with dates, rates, and status
- Address: Value object for guest addresses
- .NET 8.0 SDK
- Git
git clone <repository-url>
cd InterviewTest
dotnet build
dotnet run --project src/InterviewTest.ApiThe API will start on http://localhost:5124 with Swagger UI available at the root URL.
dotnet testGET /api/guests- Get all guestsGET /api/guests/{id}- Get guest by IDGET /api/guests/with-bookings- Get guests with their bookings (β οΈ Performance Issue)GET /api/guests/search?term={searchTerm}- Search guestsPOST /api/guests- Create new guest (π Validation Bug)PUT /api/guests/{id}- Update guestDELETE /api/guests/{id}- Delete guestGET /api/guests/{id}/bookings- Get guest's bookings
GET /api/bookings- Get all bookingsGET /api/bookings/{id}- Get booking by IDGET /api/bookings/active- Get active bookingsPOST /api/bookings- Create new booking (π Validation Bug)PUT /api/bookings/{id}- Update bookingDELETE /api/bookings/{id}- Delete booking
Location: GuestRepository.GetGuestsWithBookingsAsync() and BookingService.CalculateBookingRevenueForGuestAsync()
Problem: The GET /api/guests/with-bookings endpoint causes N+1 queries.
Test:
curl http://localhost:5124/api/guests/with-bookingsDiscussion Points:
- How to identify N+1 problems
- Entity Framework's Include() method
- Query optimization strategies
Location: GuestsController.CreateGuest() and BookingService.CreateBookingAsync()
Problem: Date validation logic is incorrect - uses >= instead of > for date of birth validation.
Test:
curl -X POST http://localhost:5124/api/guests \
-H "Content-Type: application/json" \
-d '{
"firstName": "Test",
"lastName": "User",
"email": "test@example.com",
"dateOfBirth": "2024-07-29T00:00:00",
"address": {"street": "123 St", "city": "City", "state": "ST", "postalCode": "12345", "country": "USA"}
}'Discussion Points:
- Debugging validation logic
- Understanding business requirements
- Testing edge cases
Location: BookingService.cs
Problems:
- Service mixes domain logic with data access concerns
- Direct console logging in domain service
- Validation logic should be separated
Discussion Points:
- Domain-Driven Design principles
- Separation of concerns
- Service layer responsibilities
- Where to place validation logic
Location: BookingTests.CalculateTotal_ShouldIncludeTax()
Problem: The Booking.CalculateTotal() method doesn't include tax in the calculation.
Run Test:
dotnet test --filter "CalculateTotal_ShouldIncludeTax"Discussion Points:
- Test-driven development
- Business logic testing
- Debugging failing tests
- Clone and run the project
- Test the guest creation endpoint with today's date
- Identify and fix the validation logic error
- Verify the fix works
- Review the
BookingServiceclass - Identify violations of DDD principles
- Explain how you would refactor it
- Discuss the benefits of the refactoring
- Run the tests and identify the failing test
- Debug the
CalculateTotal()method - Fix the business logic bug
- Verify all tests pass
- Test the
/api/guests/with-bookingsendpoint - Identify the N+1 query problem
- Fix the repository method to use eager loading
- Explain other optimization strategies
Add a GET /api/guests/{id}/bookings/active endpoint that returns only active bookings for a specific guest.
- How would you approach running this project for the first time?
- What would you do if the API didn't start properly?
- How do you identify performance issues in APIs?
- What DDD principles are violated in this codebase?
- How would you improve the separation of concerns?
- What would you refactor first and why?
- How would you optimize the database queries?
- What EF Core features would you use for better performance?
- How would you handle database migrations in production?
- What testing strategies would you implement?
- How would you improve the current test coverage?
- What tools would you use for API testing?
InterviewTest/
βββ src/
β βββ InterviewTest.Api/ # Web API layer
β βββ InterviewTest.Core/ # Domain layer (entities, services, interfaces)
β βββ InterviewTest.Infrastructure/ # Data access layer
βββ tests/
βββ InterviewTest.Api.Tests/ # API integration tests
βββ InterviewTest.Core.Tests/ # Unit tests
- Clean Architecture
- Repository Pattern
- Domain-Driven Design
- Dependency Injection
- RESTful API design
Build Failures
- Ensure .NET 8.0 SDK is installed
- Run
dotnet restoreto restore packages
Port Already in Use
- The API runs on port 5124 (HTTP) and 7126 (HTTPS)
- Change ports in
launchSettings.jsonif needed
Database Issues
- Project uses In-Memory database - no setup required
- Data is seeded automatically on startup
- Allow 5-10 minutes for initial setup and exploration
- Focus on problem-solving approach rather than perfect solutions
- Encourage candidates to explain their thought process
- Use the built-in issues as conversation starters
- Observe coding style and testing practices
Expected completion time: 45-60 minutes for all tasks.