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
- π Realtime Pizza - Full Stack Pizza Ordering Application
- π Table of Contents
- π Overview
- β¨ Features
- π― Demo
- ποΈ Architecture
- π οΈ Tech Stack
- β‘ Quick Start
- π§ Installation
- π Usage
- π Project Structure
- π API Endpoints
- π¨ Frontend Components
- π± Real-time Features
- π Authentication & Security
- π Database Schema
- π― Environment Variables
- π³ Docker Support
- π Scripts
- π§ͺ Testing
- π Deployment
- π€ Contributing
- π License
- π¨βπ» Author
- π Acknowledgments
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.
- 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
- 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
- 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
- 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
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 β β β
βββββββββββββββββββ βββββββββββββββββββ βββββββββββββββββββ
- 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
- 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
- Laravel Mix - Asset compilation
- Sass - CSS preprocessor
- Nodemon - Development server
- cross-env - Environment variable management
- Vercel - Hosting platform
- MongoDB Atlas - Cloud database
# 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:3000Before 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
-
Clone the Repository
git clone https://github.com/laladwesh/realtime-pizza.git cd realtime-pizza -
Install Dependencies
npm install
-
Environment Setup
Create a
.envfile 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
-
Database Setup
If using local MongoDB:
# Start MongoDB service mongod # Create database (optional - will be created automatically) mongo > use realtime-pizza
-
Compile Assets
npm run development
-
Start the Application
# Development mode with auto-restart npm run dev # Production mode npm start
-
Access the Application
Open your browser and navigate to
http://localhost:3000
-
Browse Menu
- Visit the homepage to view available pizzas
- Each pizza displays name, image, size, and price
-
Add to Cart
- Click the '+' button to add pizzas to your cart
- Cart counter updates in real-time
-
Create Account
- Register a new account or login to existing account
- Required for placing orders
-
Place Order
- Go to cart page and proceed to checkout
- Fill in delivery details and place order
-
Track Order
- View real-time order status updates
- Receive notifications for status changes
-
Admin Access
- Login with admin credentials
- Access admin dashboard at
/admin/orders
-
Manage Orders
- View all orders with customer details
- Update order status using dropdown menus
- Orders automatically notify customers of changes
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
| 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 |
| Method | Endpoint | Description |
|---|---|---|
| POST | /orders |
Place new order |
| GET | /customer/orders |
View order history |
| GET | /customer/orders/:id |
View specific order |
| Method | Endpoint | Description |
|---|---|---|
| GET | /admin/orders |
Admin dashboard |
| POST | /admin/order/status |
Update order status |
- 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
- Tailwind CSS: Utility-first CSS framework
- Responsive Design: Mobile-first approach
- Custom SCSS: Additional styling with Sass preprocessing
The application uses Socket.io for real-time communication:
// 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
})// 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)
})- 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
- Customer: Can browse, order, and track pizzas
- Admin: Can manage orders and update status
{
name: String (required),
email: String (required, unique),
password: String (required, hashed),
role: String (default: 'customer'),
timestamps: true
}{
name: String (required),
image: String (required),
price: Number (required),
size: String (required)
}{
customerId: ObjectId (ref: 'User'),
items: Object (required),
phone: Number (required),
address: String (required),
paymentType: String (default: 'COD'),
status: String (default: 'order_placed'),
timestamps: true
}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-passwordFROM node:16-alpine
WORKDIR /app
COPY package*.json ./
RUN npm ci --only=production
COPY . .
RUN npm run production
EXPOSE 3000
CMD ["npm", "start"]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:{
"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"
}# Run all tests
npm test
# Run tests in watch mode
npm run test:watch
# Run tests with coverage
npm run test:coverage- Unit Tests: Controller and model testing
- Integration Tests: Route and middleware testing
- E2E Tests: Complete user flow testing
-
Install Vercel CLI
npm i -g vercel
-
Deploy
vercel
-
Environment Variables Set environment variables in Vercel dashboard:
MONGO_CONNECTION_URLCOOKIE_SECRET
- Heroku: Add
Procfilewithweb: node index.js - Railway: Connect GitHub repository
- DigitalOcean: Use App Platform
- AWS: Deploy using Elastic Beanstalk
We welcome contributions! Please follow these steps:
-
Fork the Repository
git fork https://github.com/laladwesh/realtime-pizza.git
-
Create Feature Branch
git checkout -b feature/amazing-feature
-
Commit Changes
git commit -m 'Add amazing feature' -
Push to Branch
git push origin feature/amazing-feature
-
Open Pull Request
- Follow the existing code style
- Add tests for new features
- Update documentation as needed
- Use conventional commit messages
This project is licensed under the ISC License. See the LICENSE file for details.
Laladwesh
- GitHub: @laladwesh
- Project Link: https://github.com/laladwesh/realtime-pizza
- Express.js - Fast, unopinionated web framework.
- Socket.io - Real-time bidirectional communication
- MongoDB - Document database
- Tailwind CSS - Utility-first CSS framework
- Vercel - Deployment platform
- Node.js - JavaScript runtime
- Passport.js - Authentication middleware
β Star this repository if you found it helpful!
Made with β€οΈ by Laladwesh