{
  "$schema": "mantara.schema.v1",
  "system_name": "Stock Listing Application",
  "schema_name": "ai_sch_20260513_065758",
  "description": "A web-based platform providing comprehensive stock information and management.",
  "menus": [
    {
      "menu_id": 1,
      "menu_name": "Stock Management",
      "sequence_number": 1,
      "description": "Manage stock information and details.",
      "submenus": [
        {
          "submenu_id": 101,
          "submenu_name": "Stock Listing",
          "sequence_number": 1,
          "description": "View and manage the list of all available stocks.",
          "tables": [
            {
              "table_name": "stocks",
              "comment": "Stores information about publicly traded stocks.",
              "columns": [
                {
                  "name": "id",
                  "type": "UUID",
                  "constraints": "PRIMARY KEY DEFAULT gen_random_uuid()"
                },
                {
                  "name": "submenu_id",
                  "type": "INT",
                  "constraints": "DEFAULT 101 NOT NULL REFERENCES sla.submenu(submenu_id)"
                },
                {
                  "name": "ticker_symbol",
                  "type": "VARCHAR(20)",
                  "constraints": "NOT NULL UNIQUE",
                  "comment": "Unique ticker symbol for the stock, uppercase only"
                },
                {
                  "name": "company_name",
                  "type": "VARCHAR(255)",
                  "constraints": "NOT NULL",
                  "comment": "Name of the company"
                },
                {
                  "name": "current_price",
                  "type": "NUMERIC(12,2)",
                  "comment": "Current trading price of the stock"
                },
                {
                  "name": "opening_price",
                  "type": "NUMERIC(12,2)",
                  "comment": "Opening price of the stock for the day"
                },
                {
                  "name": "closing_price",
                  "type": "NUMERIC(12,2)",
                  "comment": "Closing price of the stock for the day"
                },
                {
                  "name": "high_price",
                  "type": "NUMERIC(12,2)",
                  "comment": "Highest price of the stock for the day"
                },
                {
                  "name": "low_price",
                  "type": "NUMERIC(12,2)",
                  "comment": "Lowest price of the stock for the day"
                },
                {
                  "name": "volume",
                  "type": "BIGINT",
                  "comment": "Trading volume of the stock"
                },
                {
                  "name": "market_cap",
                  "type": "NUMERIC(20,2)",
                  "comment": "Market capitalization of the company"
                },
                {
                  "name": "sector_id",
                  "type": "UUID",
                  "constraints": "NOT NULL REFERENCES sla.sectors(id)",
                  "comment": "Sector classification of the stock"
                },
                {
                  "name": "industry",
                  "type": "VARCHAR(200)",
                  "comment": "Industry classification of the stock"
                },
                {
                  "name": "exchange_id",
                  "type": "UUID",
                  "constraints": "NOT NULL REFERENCES sla.exchanges(id)",
                  "comment": "Exchange where the stock is listed"
                },
                {
                  "name": "currency",
                  "type": "VARCHAR(10)",
                  "constraints": "NOT NULL",
                  "comment": "Currency code for the stock prices, ISO 4217"
                },
                {
                  "name": "last_updated",
                  "type": "TIMESTAMP",
                  "comment": "Timestamp of the last update to the stock information"
                },
                {
                  "name": "description",
                  "type": "TEXT",
                  "comment": "Description of the company"
                },
                {
                  "name": "logo_url",
                  "type": "VARCHAR(500)",
                  "comment": "URL to the company's logo"
                },
                {
                  "name": "website_url",
                  "type": "VARCHAR(500)",
                  "comment": "URL to the company's website"
                },
                {
                  "name": "country",
                  "type": "VARCHAR(100)",
                  "comment": "Country where the company is based"
                },
                {
                  "name": "ipo_date",
                  "type": "DATE",
                  "comment": "Initial public offering date"
                },
                {
                  "name": "status",
                  "type": "VARCHAR(50)",
                  "constraints": "NOT NULL CHECK (status IN ('active', 'inactive'))",
                  "comment": "Current status of the stock"
                },
                {
                  "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": "sector_id",
                  "references": "sla.sectors(id)",
                  "on_delete": "RESTRICT"
                },
                {
                  "column": "exchange_id",
                  "references": "sla.exchanges(id)",
                  "on_delete": "RESTRICT"
                }
              ]
            }
          ]
        },
        {
          "submenu_id": 102,
          "submenu_name": "Stock History",
          "sequence_number": 2,
          "description": "Manage historical price data for stocks.",
          "tables": [
            {
              "table_name": "stock_history",
              "comment": "Stores historical price data for stocks.",
              "columns": [
                {
                  "name": "id",
                  "type": "UUID",
                  "constraints": "PRIMARY KEY DEFAULT gen_random_uuid()"
                },
                {
                  "name": "submenu_id",
                  "type": "INT",
                  "constraints": "DEFAULT 102 NOT NULL REFERENCES sla.submenu(submenu_id)"
                },
                {
                  "name": "stock_id",
                  "type": "UUID",
                  "constraints": "NOT NULL REFERENCES sla.stocks(id)",
                  "comment": "Reference to the stock"
                },
                {
                  "name": "date",
                  "type": "DATE",
                  "constraints": "NOT NULL",
                  "comment": "Date of the historical record"
                },
                {
                  "name": "open_price",
                  "type": "NUMERIC(12,2)",
                  "constraints": "NOT NULL",
                  "comment": "Opening price on the given date"
                },
                {
                  "name": "close_price",
                  "type": "NUMERIC(12,2)",
                  "constraints": "NOT NULL",
                  "comment": "Closing price on the given date"
                },
                {
                  "name": "high_price",
                  "type": "NUMERIC(12,2)",
                  "constraints": "NOT NULL",
                  "comment": "Highest price on the given date"
                },
                {
                  "name": "low_price",
                  "type": "NUMERIC(12,2)",
                  "constraints": "NOT NULL",
                  "comment": "Lowest price on the given date"
                },
                {
                  "name": "volume",
                  "type": "BIGINT",
                  "constraints": "NOT NULL",
                  "comment": "Trading volume on the given date"
                },
                {
                  "name": "adjusted_close_price",
                  "type": "NUMERIC(12,2)",
                  "comment": "Adjusted closing price for dividends/splits"
                },
                {
                  "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": "stock_id",
                  "references": "sla.stocks(id)",
                  "on_delete": "CASCADE"
                }
              ]
            }
          ]
        }
      ]
    },
    {
      "menu_id": 2,
      "menu_name": "User Management",
      "sequence_number": 2,
      "description": "Manage user accounts and their activities.",
      "submenus": [
        {
          "submenu_id": 201,
          "submenu_name": "User Accounts",
          "sequence_number": 1,
          "description": "Manage user account information and roles.",
          "tables": [
            {
              "table_name": "users",
              "comment": "Stores user account information and roles.",
              "columns": [
                {
                  "name": "id",
                  "type": "UUID",
                  "constraints": "PRIMARY KEY DEFAULT gen_random_uuid()"
                },
                {
                  "name": "submenu_id",
                  "type": "INT",
                  "constraints": "DEFAULT 201 NOT NULL REFERENCES sla.submenu(submenu_id)"
                },
                {
                  "name": "email",
                  "type": "VARCHAR(255)",
                  "constraints": "NOT NULL UNIQUE",
                  "comment": "User's email address, must be unique"
                },
                {
                  "name": "password_hash",
                  "type": "VARCHAR(255)",
                  "constraints": "NOT NULL",
                  "comment": "Stores bcrypt hash of the user's password"
                },
                {
                  "name": "first_name",
                  "type": "VARCHAR(100)",
                  "comment": "User's first name"
                },
                {
                  "name": "last_name",
                  "type": "VARCHAR(100)",
                  "comment": "User's last name"
                },
                {
                  "name": "role",
                  "type": "VARCHAR(50)",
                  "constraints": "NOT NULL CHECK (role IN ('anonymous', 'registered', 'data_manager', 'administrator'))",
                  "comment": "Role of the user in the system"
                },
                {
                  "name": "registration_date",
                  "type": "TIMESTAMP",
                  "constraints": "NOT NULL DEFAULT CURRENT_TIMESTAMP",
                  "comment": "Date when the user registered"
                },
                {
                  "name": "last_login_date",
                  "type": "TIMESTAMP",
                  "comment": "Date of the user's last login"
                },
                {
                  "name": "status",
                  "type": "VARCHAR(50)",
                  "constraints": "NOT NULL CHECK (status IN ('active', 'inactive', 'suspended'))",
                  "comment": "Current status of the user account"
                },
                {
                  "name": "profile_picture_url",
                  "type": "VARCHAR(500)",
                  "comment": "URL to the user's profile picture"
                },
                {
                  "name": "preferences",
                  "type": "JSONB",
                  "comment": "User's preferences stored in JSON format"
                },
                {
                  "name": "created_at",
                  "type": "TIMESTAMP",
                  "constraints": "NOT NULL DEFAULT CURRENT_TIMESTAMP"
                },
                {
                  "name": "updated_at",
                  "type": "TIMESTAMP",
                  "constraints": "NOT NULL DEFAULT CURRENT_TIMESTAMP"
                }
              ]
            }
          ]
        },
        {
          "submenu_id": 202,
          "submenu_name": "User Activities",
          "sequence_number": 2,
          "description": "Track user interactions with stocks.",
          "tables": [
            {
              "table_name": "user_activities",
              "comment": "Tracks user interactions with stocks.",
              "columns": [
                {
                  "name": "id",
                  "type": "UUID",
                  "constraints": "PRIMARY KEY DEFAULT gen_random_uuid()"
                },
                {
                  "name": "submenu_id",
                  "type": "INT",
                  "constraints": "DEFAULT 202 NOT NULL REFERENCES sla.submenu(submenu_id)"
                },
                {
                  "name": "user_id",
                  "type": "UUID",
                  "constraints": "NOT NULL REFERENCES sla.users(id)",
                  "comment": "Reference to the user"
                },
                {
                  "name": "stock_id",
                  "type": "UUID",
                  "constraints": "NOT NULL REFERENCES sla.stocks(id)",
                  "comment": "Reference to the stock"
                },
                {
                  "name": "activity_type",
                  "type": "VARCHAR(50)",
                  "constraints": "NOT NULL CHECK (activity_type IN ('view', 'search', 'favorite'))",
                  "comment": "Type of activity performed by the user"
                },
                {
                  "name": "timestamp",
                  "type": "TIMESTAMP",
                  "constraints": "NOT NULL DEFAULT CURRENT_TIMESTAMP",
                  "comment": "Timestamp of the activity"
                },
                {
                  "name": "session_id",
                  "type": "VARCHAR(255)",
                  "comment": "Session ID during the activity"
                },
                {
                  "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": "sla.users(id)",
                  "on_delete": "CASCADE"
                },
                {
                  "column": "stock_id",
                  "references": "sla.stocks(id)",
                  "on_delete": "CASCADE"
                }
              ]
            }
          ]
        }
      ]
    },
    {
      "menu_id": 3,
      "menu_name": "Watchlist Management",
      "sequence_number": 3,
      "description": "Manage user watchlists and their items.",
      "submenus": [
        {
          "submenu_id": 301,
          "submenu_name": "Watchlists",
          "sequence_number": 1,
          "description": "Manage user watchlists.",
          "tables": [
            {
              "table_name": "watchlists",
              "comment": "Stores user watchlists.",
              "columns": [
                {
                  "name": "id",
                  "type": "UUID",
                  "constraints": "PRIMARY KEY DEFAULT gen_random_uuid()"
                },
                {
                  "name": "submenu_id",
                  "type": "INT",
                  "constraints": "DEFAULT 301 NOT NULL REFERENCES sla.submenu(submenu_id)"
                },
                {
                  "name": "user_id",
                  "type": "UUID",
                  "constraints": "NOT NULL REFERENCES sla.users(id)",
                  "comment": "Reference to the user who owns the watchlist"
                },
                {
                  "name": "name",
                  "type": "VARCHAR(200)",
                  "constraints": "NOT NULL",
                  "comment": "Name of the watchlist"
                },
                {
                  "name": "description",
                  "type": "TEXT",
                  "comment": "Description of the watchlist"
                },
                {
                  "name": "is_default",
                  "type": "BOOLEAN",
                  "constraints": "NOT NULL DEFAULT false",
                  "comment": "Indicates if this is the default watchlist"
                },
                {
                  "name": "sort_order",
                  "type": "INT",
                  "constraints": "NOT NULL DEFAULT 0",
                  "comment": "Order of the watchlist in the user's list"
                },
                {
                  "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": "sla.users(id)",
                  "on_delete": "CASCADE"
                }
              ]
            }
          ]
        },
        {
          "submenu_id": 302,
          "submenu_name": "Watchlist Items",
          "sequence_number": 2,
          "description": "Manage stocks within user watchlists.",
          "tables": [
            {
              "table_name": "watchlist_items",
              "comment": "Stores stocks within user watchlists.",
              "columns": [
                {
                  "name": "id",
                  "type": "UUID",
                  "constraints": "PRIMARY KEY DEFAULT gen_random_uuid()"
                },
                {
                  "name": "submenu_id",
                  "type": "INT",
                  "constraints": "DEFAULT 302 NOT NULL REFERENCES sla.submenu(submenu_id)"
                },
                {
                  "name": "watchlist_id",
                  "type": "UUID",
                  "constraints": "NOT NULL REFERENCES sla.watchlists(id)",
                  "comment": "Reference to the watchlist"
                },
                {
                  "name": "stock_id",
                  "type": "UUID",
                  "constraints": "NOT NULL REFERENCES sla.stocks(id)",
                  "comment": "Reference to the stock"
                },
                {
                  "name": "added_date",
                  "type": "TIMESTAMP",
                  "constraints": "NOT NULL DEFAULT CURRENT_TIMESTAMP",
                  "comment": "Date when the stock was added to the watchlist"
                },
                {
                  "name": "notes",
                  "type": "TEXT",
                  "comment": "Optional notes about the stock in the watchlist"
                },
                {
                  "name": "sort_order",
                  "type": "INT",
                  "constraints": "NOT NULL DEFAULT 0",
                  "comment": "Order of the stock in the watchlist"
                },
                {
                  "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": "watchlist_id",
                  "references": "sla.watchlists(id)",
                  "on_delete": "CASCADE"
                },
                {
                  "column": "stock_id",
                  "references": "sla.stocks(id)",
                  "on_delete": "CASCADE"
                }
              ]
            }
          ]
        }
      ]
    },
    {
      "menu_id": 4,
      "menu_name": "Configuration",
      "sequence_number": 4,
      "description": "Manage system-wide settings and configurations.",
      "submenus": [
        {
          "submenu_id": 401,
          "submenu_name": "Sectors",
          "sequence_number": 1,
          "description": "Manage stock sectors.",
          "tables": [
            {
              "table_name": "sectors",
              "comment": "Stores industry sector classifications for stocks.",
              "columns": [
                {
                  "name": "id",
                  "type": "UUID",
                  "constraints": "PRIMARY KEY DEFAULT gen_random_uuid()"
                },
                {
                  "name": "submenu_id",
                  "type": "INT",
                  "constraints": "DEFAULT 401 NOT NULL REFERENCES sla.submenu(submenu_id)"
                },
                {
                  "name": "name",
                  "type": "VARCHAR(100)",
                  "constraints": "NOT NULL UNIQUE",
                  "comment": "Name of the sector"
                },
                {
                  "name": "description",
                  "type": "TEXT",
                  "comment": "Description of the sector"
                },
                {
                  "name": "icon_url",
                  "type": "VARCHAR(500)",
                  "comment": "URL to the sector's icon/image"
                },
                {
                  "name": "display_order",
                  "type": "INT",
                  "constraints": "NOT NULL DEFAULT 0",
                  "comment": "Order of the sector in listings"
                },
                {
                  "name": "created_at",
                  "type": "TIMESTAMP",
                  "constraints": "NOT NULL DEFAULT CURRENT_TIMESTAMP"
                },
                {
                  "name": "updated_at",
                  "type": "TIMESTAMP",
                  "constraints": "NOT NULL DEFAULT CURRENT_TIMESTAMP"
                }
              ]
            }
          ]
        },
        {
          "submenu_id": 402,
          "submenu_name": "Exchanges",
          "sequence_number": 2,
          "description": "Manage stock exchanges.",
          "tables": [
            {
              "table_name": "exchanges",
              "comment": "Stores stock exchange information.",
              "columns": [
                {
                  "name": "id",
                  "type": "UUID",
                  "constraints": "PRIMARY KEY DEFAULT gen_random_uuid()"
                },
                {
                  "name": "submenu_id",
                  "type": "INT",
                  "constraints": "DEFAULT 402 NOT NULL REFERENCES sla.submenu(submenu_id)"
                },
                {
                  "name": "name",
                  "type": "VARCHAR(200)",
                  "constraints": "NOT NULL",
                  "comment": "Name of the exchange"
                },
                {
                  "name": "code",
                  "type": "VARCHAR(20)",
                  "constraints": "NOT NULL UNIQUE",
                  "comment": "Unique code for the exchange"
                },
                {
                  "name": "country",
                  "type": "VARCHAR(100)",
                  "constraints": "NOT NULL",
                  "comment": "Country where the exchange is located"
                },
                {
                  "name": "timezone",
                  "type": "VARCHAR(100)",
                  "constraints": "NOT NULL",
                  "comment": "Timezone of the exchange"
                },
                {
                  "name": "trading_hours",
                  "type": "VARCHAR(100)",
                  "comment": "Trading hours of the exchange"
                },
                {
                  "name": "currency",
                  "type": "VARCHAR(10)",
                  "constraints": "NOT NULL",
                  "comment": "Currency used in the exchange, ISO 4217"
                },
                {
                  "name": "website_url",
                  "type": "VARCHAR(500)",
                  "comment": "URL to the exchange's website"
                },
                {
                  "name": "description",
                  "type": "TEXT",
                  "comment": "Description of the exchange"
                },
                {
                  "name": "created_at",
                  "type": "TIMESTAMP",
                  "constraints": "NOT NULL DEFAULT CURRENT_TIMESTAMP"
                },
                {
                  "name": "updated_at",
                  "type": "TIMESTAMP",
                  "constraints": "NOT NULL DEFAULT CURRENT_TIMESTAMP"
                }
              ]
            }
          ]
        },
        {
          "submenu_id": 403,
          "submenu_name": "System Configurations",
          "sequence_number": 3,
          "description": "Manage application-wide settings.",
          "tables": [
            {
              "table_name": "system_configurations",
              "comment": "Stores application-wide settings and configurations.",
              "columns": [
                {
                  "name": "id",
                  "type": "UUID",
                  "constraints": "PRIMARY KEY DEFAULT gen_random_uuid()"
                },
                {
                  "name": "submenu_id",
                  "type": "INT",
                  "constraints": "DEFAULT 403 NOT NULL REFERENCES sla.submenu(submenu_id)"
                },
                {
                  "name": "key",
                  "type": "VARCHAR(200)",
                  "constraints": "NOT NULL UNIQUE",
                  "comment": "Configuration key"
                },
                {
                  "name": "value",
                  "type": "TEXT",
                  "constraints": "NOT NULL",
                  "comment": "Configuration value"
                },
                {
                  "name": "data_type",
                  "type": "VARCHAR(50)",
                  "constraints": "NOT NULL CHECK (data_type IN ('string', 'integer', 'boolean', 'json', 'decimal'))",
                  "comment": "Data type of the configuration value"
                },
                {
                  "name": "description",
                  "type": "TEXT",
                  "comment": "Description of the configuration"
                },
                {
                  "name": "last_modified_date",
                  "type": "TIMESTAMP",
                  "constraints": "NOT NULL DEFAULT CURRENT_TIMESTAMP",
                  "comment": "Date when the configuration was last modified"
                },
                {
                  "name": "modified_by_user_id",
                  "type": "UUID",
                  "constraints": "REFERENCES sla.users(id) ON DELETE SET NULL",
                  "comment": "User who last modified the configuration"
                },
                {
                  "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": "modified_by_user_id",
                  "references": "sla.users(id)",
                  "on_delete": "SET NULL"
                }
              ]
            }
          ]
        }
      ]
    }
  ],
  "assumptions": [
    "Ticker symbols are unique and consist of uppercase letters only.",
    "Stocks must belong to exactly one sector and be listed on one exchange.",
    "User roles are predefined and cannot be changed by the users themselves.",
    "Historical stock data is retained for a minimum of 5 years."
  ],
  "open_questions": [
    "Should the system support multi-currency stock listings?",
    "Is there a need for role-based access beyond the predefined roles?"
  ]
}
