Skip to content

M-R-Saad/DineFlow-server

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

2 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

DineFlow Logo

DineFlow β€” Server

🍽️ Restaurant Management REST API

A robust, scalable Node.js + Express backend powering the DineFlow restaurant management platform β€” featuring JWT authentication, role-based access control, and a comprehensive REST API.

Node.js Express MongoDB JWT License

API Base URL Β· Report Bug Β· Request Feature


πŸ“‘ Table of Contents


πŸ“– About The Project

DineFlow Server is the backend API for the DineFlow restaurant management platform. Built with Node.js and Express 5, it provides a comprehensive RESTful API that handles everything from user authentication to inventory management.

The server supports two user roles β€” Customer and Admin β€” with fine-grained, middleware-based access control. It integrates with Firebase for authentication, MongoDB for data persistence, Cloudinary for image management, and uses JWT tokens for secure API communication.


✨ Key Features

πŸ” Security & Auth

  • JWT-based authentication with Bearer tokens
  • Firebase token verification (Email + Google OAuth)
  • Role-based access control (Customer / Admin)
  • Password hashing with bcrypt
  • CORS configuration with credentials

πŸ—οΈ Architecture

  • RESTful API design with consistent response format
  • MVC architecture (Models, Controllers, Routes)
  • Centralized error handling middleware
  • ES Modules throughout
  • Environment-based configuration

πŸ“¦ Data Management

  • 10 Mongoose models with validations
  • Soft-delete pattern for data integrity
  • Price snapshot in orders for historical accuracy
  • Inventory audit trail with log entries
  • Query param filtering, sorting, and pagination

πŸ”Œ Integrations

  • MongoDB Atlas (cloud database)
  • Cloudinary (image storage & transformation)
  • Firebase Admin (token verification)
  • Nodemon (development hot-reload)

πŸ› οΈ Tech Stack

Category Technology Version
Runtime Node.js 18+
Framework Express.js 5.x
Database MongoDB (Mongoose ODM) 9.x
Authentication JSON Web Tokens (JWT) 9.x
Password Hashing bcryptjs 3.x
Image Upload Cloudinary SDK 2.x
File Upload Multer 2.x
Environment Config dotenv 17.x
CORS cors 2.x
Dev Server Nodemon 3.x

πŸš€ Getting Started

Prerequisites

  • Node.js β‰₯ 18.x
  • npm β‰₯ 9.x (or yarn / pnpm)
  • MongoDB instance (local or MongoDB Atlas)
  • Cloudinary account (Sign up free)
  • Firebase project with Authentication enabled

Installation

  1. Clone the repository

    git clone https://github.com/M-R-Saad/DineFlow-server.git
    cd DineFlow-server
  2. Install dependencies

    npm install
  3. Set up environment variables

    Create a .env file in the root directory (see Environment Variables below).

  4. Start the development server

    npm run dev

    The server will be running at http://localhost:5000.

  5. Verify the server is running

    curl http://localhost:5000
    # Response: { "message": "DineFlow API is running" }

Production

npm start

πŸ” Environment Variables

Create a .env file in the project root with the following variables:

# Server
PORT=5000

# MongoDB
MONGO_URI=mongodb+srv://username:password@cluster.mongodb.net/dineflow?retryWrites=true&w=majority

# JWT
JWT_SECRET=your_super_secret_jwt_key_here

# Client URL (for CORS)
CLIENT_URL=http://localhost:5173

# Cloudinary
CLOUDINARY_CLOUD_NAME=your_cloud_name
CLOUDINARY_API_KEY=your_api_key
CLOUDINARY_API_SECRET=your_api_secret

⚠️ Important: Never commit your .env file to version control. It is already included in .gitignore.


πŸ“ Project Structure

DineFlow-server/
β”œβ”€β”€ config/
β”‚   └── db.js                    # MongoDB connection via Mongoose
β”œβ”€β”€ controllers/                 # Route handler logic (business layer)
β”‚   β”œβ”€β”€ authController.js        #   Register, login, Firebase auth
β”‚   β”œβ”€β”€ userController.js        #   Profile & user management
β”‚   β”œβ”€β”€ menuController.js        #   Menu item CRUD
β”‚   β”œβ”€β”€ categoryController.js    #   Category CRUD
β”‚   β”œβ”€β”€ bookingController.js     #   Table booking operations
β”‚   β”œβ”€β”€ orderController.js       #   Order placement & management
β”‚   β”œβ”€β”€ reviewController.js      #   Dish review operations
β”‚   β”œβ”€β”€ inventoryController.js   #   Inventory & stock management
β”‚   β”œβ”€β”€ tableController.js       #   Table management
β”‚   └── testimonialController.js #   Testimonial operations
β”œβ”€β”€ middleware/
β”‚   β”œβ”€β”€ verifyToken.js           # JWT verification middleware
β”‚   β”œβ”€β”€ verifyAdmin.js           # Admin role-check middleware
β”‚   └── errorHandler.js          # Global error handling middleware
β”œβ”€β”€ models/                      # Mongoose schema definitions
β”‚   β”œβ”€β”€ User.js                  #   User accounts & roles
β”‚   β”œβ”€β”€ Category.js              #   Menu categories
β”‚   β”œβ”€β”€ MenuItem.js              #   Menu items (dishes)
β”‚   β”œβ”€β”€ Table.js                 #   Restaurant tables
β”‚   β”œβ”€β”€ Booking.js               #   Table reservations
β”‚   β”œβ”€β”€ Order.js                 #   Customer orders
β”‚   β”œβ”€β”€ Review.js                #   Dish reviews & ratings
β”‚   β”œβ”€β”€ Inventory.js             #   Inventory items & stock levels
β”‚   β”œβ”€β”€ InventoryLog.js          #   Stock change audit trail
β”‚   └── Testimonial.js           #   Customer testimonials
β”œβ”€β”€ routes/                      # Express route definitions
β”‚   β”œβ”€β”€ authRoutes.js
β”‚   β”œβ”€β”€ userRoutes.js
β”‚   β”œβ”€β”€ menuRoutes.js
β”‚   β”œβ”€β”€ categoryRoutes.js
β”‚   β”œβ”€β”€ bookingRoutes.js
β”‚   β”œβ”€β”€ orderRoutes.js
β”‚   β”œβ”€β”€ reviewRoutes.js
β”‚   β”œβ”€β”€ inventoryRoutes.js
β”‚   β”œβ”€β”€ tableRoutes.js
β”‚   └── testimonialRoutes.js
β”œβ”€β”€ utils/
β”‚   └── generateOrderNumber.js   # Unique order number generator
β”œβ”€β”€ .env                         # Environment variables (not committed)
β”œβ”€β”€ .gitignore
β”œβ”€β”€ index.js                     # App entry point
└── package.json

πŸ“‘ API Reference

Base URL: http://localhost:5000/api

Access Levels: 🌐 Public Β· πŸ”’ Customer Β· πŸ›‘οΈ Admin


πŸ”‘ Auth β€” /api/auth

Method Endpoint Access Description
POST /register 🌐 Public Register a new user account
POST /login 🌐 Public Login with email & password
POST /firebase 🌐 Public Login / register via Firebase token

πŸ‘€ Users β€” /api/users

Method Endpoint Access Description
GET /me πŸ”’ Customer Get own profile
PATCH /me πŸ”’ Customer Update own profile
GET / πŸ›‘οΈ Admin Get all users
PATCH /:id/role πŸ›‘οΈ Admin Change a user's role
PATCH /:id/status πŸ›‘οΈ Admin Activate / deactivate user

πŸ“‚ Categories β€” /api/categories

Method Endpoint Access Description
GET / 🌐 Public Get all active categories
POST / πŸ›‘οΈ Admin Create new category
PATCH /:id πŸ›‘οΈ Admin Update category
DELETE /:id πŸ›‘οΈ Admin Soft delete category

πŸ” Menu Items β€” /api/menu

Method Endpoint Access Description
GET / 🌐 Public Get all items (?category, ?search, ?sort)
GET /featured 🌐 Public Get featured items for homepage
GET /:id 🌐 Public Get single item detail
POST / πŸ›‘οΈ Admin Add new menu item
PATCH /:id πŸ›‘οΈ Admin Update menu item
DELETE /:id πŸ›‘οΈ Admin Soft delete (set isAvailable: false)

πŸ“… Bookings β€” /api/bookings

Method Endpoint Access Description
GET /available-slots 🌐 Public Get available time slots for a date
POST / πŸ”’ Customer Create a booking
GET /my πŸ”’ Customer Get own bookings
PATCH /my/:id/cancel πŸ”’ Customer Cancel own booking
GET / πŸ›‘οΈ Admin Get all bookings (?date, ?status)
PATCH /:id/status πŸ›‘οΈ Admin Confirm or cancel a booking

πŸ“¦ Orders β€” /api/orders

Method Endpoint Access Description
POST / πŸ”’ Customer Place a new order
GET /my πŸ”’ Customer Get own order history
GET /my/:id πŸ”’ Customer Get single order detail
GET / πŸ›‘οΈ Admin Get all orders (?status)
PATCH /:id/status πŸ›‘οΈ Admin Update order status
GET /stats πŸ›‘οΈ Admin Revenue & order stats for dashboard

⭐ Reviews β€” /api/reviews

Method Endpoint Access Description
GET /menu/:menuItemId 🌐 Public Get all reviews for a menu item
POST / πŸ”’ Customer Submit a review for a menu item
DELETE /:id πŸ›‘οΈ Admin Remove an inappropriate review

πŸ“¦ Inventory β€” /api/inventory

Method Endpoint Access Description
GET / πŸ›‘οΈ Admin Get all inventory items
GET /low-stock πŸ›‘οΈ Admin Get items below minimum stock level
POST / πŸ›‘οΈ Admin Add new inventory item
PATCH /:id πŸ›‘οΈ Admin Update item details
POST /:id/restock πŸ›‘οΈ Admin Add stock + create audit log entry
GET /:id/logs πŸ›‘οΈ Admin Get stock change history

πŸ’¬ Testimonials β€” /api/testimonials

Method Endpoint Access Description
GET / 🌐 Public Get all approved testimonials
POST / πŸ”’ Customer Submit a testimonial
GET /all πŸ›‘οΈ Admin Get all (approved + pending)
PATCH /:id/approve πŸ›‘οΈ Admin Approve a testimonial
DELETE /:id πŸ›‘οΈ Admin Delete a testimonial

πŸͺ‘ Tables β€” /api/tables

Method Endpoint Access Description
GET / πŸ›‘οΈ Admin Get all tables
POST / πŸ›‘οΈ Admin Add a new table
PATCH /:id πŸ›‘οΈ Admin Update table details
DELETE /:id πŸ›‘οΈ Admin Remove a table

πŸ—„οΈ Database Models

The application uses 10 Mongoose models reflecting a normalized MongoDB schema:

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”     β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”     β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚    User      │────▢│   Booking    β”‚     β”‚   Category   β”‚
β”‚              │────▢│   Order      β”‚     β”‚              β”‚
β”‚              │────▢│   Review     β”‚     β””β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”˜
β”‚              │────▢│  Testimonial β”‚            β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜     β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜     β”Œβ”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”
                                          β”‚  MenuItem    β”‚
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”     β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”     β”‚              β”‚
β”‚   Table      │────▢│   Booking    β”‚     β””β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”˜
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜     β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜            β”‚
                                          β”Œβ”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”     β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”     β”‚   Review     β”‚
β”‚  Inventory   │────▢│ InventoryLog β”‚     β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜     β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
Model Description
User User accounts with roles (customer, admin), soft-delete support
Category Menu categories with soft-delete
MenuItem Dishes with pricing, images, availability, featured flag
Table Restaurant tables with capacity and status
Booking Table reservations with date, time slot, guests, status
Order Customer orders with price snapshots and status pipeline
Review Dish reviews with ratings (1–5)
Inventory Stock items with minimum level tracking
InventoryLog Audit trail for all stock changes
Testimonial Customer testimonials with approval workflow

πŸ” Authentication Flow

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”     β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”     β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”     β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚  Client  │────▢│ Firebase │────▢│  Backend  │────▢│ MongoDB  β”‚
β”‚          β”‚     β”‚   Auth   β”‚     β”‚  /auth/*  β”‚     β”‚          β”‚
β”‚          │◀────│          │◀────│  JWT Gen  β”‚     β”‚          β”‚
β”‚          β”‚     β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜     β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜     β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
β”‚          β”‚                                               β”‚
β”‚          │─── Bearer Token ──▢ verifyToken ──▢ verifyAdmin ──▢ Controller
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
  1. User authenticates via Firebase (Email/Password or Google OAuth)
  2. Firebase token is sent to /api/auth/firebase
  3. Server verifies the token, creates/finds user in MongoDB
  4. Server issues a JWT and returns it to the client
  5. Client stores JWT and attaches it to every secure request via Axios interceptor
  6. verifyToken middleware validates the JWT on protected routes
  7. verifyAdmin middleware checks user role for admin-only routes

⚠️ Error Handling

All API responses follow a consistent format:

Success Response:

{
  "success": true,
  "data": { ... }
}

Error Response:

{
  "success": false,
  "message": "Descriptive error message"
}

The global errorHandler middleware catches unhandled errors and returns appropriate HTTP status codes.


πŸ”— Related Repository

Repository Description
DineFlow Client React 19 + Vite frontend application

🀝 Contributing

Contributions are welcome! Here's how you can help:

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

Please make sure to follow the existing code style and test your changes thoroughly.


πŸ“„ License

Distributed under the MIT License. See LICENSE for more information.


DineFlow

Built with ❀️ using Node.js, Express, and MongoDB

⬆️ Back to Top

About

πŸš€ A scalable Node.js REST API for restaurant management, featuring JWT authentication, role-based access control, MongoDB integration, inventory management, and booking/order workflows.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors