A NestJS-based REST API for managing hotel service bookings between clients and professionals.
- Booking Management: Create bookings with automatic conflict detection
- Professional Search: Find professionals by location, category, and price
- Idempotency: Prevent duplicate requests with idempotency keys
- Double-booking Prevention: Multi-layered approach to prevent scheduling conflicts
- Location-based Search: Haversine formula for distance calculations
- Framework: NestJS
- Database: SQLite (development) / PostgreSQL (production)
- ORM: TypeORM
- Validation: class-validator, class-transformer
- Documentation: Swagger/OpenAPI
- DESIGN_ARCHITECTURE.md - System design and architecture decisions
- DEEP_THINKING_ANSWERS.md - Answers to architectural scalability questions
- Node.js 18+
- npm or yarn
npm installCopy the example environment file:
cp env.example .envThe application uses SQLite by default. For production, configure PostgreSQL in .env.
# Development
npm run start:dev
# Production
npm run build
npm run start:prodnpm run db:seedPOST /bookings
Headers: Idempotency-Key: <unique-key>
Body: {
"professionalId": "uuid",
"clientId": "uuid",
"startTime": "2025-08-25T10:00:00Z",
"durationHours": 2,
"notes": "Optional notes"
}GET /search/pros?category=cleaning&locationLat=40.7128&locationLng=-74.0060&maxDistanceKm=10Query Parameters:
category: Service category (e.g., cleaning, plumbing)locationLat: Search location latitudelocationLng: Search location longitudemaxDistanceKm: Maximum distance in kilometersmaxHourlyRateCents: Maximum hourly ratetravelMode: local or travel
GET /clients/:id# Run tests
npm test
# Run tests with coverage
npm run test:cov
# Run tests in watch mode
npm run test:watch- professionals: Service providers with location and pricing
- clients: Customers who book services
- bookings: Service appointments with conflict prevention
- availabilities: Professional working hours
- idempotency_keys: Request deduplication
bookings(professional_id, start_time, end_time)- Conflict detectionbookings(idempotency_key)- Idempotency lookupsprofessionals(category, location_lat, location_lng)- Search optimization
- Modular Design: Feature-based module organization
- Service Layer: Business logic separation
- Repository Pattern: Data access abstraction
- DTO Validation: Input/output data validation
- Transaction Safety: Database transaction management
src/
├── bookings/ # Booking management
├── professionals/ # Professional search
├── clients/ # Client management
├── availabilities/ # Availability management
├── common/ # Shared services
└── database/ # Database configuration
- BookingsService: Core booking logic with conflict prevention
- ProfessionalsService: Search with location-based filtering
- IdempotencyService: Request deduplication
- ClientsService: Client data management
- Database: Use PostgreSQL for production
- Caching: Implement Redis for idempotency keys
- Monitoring: Add application and business metrics
- Security: Implement authentication and rate limiting
- Scaling: Horizontal scaling with load balancers
Private - Assessment Project