{
  "$schema": "mantara.schema.v1",
  "system_name": "Pokémon Resell Platform",
  "schema_name": "ai_sch_20260512_074952",
  "description": "A marketplace for buying and selling Pokémon trading cards.",
  "menus": [
    {
      "menu_id": 1,
      "menu_name": "User Management",
      "sequence_number": 1,
      "description": "Manage user accounts, roles, and profiles.",
      "submenus": [
        {
          "submenu_id": 101,
          "submenu_name": "User Registration",
          "sequence_number": 1,
          "description": "Register new users and manage authentication credentials.",
          "tables": [
            {
              "table_name": "users",
              "comment": "Stores registered users with authentication credentials and profile information.",
              "columns": [
                {
                  "name": "id",
                  "type": "UUID",
                  "constraints": "PRIMARY KEY DEFAULT gen_random_uuid()"
                },
                {
                  "name": "submenu_id",
                  "type": "INT",
                  "constraints": "DEFAULT 101 NOT NULL REFERENCES prp.submenu(submenu_id)"
                },
                {
                  "name": "email",
                  "type": "VARCHAR(255)",
                  "constraints": "NOT NULL UNIQUE"
                },
                {
                  "name": "username",
                  "type": "VARCHAR(100)",
                  "constraints": "NOT NULL UNIQUE"
                },
                {
                  "name": "password_hash",
                  "type": "VARCHAR(255)",
                  "constraints": "NOT NULL",
                  "comment": "Stores bcrypt hash, never plain text"
                },
                {
                  "name": "role",
                  "type": "VARCHAR(50)",
                  "constraints": "NOT NULL CHECK (role IN ('buyer','seller','admin'))"
                },
                {
                  "name": "status",
                  "type": "VARCHAR(50)",
                  "constraints": "NOT NULL DEFAULT 'active' CHECK (status IN ('active','suspended','inactive'))"
                },
                {
                  "name": "created_at",
                  "type": "TIMESTAMP",
                  "constraints": "NOT NULL DEFAULT CURRENT_TIMESTAMP"
                },
                {
                  "name": "updated_at",
                  "type": "TIMESTAMP",
                  "constraints": "NOT NULL DEFAULT CURRENT_TIMESTAMP"
                }
              ]
            }
          ]
        },
        {
          "submenu_id": 102,
          "submenu_name": "User Profiles",
          "sequence_number": 2,
          "description": "Manage user profile information and settings."
        }
      ]
    },
    {
      "menu_id": 2,
      "menu_name": "Marketplace",
      "sequence_number": 2,
      "description": "Browse and search for Pokémon card listings.",
      "submenus": [
        {
          "submenu_id": 201,
          "submenu_name": "Card Listings",
          "sequence_number": 1,
          "description": "Create, edit, and manage Pokémon card listings.",
          "tables": [
            {
              "table_name": "card_listings",
              "comment": "Stores Pokémon card listings with details and availability status.",
              "columns": [
                {
                  "name": "id",
                  "type": "UUID",
                  "constraints": "PRIMARY KEY DEFAULT gen_random_uuid()"
                },
                {
                  "name": "submenu_id",
                  "type": "INT",
                  "constraints": "DEFAULT 201 NOT NULL REFERENCES prp.submenu(submenu_id)"
                },
                {
                  "name": "seller_id",
                  "type": "UUID",
                  "constraints": "NOT NULL REFERENCES prp.users(id) ON DELETE CASCADE"
                },
                {
                  "name": "card_name",
                  "type": "VARCHAR(255)",
                  "constraints": "NOT NULL"
                },
                {
                  "name": "pokemon_name",
                  "type": "VARCHAR(255)",
                  "constraints": "NOT NULL"
                },
                {
                  "name": "card_set",
                  "type": "VARCHAR(255)",
                  "constraints": "NOT NULL"
                },
                {
                  "name": "card_number",
                  "type": "VARCHAR(50)",
                  "constraints": "NOT NULL"
                },
                {
                  "name": "rarity",
                  "type": "VARCHAR(100)",
                  "constraints": "NOT NULL"
                },
                {
                  "name": "condition",
                  "type": "VARCHAR(50)",
                  "constraints": "NOT NULL CHECK (condition IN ('mint','near_mint','lightly_played','moderately_played','heavily_played','damaged'))"
                },
                {
                  "name": "price",
                  "type": "NUMERIC(10,2)",
                  "constraints": "NOT NULL CHECK (price >= 0)"
                },
                {
                  "name": "quantity",
                  "type": "INTEGER",
                  "constraints": "NOT NULL DEFAULT 1 CHECK (quantity >= 0)"
                },
                {
                  "name": "description",
                  "type": "TEXT"
                },
                {
                  "name": "status",
                  "type": "VARCHAR(50)",
                  "constraints": "NOT NULL DEFAULT 'available' CHECK (status IN ('available','sold','removed'))"
                },
                {
                  "name": "created_at",
                  "type": "TIMESTAMP",
                  "constraints": "NOT NULL DEFAULT CURRENT_TIMESTAMP"
                },
                {
                  "name": "updated_at",
                  "type": "TIMESTAMP",
                  "constraints": "NOT NULL DEFAULT CURRENT_TIMESTAMP"
                }
              ],
              "foreign_keys": [
                {
                  "column": "seller_id",
                  "references": "prp.users(id)",
                  "on_delete": "CASCADE"
                }
              ]
            },
            {
              "table_name": "card_images",
              "comment": "Stores images for Pokémon card listings.",
              "columns": [
                {
                  "name": "id",
                  "type": "UUID",
                  "constraints": "PRIMARY KEY DEFAULT gen_random_uuid()"
                },
                {
                  "name": "submenu_id",
                  "type": "INT",
                  "constraints": "DEFAULT 201 NOT NULL REFERENCES prp.submenu(submenu_id)"
                },
                {
                  "name": "card_listing_id",
                  "type": "UUID",
                  "constraints": "NOT NULL REFERENCES prp.card_listings(id) ON DELETE CASCADE"
                },
                {
                  "name": "image_url",
                  "type": "VARCHAR(500)",
                  "constraints": "NOT NULL"
                },
                {
                  "name": "display_order",
                  "type": "INTEGER",
                  "constraints": "NOT NULL DEFAULT 0"
                },
                {
                  "name": "created_at",
                  "type": "TIMESTAMP",
                  "constraints": "NOT NULL DEFAULT CURRENT_TIMESTAMP"
                },
                {
                  "name": "updated_at",
                  "type": "TIMESTAMP",
                  "constraints": "NOT NULL DEFAULT CURRENT_TIMESTAMP"
                }
              ],
              "foreign_keys": [
                {
                  "column": "card_listing_id",
                  "references": "prp.card_listings(id)",
                  "on_delete": "CASCADE"
                }
              ]
            }
          ]
        },
        {
          "submenu_id": 202,
          "submenu_name": "Search & Filter",
          "sequence_number": 2,
          "description": "Search and filter card listings based on various criteria."
        }
      ]
    },
    {
      "menu_id": 3,
      "menu_name": "Shopping Cart",
      "sequence_number": 3,
      "description": "Manage items in the shopping cart and proceed to checkout.",
      "submenus": [
        {
          "submenu_id": 301,
          "submenu_name": "Cart Management",
          "sequence_number": 1,
          "description": "Manage items in the user's shopping cart.",
          "tables": [
            {
              "table_name": "carts",
              "comment": "Stores shopping carts for users, each containing multiple items.",
              "columns": [
                {
                  "name": "id",
                  "type": "UUID",
                  "constraints": "PRIMARY KEY DEFAULT gen_random_uuid()"
                },
                {
                  "name": "submenu_id",
                  "type": "INT",
                  "constraints": "DEFAULT 301 NOT NULL REFERENCES prp.submenu(submenu_id)"
                },
                {
                  "name": "user_id",
                  "type": "UUID",
                  "constraints": "NOT NULL UNIQUE REFERENCES prp.users(id) ON DELETE CASCADE"
                },
                {
                  "name": "created_at",
                  "type": "TIMESTAMP",
                  "constraints": "NOT NULL DEFAULT CURRENT_TIMESTAMP"
                },
                {
                  "name": "updated_at",
                  "type": "TIMESTAMP",
                  "constraints": "NOT NULL DEFAULT CURRENT_TIMESTAMP"
                }
              ],
              "foreign_keys": [
                {
                  "column": "user_id",
                  "references": "prp.users(id)",
                  "on_delete": "CASCADE"
                }
              ]
            },
            {
              "table_name": "cart_items",
              "comment": "Stores individual card listings within a user's shopping cart.",
              "columns": [
                {
                  "name": "id",
                  "type": "UUID",
                  "constraints": "PRIMARY KEY DEFAULT gen_random_uuid()"
                },
                {
                  "name": "submenu_id",
                  "type": "INT",
                  "constraints": "DEFAULT 301 NOT NULL REFERENCES prp.submenu(submenu_id)"
                },
                {
                  "name": "cart_id",
                  "type": "UUID",
                  "constraints": "NOT NULL REFERENCES prp.carts(id) ON DELETE CASCADE"
                },
                {
                  "name": "card_listing_id",
                  "type": "UUID",
                  "constraints": "NOT NULL REFERENCES prp.card_listings(id) ON DELETE CASCADE"
                },
                {
                  "name": "created_at",
                  "type": "TIMESTAMP",
                  "constraints": "NOT NULL DEFAULT CURRENT_TIMESTAMP"
                },
                {
                  "name": "updated_at",
                  "type": "TIMESTAMP",
                  "constraints": "NOT NULL DEFAULT CURRENT_TIMESTAMP"
                }
              ],
              "foreign_keys": [
                {
                  "column": "cart_id",
                  "references": "prp.carts(id)",
                  "on_delete": "CASCADE"
                },
                {
                  "column": "card_listing_id",
                  "references": "prp.card_listings(id)",
                  "on_delete": "CASCADE"
                }
              ]
            }
          ]
        }
      ]
    },
    {
      "menu_id": 4,
      "menu_name": "Order Management",
      "sequence_number": 4,
      "description": "Handle order creation, tracking, and fulfillment.",
      "submenus": [
        {
          "submenu_id": 401,
          "submenu_name": "Order Processing",
          "sequence_number": 1,
          "description": "Process and manage orders from creation to fulfillment.",
          "tables": [
            {
              "table_name": "orders",
              "comment": "Stores orders placed by buyers, including shipping details and status.",
              "columns": [
                {
                  "name": "id",
                  "type": "UUID",
                  "constraints": "PRIMARY KEY DEFAULT gen_random_uuid()"
                },
                {
                  "name": "submenu_id",
                  "type": "INT",
                  "constraints": "DEFAULT 401 NOT NULL REFERENCES prp.submenu(submenu_id)"
                },
                {
                  "name": "buyer_id",
                  "type": "UUID",
                  "constraints": "NOT NULL REFERENCES prp.users(id) ON DELETE CASCADE"
                },
                {
                  "name": "total_amount",
                  "type": "NUMERIC(10,2)",
                  "constraints": "NOT NULL CHECK (total_amount >= 0)"
                },
                {
                  "name": "status",
                  "type": "VARCHAR(50)",
                  "constraints": "NOT NULL DEFAULT 'pending' CHECK (status IN ('pending','paid','shipped','delivered','cancelled','refunded'))"
                },
                {
                  "name": "shipping_address_line1",
                  "type": "VARCHAR(255)",
                  "constraints": "NOT NULL"
                },
                {
                  "name": "shipping_address_line2",
                  "type": "VARCHAR(255)"
                },
                {
                  "name": "shipping_city",
                  "type": "VARCHAR(100)",
                  "constraints": "NOT NULL"
                },
                {
                  "name": "shipping_state",
                  "type": "VARCHAR(100)",
                  "constraints": "NOT NULL"
                },
                {
                  "name": "shipping_postal_code",
                  "type": "VARCHAR(20)",
                  "constraints": "NOT NULL"
                },
                {
                  "name": "shipping_country",
                  "type": "VARCHAR(100)",
                  "constraints": "NOT NULL"
                },
                {
                  "name": "created_at",
                  "type": "TIMESTAMP",
                  "constraints": "NOT NULL DEFAULT CURRENT_TIMESTAMP"
                },
                {
                  "name": "updated_at",
                  "type": "TIMESTAMP",
                  "constraints": "NOT NULL DEFAULT CURRENT_TIMESTAMP"
                }
              ],
              "foreign_keys": [
                {
                  "column": "buyer_id",
                  "references": "prp.users(id)",
                  "on_delete": "CASCADE"
                }
              ]
            },
            {
              "table_name": "order_items",
              "comment": "Stores individual card listings within an order.",
              "columns": [
                {
                  "name": "id",
                  "type": "UUID",
                  "constraints": "PRIMARY KEY DEFAULT gen_random_uuid()"
                },
                {
                  "name": "submenu_id",
                  "type": "INT",
                  "constraints": "DEFAULT 401 NOT NULL REFERENCES prp.submenu(submenu_id)"
                },
                {
                  "name": "order_id",
                  "type": "UUID",
                  "constraints": "NOT NULL REFERENCES prp.orders(id) ON DELETE CASCADE"
                },
                {
                  "name": "card_listing_id",
                  "type": "UUID",
                  "constraints": "NOT NULL REFERENCES prp.card_listings(id) ON DELETE CASCADE"
                },
                {
                  "name": "price_at_purchase",
                  "type": "NUMERIC(10,2)",
                  "constraints": "NOT NULL CHECK (price_at_purchase >= 0)"
                },
                {
                  "name": "created_at",
                  "type": "TIMESTAMP",
                  "constraints": "NOT NULL DEFAULT CURRENT_TIMESTAMP"
                },
                {
                  "name": "updated_at",
                  "type": "TIMESTAMP",
                  "constraints": "NOT NULL DEFAULT CURRENT_TIMESTAMP"
                }
              ],
              "foreign_keys": [
                {
                  "column": "order_id",
                  "references": "prp.orders(id)",
                  "on_delete": "CASCADE"
                },
                {
                  "column": "card_listing_id",
                  "references": "prp.card_listings(id)",
                  "on_delete": "CASCADE"
                }
              ]
            }
          ]
        },
        {
          "submenu_id": 402,
          "submenu_name": "Transaction Records",
          "sequence_number": 2,
          "description": "Record financial transactions for completed orders.",
          "tables": [
            {
              "table_name": "transactions",
              "comment": "Stores financial records of completed orders, including payment details.",
              "columns": [
                {
                  "name": "id",
                  "type": "UUID",
                  "constraints": "PRIMARY KEY DEFAULT gen_random_uuid()"
                },
                {
                  "name": "submenu_id",
                  "type": "INT",
                  "constraints": "DEFAULT 402 NOT NULL REFERENCES prp.submenu(submenu_id)"
                },
                {
                  "name": "order_id",
                  "type": "UUID",
                  "constraints": "NOT NULL UNIQUE REFERENCES prp.orders(id) ON DELETE CASCADE"
                },
                {
                  "name": "payment_method",
                  "type": "VARCHAR(50)",
                  "constraints": "NOT NULL CHECK (payment_method IN ('credit_card','debit_card','paypal','stripe','bank_transfer'))"
                },
                {
                  "name": "payment_status",
                  "type": "VARCHAR(50)",
                  "constraints": "NOT NULL DEFAULT 'pending' CHECK (payment_status IN ('pending','completed','failed','refunded'))"
                },
                {
                  "name": "amount",
                  "type": "NUMERIC(10,2)",
                  "constraints": "NOT NULL CHECK (amount >= 0)"
                },
                {
                  "name": "transaction_reference",
                  "type": "VARCHAR(255)"
                },
                {
                  "name": "created_at",
                  "type": "TIMESTAMP",
                  "constraints": "NOT NULL DEFAULT CURRENT_TIMESTAMP"
                },
                {
                  "name": "updated_at",
                  "type": "TIMESTAMP",
                  "constraints": "NOT NULL DEFAULT CURRENT_TIMESTAMP"
                }
              ],
              "foreign_keys": [
                {
                  "column": "order_id",
                  "references": "prp.orders(id)",
                  "on_delete": "CASCADE"
                }
              ]
            }
          ]
        }
      ]
    },
    {
      "menu_id": 5,
      "menu_name": "Reviews & Ratings",
      "sequence_number": 5,
      "description": "Manage reviews and ratings for card listings.",
      "submenus": [
        {
          "submenu_id": 501,
          "submenu_name": "Review Management",
          "sequence_number": 1,
          "description": "Create and manage reviews for purchased card listings.",
          "tables": [
            {
              "table_name": "reviews",
              "comment": "Stores reviews and ratings for card listings by buyers.",
              "columns": [
                {
                  "name": "id",
                  "type": "UUID",
                  "constraints": "PRIMARY KEY DEFAULT gen_random_uuid()"
                },
                {
                  "name": "submenu_id",
                  "type": "INT",
                  "constraints": "DEFAULT 501 NOT NULL REFERENCES prp.submenu(submenu_id)"
                },
                {
                  "name": "card_listing_id",
                  "type": "UUID",
                  "constraints": "NOT NULL REFERENCES prp.card_listings(id) ON DELETE CASCADE"
                },
                {
                  "name": "user_id",
                  "type": "UUID",
                  "constraints": "NOT NULL REFERENCES prp.users(id) ON DELETE CASCADE"
                },
                {
                  "name": "rating",
                  "type": "INTEGER",
                  "constraints": "NOT NULL CHECK (rating >= 1 AND rating <= 5)"
                },
                {
                  "name": "comment",
                  "type": "TEXT"
                },
                {
                  "name": "created_at",
                  "type": "TIMESTAMP",
                  "constraints": "NOT NULL DEFAULT CURRENT_TIMESTAMP"
                },
                {
                  "name": "updated_at",
                  "type": "TIMESTAMP",
                  "constraints": "NOT NULL DEFAULT CURRENT_TIMESTAMP"
                }
              ],
              "foreign_keys": [
                {
                  "column": "card_listing_id",
                  "references": "prp.card_listings(id)",
                  "on_delete": "CASCADE"
                },
                {
                  "column": "user_id",
                  "references": "prp.users(id)",
                  "on_delete": "CASCADE"
                }
              ]
            }
          ]
        }
      ]
    },
    {
      "menu_id": 6,
      "menu_name": "Admin Management",
      "sequence_number": 6,
      "description": "Admin functionalities for managing users, listings, and platform analytics.",
      "submenus": [
        {
          "submenu_id": 601,
          "submenu_name": "User Administration",
          "sequence_number": 1,
          "description": "Admin tools for managing user accounts and roles."
        },
        {
          "submenu_id": 602,
          "submenu_name": "Listing Moderation",
          "sequence_number": 2,
          "description": "Admin tools for moderating card listings and resolving disputes."
        }
      ]
    }
  ],
  "assumptions": [
    "Each user has a unique cart associated with their account.",
    "Orders consist of multiple order items, each linked to a specific card listing.",
    "Transactions are recorded for each order to track payment details."
  ],
  "open_questions": [
    "Should the platform support multiple currencies for international transactions?",
    "Is there a need for a detailed audit log for all admin actions?"
  ]
}
