A complete online food ordering system built with Python and MySQL using only syllabus-approved modules.
restaurant_ordering_system/
├── main.py # Database module with all operations
├── client.py # Console-based client interface
├── database_setup.sql # SQL script for database initialization
├── requirements.txt # Python dependencies
└── README.md # This file
- Programming Language: Python 3.x
- Database: MySQL
- Python Modules:
mysql.connector- MySQL database connectivitycsv- CSV file operationsmath- Mathematical calculationshashlib- Password hashingdatetime- Date and time operationsos- Operating system interfacesys- System-specific functions
Only one external package is required:
pip install mysql-connector-pythonAll other modules (csv, math, hashlib, datetime, os, sys) are built-in Python modules.
You can also create a requirements.txt file:
mysql-connector-python==8.2.0
Then install:
pip install -r requirements.txt- Install MySQL Server on your system
- Open MySQL Command Line or MySQL Workbench
- Run the SQL script:
SOURCE database_setup.sql;Or manually copy and execute the SQL commands from database_setup.sql
Edit main.py and update the database configuration in the RestaurantDatabase class:
self.DB_CONFIG = {
'host': 'localhost',
'user': 'root', # Your MySQL username
'password': 'your_password', # Your MySQL password
'database': 'restaurant_db'
}First, test if the database module works correctly:
python main.pyYou should see:
✓ Database connected successfully!
Database initialized successfully!
python client.pyThe console-based menu system will appear!
- User Registration - Create a new account with name, email, password, phone
- User Login - Secure authentication with SHA-256 hashed passwords
- Browse Menu - View all available items, filter by category
- Add to Cart - Select items and quantities
- View Cart - Review cart with automatic price calculations
- Modify Cart - Update quantities, remove items, clear cart
- Place Order - Confirm and place orders with bill generation
- Order History - View all past orders with details
- Add Menu Items - Add new dishes to the menu
- View All Orders - Monitor all orders in system
- Export Menu - Export menu data to CSV file
- Export Orders - Export order history to CSV file
- View Analytics - See revenue, popular items, category sales
- Password Security: SHA-256 hashing using
hashlibmodule - Tax Calculation: Automatic 5% GST calculation using
math.ceil()for proper rounding - Real-time Calculations: Dynamic price calculations for cart and orders
- Database Transactions: Ensures data consistency during order placement
- CSV Export: Export data using
csvmodule for reports - Error Handling: Comprehensive error handling throughout
users
- user_id (Primary Key, Auto Increment)
- name (VARCHAR 100)
- email (VARCHAR 100, Unique)
- password (VARCHAR 255, Hashed)
- phone (VARCHAR 15)
- created_at (TIMESTAMP)
menu
- item_id (Primary Key, Auto Increment)
- name (VARCHAR 100)
- category (VARCHAR 50)
- price (DECIMAL 10,2)
- availability (BOOLEAN)
- created_at (TIMESTAMP)
orders
- order_id (Primary Key, Auto Increment)
- user_id (Foreign Key → users)
- order_date (TIMESTAMP)
- total_amount (DECIMAL 10,2)
- tax_amount (DECIMAL 10,2)
- final_amount (DECIMAL 10,2)
- status (VARCHAR 20)
order_details
- detail_id (Primary Key, Auto Increment)
- order_id (Foreign Key → orders)
- item_id (Foreign Key → menu)
- quantity (INT)
- price (DECIMAL 10,2)
- subtotal (DECIMAL 10,2)
-
Run the Application
python client.py
-
Register Account
- Select option 1 (Register)
- Enter: Name, Email, Password, Phone
-
Login
- Select option 2 (Login)
- Enter your email and password
-
Browse Menu
- Select option 3 (Browse Menu)
- Choose a category or view all items
-
Order Food
- Select option 4 (Add to Cart)
- Enter item ID and quantity
- Repeat for multiple items
- Select option 5 to view cart
- Select option 7 to place order
-
View Order History
- Select option 8 (Order History)
- See all your past orders
import mysql.connector
from mysql.connector import Error
# Connecting to database
connection = mysql.connector.connect(
host='localhost',
user='root',
password='password',
database='restaurant_db'
)
# Using cursor for queries
cursor = connection.cursor(dictionary=True)
cursor.execute("SELECT * FROM menu")
results = cursor.fetchall()Used for:
- Database connectivity
- Executing SQL queries
- Fetching results
- Transaction management
import csv
# Writing to CSV
with open('menu_export.csv', 'w', newline='') as file:
writer = csv.writer(file)
writer.writerow(['ID', 'Name', 'Price'])
writer.writerows(data)Used for:
- Exporting menu to CSV files
- Exporting orders to CSV files
- Creating reports for analysis
import math
# Tax calculation with proper rounding
total = 1000
tax = math.ceil(total * 0.05 * 100) / 100
# Result: 50.00 (rounded up to 2 decimal places)Used for:
- Calculating GST (5% tax)
- Rounding up amounts using
math.ceil() - Ensuring accurate financial calculations
import hashlib
# Hashing passwords
password = "mypassword"
hashed = hashlib.sha256(password.encode()).hexdigest()
# Result: Secure SHA-256 hashUsed for:
- Password encryption
- Secure user authentication
- Data security
from datetime import datetime
# Timestamps are handled automatically by MySQL
# But datetime can be used for date formatting
current_time = datetime.now()Used for:
- Date and time operations
- Order timestamps
- Time-based queries
import os
import sys
# Clear screen
os.system('cls' if os.name == 'nt' else 'clear')
# Exit program
sys.exit(1)Used for:
- Screen clearing for better UI
- System operations
- Program control flow
The database comes pre-loaded with 18 items across 6 categories:
- Starters: Paneer Tikka (₹250), Chicken Tikka (₹300), Veg Spring Roll (₹180)
- Main Course: Butter Chicken (₹350), Paneer Butter Masala (₹280), Dal Makhani (₹220)
- Rice: Veg Biryani (₹240), Chicken Biryani (₹320), Jeera Rice (₹150)
- Breads: Naan (₹40), Butter Naan (₹50), Garlic Naan (₹60)
- Desserts: Gulab Jamun (₹80), Ice Cream (₹100), Rasgulla (₹70)
- Beverages: Coke (₹40), Lassi (₹60), Fresh Lime Soda (₹50)
This project demonstrates:
-
Python Programming
- Functions and methods
- Object-oriented programming (Classes)
- Error handling (try-except)
- Module imports
- File I/O operations
-
Database Management
- Database connectivity
- CRUD operations (Create, Read, Update, Delete)
- SQL queries (SELECT, INSERT, UPDATE)
- Joins and aggregations
- Foreign key relationships
-
Data Structures
- Lists for cart management
- Dictionaries for data storage
- Tuples from database results
-
Mathematical Operations
- Price calculations
- Tax computation using
math.ceil() - Subtotal and total calculations
-
File Handling
- CSV file creation
- Writing data to files
- Exporting database records
-
Security
- Password hashing with SHA-256
- SQL injection prevention
- Input validation
-
User Interface
- Console-based menu system
- Formatted output
- User input handling
1. Database Connection Error
Error: Can't connect to MySQL server
Solution:
- Verify MySQL is running
- Check username/password in
main.py - Ensure database 'restaurant_db' exists
2. Module Not Found Error
ModuleNotFoundError: No module named 'mysql'
Solution:
pip install mysql-connector-python3. Import Error in client.py
ImportError: No module named 'main'
Solution:
- Ensure
main.pyis in the same directory asclient.py - Run
client.pyfrom the project directory
4. Permission Denied on CSV Export
PermissionError: [Errno 13] Permission denied
Solution:
- Close any CSV files if they're open
- Check folder write permissions
5. Table Already Exists Error
Table 'users' already exists
Solution:
- This is normal if tables were created before
- The application will continue to work
Key Components:
# Database Configuration
DB_CONFIG = {
'host': 'localhost',
'user': 'root',
'password': 'password',
'database': 'restaurant_db'
}
# Password Hashing
def hash_password(self, password):
return hashlib.sha256(password.encode()).hexdigest()
# Tax Calculation with math.ceil
tax = math.ceil(total * 0.05 * 100) / 100Key Features:
# Cart Management
self.cart = [] # List to store cart items
# Adding to cart
self.cart.append({
'item_id': item_id,
'name': item['name'],
'price': float(item['price']),
'quantity': quantity
})
# Order placement with database transaction
result = self.db.place_order(user_id, items)Sample Queries:
-- User Registration
INSERT INTO users (name, email, password, phone)
VALUES (%s, %s, %s, %s)
-- Get Menu Items
SELECT * FROM menu WHERE category = %s AND availability = TRUE
-- Place Order
INSERT INTO orders (user_id, total_amount, tax_amount, final_amount)
VALUES (%s, %s, %s, %s)-
Start with Overview
- Explain the project purpose
- Show the technology stack
- Demonstrate real-world application
-
Database Schema
- Show ER diagram or table relationships
- Explain foreign keys and normalization
- Display sample data
-
Module Explanation
- Explain why each module was used
- Show specific code examples
- Demonstrate module functionality
-
Live Demonstration
- Register a new user
- Browse menu and add items to cart
- Place an order
- Show order in database
- Export data to CSV
-
Security Features
- Demonstrate password hashing
- Show hashed passwords in database
- Explain SQL injection prevention
-
Mathematical Calculations
- Show tax calculation code
- Explain
math.ceil()usage - Demonstrate with examples
-
CSV Export
- Export menu to CSV
- Open and show the file
- Explain practical use cases
Main Menu:
======================================================================
RESTAURANT FOOD ORDERING SYSTEM
======================================================================
Logged in as: John Doe (john@example.com)
Cart items: 2
1. Register
2. Login
3. Browse Menu
4. Add to Cart
5. View Cart
...
Order Confirmation:
======================================================================
ORDER PLACED SUCCESSFULLY!
======================================================================
Order ID: 1
Total: ₹525.00
Payment Mode: Cash on Delivery
Thank you for your order, John Doe!
======================================================================
- GUI using Tkinter
- Payment gateway integration
- Email notifications
- Rating and review system
- Delivery tracking
- Admin dashboard with graphs
- Mobile app integration
- Online payment options
For any issues or questions:
- Check the troubleshooting section
- Verify all modules are installed
- Ensure MySQL is running
- Check database configuration
Before submission, ensure:
- All modules are syllabus-approved
- Database is properly normalized
- Code is well-commented
- All features work correctly
- Security measures implemented
- CSV export functions work
- Documentation is complete
- Sample data is loaded
- Screenshots/outputs prepared
- Presentation ready
Made for Class 12 Computer Science Project (2024-25)
Modules Used (All Syllabus-Approved):
- mysql.connector
- csv
- math
- hashlib
- datetime
- os
- sys