This project implements a NoSQL document-oriented database in MongoDB for a UK-based online shopping and grocery delivery platform. It was developed to simulate the backend data architecture and functionality for an e-commerce business expanding into fresh grocery delivery via a partner model.
The repository includes MongoDB collection modeling, realistic operational queries, data seeding scripts, and command-line interfaces to simulate backend operations like order placement, partner assignment, inventory tracking, and personalized recommendations.
The platform merges two business models:
- Regular Product Orders – Standard e-commerce orders for books, CDs, phones, and appliances.
- Fresh Product Orders – Same-day or instant delivery groceries from local stores in Manchester, handled by delivery partners.
The database is designed to support:
- Multiple product categories with complex metadata
- Fresh product logistics using geo-coordinates
- Real-time order processing and driver assignment
- Customer recommendations based on ratings
- Inventory management
conda activate mongo_venv
- Create a MongoDB Atlas cluster (or run locally)
- Create a database named Amazone
- In scripts/db_connect.py, update your connection string:
conn_str = "mongodb+srv://<ID>:<password>@udatabases.a2oqj.mongodb.net/?retryWrites=true&w=majority&appName=UDatabases"
- Create collections by loading sample data from the data/ folder or through this script
python scripts/seed_database.py
| Collection Name | Description |
|---|---|
amazone_partners |
Delivery partners/drivers with status and live location |
books |
Book products with metadata like author, publisher, ISBN |
cds |
CD products with artist, track count, and duration |
current_orders |
Active (pending/confirmed) customer orders |
customer_address |
One-to-many addresses linked to customers (billing/shipping) |
customers |
Customer data including demographics, ID, and recommendation list |
daily_inventory_level |
Historical inventory levels by warehouse and product |
delivery_records |
Records of past deliveries, possibly for partner payout tracking |
fresh_products |
Grocery items linked to stores |
home_appliances |
Appliance products with specs like voltage, style, and color |
mobile_phones |
Phone products with brand, model, color, and features |
past_orders |
Delivered orders including total cost and order items |
products |
Unified product master data used for lookups and categorization |
ratings |
Customer-product rating documents (sparse but frequently queried) |
regular_products |
Non-grocery products (books, CDs, phones, appliances) |
stores |
Store metadata with geo-coordinates and available inventory |
Each query is implemented as a standalone CLI script inside the queries/ folder.
Each script accepts arguments via --flags.
Function: Add a fresh grocery product to a customer’s cart. If a pending order already exists, update it; else, create a new order.
Usage:
python -m queries.insert_fresh_product --customer_id 1 --store_id 1 --product_id 45 --quantity 1
Function: Confirm a fresh order and assign the nearest available delivery partner (based on store and driver location).
Usage:
python -m queries.confirm_order --customer_id 1 --store_id 1
Function: Fetch detailed info about a shipped fresh order, including products, prices, delivery partner info, and ETA.
Usage:
python -m queries.get_order --order_id 2025
Function: Retrieve fresh grocery products available in nearby stores based on user’s latitude and longitude.
Usage:
python -m queries.list_fresh_products --latitude 53.4668 --longitude -2.2339
Function: Calculate total sales revenue grouped by product category (across fresh and regular products).
Usage:
python -m queries.sales_by_category
Function: Aggregate and visualize total inventory quantity stored in each warehouse using a pie chart.
Usage:
python -m queries.inventory_by_warehouse
Function: Move a completed order from current_orders to past_orders, log delivery time, and update driver status.
Usage:
python -m queries.process_delivered_order --order_id 2025
Function: Fetch top recommended products for a customer based on predicted ratings.
Usage:
python -m queries.customer_recommendations --customer_id 123
Function: Calculate the average rating and total number of ratings for each product.
Usage:
python -m queries.product_rating
Function: Display the top 10 customers ranked by total spending.
Usage:
python -m queries.top_customers