{
  "$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 BMI category classification."
                },
                {
                  "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"
                }
              ]
            }
          ]
        },
        {
          "submenu_id": 102,
          "submenu_name": "Calculation History",
          "sequence_number": 2,
          "description": "Displays the history of BMI calculations for the current session."
        }
      ]
    },
    {
      "menu_id": 2,
      "menu_name": "BMI Categories",
      "sequence_number": 2,
      "description": "Manages BMI category classifications and related information.",
      "submenus": [
        {
          "submenu_id": 201,
          "submenu_name": "Manage BMI Categories",
          "sequence_number": 1,
          "description": "Stores reference data for BMI classification ranges.",
          "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 CHECK (name IN ('Underweight', 'Normal weight', 'Overweight', 'Obese'))",
                  "comment": "Category name."
                },
                {
                  "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": [
    "Session-based history tracking is implemented using session IDs.",
    "BMI categories are fixed and follow WHO standards."
  ],
  "open_questions": [
    "Should the application support persistent user accounts for history tracking?",
    "Is there a need to support additional health metrics beyond BMI?"
  ]
}
