A complete full-stack hotel booking application built with the MERN stack (MongoDB, Express.js, React, Node.js) featuring user authentication, hotel management, room booking, and admin dashboard.
- User registration and login with JWT
- Protected routes and middleware
- Role-based access (Guest/Admin)
- Password hashing with bcrypt
- Browse hotels with search and filtering
- View hotel details and images
- Search by location, price range, and rating
- Admin functions to add/edit/delete hotels
- View available rooms for each hotel
- Check room availability for specific dates
- Create bookings with date validation
- Cancel bookings with restrictions
- Booking status management
- View personal profile information
- Manage bookings (view/cancel)
- Booking history and status tracking
- Manage all hotels and rooms
- View and manage all bookings
- Update booking statuses
- System statistics and overview
- Frontend: React, React Router, Axios, CSS3
- Backend: Node.js, Express.js, JWT, bcryptjs
- Database: MongoDB with Mongoose ODM
- Development: Vite, nodemon
Hotel-Booking-System/
βββ backend/
β βββ config/
β β βββ db.js # Database configuration
β βββ controllers/
β β βββ authController.js # Authentication logic
β β βββ hotelController.js # Hotel management logic
β β βββ roomController.js # Room management logic
β β βββ bookingController.js # Booking logic
β βββ middleware/
β β βββ authMiddleware.js # JWT authentication middleware
β βββ models/
β β βββ User.js # User schema and model
β β βββ Hotel.js # Hotel schema and model
β β βββ Room.js # Room schema and model
β β βββ Booking.js # Booking schema and model
β βββ routes/
β β βββ authRoutes.js # Authentication endpoints
β β βββ hotelRoutes.js # Hotel endpoints
β β βββ roomRoutes.js # Room endpoints
β β βββ bookingRoutes.js # Booking endpoints
β βββ utils/
β β βββ generateToken.js # JWT token generation
β βββ server.js # Express server setup
β βββ .env.example # Environment variables template
β βββ package.json # Backend dependencies
βββ frontend/
β βββ src/
β β βββ components/
β β β βββ ProtectedRoute.jsx # Route protection component
β β βββ context/
β β β βββ AuthContext.jsx # Authentication context
β β βββ pages/
β β β βββ Login.jsx # Login page
β β β βββ Signup.jsx # Registration page
β β β βββ Home.jsx # Hotel listings page
β β β βββ HotelDetails.jsx # Hotel details page
β β β βββ BookingConfirmation.jsx # Booking confirmation page
β β β βββ Dashboard.jsx # User dashboard
β β β βββ AdminDashboard.jsx # Admin dashboard
β β βββ services/
β β β βββ api.js # API service with Axios
β β βββ App.jsx # Main app component with routing
β β βββ main.jsx # App entry point
β β βββ index.css # Global styles
β βββ .env.example # Environment variables template
β βββ index.html # HTML template
β βββ package.json # Frontend dependencies
β βββ vite.config.js # Vite configuration
βββ README.md # This file
- Node.js (v14 or higher)
- npm or yarn
- MongoDB (running locally or MongoDB Atlas)
git clone <repository-url>
cd Hotel-Booking-Systemcd backend
# Install dependencies
npm install
# Create environment file
cp .env.example .env
# Edit .env file with your configurationPORT=5000
NODE_ENV=development
MONGODB_URI=mongodb://localhost:27017/hotel-booking
JWT_SECRET=your-super-secret-jwt-key-change-this-in-production
FRONTEND_URL=http://localhost:3000cd ../frontend
# Install dependencies
npm install
# Create environment file
cp .env.example .envVITE_API_URL=http://localhost:5000/api- Make sure MongoDB is running on your system
- Or use MongoDB Atlas and update the
MONGODB_URIin backend/.env
cd backend
npm run devBackend will run on http://localhost:5000
cd frontend
npm run devFrontend will run on http://localhost:3000
- Browse Hotels: Visit the homepage to search and browse hotels
- Register Account: Click "Sign Up" to create a new account
- Login: Use your credentials to access the system
- Book Hotels: View hotel details and book rooms with selected dates
- Admin Access: Register with any email and manually set role to 'admin' in the database
- Admin Dashboard: Access admin panel to manage hotels, rooms, and bookings
- Management: Add/edit hotels, manage room inventory, update booking statuses
POST /api/auth/register- User registrationPOST /api/auth/login- User loginGET /api/auth/profile- Get user profilePUT /api/auth/profile- Update user profile
GET /api/hotels- Get all hotels (with search/filter)GET /api/hotels/:id- Get hotel details with roomsPOST /api/hotels- Create hotel (admin only)PUT /api/hotels/:id- Update hotel (admin only)DELETE /api/hotels/:id- Delete hotel (admin only)POST /api/hotels/availability- Check room availability
GET /api/rooms/hotel/:hotelId- Get rooms for a hotelGET /api/rooms/:id- Get room detailsPOST /api/rooms- Create room (admin only)PUT /api/rooms/:id- Update room (admin only)DELETE /api/rooms/:id- Delete room (admin only)
GET /api/bookings- Get user bookingsPOST /api/bookings- Create new bookingGET /api/bookings/:id- Get booking detailsPUT /api/bookings/:id/cancel- Cancel bookingGET /api/bookings/admin/all- Get all bookings (admin only)
- User registers/logs in with email and password
- Server validates credentials and returns JWT token
- Token stored in localStorage and sent with subsequent requests
- Protected routes require valid JWT token
- User searches and browses hotels
- User selects hotel and available room
- User selects check-in and check-out dates
- System checks room availability
- User confirms booking details
- Booking created with pending status
- Admin can confirm or cancel bookings
- View system statistics
- Manage all bookings and update statuses
- Hotel and room management (basic implementation)
- User management capabilities
- JWT-based authentication with 24-hour expiration
- Password hashing with bcrypt (10 salt rounds)
- Protected API routes with middleware
- Input validation and sanitization
- CORS configuration
- Rate limiting on API endpoints
- Admin role-based access control
- Comprehensive error handling on both frontend and backend
- User-friendly error messages
- Form validation with immediate feedback
- Network error handling
- API timeout handling
- Hotel and room image uploads
- Advanced search with map integration
- Payment processing integration
- Email notifications for booking confirmations
- Review and rating system
- Advanced admin analytics
- Multi-language support
- Mobile responsive design improvements
- Fork the repository
- Create a feature branch (
git checkout -b feature/AmazingFeature) - Commit your changes (
git commit -m 'Add some AmazingFeature') - Push to the branch (
git push origin feature/AmazingFeature) - Open a Pull Request
This project is licensed under the ISC License.
For support, please open an issue in the repository or contact the development team.