{
  "$schema": "mantara.schema.v1",
  "system_name": "Utility Calculator",
  "schema_name": "ai_sch_20260512_075826",
  "description": "Schema for a web application providing various calculation tools for mathematical, financial, and utility computations.",
  "menus": [
    {
      "menu_id": 1,
      "menu_name": "Calculator Management",
      "sequence_number": 1,
      "description": "Manage different types of calculators available in the application.",
      "submenus": [
        {
          "submenu_id": 101,
          "submenu_name": "Calculator Types",
          "sequence_number": 1,
          "description": "Define and manage different calculator types.",
          "tables": [
            {
              "table_name": "calculators",
              "comment": "Stores information about each calculator type available in the application.",
              "columns": [
                {
                  "name": "id",
                  "type": "UUID",
                  "constraints": "PRIMARY KEY DEFAULT gen_random_uuid()"
                },
                {
                  "name": "submenu_id",
                  "type": "INT",
                  "constraints": "DEFAULT 101 NOT NULL REFERENCES uc.submenu(submenu_id)"
                },
                {
                  "name": "name",
                  "type": "VARCHAR(255)",
                  "constraints": "NOT NULL",
                  "comment": "Display name of the calculator"
                },
                {
                  "name": "description",
                  "type": "TEXT",
                  "constraints": "NOT NULL",
                  "comment": "Brief description of the calculator's purpose"
                },
                {
                  "name": "category",
                  "type": "VARCHAR(50)",
                  "constraints": "NOT NULL CHECK (category IN ('Basic Math', 'Financial', 'Unit Conversion', 'Date/Time', 'Health & Fitness'))",
                  "comment": "Category grouping for the calculator"
                },
                {
                  "name": "icon",
                  "type": "VARCHAR(100)",
                  "constraints": "NOT NULL",
                  "comment": "Icon identifier for UI display"
                },
                {
                  "name": "is_active",
                  "type": "BOOLEAN",
                  "constraints": "NOT NULL DEFAULT true",
                  "comment": "Whether the calculator is currently available"
                },
                {
                  "name": "display_order",
                  "type": "INTEGER",
                  "constraints": "NOT NULL DEFAULT 0",
                  "comment": "Order in which the calculator is displayed"
                },
                {
                  "name": "created_at",
                  "type": "TIMESTAMP",
                  "constraints": "NOT NULL DEFAULT CURRENT_TIMESTAMP"
                },
                {
                  "name": "updated_at",
                  "type": "TIMESTAMP",
                  "constraints": "NOT NULL DEFAULT CURRENT_TIMESTAMP"
                }
              ]
            }
          ]
        },
        {
          "submenu_id": 102,
          "submenu_name": "Calculator Fields",
          "sequence_number": 2,
          "description": "Define input and output fields for each calculator type.",
          "tables": [
            {
              "table_name": "calculator_fields",
              "comment": "Stores the fields associated with each calculator, defining inputs and outputs.",
              "columns": [
                {
                  "name": "id",
                  "type": "UUID",
                  "constraints": "PRIMARY KEY DEFAULT gen_random_uuid()"
                },
                {
                  "name": "submenu_id",
                  "type": "INT",
                  "constraints": "DEFAULT 102 NOT NULL REFERENCES uc.submenu(submenu_id)"
                },
                {
                  "name": "calculator_id",
                  "type": "UUID",
                  "constraints": "NOT NULL REFERENCES uc.calculators(id) ON DELETE CASCADE",
                  "comment": "Reference to the calculator this field belongs to"
                },
                {
                  "name": "field_name",
                  "type": "VARCHAR(100)",
                  "constraints": "NOT NULL",
                  "comment": "Internal identifier for the field"
                },
                {
                  "name": "label",
                  "type": "VARCHAR(255)",
                  "constraints": "NOT NULL",
                  "comment": "Display label for the field"
                },
                {
                  "name": "field_type",
                  "type": "VARCHAR(50)",
                  "constraints": "NOT NULL CHECK (field_type IN ('number', 'text', 'select', 'checkbox', 'radio', 'date', 'time'))",
                  "comment": "Data type of the field"
                },
                {
                  "name": "is_required",
                  "type": "BOOLEAN",
                  "constraints": "NOT NULL DEFAULT false",
                  "comment": "Whether the field is mandatory"
                },
                {
                  "name": "validation_rules",
                  "type": "JSONB",
                  "comment": "Validation constraints for the field"
                },
                {
                  "name": "default_value",
                  "type": "TEXT",
                  "comment": "Default value for the field"
                },
                {
                  "name": "display_order",
                  "type": "INTEGER",
                  "constraints": "NOT NULL DEFAULT 0",
                  "comment": "Order in which the field is displayed"
                },
                {
                  "name": "created_at",
                  "type": "TIMESTAMP",
                  "constraints": "NOT NULL DEFAULT CURRENT_TIMESTAMP"
                },
                {
                  "name": "updated_at",
                  "type": "TIMESTAMP",
                  "constraints": "NOT NULL DEFAULT CURRENT_TIMESTAMP"
                }
              ]
            }
          ]
        }
      ]
    },
    {
      "menu_id": 2,
      "menu_name": "Session Management",
      "sequence_number": 2,
      "description": "Manage user sessions and track calculations performed during each session.",
      "submenus": [
        {
          "submenu_id": 201,
          "submenu_name": "Sessions",
          "sequence_number": 1,
          "description": "Track user sessions and their activity.",
          "tables": [
            {
              "table_name": "sessions",
              "comment": "Stores session data for tracking user activity and calculation history.",
              "columns": [
                {
                  "name": "id",
                  "type": "UUID",
                  "constraints": "PRIMARY KEY DEFAULT gen_random_uuid()"
                },
                {
                  "name": "submenu_id",
                  "type": "INT",
                  "constraints": "DEFAULT 201 NOT NULL REFERENCES uc.submenu(submenu_id)"
                },
                {
                  "name": "session_id",
                  "type": "VARCHAR(255)",
                  "constraints": "NOT NULL UNIQUE",
                  "comment": "Unique identifier for the browser session"
                },
                {
                  "name": "start_time",
                  "type": "TIMESTAMP",
                  "constraints": "NOT NULL DEFAULT CURRENT_TIMESTAMP",
                  "comment": "Timestamp when the session started"
                },
                {
                  "name": "last_activity",
                  "type": "TIMESTAMP",
                  "constraints": "NOT NULL DEFAULT CURRENT_TIMESTAMP",
                  "comment": "Timestamp of the last interaction in the session"
                },
                {
                  "name": "calculation_count",
                  "type": "INTEGER",
                  "constraints": "NOT NULL DEFAULT 0",
                  "comment": "Number of calculations performed in this session"
                },
                {
                  "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": "Calculation Tracking",
      "sequence_number": 3,
      "description": "Track individual calculations performed by users during their sessions.",
      "submenus": [
        {
          "submenu_id": 301,
          "submenu_name": "Calculations",
          "sequence_number": 1,
          "description": "Record each calculation performed by users.",
          "tables": [
            {
              "table_name": "calculations",
              "comment": "Stores individual calculation operations performed by users.",
              "columns": [
                {
                  "name": "id",
                  "type": "UUID",
                  "constraints": "PRIMARY KEY DEFAULT gen_random_uuid()"
                },
                {
                  "name": "submenu_id",
                  "type": "INT",
                  "constraints": "DEFAULT 301 NOT NULL REFERENCES uc.submenu(submenu_id)"
                },
                {
                  "name": "calculator_id",
                  "type": "UUID",
                  "constraints": "NOT NULL REFERENCES uc.calculators(id) ON DELETE CASCADE",
                  "comment": "Reference to the calculator used for this calculation"
                },
                {
                  "name": "session_id",
                  "type": "UUID",
                  "constraints": "NOT NULL REFERENCES uc.sessions(id) ON DELETE CASCADE",
                  "comment": "Reference to the session during which this calculation was performed"
                },
                {
                  "name": "inputs",
                  "type": "JSONB",
                  "constraints": "NOT NULL",
                  "comment": "Key-value pairs of input parameters for the calculation"
                },
                {
                  "name": "result",
                  "type": "JSONB",
                  "constraints": "NOT NULL",
                  "comment": "Calculated output values"
                },
                {
                  "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"
                }
              ]
            }
          ]
        }
      ]
    }
  ],
  "assumptions": [
    "Calculators are categorized into predefined groups such as 'Basic Math', 'Financial', 'Unit Conversion', 'Date/Time', and 'Health & Fitness'.",
    "Sessions are tracked using a unique session identifier stored in the browser.",
    "Calculations are stored temporarily within the session and are not persisted beyond the session's lifetime."
  ],
  "open_questions": [
    "Should there be a limit on the number of calculator types that can be active at once?",
    "Is there a need for additional security measures to protect session data beyond browser storage?"
  ]
}
