This project defines the database schema for the iShop4U system using Flask + SQLAlchemy. It provides a unified shopping cart across multiple affiliate platforms (Amazon, AliExpress, etc.) while maintaining affiliate links for checkout.
cart_items
).users products affiliate_sources │ │ │ │ 1 │ 1 │ 1 │ │ │ └──────< cart_items >────────┘ └───< products (quantity, notes)
A user can have many cart items.
A product can appear in many users’ carts (many-to-many via cart_items).
Each product belongs to one affiliate source (Amazon, AliExpress, etc.).
CREATE TABLE users (
id SERIAL PRIMARY KEY,
name VARCHAR(100) NOT NULL,
email VARCHAR(150) UNIQUE NOT NULL,
password_hash TEXT NOT NULL,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
CREATE TABLE affiliate_sources (
id SERIAL PRIMARY KEY,
name VARCHAR(100) NOT NULL,
api_name VARCHAR(100),
base_url TEXT
);
CREATE TABLE products (
id SERIAL PRIMARY KEY,
name VARCHAR(255) NOT NULL,
image_url TEXT,
price DECIMAL(10,2),
affiliate_link TEXT NOT NULL,
affiliate_source_id INT REFERENCES affiliate_sources(id) ON DELETE CASCADE
);
CREATE TABLE cart_items (
id SERIAL PRIMARY KEY,
user_id INT REFERENCES users(id) ON DELETE CASCADE,
product_id INT REFERENCES products(id) ON DELETE CASCADE,
quantity INT DEFAULT 1,
notes TEXT,
added_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
UNIQUE (user_id, product_id)
);
git clone git@github.com:chiznox6/ishop4u-backend.git
cd ishop4u-backend
pip install -r requirements.txt
flask db upgrade
sqlite3 ishop4u.db ".tables"
This repository is published on GitHub Pages as documentation:
https://chiznox6.github.io/ishop4u-backend/
CartItem
and read/create for Product
.