Skip to content

Repository files navigation

Commerce

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.

Features

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

Tech stack

  • Backend: Python 3, Flask
  • Database: SQLite
  • Auth: Werkzeug password hashing, session-based login
  • Frontend: Jinja2 templates, Tailwind CSS via CDN
  • Config: python-dotenv for .env (e.g. admin credentials)

Prerequisites

  • Python 3.10+
  • pip

Setup

  1. Clone or enter the project directory

    cd /path/to/commerce
  2. Create a virtual environment

    python3 -m venv venv
    source venv/bin/activate   # Linux/macOS
    # or: venv\Scripts\activate   # Windows
  3. Install dependencies

    pip install -r requirements.txt
  4. Configure environment (optional) Create a .env file 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.

  5. Run the application

    python app.py

    The app runs at http://127.0.0.1:5000 (Flask debug server).

First run

  • On first run, the database is created from schema.sql and, if needed, migrated for older schemas. A default admin user is created if none exists (using ADMIN_EMAIL / ADMIN_PASSWORD from .env or 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.

Project structure

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/)

Default URLs

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

Notes

  • Secret key: The app uses a fixed secret_key; set app.config['SECRET_KEY'] from env in production.
  • Database: To reset the DB, delete app.db and 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.

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages