A full-stack restaurant seat booking system built with React, Node.js, Express, and MongoDB.
http://localhost:5555/api-docs
- Time Slot Management: 1-hour time slots for booking
- Multiple Seats Booking: Book multiple seats at once
- Real-time Availability: Check available seats for each time slot
- Booking Management: Create, view, modify, and cancel bookings
- Calendar View: Visual representation of bookings by date
- Responsive Design: Works on desktop and mobile devices
- React 18
- React Router
- React DatePicker
- React Toastify (notifications)
- Axios (API calls)
- Node.js
- Express.js
- MongoDB with Mongoose
- CORS enabled
- Environment variables with dotenv
This section details how the different parts of the application interact to provide a seamless booking experience.
The application follows a standard Client-Server-Database architecture:
- Frontend (React): The user interface where customers interact with the system (view availability, book seats).
- Backend (Express/Node.js): The RESTful API that handles business logic, validation, and database interactions.
- Database (MongoDB): Stores persistent data like bookings and restaurant settings.
The frontend is a React Single Page Application (SPA).
- Entry Point:
src/index.jsbootstraps the React app by renderingsrc/App.jsinto the DOM. - Routing (
src/App.js): Usesreact-router-domto manage navigation:/-> LandingPage: A static welcome page with a "Start" button./app-> MainApp: The core booking application dashboard.
- Main Application (
src/components/MainApp.js): Manages the state of the active view (form,calendar,list) and renders the corresponding components:- BookingForm: A form to capture customer details and desired booking time. It calls
checkAvailabilityAPI on date/time selection. - BookingCalendar: Displays a visual calendar to see bookings per day.
- BookingList: A list view of all bookings, allowing cancellation or deletion.
- BookingForm: A form to capture customer details and desired booking time. It calls
- API Layer (
src/services/api.js): A centralized Axios instance configured with the base URL. It exports methods likebookingAPI.createBookingorbookingAPI.checkAvailabilitythat components use to fetch data. This decouples UI components from direct HTTP calls.
The backend is an Express.js server providing a JSON API.
- Entry Point:
server.jsinitializes the Express app, connects to MongoDB viaconfig/db.js, sets up middleware (CORS, Body Parser), and mounts routes. - Routes (
backend/routes/):bookingRoutes.js: Maps HTTP endpoints (e.g.,POST /,GET /availability) to controller functions.restaurantRoutes.js: Handles restaurant configuration endpoints.
- Controllers (
backend/controllers/): Contains the business logic:bookingController.js:createBooking: Validates input -> Checks capacity (Total Seats - Booked Seats) -> Saves booking -> Returns success.checkAvailability: Aggregates confirmed bookings for a specific slot to calculate remaining seats.
- Data Models (
backend/models/): Mongoose schemas defining data structure:Booking.js: Stores customer info, date, time slot, seat count, and status (confirmed,cancelled).Restaurant.js: Stores global settings like total seats, opening hours, etc.
- User Action: User selects a date and time on the
BookingForm. - Frontend Check:
BookingFormcallsbookingAPI.checkAvailability(date, time). - API Request: Frontend sends
GET /api/bookings/availability?date=...&timeSlot=...to Backend. - Backend Logic:
bookingController.checkAvailabilityruns.- Queries
Restaurantmodel for total seats (default 100). - Queries
Bookingmodel for all confirmed bookings at that time. - Calculates
Available = Total - Sum(Booked). - Returns JSON
{ availableSeats: 5 }.
- UI Update: Frontend displays "5 seats available".
- Submission: User clicks "Book".
- Final Validation: Backend performs the check again (concurrency safety) before saving to ensure seats weren't taken in the interim.
- Persistence: Booking is saved to MongoDB.
SeatBooking/
├── backend/
│ ├── config/ # Database connection logic
│ ├── controllers/ # Request handlers (Business logic)
│ ├── models/ # Mongoose schemas (Data definitions)
│ ├── routes/ # API route definitions
│ └── server.js # App entry point & configuration
└── frontend/
├── src/
│ ├── components/ # UI Components (Forms, Lists, Calendar)
│ ├── services/ # API integration service
│ ├── App.js # Routing configuration
│ ├── MainApp.js # Main dashboard layout
│ └── LandingPage.js # Welcome page
- Node.js (v14 or higher)
- MongoDB installed and running
- npm or yarn
-
Navigate to backend directory:
cd backend -
Install dependencies:
npm install
-
Configure environment variables in
.env:PORT=5555 MONGODB_URI= your mongodb connection string NODE_ENV=development -
Start the backend server:
npm start
For development with auto-reload:
npm run dev
The backend will run on http://localhost:5000
-
Navigate to frontend directory:
cd frontend -
Install dependencies:
npm install
-
Start the React development server:
npm start
The frontend will run on http://localhost:3000
GET /- Get all bookingsGET /availability?date=YYYY-MM-DD&timeSlot=HH:MM-HH:MM- Check availabilityGET /date/:date- Get bookings by dateGET /:id- Get booking by IDPOST /- Create new bookingPUT /:id- Update bookingPATCH /:id/cancel- Cancel bookingDELETE /:id- Delete booking
GET /- Get restaurant settingsPUT /- Update restaurant settingsGET /timeslots- Get available time slots
MIT