{
  "$schema": "mantara.schema.v1",
  "system_name": "BMI Calculator App",
  "schema_name": "bmi_calc",
  "description": "A web application for calculating Body Mass Index (BMI) and storing calculation history.",
  "menus": [
    {
      "menu_id": 1,
      "menu_name": "BMI Calculations",
      "sequence_number": 1,
      "description": "Handles BMI calculations and history.",
      "submenus": [
        {
          "submenu_id": 101,
          "submenu_name": "Perform Calculation",
          "sequence_number": 1,
          "description": "Allows users to perform BMI calculations.",
          "tables": [
            {
              "table_name": "calculation",
              "comment": "Stores individual BMI calculations performed by users.",
              "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(10)",
                  "constraints": "NOT NULL CHECK (height_unit IN ('cm', 'm', 'ft', 'in'))",
                  "comment": "Unit of height measurement"
                },
                {
                  "name": "weight_unit",
                  "type": "VARCHAR(10)",
                  "constraints": "NOT NULL CHECK (weight_unit IN ('kg', 'lbs'))",
                  "comment": "Unit of weight measurement"
                },
                {
                  "name": "bmi_value",
                  "type": "DECIMAL(5,2)",
                  "constraints": "NOT NULL CHECK (bmi_value >= 0)",
                  "comment": "Calculated BMI result"
                },
                {
                  "name": "category",
                  "type": "VARCHAR(50)",
                  "constraints": "NOT NULL",
                  "comment": "Health category classification"
                },
                {
                  "name": "bmi_category_id",
                  "type": "UUID",
                  "constraints": "NOT NULL REFERENCES bmi_calc.bmi_category(id) ON DELETE RESTRICT",
                  "comment": "References the BMI category"
                },
                {
                  "name": "timestamp",
                  "type": "TIMESTAMP",
                  "constraints": "NOT NULL DEFAULT CURRENT_TIMESTAMP",
                  "comment": "When the 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"
                }
              ]
            }
          ]
        },
        {
          "submenu_id": 102,
          "submenu_name": "Calculation History",
          "sequence_number": 2,
          "description": "Displays the history of BMI calculations."
        }
      ]
    },
    {
      "menu_id": 2,
      "menu_name": "Configuration",
      "sequence_number": 2,
      "description": "Stores configuration data for measurement units and BMI categories.",
      "submenus": [
        {
          "submenu_id": 201,
          "submenu_name": "Measurement Units",
          "sequence_number": 1,
          "description": "Defines available measurement systems and units.",
          "tables": [
            {
              "table_name": "measurement_unit",
              "comment": "Defines available measurement systems and units.",
              "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": "system",
                  "type": "VARCHAR(20)",
                  "constraints": "NOT NULL CHECK (system IN ('metric', 'imperial'))",
                  "comment": "Measurement system (metric, imperial)"
                },
                {
                  "name": "height_units",
                  "type": "TEXT[]",
                  "constraints": "NOT NULL",
                  "comment": "Available height units for this system"
                },
                {
                  "name": "weight_units",
                  "type": "TEXT[]",
                  "constraints": "NOT NULL",
                  "comment": "Available weight units for this system"
                },
                {
                  "name": "default_height_unit",
                  "type": "VARCHAR(10)",
                  "constraints": "NOT NULL",
                  "comment": "Default height unit"
                },
                {
                  "name": "default_weight_unit",
                  "type": "VARCHAR(10)",
                  "constraints": "NOT NULL",
                  "comment": "Default weight unit"
                },
                {
                  "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": "BMI Categories",
          "sequence_number": 2,
          "description": "Defines BMI ranges and their corresponding health categories.",
          "tables": [
            {
              "table_name": "bmi_category",
              "comment": "Defines BMI ranges and their corresponding health categories.",
              "columns": [
                {
                  "name": "id",
                  "type": "UUID",
                  "constraints": "PRIMARY KEY DEFAULT gen_random_uuid()"
                },
                {
                  "name": "submenu_id",
                  "type": "INT",
                  "constraints": "DEFAULT 202 NOT NULL REFERENCES bmi_calc.submenu(submenu_id)"
                },
                {
                  "name": "name",
                  "type": "VARCHAR(50)",
                  "constraints": "NOT NULL",
                  "comment": "Category name (e.g., 'Underweight', 'Normal weight')"
                },
                {
                  "name": "min_bmi",
                  "type": "DECIMAL(5,2)",
                  "constraints": "NOT NULL CHECK (min_bmi >= 0)",
                  "comment": "Minimum BMI value for this category"
                },
                {
                  "name": "max_bmi",
                  "type": "DECIMAL(5,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)",
                  "constraints": "NOT NULL",
                  "comment": "UI color indicator for this category"
                },
                {
                  "name": "created_at",
                  "type": "TIMESTAMP",
                  "constraints": "NOT NULL DEFAULT CURRENT_TIMESTAMP"
                },
                {
                  "name": "updated_at",
                  "type": "TIMESTAMP",
                  "constraints": "NOT NULL DEFAULT CURRENT_TIMESTAMP"
                }
              ]
            }
          ]
        }
      ]
    }
  ],
  "assumptions": [
    "Calculations are stored in browser session/local storage and not in a persistent database.",
    "Each calculation is associated with a BMI category based on the calculated BMI value."
  ],
  "open_questions": [
    "Should the application support additional health metrics beyond BMI?",
    "Is there a need for user authentication to save calculations across sessions?"
  ]
}
