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.
- About The Project
- Key Features
- Tech Stack
- Getting Started
- Environment Variables
- Project Structure
- API Reference
- Database Models
- Authentication Flow
- Error Handling
- Related Repository
- Contributing
- License
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.
|
|
|
|
| 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 |
- 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
-
Clone the repository
git clone https://github.com/M-R-Saad/DineFlow-server.git cd DineFlow-server -
Install dependencies
npm install
-
Set up environment variables
Create a
.envfile in the root directory (see Environment Variables below). -
Start the development server
npm run dev
The server will be running at
http://localhost:5000. -
Verify the server is running
curl http://localhost:5000 # Response: { "message": "DineFlow API is running" }
npm startCreate 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.envfile to version control. It is already included in.gitignore.
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
Base URL: http://localhost:5000/api
Access Levels: π Public Β· π Customer Β· π‘οΈ Admin
| 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 |
| 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 |
| 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 |
| 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) |
| 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 |
| 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 |
| 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 |
| 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 |
| 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 |
| 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 |
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 |
βββββββββββ ββββββββββββ βββββββββββββ ββββββββββββ
β Client ββββββΆβ Firebase ββββββΆβ Backend ββββββΆβ MongoDB β
β β β Auth β β /auth/* β β β
β βββββββ βββββββ JWT Gen β β β
β β ββββββββββββ βββββββββββββ ββββββββββββ
β β β
β ββββ Bearer Token βββΆ verifyToken βββΆ verifyAdmin βββΆ Controller
βββββββββββ
- User authenticates via Firebase (Email/Password or Google OAuth)
- Firebase token is sent to
/api/auth/firebase - Server verifies the token, creates/finds user in MongoDB
- Server issues a JWT and returns it to the client
- Client stores JWT and attaches it to every secure request via Axios interceptor
verifyTokenmiddleware validates the JWT on protected routesverifyAdminmiddleware checks user role for admin-only routes
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.
| Repository | Description |
|---|---|
| DineFlow Client | React 19 + Vite frontend application |
Contributions are welcome! Here's how you can help:
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
Please make sure to follow the existing code style and test your changes thoroughly.
Distributed under the MIT License. See LICENSE for more information.