{
  "$schema": "mantara.schema.v1",
  "system_name": "BMI Calculator App",
  "schema_name": "bmi_calc",
  "description": "A web application for calculating and tracking Body Mass Index (BMI) with health category classification and history tracking.",
  "menus": [
    {
      "menu_id": 1,
      "menu_name": "BMI Calculation",
      "sequence_number": 1,
      "description": "Handles BMI calculations and displays results.",
      "submenus": [
        {
          "submenu_id": 101,
          "submenu_name": "Calculate BMI",
          "sequence_number": 1,
          "description": "Allows users to input height and weight to calculate BMI.",
          "tables": [
            {
              "table_name": "calculation",
              "comment": "Stores individual BMI calculation records.",
              "columns": [
                {
                  "name": "id",
                  "type": "UUID",
                  "constraints": "PRIMARY KEY DEFAULT gen_random_uuid()"
                },
                {
                  "name": "submenu_id",
                  "type": "INT",
                  "constraints": "DEFAULT 101 NOT NULL REFERENCES bmi_calc.submenu(submenu_id)"
                },
                {
                  "name": "height",
                  "type": "DECIMAL(10,2)",
                  "constraints": "NOT NULL CHECK (height > 0)",
                  "comment": "Height value entered by user."
                },
                {
                  "name": "weight",
                  "type": "DECIMAL(10,2)",
                  "constraints": "NOT NULL CHECK (weight > 0)",
                  "comment": "Weight value entered by user."
                },
                {
                  "name": "height_unit",
                  "type": "VARCHAR(20)",
                  "constraints": "NOT NULL CHECK (height_unit IN ('cm', 'meters', 'feet', 'inches', 'feet_inches'))",
                  "comment": "Unit of height measurement."
                },
                {
                  "name": "weight_unit",
                  "type": "VARCHAR(20)",
                  "constraints": "NOT NULL CHECK (weight_unit IN ('kg', 'lbs'))",
                  "comment": "Unit of weight measurement."
                },
                {
                  "name": "bmi_value",
                  "type": "DECIMAL(4,1)",
                  "constraints": "NOT NULL CHECK (bmi_value > 0)",
                  "comment": "Calculated BMI result."
                },
                {
                  "name": "bmi_category_id",
                  "type": "UUID",
                  "constraints": "NOT NULL",
                  "comment": "References the BMI category based on the calculated BMI value."
                },
                {
                  "name": "session_id",
                  "type": "VARCHAR(255)",
                  "comment": "Optional identifier to group calculations by session/user."
                },
                {
                  "name": "timestamp",
                  "type": "TIMESTAMP",
                  "constraints": "NOT NULL DEFAULT CURRENT_TIMESTAMP",
                  "comment": "Date and time when calculation was performed."
                },
                {
                  "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": "bmi_category_id",
                  "references": "bmi_calc.bmi_category(id)",
                  "on_delete": "RESTRICT"
                }
              ]
            }
          ]
        }
      ]
    },
    {
      "menu_id": 2,
      "menu_name": "BMI Categories",
      "sequence_number": 2,
      "description": "Stores reference data for BMI classification ranges.",
      "submenus": [
        {
          "submenu_id": 201,
          "submenu_name": "Manage BMI Categories",
          "sequence_number": 1,
          "description": "Defines BMI categories and their attributes.",
          "tables": [
            {
              "table_name": "bmi_category",
              "comment": "Reference data for BMI classification ranges.",
              "columns": [
                {
                  "name": "id",
                  "type": "UUID",
                  "constraints": "PRIMARY KEY DEFAULT gen_random_uuid()"
                },
                {
                  "name": "submenu_id",
                  "type": "INT",
                  "constraints": "DEFAULT 201 NOT NULL REFERENCES bmi_calc.submenu(submenu_id)"
                },
                {
                  "name": "name",
                  "type": "VARCHAR(50)",
                  "constraints": "NOT NULL UNIQUE",
                  "comment": "Category name (Underweight, Normal weight, Overweight, Obese)."
                },
                {
                  "name": "min_bmi",
                  "type": "DECIMAL(4,2)",
                  "constraints": "NOT NULL CHECK (min_bmi >= 0)",
                  "comment": "Minimum BMI value for this category."
                },
                {
                  "name": "max_bmi",
                  "type": "DECIMAL(4,2)",
                  "constraints": "CHECK (max_bmi IS NULL OR max_bmi > min_bmi)",
                  "comment": "Maximum BMI value for this category."
                },
                {
                  "name": "description",
                  "type": "TEXT",
                  "comment": "Health information about this category."
                },
                {
                  "name": "color_code",
                  "type": "VARCHAR(7)",
                  "comment": "UI color indicator for the category."
                },
                {
                  "name": "created_at",
                  "type": "TIMESTAMP",
                  "constraints": "NOT NULL DEFAULT CURRENT_TIMESTAMP"
                },
                {
                  "name": "updated_at",
                  "type": "TIMESTAMP",
                  "constraints": "NOT NULL DEFAULT CURRENT_TIMESTAMP"
                }
              ]
            }
          ]
        }
      ]
    }
  ],
  "assumptions": [
    "The application will use UUIDs for primary keys to ensure uniqueness across distributed systems.",
    "BMI calculations are performed using metric units internally, with conversions handled as needed.",
    "Session management is optional and can be implemented using session or local storage for history tracking."
  ],
  "open_questions": [
    "Should the application support additional health metrics beyond BMI?",
    "Is there a need for user authentication to persist history across sessions?"
  ]
}
