Skip to content

laladwesh/realtime-pizza

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

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

Repository files navigation

πŸ• Realtime Pizza - Full Stack Pizza Ordering Application

Live Demo JavaScript Node.js Express.js MongoDB Socket.io

A modern, full-stack real-time pizza ordering application built with Node.js, Express, MongoDB, and Socket.io

Features β€’ Demo β€’ Installation β€’ Usage β€’ API Documentation β€’ Contributing


πŸ“– Table of Contents


🌟 Overview

Realtime Pizza is a comprehensive, full-stack web application that allows users to order pizzas online with real-time order tracking. Built with modern web technologies, it provides a seamless experience from browsing the menu to receiving live updates about order status.

The application features a responsive design, secure user authentication, real-time notifications, and an intuitive admin panel for order management. It is designed to handle the complete pizza ordering workflow with real-time communication between customers and administrators.

🎯 Key Highlights

  • Real-time Order Tracking: Live updates using Socket.io for instant order status changes
  • Secure Authentication: Passport.js integration with bcrypt password hashing
  • Responsive Design: Tailwind CSS for mobile-first, responsive UI
  • Admin Dashboard: Complete order management system for administrators
  • Session Management: Persistent shopping cart with MongoDB session store
  • Modern Architecture: Clean MVC architecture with Express.js and EJS templating

✨ Features

πŸ›’ Customer Features

  • Browse Menu: View all available pizzas with images, prices, and descriptions
  • Shopping Cart: Add/remove items with persistent session storage
  • User Authentication: Secure login and registration system
  • Order Placement: Place orders with delivery information
  • Real-time Tracking: Live order status updates (Placed β†’ Confirmed β†’ Prepared β†’ Delivered)
  • Order History: View past orders and their details
  • Responsive Design: Optimized for desktop, tablet, and mobile devices

πŸ‘¨β€πŸ’Ό Admin Features

  • Order Management: View all orders in a comprehensive dashboard
  • Status Updates: Change order status with real-time customer notifications
  • Real-time Notifications: Instant alerts for new orders
  • Order Analytics: View order details, customer information, and timestamps
  • Secure Access: Admin-only routes with authentication middleware

πŸ”§ Technical Features

  • Real-time Communication: WebSocket connections for live updates
  • Session Persistence: Shopping cart data preserved across sessions
  • Security: Password hashing, session management, and route protection
  • Database Integration: MongoDB with Mongoose ODM
  • Asset Compilation: Laravel Mix for SCSS and JavaScript bundling
  • Deployment Ready: Configured for Vercel deployment

πŸ—οΈ Architecture

The application follows a traditional MVC (Model-View-Controller) architecture with the following components:

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚   Frontend      β”‚    β”‚   Backend       β”‚    β”‚   Database      β”‚
β”‚                 β”‚    β”‚                 β”‚    β”‚                 β”‚
β”‚ β€’ EJS Templates β”‚    β”‚ β€’ Express.js    β”‚    β”‚ β€’ MongoDB       β”‚
β”‚ β€’ Tailwind CSS  │◄──►│ β€’ Socket.io     │◄──►│ β€’ Mongoose      β”‚
β”‚ β€’ Vanilla JS    β”‚    β”‚ β€’ Passport.js   β”‚    β”‚ β€’ Session Store β”‚
β”‚ β€’ Axios         β”‚    β”‚ β€’ Middleware    β”‚    β”‚                 β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

πŸ› οΈ Tech Stack

Backend

  • Node.js - Runtime environment
  • Express.js - Web application framework
  • MongoDB - NoSQL database
  • Mongoose - MongoDB object modeling
  • Socket.io - Real-time bidirectional communication
  • Passport.js - Authentication middleware
  • bcrypt - Password hashing
  • express-session - Session management
  • connect-mongo - MongoDB session store

Frontend

  • EJS - Templating engine
  • Tailwind CSS - Utility-first CSS framework
  • Vanilla JavaScript - Client-side scripting
  • Axios - HTTP client for API requests
  • Noty - Notification library
  • Moment.js - Date manipulation

Development Tools

  • Laravel Mix - Asset compilation
  • Sass - CSS preprocessor
  • Nodemon - Development server
  • cross-env - Environment variable management

Deployment

  • Vercel - Hosting platform
  • MongoDB Atlas - Cloud database

⚑ Quick Start

# Clone the repository
git clone https://github.com/laladwesh/realtime-pizza.git

# Navigate to project directory
cd realtime-pizza

# Install dependencies
npm install

# Set up environment variables
cp .env.example .env
# Edit .env with your configuration

# Start development server
npm run dev

# Visit http://localhost:3000

πŸ”§ Installation

Prerequisites

Before you begin, ensure you have the following installed:

  • Node.js (v14.0.0 or higher)
  • npm (v6.0.0 or higher)
  • MongoDB (v4.0.0 or higher) or MongoDB Atlas account
  • Git

Step-by-Step Installation

  1. Clone the Repository

    git clone https://github.com/laladwesh/realtime-pizza.git
    cd realtime-pizza
  2. Install Dependencies

    npm install
  3. Environment Setup

    Create a .env file in the root directory:

    # Database Configuration
    MONGO_CONNECTION_URL=mongodb://localhost:27017/realtime-pizza
    # For MongoDB Atlas:
    # MONGO_CONNECTION_URL=mongodb+srv://username:password@cluster.mongodb.net/realtime-pizza
    
    # Session Secret
    COOKIE_SECRET=your-super-secret-cookie-key
    
    # Application Port
    PORT=3000
    
    # Node Environment
    NODE_ENV=development
  4. Database Setup

    If using local MongoDB:

    # Start MongoDB service
    mongod
    
    # Create database (optional - will be created automatically)
    mongo
    > use realtime-pizza
  5. Compile Assets

    npm run development
  6. Start the Application

    # Development mode with auto-restart
    npm run dev
    
    # Production mode
    npm start
  7. Access the Application

    Open your browser and navigate to http://localhost:3000


πŸš€ Usage

For Customers

  1. Browse Menu

    • Visit the homepage to view available pizzas
    • Each pizza displays name, image, size, and price
  2. Add to Cart

    • Click the '+' button to add pizzas to your cart
    • Cart counter updates in real-time
  3. Create Account

    • Register a new account or login to existing account
    • Required for placing orders
  4. Place Order

    • Go to cart page and proceed to checkout
    • Fill in delivery details and place order
  5. Track Order

    • View real-time order status updates
    • Receive notifications for status changes

For Administrators

  1. Admin Access

    • Login with admin credentials
    • Access admin dashboard at /admin/orders
  2. Manage Orders

    • View all orders with customer details
    • Update order status using dropdown menus
    • Orders automatically notify customers of changes

πŸ“‚ Project Structure

realtime-pizza/
β”œβ”€β”€ πŸ“ app/
β”‚   β”œβ”€β”€ πŸ“ config/
β”‚   β”‚   └── passport.js           # Passport authentication configuration
β”‚   β”œβ”€β”€ πŸ“ http/
β”‚   β”‚   β”œβ”€β”€ πŸ“ controllers/
β”‚   β”‚   β”‚   β”œβ”€β”€ πŸ“ admin/
β”‚   β”‚   β”‚   β”‚   β”œβ”€β”€ orderController.js
β”‚   β”‚   β”‚   β”‚   └── statusController.js
β”‚   β”‚   β”‚   β”œβ”€β”€ πŸ“ customers/
β”‚   β”‚   β”‚   β”‚   β”œβ”€β”€ cartController.js
β”‚   β”‚   β”‚   β”‚   └── orderController.js
β”‚   β”‚   β”‚   β”œβ”€β”€ authController.js
β”‚   β”‚   β”‚   └── homeController.js
β”‚   β”‚   └── πŸ“ middleware/
β”‚   β”‚       β”œβ”€β”€ admin.js          # Admin route protection
β”‚   β”‚       β”œβ”€β”€ auth.js           # Authentication middleware
β”‚   β”‚       └── guest.js          # Guest route protection
β”‚   └── πŸ“ models/
β”‚       β”œβ”€β”€ menu.js               # Pizza menu model
β”‚       β”œβ”€β”€ order.js              # Order model
β”‚       └── user.js               # User model
β”œβ”€β”€ πŸ“ public/                    # Compiled assets
β”‚   β”œβ”€β”€ πŸ“ css/
β”‚   β”œβ”€β”€ πŸ“ js/
β”‚   └── πŸ“ img/
β”œβ”€β”€ πŸ“ resources/
β”‚   β”œβ”€β”€ πŸ“ js/
β”‚   β”‚   β”œβ”€β”€ admin.js              # Admin dashboard JavaScript
β”‚   β”‚   └── app.js                # Main application JavaScript
β”‚   β”œβ”€β”€ πŸ“ scss/
β”‚   β”‚   └── app.scss              # Main stylesheet
β”‚   └── πŸ“ views/
β”‚       β”œβ”€β”€ πŸ“ admin/
β”‚       β”œβ”€β”€ πŸ“ auth/
β”‚       β”œβ”€β”€ πŸ“ customers/
β”‚       β”œβ”€β”€ πŸ“ errors/
β”‚       β”œβ”€β”€ πŸ“ layouts/
β”‚       └── home.ejs
β”œβ”€β”€ πŸ“ routes/
β”‚   └── web.js                    # Application routes
β”œβ”€β”€ πŸ“„ index.js                   # Main application entry point
β”œβ”€β”€ πŸ“„ package.json               # Dependencies and scripts
β”œβ”€β”€ πŸ“„ webpack.mix.js             # Asset compilation configuration
β”œβ”€β”€ πŸ“„ vercel.json                # Vercel deployment configuration
└── πŸ“„ .env                       # Environment variables

πŸ”Œ API Endpoints

Public Routes

Method Endpoint Description
GET / Homepage with pizza menu
GET /login Login page
POST /login User authentication
GET /register Registration page
POST /register User registration
POST /logout User logout
GET /cart Shopping cart page
POST /update-cart Add items to cart

Protected Customer Routes

Method Endpoint Description
POST /orders Place new order
GET /customer/orders View order history
GET /customer/orders/:id View specific order

Admin Routes

Method Endpoint Description
GET /admin/orders Admin dashboard
POST /admin/order/status Update order status

🎨 Frontend Components

Main JavaScript Features

  • Cart Management: Real-time cart updates using Axios
  • Order Tracking: Live order status updates via Socket.io
  • Notifications: Toast notifications using Noty library
  • Admin Dashboard: Dynamic order table with real-time updates

Styling

  • Tailwind CSS: Utility-first CSS framework
  • Responsive Design: Mobile-first approach
  • Custom SCSS: Additional styling with Sass preprocessing

πŸ“± Real-time Features

The application uses Socket.io for real-time communication:

Client-side Events

// Join order room for updates
socket.emit('join', `order_${orderId}`)

// Listen for order updates
socket.on('orderUpdated', (data) => {
    // Update order status in real-time
})

// Admin joins admin room
socket.emit('join', 'adminRoom')

// Listen for new orders (admin)
socket.on('orderPlaced', (order) => {
    // Add new order to admin dashboard
})

Server-side Events

// Order status update
eventEmitter.on('orderUpdated', (data) => {
    io.to(`order_${data.id}`).emit('orderUpdated', data)
})

// New order placed
eventEmitter.on('orderPlaced', (data) => {
    io.to('adminRoom').emit('orderPlaced', data)
})

πŸ” Authentication & Security

Security Features

  • Password Hashing: bcrypt with salt rounds
  • Session Management: Secure session storage in MongoDB
  • Route Protection: Middleware for authenticated and admin routes
  • CSRF Protection: Express session-based protection
  • Input Validation: Server-side validation for all inputs

User Roles

  • Customer: Can browse, order, and track pizzas
  • Admin: Can manage orders and update status

πŸ“Š Database Schema

User Model

{
  name: String (required),
  email: String (required, unique),
  password: String (required, hashed),
  role: String (default: 'customer'),
  timestamps: true
}

Menu Model

{
  name: String (required),
  image: String (required),
  price: Number (required),
  size: String (required)
}

Order Model

{
  customerId: ObjectId (ref: 'User'),
  items: Object (required),
  phone: Number (required),
  address: String (required),
  paymentType: String (default: 'COD'),
  status: String (default: 'order_placed'),
  timestamps: true
}

🎯 Environment Variables

Create a .env file with the following variables:

# Database
MONGO_CONNECTION_URL=mongodb://localhost:27017/realtime-pizza

# Session
COOKIE_SECRET=your-super-secret-key-here

# Application
PORT=3000
NODE_ENV=development

# Optional: Email configuration for notifications
EMAIL_HOST=smtp.gmail.com
EMAIL_PORT=587
EMAIL_USER=your-email@gmail.com
EMAIL_PASS=your-app-password

🐳 Docker Support

Dockerfile

FROM node:16-alpine

WORKDIR /app

COPY package*.json ./
RUN npm ci --only=production

COPY . .

RUN npm run production

EXPOSE 3000

CMD ["npm", "start"]

Docker Compose

version: '3.8'
services:
  app:
    build: .
    ports:
      - "3000:3000"
    environment:
      - MONGO_CONNECTION_URL=mongodb://mongo:27017/realtime-pizza
      - COOKIE_SECRET=your-secret-key
    depends_on:
      - mongo
  
  mongo:
    image: mongo:5
    ports:
      - "27017:27017"
    volumes:
      - mongo_data:/data/db

volumes:
  mongo_data:

πŸ“ Scripts

{
  "start": "node index.js",
  "dev": "nodemon server.js",
  "serve": "node server.js",
  "development": "cross-env NODE_ENV=development webpack",
  "watch": "npm run development -- --watch",
  "production": "cross-env NODE_ENV=production webpack",
  "test": "jest",
  "test:watch": "jest --watch"
}

πŸ§ͺ Testing

Running Tests

# Run all tests
npm test

# Run tests in watch mode
npm run test:watch

# Run tests with coverage
npm run test:coverage

Test Structure

  • Unit Tests: Controller and model testing
  • Integration Tests: Route and middleware testing
  • E2E Tests: Complete user flow testing

πŸš€ Deployment

Vercel Deployment

  1. Install Vercel CLI

    npm i -g vercel
  2. Deploy

    vercel
  3. Environment Variables Set environment variables in Vercel dashboard:

    • MONGO_CONNECTION_URL
    • COOKIE_SECRET

Other Platforms

  • Heroku: Add Procfile with web: node index.js
  • Railway: Connect GitHub repository
  • DigitalOcean: Use App Platform
  • AWS: Deploy using Elastic Beanstalk

🀝 Contributing

We welcome contributions! Please follow these steps:

  1. Fork the Repository

    git fork https://github.com/laladwesh/realtime-pizza.git
  2. Create Feature Branch

    git checkout -b feature/amazing-feature
  3. Commit Changes

    git commit -m 'Add amazing feature'
  4. Push to Branch

    git push origin feature/amazing-feature
  5. Open Pull Request

Contribution Guidelines

  • Follow the existing code style
  • Add tests for new features
  • Update documentation as needed
  • Use conventional commit messages

πŸ“„ License

This project is licensed under the ISC License. See the LICENSE file for details.


πŸ‘¨β€πŸ’» Author

Laladwesh


πŸ™ Acknowledgments


⭐ Star this repository if you found it helpful!

Made with ❀️ by Laladwesh

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages