Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/aluxey/E-Commerce/llms.txt

Use this file to discover all available pages before exploring further.

categories

Hierarchical product category structure supporting parent-child relationships.
ColumnTypeConstraintsDescription
idbigserialPRIMARY KEYAuto-incrementing category identifier
nametextNOT NULLCategory display name
parent_idbigintFOREIGN KEY → categories(id)Reference to parent category (NULL for root categories)
created_attimestampDEFAULT now()Category creation timestamp

Constraints

  • Unique: (name, parent_id) - Category names must be unique within the same parent
  • Foreign Key: parent_id references categories(id) with ON DELETE CASCADE

Indexes

create unique index ux_categories_name_parent on categories (name, parent_id);
create index idx_categories_parent on categories(parent_id);

Example

-- Create root category
INSERT INTO categories (name, parent_id) VALUES ('Clothing', NULL);

-- Create subcategory
INSERT INTO categories (name, parent_id) 
VALUES ('Sweaters', (SELECT id FROM categories WHERE name = 'Clothing'));

colors

Color definitions for product customization with hex codes.
ColumnTypeConstraintsDescription
idbigserialPRIMARY KEYAuto-incrementing color identifier
nametextNOT NULLHuman-readable color name
codetextNOT NULL, UNIQUEInternal color code (e.g., “blue_navy”)
hex_codetextNOT NULL, UNIQUEHex color value (e.g., “#1A2B3C”)
created_attimestampDEFAULT now()Color creation timestamp

Constraints

  • Check: hex_code must match pattern ^#([0-9A-Fa-f]{6})$
  • Unique: Both code and hex_code must be globally unique
Colors cannot be deleted if they’re assigned to any items due to ON DELETE RESTRICT in the item_colors table.

Example

INSERT INTO colors (name, code, hex_code)
VALUES ('Navy Blue', 'blue_navy', '#001f3f');

users

User accounts extending Supabase auth.users with role-based access.
ColumnTypeConstraintsDescription
iduuidPRIMARY KEY, FOREIGN KEY → auth.users(id)User identifier (from Supabase Auth)
emailtextNOT NULL, UNIQUEUser email address
roletextNOT NULL, DEFAULT ‘client’User role: ‘client’ or ‘admin’
created_attimestampDEFAULT now()Account creation timestamp
updated_attimestampDEFAULT now()Last update timestamp (auto-managed)

Constraints

  • Check: role IN ('client', 'admin')
  • Foreign Key: id references auth.users(id) with ON DELETE CASCADE

Triggers

  • trg_users_updated_at - Automatically updates updated_at on row modification

items

Core product catalog with pricing, status, and categorization.
ColumnTypeConstraintsDescription
idbigserialPRIMARY KEYAuto-incrementing item identifier
nametextNOT NULLProduct name
descriptiontextNULLProduct description (markdown supported)
pricenumeric(10,2)NOT NULL, CHECK >= 0Base price in EUR
image_urltextNULLPrimary product image URL
category_idbigintFOREIGN KEY → categories(id)Product category
statustextNOT NULL, DEFAULT ‘draft’Product status
pattern_typetextNULLKnitting pattern type (optional)
created_attimestampDEFAULT now()Creation timestamp
updated_attimestampDEFAULT now()Last update timestamp (auto-managed)

Constraints

  • Check: status IN ('draft', 'active', 'archived')
  • Check: pattern_type IS NULL OR pattern_type IN ('rechtsmuster', 'gaensefuesschen')
  • Foreign Key: category_id references categories(id) with ON DELETE SET NULL
Every item must have at least one color assigned via the item_colors table. This is enforced by a deferred constraint trigger.

Indexes

create index idx_items_category on items(category_id);
create index idx_items_name on items using gin (to_tsvector('simple', coalesce(name,'')));

Triggers

  • trg_items_updated_at - Automatically updates updated_at
  • ctr_items_require_color - Ensures at least one color is assigned (deferred)

item_colors

Many-to-many junction table linking items to available colors.
ColumnTypeConstraintsDescription
item_idbigintPRIMARY KEY, FOREIGN KEY → items(id)Item identifier
color_idbigintPRIMARY KEY, FOREIGN KEY → colors(id)Color identifier

Constraints

  • Primary Key: Composite (item_id, color_id)
  • Foreign Key: item_id references items(id) with ON DELETE CASCADE
  • Foreign Key: color_id references colors(id) with ON DELETE RESTRICT

Indexes

create index idx_item_colors_color on item_colors(color_id);

Triggers

  • ctr_item_colors_require_color - Prevents removing the last color from an item

Example

-- Assign multiple colors to an item
INSERT INTO item_colors (item_id, color_id)
VALUES 
  (1, 5),  -- Navy Blue
  (1, 7),  -- Charcoal Grey
  (1, 12); -- Burgundy

item_images

Additional product images for galleries.
ColumnTypeConstraintsDescription
idbigserialPRIMARY KEYAuto-incrementing image identifier
item_idbigintNOT NULL, FOREIGN KEY → items(id)Associated item
image_urltextNOT NULLImage storage URL
created_attimestampDEFAULT now()Upload timestamp

Constraints

  • Foreign Key: item_id references items(id) with ON DELETE CASCADE

Indexes

create index idx_item_images_item on item_images(item_id);

item_variants

Size-based product variants with individual SKUs, pricing, and stock tracking.
ColumnTypeConstraintsDescription
idbigserialPRIMARY KEYAuto-incrementing variant identifier
item_idbigintNOT NULL, FOREIGN KEY → items(id)Parent item
skutextUNIQUEStock Keeping Unit (optional)
sizetextNULLSize designation (e.g., “S”, “M”, “L”)
stockintegerNOT NULL, DEFAULT 0, CHECK >= 0Available inventory count
pricenumeric(10,2)NOT NULL, CHECK >= 0Variant-specific price
created_attimestampDEFAULT now()Creation timestamp

Constraints

  • Unique: (item_id, coalesce(size, '')) - Prevents duplicate size variants per item
  • Foreign Key: item_id references items(id) with ON DELETE CASCADE

Indexes

create index idx_variants_item on item_variants(item_id);
create unique index ux_item_variants_combo on item_variants (item_id, coalesce(size,''));
create index idx_item_variants_item_size on item_variants (item_id, size);

Example

INSERT INTO item_variants (item_id, sku, size, stock, price)
VALUES 
  (1, 'SWE-NAV-S', 'S', 10, 89.99),
  (1, 'SWE-NAV-M', 'M', 15, 89.99),
  (1, 'SWE-NAV-L', 'L', 8, 94.99);

item_ratings

Customer product reviews and ratings.
ColumnTypeConstraintsDescription
idbigserialPRIMARY KEYAuto-incrementing rating identifier
item_idbigintNOT NULL, FOREIGN KEY → items(id)Rated item
user_iduuidNOT NULL, FOREIGN KEY → users(id)Reviewer
ratingintegerNOT NULL, CHECK 1-5Star rating (1-5)
commenttextNULLReview text (optional)
created_attimestampDEFAULT now()Review submission timestamp
updated_attimestampDEFAULT now()Last update timestamp (auto-managed)

Constraints

  • Check: rating BETWEEN 1 AND 5
  • Unique: (item_id, user_id) - One review per user per item
  • Foreign Key: item_id references items(id) with ON DELETE CASCADE
  • Foreign Key: user_id references users(id) with ON DELETE CASCADE

Indexes

create index idx_ratings_item on item_ratings(item_id);

Triggers

  • trg_ratings_updated_at - Automatically updates updated_at

orders

Order headers with status tracking, shipping, and payment integration.
ColumnTypeConstraintsDescription
iduuidPRIMARY KEY, DEFAULT gen_random_uuid()Order identifier
user_iduuidNOT NULL, FOREIGN KEY → users(id)Customer who placed the order
statustextNOT NULL, DEFAULT ‘pending’Order status
currencytextNOT NULL, DEFAULT ‘eur’Currency code
totalnumeric(10,2)NOT NULL, DEFAULT 0, CHECK >= 0Order total amount
shipping_addressjsonbNULLShipping address (JSON structure)
payment_intent_idtextUNIQUEStripe PaymentIntent ID
created_attimestampDEFAULT now()Order creation timestamp
updated_attimestampDEFAULT now()Last update timestamp (auto-managed)

Constraints

  • Check: status IN ('pending', 'paid', 'failed', 'canceled', 'shipped', 'refunded')
  • Foreign Key: user_id references users(id) with ON DELETE CASCADE

Indexes

create index idx_orders_user on orders(user_id);

Triggers

  • trg_orders_updated_at - Automatically updates updated_at

Shipping Address Format

{
  "name": "Jane Doe",
  "line1": "123 Main Street",
  "line2": "Apt 4B",
  "city": "Paris",
  "postal_code": "75001",
  "country": "FR"
}

order_items

Individual line items within orders.
ColumnTypeConstraintsDescription
idbigserialPRIMARY KEYAuto-incrementing line item identifier
order_iduuidNOT NULL, FOREIGN KEY → orders(id)Parent order
item_idbigintNOT NULL, FOREIGN KEY → items(id)Ordered item
variant_idbigintNOT NULL, FOREIGN KEY → item_variants(id)Specific variant (size)
quantityintegerNOT NULL, CHECK > 0Quantity ordered
unit_pricenumeric(10,2)NOT NULL, DEFAULT 0, CHECK >= 0Price per unit at time of order
total_pricenumeric(10,2)GENERATED ALWAYS AS STOREDComputed: quantity × unit_price
customizationjsonbDEFAULT ''::jsonbCustom options (e.g., embroidery)
created_attimestampDEFAULT now()Line item creation timestamp

Constraints

  • Foreign Key: order_id references orders(id) with ON DELETE CASCADE
  • Foreign Key: item_id references items(id) with ON DELETE RESTRICT
  • Foreign Key: variant_id references item_variants(id) with ON DELETE RESTRICT
total_price is a generated column automatically calculated as quantity * unit_price. You cannot insert or update this value directly.

Indexes

create index idx_order_items_order on order_items(order_id);
create index idx_order_items_item on order_items(item_id);

Customization Format

{
  "color": "Navy Blue",
  "embroidery": {
    "text": "JD",
    "position": "left chest"
  }
}

payments

Payment transaction records with Stripe integration.
ColumnTypeConstraintsDescription
iduuidPRIMARY KEY, DEFAULT gen_random_uuid()Payment identifier
order_iduuidNOT NULL, FOREIGN KEY → orders(id)Associated order
providertextNOT NULL, DEFAULT ‘stripe’Payment provider name
provider_idtextNOT NULLExternal payment ID (e.g., PaymentIntent)
amountnumeric(10,2)NOT NULL, CHECK >= 0Payment amount
currencytextNOT NULL, DEFAULT ‘eur’Currency code
statustextNOT NULLPayment status from provider
rawjsonbDEFAULT ''::jsonbComplete provider response
created_attimestampDEFAULT now()Payment creation timestamp
updated_attimestampDEFAULT now()Last update timestamp (auto-managed)

Constraints

  • Unique: (provider, provider_id) - Prevents duplicate payment records
  • Foreign Key: order_id references orders(id) with ON DELETE CASCADE

Indexes

create index idx_payments_order on payments(order_id);

Triggers

  • trg_payments_updated_at - Automatically updates updated_at

stripe_events

Idempotency tracking for Stripe webhook events.
ColumnTypeConstraintsDescription
event_idtextPRIMARY KEYStripe event ID (e.g., “evt_1234…”)
received_attimestampDEFAULT now()Event processing timestamp

Usage

Insert event IDs when processing webhooks to prevent duplicate processing:
-- Check if event already processed
INSERT INTO stripe_events (event_id) 
VALUES ('evt_1234567890')
ON CONFLICT (event_id) DO NOTHING
RETURNING event_id;

-- If no rows returned, event was already processed

customer_photos

Customer-submitted photos for gallery display and social proof.
ColumnTypeConstraintsDescription
idbigserialPRIMARY KEYAuto-incrementing photo identifier
image_urltextNOT NULLPhoto storage URL
positionintegerNOT NULL, DEFAULT 0Display order (ascending)
is_visiblebooleanNOT NULL, DEFAULT trueVisibility toggle
created_attimestampDEFAULT now()Upload timestamp

Indexes

create index idx_customer_photos_visible 
  on customer_photos(is_visible, position asc)
  where is_visible = true;

Example Query

-- Get visible photos in display order
SELECT image_url, position
FROM customer_photos
WHERE is_visible = true
ORDER BY position ASC;

Build docs developers (and LLMs) love