A minimal e-commerce web application built with Flask. Customers can browse products, add items to a cart, place orders, and submit inquiries. Administrators manage products, categories, and users via a separate admin area.
Customers
- Register and log in (unique customer ID, e.g.
cust_0001) - Browse products with search and filter (name, price range)
- Add products to cart (multiple products, adjust quantities)
- Place order from cart and view order history (My orders)
- Submit inquiries (general or product-specific) and view My inquiries
Administrators
- Log in with admin credentials (redirected to admin dashboard)
- Manage products: add, edit, delete (name, price, description, category, availability)
- Manage categories: add, edit, delete
- View users (customer ID, name, email, admin flag)
Technical
- SQLite database; admin and customer areas are separate (no mixed UI)
- Session-based cart; input validation (e.g. email format); Tailwind CSS (CDN) for UI
- Backend: Python 3, Flask
- Database: SQLite
- Auth: Werkzeug password hashing, session-based login
- Frontend: Jinja2 templates, Tailwind CSS via CDN
- Config:
python-dotenvfor.env(e.g. admin credentials)
- Python 3.10+
- pip
-
Clone or enter the project directory
cd /path/to/commerce -
Create a virtual environment
python3 -m venv venv source venv/bin/activate # Linux/macOS # or: venv\Scripts\activate # Windows
-
Install dependencies
pip install -r requirements.txt
-
Configure environment (optional) Create a
.envfile in the project root to set the default admin account (used when no admin exists yet):ADMIN_EMAIL=admin@commerce.local ADMIN_PASSWORD=admin123 ADMIN_NAME=Admin
If you omit
.env, these defaults are used. Change them in production. -
Run the application
python app.py
The app runs at http://127.0.0.1:5000 (Flask debug server).
- On first run, the database is created from
schema.sqland, if needed, migrated for older schemas. A default admin user is created if none exists (usingADMIN_EMAIL/ADMIN_PASSWORDfrom.envor config defaults). - Admin: log in with the admin email and password → you are redirected to the admin dashboard (
/admin). Use it to add categories and products. - Customer: register a new account → you are redirected to the customer home. Use Products, Cart, and Place order to create orders; view them under My orders.
commerce/
├── app.py # Flask app, loads .env, registers blueprint
├── config.py # DATABASE path, ADMIN_* from env
├── db.py # DB connection, init_db, migration
├── models.py # Users, categories, products, orders, inquiries
├── routes.py # All routes (customer + admin)
├── validation.py # Input validation (email, name, etc.)
├── schema.sql # Table definitions
├── requirements.txt
├── .env # Optional; ADMIN_EMAIL, ADMIN_PASSWORD, ADMIN_NAME
├── app.db # SQLite DB (created on first run)
└── templates/ # Jinja2 HTML (customer + admin/)
| URL | Description |
|---|---|
/ |
Customer home (login required) |
/login |
Login |
/register |
Customer registration |
/products |
Product list, search & filter |
/products/<id> |
Product detail, add to cart |
/cart |
Cart, update quantities, place order |
/orders |
My orders |
/inquiries |
My inquiries |
/inquiries/new |
New inquiry |
/admin |
Admin dashboard (admin only) |
/admin/products |
Admin products CRUD |
/admin/users |
Admin users list |
/admin/categories |
Admin categories CRUD |
- Secret key: The app uses a fixed
secret_key; setapp.config['SECRET_KEY']from env in production. - Database: To reset the DB, delete
app.dband restart the app (init_db will recreate it). - Admin vs customer: Admin and customer UIs are separate; admins go to
/admin, customers use the main site. Login redirects admins to the admin dashboard and customers to the home page.