Skip to content
itsmohitkrPublic

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

ย 

History

44 Commits

Folders and files

Repository files navigation

Restofy - Restaurant Management Platform

๐Ÿฝ๏ธ Overview

Restofy is a comprehensive, production-ready restaurant management platform built with modern technologies. It provides a complete solution for restaurant owners to manage their operations, including reservations, orders, payments, staff, and analytics.

๐Ÿ—๏ธ Architecture

  • Frontend: React 19 with Material-UI, Vite build system
  • Backend: Node.js/Express.js with Domain-Driven Design (DDD) architecture
  • Notification Service: Event-driven microservice with RabbitMQ
  • Database: PostgreSQL with Prisma ORM
  • Message Broker: RabbitMQ for asynchronous communication
  • Authentication: JWT-based with role-based access control (RBAC)

Features

  • Authentication & RBAC: JWT-based login, role-based access for owners and staff
  • Restaurant Management: CRUD for restaurants, tables, menus, menu items, and reservations
  • Validation: Joi-based request validation for all endpoints
  • Centralized Error Handling: Consistent error responses and logging
  • Rate Limiting: Protects APIs from abuse
  • Logging: Winston-based logging to files and console
  • Testing: Jest and Supertest for unit and integration tests
  • Prisma ORM: Type-safe DB access and migrations
  • Extensible: Modular Domain-Driven Design architecture

๐Ÿ“ Project Structure

Restofy/
โ”œโ”€โ”€ back-end/                          # Node.js/Express Backend API
โ”‚   โ”œโ”€โ”€ src/
โ”‚   โ”‚   โ”œโ”€โ”€ domains/                   # Business Domains (DDD)
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ analytics/             # Analytics & Reporting
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ authentication/        # User Authentication
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ bill/                  # Bill Management
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ menu/                  # Menu Management
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ menuItem/              # Menu Item Management
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ order/                 # Order Management
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ payment/               # Payment Processing
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ profile/               # User Profile Management
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ reservation/           # Reservation Management
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ restaurant/            # Restaurant Management
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ tables/                # Table Management
โ”‚   โ”‚   โ”‚   โ””โ”€โ”€ user/                  # User Management
โ”‚   โ”‚   โ”œโ”€โ”€ infrastructure/            # External Dependencies
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ database/
โ”‚   โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ prisma/
โ”‚   โ”‚   โ”‚   โ”‚   โ””โ”€โ”€ redis/
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ external-services/
โ”‚   โ”‚   โ”‚   โ””โ”€โ”€ monitoring/
โ”‚   โ”‚   โ”œโ”€โ”€ routes/                    # API Routing Layer
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ index.js               # Main router
โ”‚   โ”‚   โ”‚   โ””โ”€โ”€ v1/
โ”‚   โ”‚   โ”‚       โ””โ”€โ”€ index.js           # V1 API routes
โ”‚   โ”‚   โ”œโ”€โ”€ shared/                    # Shared Components
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ error/                 # Error Handling
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ jobs/                  # Background Jobs
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ middleware/            # Express Middleware
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ queues/                # Message Queues
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ security/              # Security Middleware
โ”‚   โ”‚   โ”‚   โ””โ”€โ”€ services/              # Shared Services
โ”‚   โ”‚   โ”œโ”€โ”€ utils/                     # Utilities
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ constants/
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ helper/
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ logger.js
โ”‚   โ”‚   โ”‚   โ””โ”€โ”€ validation/            # Joi Validation Schemas
โ”‚   โ”‚   โ”œโ”€โ”€ admin/                     # Admin Panel
โ”‚   โ”‚   โ”œโ”€โ”€ app.js                     # Express App Setup
โ”‚   โ”‚   โ””โ”€โ”€ server.js                  # Server Entry Point
โ”‚   โ”œโ”€โ”€ tests/                         # Test Files
โ”‚   โ”œโ”€โ”€ logs/                          # Winston Log Files
โ”‚   โ”œโ”€โ”€ assests/                       # Assets
โ”‚   โ”œโ”€โ”€ .dockerignore
โ”‚   โ”œโ”€โ”€ .gitignore
โ”‚   โ”œโ”€โ”€ BLOCKERS.md                    # Development Notes
โ”‚   โ”œโ”€โ”€ LEARNING_GUIDE.md              # Learning Resources
โ”‚   โ”œโ”€โ”€ future.md                      # Future Plans
โ”‚   โ”œโ”€โ”€ env.example                    # Environment Template
โ”‚   โ”œโ”€โ”€ jest.config.js                 # Jest Configuration
โ”‚   โ”œโ”€โ”€ package.json
โ”‚   โ”œโ”€โ”€ package-lock.json
โ”‚   โ”œโ”€โ”€ dockerfile                     # Docker Configuration
โ”‚   โ””โ”€โ”€ README.md
โ”‚
โ”œโ”€โ”€ front-end/                         # React Frontend Application
โ”‚   โ”œโ”€โ”€ src/
โ”‚   โ”‚   โ”œโ”€โ”€ AuthPage/                  # Authentication Pages
โ”‚   โ”‚   โ”œโ”€โ”€ Component/                 # Reusable Components
โ”‚   โ”‚   โ”œโ”€โ”€ Context/                   # React Context Providers
โ”‚   โ”‚   โ”œโ”€โ”€ Layout/                    # Page Layouts & Components
โ”‚   โ”‚   โ”œโ”€โ”€ assets/                    # Static Assets
โ”‚   โ”‚   โ”œโ”€โ”€ App.css
โ”‚   โ”‚   โ”œโ”€โ”€ App.jsx                    # Main App Component
โ”‚   โ”‚   โ””โ”€โ”€ main.jsx                   # React Entry Point
โ”‚   โ”œโ”€โ”€ public/                        # Public Assets
โ”‚   โ”œโ”€โ”€ .dockerignore
โ”‚   โ”œโ”€โ”€ .gitignore
โ”‚   โ”œโ”€โ”€ eslint.config.js
โ”‚   โ”œโ”€โ”€ index.html
โ”‚   โ”œโ”€โ”€ package.json
โ”‚   โ”œโ”€โ”€ package-lock.json
โ”‚   โ”œโ”€โ”€ README.md
โ”‚   โ”œโ”€โ”€ dockerfile                     # Docker Configuration
โ”‚   โ”œโ”€โ”€ nginx.conf                     # Nginx Configuration
โ”‚   โ””โ”€โ”€ vite.config.js                 # Vite Configuration
โ”‚
โ”œโ”€โ”€ notification-service/              # Event-Driven Notification Service
โ”‚   โ”œโ”€โ”€ src/
โ”‚   โ”‚   โ”œโ”€โ”€ channel/                   # Notification Channels
โ”‚   โ”‚   โ”œโ”€โ”€ dispatcher/                # Message Dispatcher
โ”‚   โ”‚   โ”œโ”€โ”€ jobs/                      # Background Job Processors
โ”‚   โ”‚   โ”œโ”€โ”€ queues/                    # Message Queue Setup
โ”‚   โ”‚   โ”œโ”€โ”€ services/                  # Business Services
โ”‚   โ”‚   โ”œโ”€โ”€ utils/                     # Utilities
โ”‚   โ”‚   โ””โ”€โ”€ index.js                   # Service Entry Point
โ”‚   โ”œโ”€โ”€ prisma/                        # Database Schema
โ”‚   โ”œโ”€โ”€ .dockerignore
โ”‚   โ”œโ”€โ”€ .gitignore
โ”‚   โ”œโ”€โ”€ package.json
โ”‚   โ”œโ”€โ”€ package-lock.json
โ”‚   โ”œโ”€โ”€ README.md
โ”‚   โ”œโ”€โ”€ dockerfile                     # Docker Configuration
โ”‚   โ””โ”€โ”€ test.js
โ”‚
โ”œโ”€โ”€ docker-compose.yml                 # Multi-Service Orchestration
โ”œโ”€โ”€ package.json                       # Root Package Configuration
โ”œโ”€โ”€ package-lock.json
โ””โ”€โ”€ README.md                          # This File

Backend Folder Structure

back-end/
โ”œโ”€โ”€ infrastructure/               # External dependencies & services
โ”‚   โ””โ”€โ”€ database/
โ”‚       โ””โ”€โ”€ prisma/              # Prisma schema & migrations
โ”‚           โ”œโ”€โ”€ client.js        # Prisma client configuration
โ”‚           โ”œโ”€โ”€ schema.prisma    # Database schema
โ”‚           โ””โ”€โ”€ migrations/      # Database migrations
โ”œโ”€โ”€ logs/                        # Winston log files (generated)
โ”œโ”€โ”€ tests/                       # Jest/Supertest tests (planned)
โ”œโ”€โ”€ src/
โ”‚   โ”œโ”€โ”€ domains/                 # Business domains (DDD approach)
โ”‚   โ”‚   โ”œโ”€โ”€ authentication/      # Auth logic (signup, login, JWT)
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ auth.controller.js
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ auth.router.js
โ”‚   โ”‚   โ”‚   โ””โ”€โ”€ auth.service.js
โ”‚   โ”‚   โ”œโ”€โ”€ restaurant/          # Restaurant CRUD
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ restaurant.controller.js
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ restaurant.router.js
โ”‚   โ”‚   โ”‚   โ””โ”€โ”€ restaurant.service.js
โ”‚   โ”‚   โ”œโ”€โ”€ menu/                # Menu management
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ menu.controller.js
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ menu.router.js
โ”‚   โ”‚   โ”‚   โ””โ”€โ”€ menu.service.js
โ”‚   โ”‚   โ”œโ”€โ”€ menuItem/            # Menu item management
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ menuItem.controller.js
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ menuItem.router.js
โ”‚   โ”‚   โ”‚   โ””โ”€โ”€ menuItem.service.js
โ”‚   โ”‚   โ”œโ”€โ”€ tables/              # Table management
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ table.controller.js
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ table.router.js
โ”‚   โ”‚   โ”‚   โ””โ”€โ”€ table.service.js
โ”‚   โ”‚   โ”œโ”€โ”€ reservation/         # Reservation management
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ reservation.controller.js
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ reservation.router.js
โ”‚   โ”‚   โ”‚   โ””โ”€โ”€ reservation.service.js
โ”‚   โ”‚   โ”œโ”€โ”€ order/               # Order management
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ order.controller.js
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ order.router.js
โ”‚   โ”‚   โ”‚   โ””โ”€โ”€ order.service.js
โ”‚   โ”‚   โ”œโ”€โ”€ bill/                # Bill management
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ bill.controller.js
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ bill.router.js
โ”‚   โ”‚   โ”‚   โ””โ”€โ”€ bill.service.js
โ”‚   โ”‚   โ”œโ”€โ”€ payment/             # Payment management
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ payment.controller.js
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ payment.router.js
โ”‚   โ”‚   โ”‚   โ””โ”€โ”€ payment.service.js
โ”‚   โ”‚   โ””โ”€โ”€ user/                # User management
โ”‚   โ”‚       โ”œโ”€โ”€ user.controller.js
โ”‚   โ”‚       โ”œโ”€โ”€ user.router.js
โ”‚   โ”‚       โ””โ”€โ”€ user.service.js
โ”‚   โ”‚
โ”‚   โ”œโ”€โ”€ routes/                  # API routing layer
โ”‚   โ”‚   โ”œโ”€โ”€ index.js             # Main router
โ”‚   โ”‚   โ”œโ”€โ”€ v1/                  # API version 1
โ”‚   โ”‚   โ”‚   โ””โ”€โ”€ index.js         # V1 main router with middleware
โ”‚   โ”‚   โ”œโ”€โ”€ public/              # Public routes (planned)
โ”‚   โ”‚   โ”‚   โ””โ”€โ”€ index.js         # Health checks, docs
โ”‚   โ”‚   โ””โ”€โ”€ admin/               # Admin routes
โ”‚   โ”‚       โ””โ”€โ”€ admin.router.js
โ”‚   โ”‚
โ”‚   โ”œโ”€โ”€ shared/                  # Shared across domains
โ”‚   โ”‚   โ”œโ”€โ”€ middleware/          # Middleware functions
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ restrictToLoggedInUser.js  # Authentication middleware
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ checkRestaurantOwnership.js # Authorization middleware
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ validate.js      # Request validation
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ validateParam.js # Parameter validation
โ”‚   โ”‚   โ”‚   โ””โ”€โ”€ requireBody.js   # Body requirement check
โ”‚   โ”‚   โ”œโ”€โ”€ security/            # Security middleware
โ”‚   โ”‚   โ”‚   โ””โ”€โ”€ apiLimiter.js    # Rate limiting
โ”‚   โ”‚   โ”œโ”€โ”€ error/               # Error handling
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ errorHandler.js  # Global error handler
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ asyncErrorBoundary.js # Async error wrapper
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ pathNotFound.js  # 404 handler
โ”‚   โ”‚   โ”‚   โ””โ”€โ”€ methodNotAllowed.js # 405 handler
โ”‚   โ”‚   โ””โ”€โ”€ utils/               # Shared utilities
โ”‚   โ”‚       โ””โ”€โ”€ helper/          # Helper functions
โ”‚   โ”‚           โ”œโ”€โ”€ responseHelpers.js # Response formatters
โ”‚   โ”‚           โ””โ”€โ”€ responseBody.js    # Response body utilities
โ”‚   โ”‚
โ”‚   โ”œโ”€โ”€ reqBodyValidation/       # Joi validation schemas
โ”‚   โ”‚   โ”œโ”€โ”€ auth.validation.js   # Authentication validation
โ”‚   โ”‚   โ”œโ”€โ”€ restaurant.validation.js # Restaurant validation
โ”‚   โ”‚   โ”œโ”€โ”€ menu.validation.js   # Menu validation
โ”‚   โ”‚   โ”œโ”€โ”€ menuItem.validation.js # Menu item validation
โ”‚   โ”‚   โ”œโ”€โ”€ table.validation.js  # Table validation
โ”‚   โ”‚   โ”œโ”€โ”€ reservation.validation.js # Reservation validation
โ”‚   โ”‚   โ”œโ”€โ”€ order.validation.js  # Order validation
โ”‚   โ”‚   โ”œโ”€โ”€ bill.validation.js   # Bill validation
โ”‚   โ”‚   โ”œโ”€โ”€ payment.validation.js # Payment validation
โ”‚   โ”‚   โ””โ”€โ”€ user.validation.js   # User validation
โ”‚   โ”‚
โ”‚   โ”œโ”€โ”€ app.js                   # Express app setup & middleware
โ”‚   โ””โ”€โ”€ server.js                # Server startup & port configuration
โ”‚
โ”œโ”€โ”€ admin/                       # Admin panel (separate from API)
โ”‚   โ””โ”€โ”€ admin.router.js          # Admin route definitions
โ”œโ”€โ”€ BLOCKERS.md                  # Architectural decisions & blockers
โ”œโ”€โ”€ LEARNING_GUIDE.md            # Learning resources and notes  
โ”œโ”€โ”€ future.md                    # Future plans & feature roadmap
โ”œโ”€โ”€ env.example                  # Environment variable template
โ”œโ”€โ”€ jest.config.js               # Jest testing configuration
โ”œโ”€โ”€ package.json                 # NPM dependencies and scripts
โ”œโ”€โ”€ package-lock.json            # NPM lockfile
โ””โ”€โ”€ README.md                    # Project documentation

Architecture Overview

Domain-Driven Design (DDD)

The project follows DDD principles with clear separation of concerns:

  • domains/: Each business domain (restaurant, menu, orders, etc.) is self-contained with its own controllers, services, and routers
  • routes/: API routing layer with versioning support (v1, public, admin)
  • shared/: Cross-cutting concerns like middleware, utilities, and error handling
  • infrastructure/: External dependencies like database connections

Current API Structure

  • Main Routes: /api/ - All API routes go through main router
  • V1 Routes: /api/v1/ - Versioned API routes with restaurant middleware
  • Auth Routes: /api/auth/ - Authentication endpoints (signup, login)
  • Admin Routes: /api/admin/ - Administrative functions

Middleware Architecture

  • Authentication: JWT-based user authentication (restrictToLoggedInUser.js)
  • Authorization: Restaurant ownership validation (checkRestaurantOwnership.js)
  • Validation: Joi-based request validation (validate.js, validateParam.js)
  • Security: Rate limiting (apiLimiter.js)
  • Error Handling: Centralized error processing (errorHandler.js)

๐Ÿ› ๏ธ Technologies Used

Backend

  • Runtime: Node.js 18+
  • Framework: Express.js 5.1.0
  • Database: PostgreSQL with Prisma ORM 6.11.1
  • Authentication: JWT (jsonwebtoken 9.0.2)
  • Validation: Joi 17.13.3
  • Security: bcrypt 6.0.0, express-rate-limit 7.5.1
  • Message Queue: RabbitMQ (amqplib 0.10.8)
  • Email: Nodemailer 7.0.3
  • Logging: Winston 3.17.0
  • Testing: Jest 30.0.2, Supertest 7.1.1

Frontend

  • Framework: React 19.1.1
  • Build Tool: Vite
  • UI Library: Material-UI (MUI) 7.3.1
  • Routing: React Router DOM 7.8.2
  • HTTP Client: Axios 1.11.0
  • Charts: Recharts 3.1.2
  • Styling: Emotion (CSS-in-JS)

Notification Service

  • Runtime: Node.js 18+
  • Message Queue: RabbitMQ (amqplib 0.10.3)
  • Database: PostgreSQL with Prisma ORM 6.14.0
  • Email: Nodemailer 6.9.8
  • PDF Generation: PDFKit 0.17.1

DevOps & Infrastructure

  • Containerization: Docker
  • Orchestration: Docker Compose
  • Web Server: Nginx (for frontend)
  • Process Management: PM2 (production)

Current Route Structure

Main API Entry Point

/api/
โ”œโ”€โ”€ /auth                        # Authentication (public)
โ”‚   โ”œโ”€โ”€ POST /signup            # User registration
โ”‚   โ”œโ”€โ”€ POST /login             # User login
โ”‚   โ””โ”€โ”€ GET /verifyToken        # Token verification
โ”‚
โ”œโ”€โ”€ /v1                         # Version 1 API (protected)
โ”‚   โ””โ”€โ”€ /restaurants            # Restaurant management
โ”‚       โ”œโ”€โ”€ GET /               # List user's restaurants
โ”‚       โ”œโ”€โ”€ POST /              # Create new restaurant
โ”‚       โ”œโ”€โ”€ GET /:id            # Get specific restaurant
โ”‚       โ”œโ”€โ”€ PUT /:id            # Update restaurant
โ”‚       โ”œโ”€โ”€ DELETE /:id         # Delete restaurant
โ”‚       โ”‚
โ”‚       โ””โ”€โ”€ /:restaurantId/     # Restaurant-scoped resources
โ”‚           โ”œโ”€โ”€ /table          # Table management
โ”‚           โ”œโ”€โ”€ /menu           # Menu management
โ”‚           โ”œโ”€โ”€ /reservations   # Reservation management
โ”‚           โ””โ”€โ”€ /menu/:menuId/menuItem # Menu item management
โ”‚
โ””โ”€โ”€ /admin                      # Admin functions (protected)
    โ””โ”€โ”€ [Admin routes]

๐Ÿš€ API Endpoints

Base URL: /api

๐Ÿ” Authentication Endpoints (/api/auth)

Method Endpoint Description Auth Required
POST /auth/signup User registration โŒ
POST /auth/login User login โŒ
POST /auth/logout User logout โœ…
GET /auth/verifyToken Verify JWT token โœ…
POST /auth/forgot-password Request password reset โŒ
POST /auth/reset-password Reset password with token โŒ

๐Ÿ‘ค Profile Endpoints (/api/v1/profile)

Method Endpoint Description Auth Required
GET /profile Get user profile โœ…
PUT /profile Update user profile โœ…

๐Ÿช Restaurant Management (/api/v1/restaurants)

Method Endpoint Description Auth Required
GET /restaurants Get all user's restaurants โœ…
POST /restaurants Create new restaurant โœ…
GET /restaurants/:restaurantId Get specific restaurant โœ…
PUT /restaurants/:restaurantId Update restaurant โœ…
DELETE /restaurants/:restaurantId Delete restaurant โœ…

๐Ÿ“Š Analytics (/api/v1/restaurants/:restaurantId/analytics)

Method Endpoint Description Auth Required
GET /analytics Get restaurant analytics โœ…

๐Ÿ‘ฅ User Management (/api/v1/restaurants/:restaurantId/user)

Method Endpoint Description Auth Required
GET /user Get all restaurant users โœ…
POST /user Create new user โœ…
GET /user/:userId Get specific user โœ…
PUT /user/:userId Update user โœ…
DELETE /user/:userId Delete user โœ…

๐Ÿช‘ Table Management (/api/v1/restaurants/:restaurantId/table)

Method Endpoint Description Auth Required
GET /table Get all restaurant tables โœ…
POST /table Create new table โœ…
GET /table/:tableId Get specific table โœ…
PUT /table/:tableId Update table โœ…
DELETE /table/:tableId Delete table โœ…
GET /table/search Search tables by keyword โœ…

๐Ÿ“‹ Menu Management (/api/v1/restaurants/:restaurantId/menu)

Method Endpoint Description Auth Required
GET /menu Get restaurant menus โœ…
POST /menu Create new menu โœ…
GET /menu/:menuId Get specific menu โœ…
DELETE /menu/:menuId Delete menu โœ…

๐Ÿฝ๏ธ Menu Item Management (/api/v1/restaurants/:restaurantId/menu/:menuId/menuItem)

Method Endpoint Description Auth Required
GET /menuItem Get all menu items โœ…
POST /menuItem Create new menu item โœ…
GET /menuItem/:menuItemId Get specific menu item โœ…
PUT /menuItem/:menuItemId Update menu item โœ…
DELETE /menuItem/:menuItemId Delete menu item โœ…
PATCH /menuItem/:menuItemId/field Update specific field โœ…

๐Ÿ“… Reservation Management (/api/v1/restaurants/:restaurantId/reservations)

Method Endpoint Description Auth Required
GET /reservations Get all reservations โœ…
POST /reservations Create new reservation โœ…
GET /reservations/search Search reservations โœ…
GET /reservations/:reservationId Get specific reservation โœ…
PUT /reservations/:reservationId Update reservation โœ…
DELETE /reservations/:reservationId Delete reservation โœ…
PUT /reservations/:reservationId/assign-table Assign table to reservation โœ…
PUT /reservations/:reservationId/completed Mark reservation as completed โœ…
PUT /reservations/:reservationId/cancel Cancel reservation โœ…

๐Ÿ›’ Order Management (/api/v1/restaurants/:restaurantId/reservations/:reservationId/order)

Method Endpoint Description Auth Required
POST /order Create new order โœ…
GET /order/:orderId Get specific order โœ…
PUT /order/:orderId Update order โœ…
PUT /order/:orderId/complete Complete order โœ…
GET /order Get all orders for reservation โœ…

๐Ÿ’ฐ Bill Management (/api/v1/restaurants/:restaurantId/reservations/:reservationId/order/:orderId/bill)

Method Endpoint Description Auth Required
POST /bill Create bill for order โœ…
GET /bill/:billId Get specific bill โœ…
GET /bill/order/:orderId Get bill by order ID โœ…

๐Ÿ’ณ Payment Management (/api/v1/restaurants/:restaurantId/reservations/:reservationId/order/:orderId/bill/:billId/payment)

Method Endpoint Description Auth Required
POST /payment Process payment โœ…

๐Ÿ”ง Admin Endpoints (/api/admin)

Method Endpoint Description Auth Required
GET /admin/* Admin panel routes โœ… (Admin only)

Request/Response Flow

Authentication Flow

  1. User calls POST /api/auth/signup or POST /api/auth/login
  2. Server validates credentials and returns JWT token
  3. Token stored in HTTP-only cookie
  4. Protected routes validate JWT via restrictToLoggedInUser.js
  5. User info stored in res.locals.user

Restaurant-Scoped Resource Access

  1. User accesses /api/v1/restaurants/:restaurantId/*
  2. validateParam("restaurantId") validates the restaurant ID
  3. isRestaurantExist checks if restaurant exists
  4. checkRestaurantOwnership verifies user owns/can access restaurant
  5. Route handler processes the request

Security & Middleware

Authentication & Authorization

  • JWT Authentication: All v1 routes require valid JWT token
  • Restaurant Ownership: Users can only access their own restaurants
  • Parameter Validation: All route parameters validated for type/format
  • Request Validation: All request bodies validated with Joi schemas

Security Features

  • Rate limiting to prevent API abuse
  • CORS protection for cross-origin requests
  • Request body validation to prevent injection
  • Centralized error handling to prevent data leaks
  • HTTP-only cookies for secure token storage

Setup & Installation

  1. Clone the repository:

    git clone <repo-url>
    cd Restofy/back-end
  2. Install dependencies:

    npm install
  3. Setup environment:

    cp env.example .env
    # Edit .env with your database URL and other configs
  4. Setup database:

    npx prisma migrate dev
    npx prisma generate
  5. Start the server:

    npm run dev        # Development mode
    npm start          # Production mode

๐Ÿš€ Quick Start

Prerequisites

  • Node.js 18+
  • PostgreSQL 13+
  • RabbitMQ 3.8+
  • Docker & Docker Compose (optional)

1. Clone Repository

git clone <repository-url>
cd Restofy

2. Backend Setup

cd back-end
npm install
cp env.example .env
# Edit .env with your database and service configurations
npx prisma migrate dev
npx prisma generate
npm run start:dev

3. Frontend Setup

cd front-end
npm install
cp .env.example .env
# Edit .env with your API base URL
npm run dev

4. Notification Service Setup

cd notification-service
npm install
cp .env.example .env
# Edit .env with your configurations
npx prisma migrate dev
npx prisma generate
npm run start:dev

5. Docker Setup (Alternative)

# From project root
docker-compose up --build

๐Ÿ”ง Environment Variables

Backend (.env)

# Database
DATABASE_URL="postgresql://username:password@localhost:5432/restofy_db"

# JWT
JWT_SECRET="your-secret-key"
JWT_EXPIRES_IN="1h"

# RabbitMQ
RABBITMQ_URL="amqp://localhost:5672"

# Server
PORT=3001
NODE_ENV="development"

# Frontend URL
CLIENT_FRONTEND_URL="http://localhost:5173"

Frontend (.env)

VITE_API_BASE_URL="http://localhost:3001"

Notification Service (.env)

# Database
DATABASE_URL="postgresql://username:password@localhost:5432/notification_db"

# RabbitMQ
RABBITMQ_URL="amqp://localhost:5672"

# Email
EMAIL_USERNAME="your-email@gmail.com"
EMAIL_PASSWORD="your-app-password"

# JWT
JWT_SECRET="your-secret-key"

# Frontend URL
CLIENT_FRONTEND_URL="http://localhost:5173"

Database Schema (Prisma)

  • RestaurantOwner: ownerId, ownerName, ownerEmail, ...
  • Restaurant: restaurantId, restaurantName, ownerId, ...
  • Table: id, tableName, tableCapacity, restaurantId, ...
  • Reservation: id, firstName, lastName, reservationTime, tableId, restaurantId, ...
  • Menu: id, restaurantId, ...
  • MenuItem: id, itemName, itemPrice, menuId, ...
  • RestaurantStaff: id, staffName, staffEmail, staffRole, restaurantId, ...

See infrastructure/database/prisma/schema.prisma for full details.


๐Ÿ” Authentication & Authorization

User Roles

  • Owner: Full access to their restaurants
  • Manager: Full access within assigned restaurants
  • Staff: Limited access (read + specific updates)
  • Customer: Basic access for reservations

Permission System

The system uses a granular permission-based access control:

  • CAN_CREATE_RESTAURANT
  • CAN_VIEW_RESTAURANT
  • CAN_UPDATE_RESTAURANT
  • CAN_DELETE_RESTAURANT
  • CAN_CREATE_RESERVATION
  • CAN_VIEW_RESERVATION
  • CAN_UPDATE_RESERVATION
  • CAN_DELETE_RESERVATION
  • CAN_ASSIGN_RESERVATION_TO_TABLE
  • CAN_MARK_RESERVATION_COMPLETED
  • CAN_CANCEL_RESERVATION
  • CAN_SEARCH_RESERVATION

๐Ÿ”„ Event-Driven Architecture

Message Flow

  1. Backend publishes events to RabbitMQ
  2. Notification Service consumes events
  3. Email notifications sent to users
  4. Invoice PDFs generated and attached

Event Types

  • Order created
  • Payment completed
  • Reservation confirmed
  • Bill generated

API Documentation

All endpoints are prefixed with /api/v1.

Auth

  • POST /api/auth/signup โ€” Register a new user (owner)
  • POST /api/auth/login โ€” Login, returns JWT cookie
  • GET /api/auth/verifyToken โ€” Verify JWT

Restaurants

  • GET /api/v1/restaurants โ€” List all restaurants for the authenticated user
  • POST /api/v1/restaurants โ€” Create a new restaurant
  • GET /api/v1/restaurants/:restaurantId โ€” Get a specific restaurant
  • PUT /api/v1/restaurants/:restaurantId โ€” Update a restaurant
  • DELETE /api/v1/restaurants/:restaurantId โ€” Delete a restaurant

Tables

  • GET /api/v1/restaurants/:restaurantId/table โ€” List all tables for a restaurant
  • POST /api/v1/restaurants/:restaurantId/table โ€” Create a table
  • GET /api/v1/restaurants/:restaurantId/table/:tableId โ€” Get a specific table
  • PUT /api/v1/restaurants/:restaurantId/table/:tableId โ€” Update a table
  • DELETE /api/v1/restaurants/:restaurantId/table/:tableId โ€” Delete a table

Menus

  • POST /api/v1/restaurants/:restaurantId/menu โ€” Create a menu
  • GET /api/v1/restaurants/:restaurantId/menu/:menuId โ€” Get a menu
  • DELETE /api/v1/restaurants/:restaurantId/menu/:menuId โ€” Delete a menu

Menu Items

  • GET /api/v1/restaurants/:restaurantId/menu/:menuId/menuItem โ€” List menu items
  • POST /api/v1/restaurants/:restaurantId/menu/:menuId/menuItem โ€” Create a menu item
  • GET /api/v1/restaurants/:restaurantId/menu/:menuId/menuItem/:menuItemId โ€” Get a menu item
  • PUT /api/v1/restaurants/:restaurantId/menu/:menuId/menuItem/:menuItemId โ€” Update a menu item
  • DELETE /api/v1/restaurants/:restaurantId/menu/:menuId/menuItem/:menuItemId โ€” Delete a menu item

Reservations

  • GET /api/v1/restaurants/:restaurantId/reservations โ€” List reservations
  • POST /api/v1/restaurants/:restaurantId/reservations โ€” Create a reservation
  • GET /api/v1/restaurants/:restaurantId/reservations/:reservationId โ€” Get a reservation
  • PUT /api/v1/restaurants/:restaurantId/reservations/:reservationId โ€” Update a reservation
  • DELETE /api/v1/restaurants/:restaurantId/reservations/:reservationId โ€” Delete a reservation

Orders

  • POST /api/v1/restaurants/:restaurantId/reservations/:reservationId/order โ€” Create an order
  • GET /api/v1/restaurants/:restaurantId/reservations/:reservationId/order/:orderId โ€” Get an order
  • PUT /api/v1/restaurants/:restaurantId/reservations/:reservationId/order/:orderId โ€” Update an order

Bills

  • POST /api/v1/restaurants/:restaurantId/reservations/:reservationId/order/:orderId/bill โ€” Create a bill
  • GET /api/v1/restaurants/:restaurantId/reservations/:reservationId/order/:orderId/bill/:billId โ€” Get a bill

Payments

  • POST /api/v1/restaurants/:restaurantId/reservations/:reservationId/order/:orderId/bill/:billId/payment โ€” Make a payment

Security & Middleware

Authentication Flow

  1. User signs up/logs in โ†’ receives JWT token
  2. Token stored in HTTP-only cookie
  3. Every protected route validates JWT
  4. User info stored in res.locals.user

Authorization (RBAC)

  • OWNER: Full access to their restaurants
  • MANAGER: Full access within assigned restaurants
  • STAFF: Limited access (read + specific updates)
  • ADMIN: Administrative functions

Security Features

  • JWT-based authentication
  • Role-based access control
  • Request validation with Joi
  • Rate limiting (prevent API abuse)
  • CORS protection
  • Security headers with Helmet
  • Centralized error handling

Request Validation

All create/update endpoints validate input using Joi schemas located in src/reqBodyValidation/.


Error Handling & Logging

  • Centralized Error Handling: All errors processed by errorHandler.js
  • Async Error Boundary: Automatic async error catching
  • Consistent Error Responses: Standardized error format across API
  • Request Validation: Joi validation with detailed error messages
  • HTTP Status Codes: Proper status codes for different error types

Validation Strategy

All endpoints use Joi schemas from reqBodyValidation/:

  • Request Body Validation: Validates POST/PUT request data
  • Parameter Validation: Validates URL parameters (IDs, etc.)
  • Required Field Checking: Ensures required fields are present
  • Data Type Validation: Enforces correct data types
  • Business Rule Validation: Custom validation rules

Best Practices Implemented

  • Domain-Driven Design: Clear business domain separation
  • Security First: Authentication and authorization on all protected routes
  • Consistent API Design: Standardized request/response patterns
  • Error Handling: Comprehensive error catching and reporting
  • Validation: Input validation on all endpoints
  • Modular Architecture: Easy to maintain and extend

Future Enhancements

See future.md for planned features:

  • Unit and integration testing with Jest
  • API documentation with Swagger
  • Logging with Winston
  • Caching with Redis
  • File upload capabilities
  • Email notifications
  • Advanced RBAC with staff roles

๐Ÿš€ Deployment

Production Build

# Backend
cd back-end
npm run build
npm start

# Frontend
cd front-end
npm run build
# Serve with Nginx

# Notification Service
cd notification-service
npm start

Docker Deployment

docker-compose -f docker-compose.prod.yml up -d

๐Ÿค Contributing

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

๐Ÿ“ License

This project is licensed under the ISC License.


๐Ÿ‘จโ€๐Ÿ’ป Author

Mohit Kumar


๐Ÿ†˜ Support

For support and questions:

  • Create an issue in the repository
  • Check the BLOCKERS.md for known issues
  • Review the LEARNING_GUIDE.md for development resources

๐Ÿ”ฎ Future Enhancements

See future.md for planned features:

  • Real-time notifications with WebSockets
  • Mobile app development
  • Advanced analytics dashboard
  • Multi-language support
  • Integration with payment gateways
  • Inventory management
  • Staff scheduling system

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Used by

Contributors

Languages