{
  "$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 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 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": "session_id",
                  "type": "UUID",
                  "constraints": "REFERENCES bmi_calc.session(id) ON DELETE CASCADE",
                  "comment": "References the session during which the calculation was made."
                },
                {
                  "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(100)",
                  "constraints": "NOT NULL",
                  "comment": "Health category classification based on BMI."
                },
                {
                  "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": "session_id",
                  "references": "bmi_calc.session(id)",
                  "on_delete": "CASCADE"
                }
              ]
            }
          ]
        }
      ]
    },
    {
      "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 or 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 for the system."
                },
                {
                  "name": "default_weight_unit",
                  "type": "VARCHAR(10)",
                  "constraints": "NOT NULL",
                  "comment": "Default weight unit for the system."
                },
                {
                  "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(100)",
                  "constraints": "NOT NULL",
                  "comment": "Category name (e.g., '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 for this category."
                },
                {
                  "name": "color_code",
                  "type": "VARCHAR(7)",
                  "constraints": "NOT NULL",
                  "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"
                }
              ]
            }
          ]
        }
      ]
    },
    {
      "menu_id": 3,
      "menu_name": "Session Management",
      "sequence_number": 3,
      "description": "Handles user session data for storing calculation history.",
      "submenus": [
        {
          "submenu_id": 301,
          "submenu_name": "Session Data",
          "sequence_number": 1,
          "description": "Stores session information for anonymous users.",
          "tables": [
            {
              "table_name": "session",
              "comment": "Stores session information for anonymous users.",
              "columns": [
                {
                  "name": "id",
                  "type": "UUID",
                  "constraints": "PRIMARY KEY DEFAULT gen_random_uuid()"
                },
                {
                  "name": "submenu_id",
                  "type": "INT",
                  "constraints": "DEFAULT 301 NOT NULL REFERENCES bmi_calc.submenu(submenu_id)"
                },
                {
                  "name": "session_token",
                  "type": "VARCHAR(255)",
                  "constraints": "NOT NULL UNIQUE",
                  "comment": "Unique token for identifying a user session."
                },
                {
                  "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 local storage and not persisted to a backend database.",
    "Measurement units are predefined constants and do not require a formal foreign key relationship."
  ],
  "open_questions": [
    "Should the application support additional health metrics beyond BMI?",
    "Is there a need for user authentication in future versions?"
  ]
}
