{
  "$schema": "mantara.schema.v1",
  "system_name": "BMI Calculator App",
  "schema_name": "bmi_calculator",
  "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": "calculations",
              "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_calculator.submenu(submenu_id)"
                },
                {
                  "name": "session_id",
                  "type": "UUID",
                  "constraints": "NOT NULL",
                  "comment": "References the session during which the calculation was made."
                },
                {
                  "name": "height",
                  "type": "NUMERIC(10,2)",
                  "constraints": "NOT NULL CHECK (height > 0)",
                  "comment": "Height value entered by user."
                },
                {
                  "name": "weight",
                  "type": "NUMERIC(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', 'inches'))",
                  "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": "NUMERIC(4,1)",
                  "constraints": "NOT NULL CHECK (bmi_value > 0)",
                  "comment": "Calculated BMI result."
                },
                {
                  "name": "category",
                  "type": "VARCHAR(50)",
                  "constraints": "NOT NULL",
                  "comment": "Health category classification."
                },
                {
                  "name": "timestamp",
                  "type": "TIMESTAMP",
                  "constraints": "NOT NULL DEFAULT CURRENT_TIMESTAMP",
                  "comment": "When the calculation was performed."
                }
              ],
              "foreign_keys": [
                {
                  "column": "session_id",
                  "references": "bmi_calculator.sessions(session_id)",
                  "on_delete": "CASCADE"
                }
              ]
            }
          ]
        },
        {
          "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": "Session Management",
      "sequence_number": 2,
      "description": "Manages user sessions and tracks calculation history.",
      "submenus": [
        {
          "submenu_id": 201,
          "submenu_name": "Session Tracking",
          "sequence_number": 1,
          "description": "Tracks user sessions and calculation counts.",
          "tables": [
            {
              "table_name": "sessions",
              "comment": "Stores user session information for tracking calculation history.",
              "columns": [
                {
                  "name": "session_id",
                  "type": "UUID",
                  "constraints": "PRIMARY KEY DEFAULT gen_random_uuid()"
                },
                {
                  "name": "submenu_id",
                  "type": "INT",
                  "constraints": "DEFAULT 201 NOT NULL REFERENCES bmi_calculator.submenu(submenu_id)"
                },
                {
                  "name": "created_at",
                  "type": "TIMESTAMP",
                  "constraints": "NOT NULL DEFAULT CURRENT_TIMESTAMP"
                },
                {
                  "name": "last_activity_at",
                  "type": "TIMESTAMP",
                  "constraints": "NOT NULL DEFAULT CURRENT_TIMESTAMP",
                  "comment": "Last calculation timestamp."
                },
                {
                  "name": "calculation_count",
                  "type": "INTEGER",
                  "constraints": "NOT NULL DEFAULT 0",
                  "comment": "Total calculations in this session."
                }
              ]
            }
          ]
        }
      ]
    },
    {
      "menu_id": 3,
      "menu_name": "BMI Categories",
      "sequence_number": 3,
      "description": "Defines BMI categories and their classification ranges.",
      "submenus": [
        {
          "submenu_id": 301,
          "submenu_name": "Category Definitions",
          "sequence_number": 1,
          "description": "Stores BMI category information and classification ranges.",
          "tables": [
            {
              "table_name": "bmi_categories",
              "comment": "Stores BMI category classification ranges and descriptions.",
              "columns": [
                {
                  "name": "id",
                  "type": "UUID",
                  "constraints": "PRIMARY KEY DEFAULT gen_random_uuid()"
                },
                {
                  "name": "submenu_id",
                  "type": "INT",
                  "constraints": "DEFAULT 301 NOT NULL REFERENCES bmi_calculator.submenu(submenu_id)"
                },
                {
                  "name": "name",
                  "type": "VARCHAR(50)",
                  "constraints": "NOT NULL UNIQUE",
                  "comment": "Category name (e.g., Underweight, Normal weight)."
                },
                {
                  "name": "min_value",
                  "type": "NUMERIC(4,1)",
                  "constraints": "NOT NULL",
                  "comment": "Minimum BMI value for this category."
                },
                {
                  "name": "max_value",
                  "type": "NUMERIC(4,1)",
                  "comment": "Maximum BMI value for this category (null for open-ended)."
                },
                {
                  "name": "description",
                  "type": "TEXT",
                  "constraints": "NOT NULL",
                  "comment": "Health information about this category."
                },
                {
                  "name": "color_code",
                  "type": "VARCHAR(7)",
                  "constraints": "NOT NULL",
                  "comment": "UI color representation for the category."
                }
              ]
            }
          ]
        }
      ]
    }
  ],
  "assumptions": [
    "Each calculation is associated with a single session identified by session_id.",
    "BMI categories are predefined and do not change frequently."
  ],
  "open_questions": [
    "Should the system support multi-language descriptions for BMI categories?",
    "Is there a need to store historical changes to BMI category ranges?"
  ]
}
