A comprehensive web-based cafΓ© management system built with Flask, MySQL, HTML, CSS, and JavaScript. This system manages users, menu items, table bookings, and orders with automated triggers and real-time statistics.
- User Management: Create and manage guest users identified by a GuestIdentifier
- Menu Management: Add and manage menu items with categories, prices, and stock tracking
- Table Booking: Book tables with automatic conflict prevention
- Order Management: Place orders linked to tables and users
- Real-time Statistics: Dashboard showing tables booked in past 2 months and most popular items
- Database Triggers: Automated triggers for double-booking prevention and total amount calculation
- Modern UI: Beautiful, responsive design with smooth animations
-
USERS
- UserID (Primary Key)
- GuestIdentifier
- CreatedAt
-
MENU_ITEMS
- ItemID (Primary Key)
- Name
- Price
- Stock
- Category
- IsAvailable
-
BOOKED_TABLES
- TableID (Primary Key)
- UserID (Foreign Key β USERS)
- SessionStartTime
- TotalAmount
-
ORDER_ITEMS
- OrderItemID (Primary Key)
- ItemID (Foreign Key β MENU_ITEMS)
- TableID (Foreign Key β BOOKED_TABLES)
- UserID (Foreign Key β USERS)
- Quantity
- UnitPrice
- OrderedAt
- USERS β BOOKED_TABLES (1:M)
- USERS β ORDER_ITEMS (1:M)
- MENU_ITEMS β ORDER_ITEMS (1:M)
- BOOKED_TABLES β ORDER_ITEMS (1:M)
-
prevent_double_booking: Prevents booking a table that's already in use
- Fires: BEFORE INSERT on BOOKED_TABLES
- Error Message: "This table is already in use."
-
update_table_total: Updates TotalAmount when order items are added
- Fires: AFTER INSERT on ORDER_ITEMS
-
update_table_total_on_update: Updates TotalAmount when order items are modified
- Fires: AFTER UPDATE on ORDER_ITEMS
-
update_table_total_on_delete: Updates TotalAmount when order items are removed
- Fires: AFTER DELETE on ORDER_ITEMS
- ClearTable: Removes a booked table and all associated orders (cascading delete)
- Python 3.8 or higher
- MySQL Server (with MySQL Workbench or command line access)
- pip (Python package manager)
Navigate to the project directory:
cd dbms1pip install -r requirements.txt-
Open MySQL Workbench (or MySQL command line)
-
Create the database:
CREATE DATABASE cafe_management;- Run the schema file:
- Open
database/schema.sqlin MySQL Workbench - Execute the entire script
- This will create all tables, triggers, and sample data
- Open
- Copy
env.exampleto.env:
copy env.example .env # Windows
# or
cp env.example .env # Linux/Mac- Edit
.envand update with your MySQL credentials:
DB_HOST=localhost
DB_USER=root
DB_PASSWORD=your_password_here
DB_NAME=cafe_management
DB_PORT=3306
python app.pyThe application will start on http://localhost:5000
- Open your web browser
- Navigate to
http://localhost:5000 - The homepage will display:
- Dashboard statistics (tables booked, most popular item)
- Currently booked tables
- Menu items
- Recent orders
- Click "Book New Table" button
- Enter Table ID and User ID
- Click "Book Table"
- If table is already booked, you'll see: "This table is already in use."
- Click "Place Order" on any booked table
- Select menu item, enter quantity
- Click "Place Order"
- Total amount is automatically calculated
- Click "Clear Table" on any booked table
- Confirm the action
- Table and all associated orders will be removed
- Tables Booked: Shows count of tables booked in the past 2 months
- Most Popular Item: Shows the most frequently ordered item
SELECT COUNT(DISTINCT TableID) AS TablesBooked
FROM BOOKED_TABLES
WHERE SessionStartTime >= DATE_SUB(NOW(), INTERVAL 2 MONTH);SELECT
mi.Name AS ItemName,
SUM(oi.Quantity) AS TotalQuantity,
COUNT(oi.OrderItemID) AS OrderCount
FROM ORDER_ITEMS oi
JOIN MENU_ITEMS mi ON oi.ItemID = mi.ItemID
GROUP BY mi.ItemID, mi.Name
ORDER BY TotalQuantity DESC
LIMIT 1;dbms1/
βββ app.py # Flask backend application
βββ requirements.txt # Python dependencies
βββ .env.example # Environment variables template
βββ README.md # This file
βββ database/
β βββ schema.sql # Database schema, triggers, sample data
β βββ ER_Diagram.md # ER diagram documentation
βββ templates/
β βββ index.html # Main HTML template
βββ static/
βββ css/
β βββ style.css # CSS styling
βββ js/
βββ main.js # JavaScript functionality
- Backend: Python Flask
- Database: MySQL (via MySQL Workbench)
- Frontend: HTML5, CSS3, JavaScript (Vanilla)
- Database Driver: mysql-connector-python
GET /api/stats/tables-booked- Get tables booked in past 2 monthsGET /api/stats/tables-booked-current- Get number of tables currently bookedGET /api/stats/most-popular-item- Get most popular menu item
GET /api/users- Get all usersPOST /api/users- Create new user
GET /api/menu-items- Get all menu itemsPOST /api/menu-items- Create new menu item
GET /api/tables- Get all booked tablesPOST /api/tables- Book a new tablePOST /api/tables/<table_id>/clear- Clear a table
GET /api/orders- Get all ordersPOST /api/orders- Create new orderGET /api/tables/<table_id>/orders- Get orders for a table
- Verify MySQL server is running
- Check
.envfile has correct credentials - Ensure database
cafe_managementexists
- Verify triggers were created successfully:
SHOW TRIGGERS;- Change port in
app.py:
app.run(debug=True, host='0.0.0.0', port=5001)- The system uses cascading deletes: When a table is cleared, all associated order items are automatically deleted
- Total amount for each table is automatically calculated via triggers
- Only available menu items are displayed for ordering
- Tables must be booked before orders can be placed
To modify the database schema:
- Update
database/schema.sql - Re-run the schema in MySQL Workbench
- Restart the Flask application
This project is created for educational purposes.
Enjoy managing your cafΓ©! β