A Full-Stack E-Commerce Web Application
Built with Flask, SQLite, and Vanilla JavaScript
ShopEase is a complete e-commerce web application that allows users to browse products, add items to cart, place orders, and manage their profile. It includes an admin dashboard for managing products, users, and viewing sales analytics.
The project demonstrates the practical implementation of 4 classic design patterns in a real-world Python application.
Feature
Description
User Authentication
Register, login, logout with session management
Product Browsing
View all products with image, price, rating
Search & Filters
Search by name, filter by category and price range
Sorting
Sort by price (low/high) and rating
Shopping Cart
Add/remove items, update quantities, persistent storage
Wishlist
Save favorite products
Order Management
Place orders, view confirmation, download receipts
Theme Toggle
Switch between dark and light mode
Feature
Description
Admin Dashboard
View store statistics (revenue, orders, users, products)
Product Management
Add, edit, and delete products
User Management
View all users, change roles, delete users
Order Management
View all customer orders with details
Analytics
Sales trends, category performance, hourly sales
π¨ Design Patterns Implemented
Pattern
Location
Purpose
Code Example
Singleton
cart_singleton.py
Single CartManager instance across entire application
cart_manager = CartSingleton()
Factory
factories.py
Creates category-specific products
factory_manager.get_factory('electronics')
Builder
factories.py
Step-by-step product construction
builder.set_name().set_price().build()
Decorator
discount_decorators.py
Dynamic discount stacking
PercentageDiscountDecorator(BasePriceCalculator(), 20)
Detailed Pattern Explanation
class CartSingleton :
_instance = None
def __new__ (cls ):
if cls ._instance is None :
cls ._instance = super ().__new__ (cls )
return cls ._instance
Ensures only ONE cart manager exists
Provides global access point for cart operations
Handles cart caching and statistics
class ProductFactoryManager :
_factories = {
'electronics' : ElectronicsFactory (),
'audio' : AudioFactory (),
'clothing' : ClothingFactory ()
}
Creates products without specifying exact class
Each category has its own factory
Easy to add new product types
product = (builder
.set_name ("Laptop" )
.set_price (999.99 )
.set_description ("Powerful laptop" )
.build ())
Fluent interface for product creation
Step-by-step construction
Same process creates different product representations
calculator = BasePriceCalculator ()
calculator = PercentageDiscountDecorator (calculator , 20 )
calculator = FixedAmountDiscountDecorator (calculator , 10 )
final_price = calculator .calculate_price (100 , 1 ) # 100 - 20% - $10 = $70
Dynamically add discounts to products
Stack multiple discounts
Open for extension, closed for modification
Technology
Purpose
Python 3.8+
Core programming language
Flask 2.3.3
Web framework
SQLAlchemy 2.0.19
ORM for database operations
SQLite
Database (lightweight, file-based)
Flask-CORS 4.0.0
Cross-origin requests handling
python-dotenv
Environment variables management
Technology
Purpose
HTML5
Structure
CSS3
Styling (dark/light themes)
JavaScript
Dynamic interactions, API calls
Font Awesome 6.4.0
Icons
shopease/
β
βββ backend/
β βββ app.py # Main Flask application (all routes)
β βββ models.py # Database models
β β βββ User # User authentication
β β βββ Product # Product catalog
β β βββ CartItem # Shopping cart items
β β βββ Order # Customer orders
β β βββ OrderItem # Individual order items
β β
β βββ database.py # Database connection & session
β βββ cart_singleton.py # SINGLETON pattern implementation
β βββ discount_decorators.py # DECORATOR pattern implementation
β βββ factories.py # FACTORY & BUILDER patterns
β βββ config.py # Configuration settings
β βββ requirements.txt # Python dependencies
β β
β βββ add_missing_columns.py # Database migration script
β βββ seed_products.py # Product seeding script
β βββ create_admin.py # Admin user creator
β βββ check_database.py # Database inspection tool
β
βββ frontend/
β βββ index.html # Homepage
β βββ products.html # Product listing with filters
β βββ product-detail.html # Individual product view
β βββ cart.html # Shopping cart
β βββ receipt.html # Order confirmation
β βββ login.html # Login page
β βββ admin-dashboard.html # Admin panel
β βββ contact.html # Contact page
β βββ privacy-policy.html # Privacy policy
β βββ disclaimer.html # Legal disclaimer
β
βββ templates/ # Flask template folder
β βββ index.html
β βββ login.html
β βββ admin-dashboard.html
β
βββ shopease.db # SQLite database file
βββ README.md # This file
Python 3.8 or higher
pip (Python package manager)
git clone https://github.com/yourusername/shopease.git
cd shopease
2. Navigate to Backend Directory
pip install -r requirements.txt
python -c " from database import init_db; init_db()"
5. Add Missing Columns (if needed)
python add_missing_columns.py
6. Seed Products into Database
Or send POST request to /api/create-admin:
{
"username" : " admin" ,
"email" : " admin@shopease.com" ,
"password" : " admin123"
}
9. Access the Application
Open your browser and go to: http://localhost:5000
Method
Endpoint
Description
POST
/api/login
User login (username/email + password)
POST
/api/register
Create new account
POST
/api/logout
Logout current user
GET
/api/check-auth
Check if user is logged in
POST
/api/create-admin
Create admin user
Method
Endpoint
Description
GET
/api/products
Get products (with filters & pagination)
GET
/api/products/<id>
Get single product by ID
GET
/api/categories
Get all product categories
Method
Endpoint
Description
GET
/api/cart?session_id=xxx
Get cart items
POST
/api/cart
Add item to cart
PUT
/api/cart/<item_id>
Update item quantity
DELETE
/api/cart/<item_id>
Remove item from cart
DELETE
/api/cart/clear?session_id=xxx
Clear entire cart
Method
Endpoint
Description
POST
/api/orders
Create new order from cart
GET
/api/orders/<order_number>
Get order details
π Admin (requires admin role)
Method
Endpoint
Description
GET
/api/admin/stats
Dashboard statistics
GET
/api/admin/products
Get all products (admin view)
POST
/api/admin/products
Create new product
PUT
/api/admin/products/<id>
Update product
DELETE
/api/admin/products/<id>
Delete product
GET
/api/admin/users
Get all users
PUT
/api/admin/users/<id>
Update user role
DELETE
/api/admin/users/<id>
Delete user
GET
/api/admin/orders
Get all orders
Method
Endpoint
Description
POST
/api/discounts/apply
Apply discounts to cart
POST
/api/discounts/validate-coupon
Validate coupon code
GET
/api/discounts/active
Get active discounts
Method
Endpoint
Description
GET
/api/health
Health check
GET
/api/debug/products
List all products
GET
/api/debug/cart-items
List all cart items
POST
/api/debug/test-cart
Test cart functionality
βββββββββββββββ βββββββββββββββ βββββββββββββββ
β users β β orders β β order_items β
βββββββββββββββ€ βββββββββββββββ€ βββββββββββββββ€
β id (PK) βββββ<β user_id (FK)β β id (PK) β
β username β β order_numberβ β order_id(FK)β>ββββ
β email β β session_id β β product_id β β
β password_hashβ β total_amountβ β quantity β β
β role β β status β β price β β
β created_at β β shipping_infoβ β created_at β β
βββββββββββββββ β created_at β βββββββββββββββ β
βββββββββββββββ β
β
βββββββββββββββ βββββββββββββββ β
β products β β cart_items β β
βββββββββββββββ€ βββββββββββββββ€ β
β id (PK) β<βββββ product_id β β
β name β β id (PK) β β
β category β β session_id β β
β price β β quantity β β
β rating β β added_at β β
β reviews β βββββββββββββββ β
β description β β
β image β β
β created_at β β
βββββββββββββββ β
β
ββββββββββββββ΄βββββββββββββ
β β
ββββββ΄βββββ ββββββββ΄ββββββ
β product β β order β
β (rel) β β (rel) β
βββββββββββ ββββββββββββββ
Product categories showcase
Featured products section
Dark/light theme toggle
Grid layout with product cards
Search bar with real-time filtering
Category dropdown, price filter, sort options
Pagination support
High-res product image with thumbnails
Rating stars, price, description
Add to cart / wishlist buttons
Related products section
List of added items with quantities
Update quantity or remove items
Subtotal, shipping, tax calculation
Proceed to checkout
Order confirmation number
Itemized order details
Shipping information display
Download receipt option
Estimated delivery date
Statistics cards (revenue, orders, users)
Recent orders table
Product management (CRUD operations)
User management with role assignment
Common Issues & Solutions
Issue
Solution
Missing columns in orders table
Run python add_missing_columns.py
No products in database
Run python seed_products.py
Database locked error
Close all connections or restart server
Table doesn't exist
Run python -c "from database import init_db; init_db()"
Issue
Solution
Flask server not running
Run python app.py in backend directory
Port 5000 already in use
Kill process or change port in app.py
CORS errors
Check CORS configuration in app.py
API_BASE_URL wrong
Update to http://localhost:5000/api
π΄ Authentication Issues
Issue
Solution
Can't login
Clear browser cookies and localStorage
Session not persisting
Check if SECRET_KEY is set in config
Admin access denied
Run python create_admin.py to create admin
Issue
Solution
Cart not saving
Check session_id is being generated
Items disappearing
Verify localStorage persistence
Add to cart failing
Check backend is running on port 5000
Fork the repository
Create a 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 a Pull Request
This project is for educational purposes only . All rights reserved.
For questions or support, please reach out:
Made with β€οΈ using Python and Flask
β Star this repository if you found it helpful!