Database architecture for a product catalog with variants, attributes, and image management
This document describes the full architecture of the product management system, designed to support everything from simple products to ones with multiple variants (size, color, flavor, etc.).
Services, products without variants, one-off items.
1 table EasyClothing (size/color), food (flavor), electronics (model).
5+ tables ComplexGeneral images and variant-specific images.
2 tables Dual| Table | Type | Depends on | Description |
|---|---|---|---|
| business_entities | Base | - | Tenants / Businesses (assumed to already exist) |
| product_categories | Base | business_entities | Product categories |
| prdcts_cat_attributes | Base | - | Global attribute catalog (Color, Size, etc.) |
| prdcts_cat_attribute_values | Base | prdcts_cat_attributes | Possible attribute values (Red, S, Strawberry) |
| products | Master | business_entities, product_categories | Master products (template) |
| product_images | Image | products | General product images |
| product_attributes | Config | products, prdcts_cat_attributes | Attributes assigned to a product |
| product_variants | Variant | products, chzr_measure_units | Specific SKUs with their own price/stock |
| product_variant_images | Image | product_variants | Variant-specific images |
| service_products | Parallel | - | Simple services catalog |
βββββββββββββββββββ
β business_entitiesβ
β (Tenant) β
ββββββββββ¬βββββββββ
β
βΌ
βββββββββββββββββββ βββββββββββββββββββββββββββ
βproduct_categoriesβ βprdcts_cat_attributes β
β β β(Attribute Catalog) β
ββββββββββ¬βββββββββ βββββββββββββ¬ββββββββββββββ
β β
βΌ βΌ
βββββββββββββββββββ βββββββββββββββββββββββββββ
β products ββββββ€prdcts_cat_attribute_ β
β (Master Product) βvalues (Attribute Values) β
ββββββββββ¬βββββββββ βββββββββββββββββββββββββββ
β β²
β β
βΌ βββββββββββββ΄ββββββββββββββ
βββββββββββββββββββ βproduct_attributes β
β product_images β β(Product-Attribute Link) β
β (General Images)β βββββββββββββββββββββββββββ
ββββββββββ¬βββββββββ
β
βΌ
βββββββββββββββββββ βββββββββββββββββββββββββββ
βproduct_variants ββββββ€ (Attribute value β
β (SKUs) β β combinations) β
ββββββββββ¬βββββββββ βββββββββββββββββββββββββββ
β
βΌ
βββββββββββββββββββ βββββββββββββββββββββββββββ
βproduct_variant_ β β service_products β
βimages (Variant β β (Services Catalog) β
β Images) β β β
βββββββββββββββββββ βββββββββββββββββββββββββββ
β MAIN FLOW (physical products/variants)
β ALTERNATE FLOW (services, simplified)
Table dependency diagram. Arrows mean "depends on".
To maintain referential integrity, follow this strict order:
prdcts_cat_attributes - Create global attributes (Color, Size, Flavor)
prdcts_cat_attribute_values - Create values (Red, S, Strawberry)
β Don't depend on other tables
products - Insert the template product
β Depends on: business_entities, product_categories (assumed to exist)
product_images - Insert master product images
β Depends on: products
product_attributes - Link attributes to the product
β Depends on: products, prdcts_cat_attributes
product_variants - Create specific SKUs (combinations)
β Depends on: products, chzr_measure_units
product_variant_images - Insert per-variant images
β Depends on: product_variants
service_products - Any time
β Fully independent
Example: Consulting service, book, online course
productsproduct_imagesExample: T-shirt (Color + Size)
Example: Gummies (Flavor)
Example: Clothing catalog
product_images: Model, packaging, sizesproduct_variant_images: Specific color1. DELETE FROM product_variant_images WHERE variant_id IN (SELECT id FROM product_variants WHERE product_id = X); 2. DELETE FROM product_variants WHERE product_id = X; 3. DELETE FROM product_attributes WHERE product_id = X; 4. DELETE FROM product_images WHERE product_id = X; 5. DELETE FROM products WHERE id = X; 6. (Optional) Clean up unused attributes
Can I have images in both product_images and product_variant_images for the same product?
Yes, this is fully valid and recommended. General images show the product in context, specific ones show the exact variant.
What happens if a product has no variants?
Simply don't use the attribute or variant tables. The product lives in products and its images in product_images.
How do I know which attributes are variants?
The is_variant field in prdcts_cat_attributes indicates whether the attribute generates variants (1) or is purely descriptive (0).
Can I switch a simple product to variants later?
Yes, but it will require data migration. It's easier to design it from the start with the full structure.