How leeeee001/hotel-room_booking_api works
Project type and purpose
• It’s a backend-only RESTful API for hotel room booking.
• Built with Node.js/Express, MongoDB (Mongoose), JWT for auth, and Stripe for payments.
• Users search rooms, create/cancel bookings, and pay via Stripe.
File structure
• server.js – entry point that wires up Express, middleware, routes.
• config/db.js – database connection to MongoDB.
• middleware/auth.js – JWT authentication/authorization.
• routes/*.js – Express routers for users, rooms, bookings, payments.
• controllers/*.controller.js – business logic per entity (CRUD, booking logic, Stripe calls).
• models/*.model.js – Mongoose schemas: Users, Hotels, Rooms, RoomAvailability, Bookings, Payments.
Main components
a. Client (frontend or API consumer)
b. API Server (Express application)
– HTTP routing layer
– Auth middleware (JWT)
– Controllers/Services layer
c. MongoDB (with collections for users, hotels, rooms, availabilities, bookings, payments)
d. External Service: Stripe API
Relationships and data flows
1. Client → HTTP request to Express routes
2. Route handler → auth middleware (if protected) → Controller
3. Controller → business logic:
• Reads/writes via Mongoose models → MongoDB
• For payments: calls Stripe REST API, then persists payment result in MongoDB
4. Controller returns JSON response → Client
Architectural patterns and design principles
• Layered MVC-style separation: Routes → Controllers → Models
• Modular and scalable: each controller and route handles one resource
• Stateless REST API with JWT auth (middleware enforces security)
• External integration as a separate service boundary (Stripe)
• Database encapsulation via Mongoose ODM
Technologies & frameworks to annotate
• Express.js (HTTP server & routing)
• Mongoose ODM (MongoDB access)
• JSON Web Tokens (authentication/authorization)
• Stripe API (payments)
• Notes on key interactions (e.g., “POST /bookings → invokes room availability logic”).