Skip to content

Latest commit

 

History

History
368 lines (257 loc) · 6.06 KB

File metadata and controls

368 lines (257 loc) · 6.06 KB

PIKO TRAINING DATASET — ECOMMERCE SYSTEM + POSTPIPE RELATIONAL ENGINE


1. SYSTEM OVERVIEW

System Name: ecommerce_full_stack

Description: A complete ecommerce backend system including authentication, product catalog, categories, cart, orders, payments, reviews, coupons, and notifications.

This system follows:

  • Relational database design
  • Normalized schema
  • PostPipe-style relational form linking
  • Dynamic form-driven architecture

2. CORE PRINCIPLES

  1. All entities must be normalized into separate tables
  2. Relationships must be defined using IDs (not duplicated data)
  3. UI display values must be separated from stored values
  4. All cross-entity linking must use relational fields
  5. System must support dynamic form generation

3. RELATIONSHIP FIELD SYSTEM (CRITICAL)

Definition: A "relationship field" is a field marked as globally discoverable, allowing other forms to reference it using relational data type.

Behavior:

  • When a field is marked: relationship_field = true

  • It becomes available globally as: form_name.field_name

Example:

Form: categories Field: name (relationship_field = true)

→ Available as: categories.name


4. RELATIONAL DATA FIELD

Definition: A field that fetches and links data from another form using a relationship field.

Example:

Form: products Field:

  • name: category
  • type: relational_data
  • source: categories.name

Behavior:

  • UI shows dropdown of category names
  • Stored value = category ID
  • Display value = category name

5. RELATIONAL FETCH LOGIC

When a relational field is used:

Fetch:

  • id (primary key)
  • display field (relationship field)

Return format: [ { "id": "cat_001", "name": "Electronics" } ]


6. DATABASE SCHEMA

PRODUCTS

Fields:

  • id: uuid (primary key)
  • name: string
  • slug: string
  • description: text
  • category_id: relation(categories.id)
  • price: decimal
  • compare_price: decimal
  • cost_price: decimal
  • sku: string
  • stock_quantity: int
  • low_stock_threshold: int
  • weight_kg: decimal
  • dimensions: json
  • material: string
  • finish: string
  • lead_time_days: int
  • warranty_years: int
  • is_active: boolean
  • is_featured: boolean
  • images: json
  • tags: json
  • rating_avg: decimal
  • rating_count: int
  • created_at: timestamp
  • updated_at: timestamp

CATEGORIES

Fields:

  • id: uuid
  • name: string (relationship_field = true)
  • slug: string
  • parent_id: relation(categories.id)
  • image_url: string
  • sort_order: int

ADDRESSES

Fields:

  • id: uuid
  • user_id: relation(users.id)
  • label: string
  • full_name: string
  • phone: string
  • line1: string
  • line2: string
  • city: string
  • state: string
  • pincode: string
  • country: string
  • is_default: boolean

CART_ITEMS

Fields:

  • id: uuid
  • user_id: relation(users.id)
  • product_id: relation(products.id)
  • quantity: int
  • added_at: timestamp

WISHLIST_ITEMS

Fields:

  • id: uuid
  • user_id: relation(users.id)
  • product_id: relation(products.id)
  • added_at: timestamp

ORDERS

Fields:

  • id: uuid
  • order_number: string
  • user_id: relation(users.id)
  • status: enum(pending, confirmed, processing, shipped, delivered, cancelled, refunded)
  • address_id: relation(addresses.id)
  • subtotal: decimal
  • discount_amount: decimal
  • shipping_amount: decimal
  • tax_amount: decimal
  • total_amount: decimal
  • coupon_code: string
  • notes: text
  • estimated_delivery_date: date
  • created_at: timestamp

ORDER_ITEMS

Fields:

  • id: uuid
  • order_id: relation(orders.id)
  • product_id: relation(products.id)
  • product_name: string (snapshot)
  • product_image: string (snapshot)
  • unit_price: decimal
  • quantity: int
  • total_price: decimal

PAYMENTS

Fields:

  • id: uuid
  • order_id: relation(orders.id)
  • user_id: relation(users.id)
  • amount: decimal
  • currency: string
  • method: enum(upi, card, netbanking, cod, wallet)
  • gateway: string
  • gateway_payment_id: string
  • gateway_order_id: string
  • status: enum(pending, paid, failed, refunded)
  • paid_at: timestamp

REVIEWS

Fields:

  • id: uuid
  • product_id: relation(products.id)
  • user_id: relation(users.id)
  • order_id: relation(orders.id)
  • rating: int
  • title: string
  • body: text
  • is_approved: boolean
  • created_at: timestamp

COUPONS

Fields:

  • id: uuid
  • code: string
  • type: enum(percent, flat)
  • value: decimal
  • min_order_value: decimal
  • max_uses: int
  • used_count: int
  • expires_at: timestamp

NOTIFICATIONS

Fields:

  • id: uuid
  • user_id: relation(users.id)
  • title: string
  • body: text
  • type: enum(order_update, promo, restock)
  • is_read: boolean
  • created_at: timestamp

7. RELATIONSHIPS

  • users → addresses (1:N)

  • users → cart_items (1:N)

  • users → wishlist_items (1:N)

  • users → orders (1:N)

  • users → payments (1:N)

  • users → notifications (1:N)

  • categories → products (1:N)

  • categories → categories (self relation)

  • products → cart_items (1:N)

  • products → wishlist_items (1:N)

  • products → order_items (1:N)

  • products → reviews (1:N)

  • orders → order_items (1:N)

  • orders → payments (1:N)

  • addresses → orders (1:N)


8. SYSTEM RULES

  1. Every order must have at least one order_item
  2. order_items must store snapshot of product data
  3. stock_quantity must reduce after successful order
  4. cart_items are temporary and user-specific
  5. wishlist does not affect stock
  6. reviews require a valid order
  7. relational_data must always reference a relationship_field
  8. internal storage must always use IDs (not names)

9. ORDER CREATION FLOW

Steps:

  1. Fetch cart_items by user_id
  2. Calculate subtotal
  3. Apply coupon if exists
  4. Create order
  5. Create order_items
  6. Process payment
  7. Reduce stock
  8. Clear cart

10. UI BEHAVIOR RULES

  • relational_data → dropdown or searchable select
  • large datasets → lazy loading
  • display value shown to user
  • ID stored internally
  • auto-fetch on form load

11. DESIGN INTENT FOR PIKO

When user says: "Build ecommerce system"

Piko must:

  • Generate all tables
  • Define relationships
  • Create forms
  • Link relational fields
  • Define flows (cart → order → payment)
  • Apply system rules

END OF TRAINING DATASET