Skip to content

promiseer/restaurent-app

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

13 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Restaurant Food Ordering Application

A full-stack web application for food ordering with role-based access control (RBAC) and country-based access management.

πŸŽ₯ Demo

Demo

πŸš€ Features

Core Functionality

-Restaurant & Menu Management: Browse restaurants and view menu items

-Order Management: Create orders, add food items to cart

-Payment Processing: Checkout and pay using different payment methods

-Order Lifecycle: Place, track, and cancel orders

Role-Based Access Control (RBAC)

-Admin: Full access to all features across all countries

-Manager: Can view, order, and cancel orders (country-specific access)

-Member: Can view and add to cart only (country-specific access)

Country-Based Access Control

-India: Managers and Members from India can only access Indian restaurants and data

-America: Managers and Members from America can only access American restaurants and data

-Admin: Can access data from all countries

πŸ—οΈ Architecture

Backend (Node.js + Express + MongoDB)

-Authentication: JWT-based authentication

-Authorization: Role-based and country-based middleware

-Database: MongoDB with Mongoose ODM

-Security: Helmet, CORS, Rate limiting

-API: RESTful API design

Frontend (Next.js + React + TypeScript)

-Framework: Next.js 14 with App Router

-Styling: Tailwind CSS

-State Management: React hooks and context

-UI Components: Custom components with responsive design

πŸ“‹ User Roles & Permissions

| Function | Admin | Manager | Member |

| ----------------------------- | ----- | ----------- | ----------- |

| View restaurants & menu items | βœ… | βœ… | βœ… |

| Create order (add food items) | βœ… | βœ… | βœ… |

| Place order (checkout & pay) | βœ… | βœ… | ❌ |

| Cancel order | βœ… | βœ… | ❌ |

| Update payment method | βœ… | ❌ | ❌ |

| Country access | All | Own country | Own country |

πŸ”§ Prerequisites

-Node.js (v18 or higher)

-MongoDB (v4.4 or higher)

-npm or yarn

πŸ“₯ Installation & Setup

1. Clone the Repository

gitclone <repository-url>

cdrestaurant-app

2. Install Dependencies

# Install root dependencies

npminstall


# Install backend dependencies

cdbackend

npminstall


# Install frontend dependencies

cd../frontend

npminstall

3. Environment Configuration

Backend Environment

Create backend/.env file:

PORT=5000

MONGODB_URI=mongodb://localhost:27017/restaurant_app

JWT_SECRET=your_jwt_secret_key_here_make_it_very_long_and_secure

NODE_ENV=development

Frontend Environment

Create frontend/.env.local file:

NEXT_PUBLIC_API_URL=http://localhost:5000/api

4. Database Setup

Start MongoDB

# Using MongoDB service (Windows)

netstartMongoDB


# Using MongoDB directly

mongod


# Using Docker

dockerrun-d-p27017:27017--namemongodbmongo:latest

Seed Database with Sample Data

cdbackend

npmrunseed

This will create:

-6 test users with different roles and countries

-4 sample restaurants (2 in India, 2 in America)

-Sample menu items for each restaurant

πŸš€ Running the Application

Development Mode

Option 1: Run both frontend and backend simultaneously

# From root directory

npmrundev

Option 2: Run separately

# Terminal 1 - Backend

cdbackend

npmrundev


# Terminal 2 - Frontend

cdfrontend

npmrundev

Production Mode

# Build frontend

cdfrontend

npmrunbuild


# Start backend

cd../backend

npmstart


# Serve frontend

cd../frontend

npmstart

🌐 Access URLs

-Frontend: http://localhost:3000

-Backend API: http://localhost:5000/api

-API Health Check: http://localhost:5000/api/health

πŸ‘₯ Test Accounts

| Name | Email | Password | Role | Country |

| --------------- | --------------------------- | ---------- | ------- | ------- |

| Nick Fury | nick.fury@admin.com | admin123 | Admin | America |

| Captain Marvel | captain.marvel@manager.com | manager123 | Manager | India |

| Captain America | captain.america@manager.com | manager123 | Manager | America |

| Thanos | thanos@member.com | member123 | Member | India |

| Thor | thor@member.com | member123 | Member | India |

| Travis | travis@member.com | member123 | Member | America |

πŸ“š API Endpoints

Authentication

-POST /api/auth/register - Register new user

-POST /api/auth/login - User login

-GET /api/auth/profile - Get user profile

-GET /api/auth/verify - Verify JWT token

Restaurants

-GET /api/restaurants - Get restaurants (country-filtered)

-GET /api/restaurants/:id - Get restaurant details

-GET /api/restaurants/:id/menu - Get restaurant menu

-POST /api/restaurants - Create restaurant (Admin only)

Orders

-GET /api/orders - Get orders (role & country filtered)

-POST /api/orders - Create order (Admin/Manager only)

-PUT /api/orders/:id/status - Update order status

-PUT /api/orders/:id/cancel - Cancel order (Admin/Manager only)

Payments

-GET /api/payments/methods - Get payment methods

-POST /api/payments/process - Process payment

-POST /api/payments/methods - Add payment method (Admin only)

Users (Admin only)

-GET /api/users - Get all users

-PUT /api/users/:id - Update user

-DELETE /api/users/:id - Delete user

πŸ§ͺ Testing the RBAC System

Test Scenarios

1.Admin Access:

  • Login as Nick Fury
  • Can see restaurants from both countries
  • Can place and cancel orders
  • Can manage payment methods

2.Manager Access:

  • Login as Captain Marvel (India) or Captain America (America)
  • Can only see restaurants from their country
  • Can place and cancel orders
  • Cannot manage payment methods

3.Member Access:

  • Login as Thanos, Thor (India) or Travis (America)
  • Can only see restaurants from their country
  • Can add items to cart but cannot place orders
  • Cannot cancel orders or manage payments

πŸ”’ Security Features

-JWT Authentication: Secure token-based authentication

-Password Hashing: bcrypt with salt rounds

-Rate Limiting: API rate limiting to prevent abuse

-CORS: Configured for secure cross-origin requests

-Helmet: Security headers for Express

-Input Validation: Server-side validation for all inputs

πŸ› οΈ Technology Stack

Backend

-Runtime: Node.js

-Framework: Express.js

-Database: MongoDB

-ODM: Mongoose

-Authentication: JSON Web Tokens (JWT)

-Password Hashing: bcryptjs

-Security: Helmet, CORS, express-rate-limit

Frontend

-Framework: Next.js 14

-Language: TypeScript

-Styling: Tailwind CSS

-HTTP Client: Fetch API

-Routing: Next.js App Router

πŸ“‚ Project Structure


restaurant-app/

β”œβ”€β”€ backend/

β”‚   β”œβ”€β”€ models/          # Database models

β”‚   β”œβ”€β”€ routes/          # API routes

β”‚   β”œβ”€β”€ middleware/      # Auth & validation middleware

β”‚   β”œβ”€β”€ scripts/         # Database seeding scripts

β”‚   └── server.js        # Express server

β”œβ”€β”€ frontend/

β”‚   β”œβ”€β”€ app/             # Next.js app directory

β”‚   β”œβ”€β”€ components/      # React components

β”‚   β”œβ”€β”€ lib/             # Utility functions

β”‚   └── styles/          # CSS styles

└── README.md

🀝 Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Test thoroughly
  5. Submit a pull request

πŸ“„ License

This project is licensed under the MIT License.

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

About

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published