{
  "$schema": "mantara.schema.v1",
  "system_name": "Simple Loan Calculator",
  "schema_name": "ai_sch_20260514_035937",
  "description": "A web application for calculating loan payments and viewing amortization schedules.",
  "menus": [
    {
      "menu_id": 1,
      "menu_name": "Loan Calculations",
      "sequence_number": 1,
      "description": "Manage loan calculation instances and results.",
      "submenus": [
        {
          "submenu_id": 101,
          "submenu_name": "Perform Loan Calculation",
          "sequence_number": 1,
          "description": "Input loan parameters and calculate results.",
          "tables": [
            {
              "table_name": "loan_calculations",
              "comment": "Stores loan calculation instances with input parameters and computed results.",
              "columns": [
                {
                  "name": "id",
                  "type": "UUID",
                  "constraints": "PRIMARY KEY DEFAULT gen_random_uuid()"
                },
                {
                  "name": "submenu_id",
                  "type": "INT",
                  "constraints": "DEFAULT 101 NOT NULL REFERENCES slc.submenu(submenu_id)"
                },
                {
                  "name": "principal_amount",
                  "type": "NUMERIC(15,2)",
                  "constraints": "NOT NULL CHECK (principal_amount >= 1 AND principal_amount <= 100000000)",
                  "comment": "Initial loan amount in dollars"
                },
                {
                  "name": "annual_interest_rate",
                  "type": "NUMERIC(6,4)",
                  "constraints": "NOT NULL CHECK (annual_interest_rate >= 0.01 AND annual_interest_rate <= 99.99)",
                  "comment": "Yearly interest rate as a percentage"
                },
                {
                  "name": "loan_term_months",
                  "type": "INTEGER",
                  "constraints": "NOT NULL CHECK (loan_term_months >= 1 AND loan_term_months <= 600)",
                  "comment": "Duration of the loan in months"
                },
                {
                  "name": "monthly_payment",
                  "type": "NUMERIC(15,2)",
                  "constraints": "NOT NULL",
                  "comment": "Calculated fixed monthly payment amount"
                },
                {
                  "name": "total_amount_paid",
                  "type": "NUMERIC(15,2)",
                  "constraints": "NOT NULL",
                  "comment": "Total amount paid over the loan lifetime"
                },
                {
                  "name": "total_interest_paid",
                  "type": "NUMERIC(15,2)",
                  "constraints": "NOT NULL",
                  "comment": "Total interest paid over the loan lifetime"
                },
                {
                  "name": "created_at",
                  "type": "TIMESTAMP",
                  "constraints": "NOT NULL DEFAULT CURRENT_TIMESTAMP"
                },
                {
                  "name": "updated_at",
                  "type": "TIMESTAMP",
                  "constraints": "NOT NULL DEFAULT CURRENT_TIMESTAMP",
                  "comment": "Set by application or trigger on update"
                }
              ]
            }
          ]
        },
        {
          "submenu_id": 102,
          "submenu_name": "Amortization Schedule",
          "sequence_number": 2,
          "description": "View detailed amortization schedule for loan calculations.",
          "tables": [
            {
              "table_name": "amortization_schedule_entries",
              "comment": "Stores amortization schedule entries for each loan calculation.",
              "columns": [
                {
                  "name": "id",
                  "type": "UUID",
                  "constraints": "PRIMARY KEY DEFAULT gen_random_uuid()"
                },
                {
                  "name": "submenu_id",
                  "type": "INT",
                  "constraints": "DEFAULT 102 NOT NULL REFERENCES slc.submenu(submenu_id)"
                },
                {
                  "name": "calculation_id",
                  "type": "UUID",
                  "constraints": "NOT NULL",
                  "comment": "References loan_calculations(id)"
                },
                {
                  "name": "payment_number",
                  "type": "INTEGER",
                  "constraints": "NOT NULL CHECK (payment_number > 0)",
                  "comment": "Sequential payment number"
                },
                {
                  "name": "payment_date",
                  "type": "DATE",
                  "comment": "Scheduled payment date"
                },
                {
                  "name": "payment_amount",
                  "type": "NUMERIC(15,2)",
                  "constraints": "NOT NULL",
                  "comment": "Total payment amount for this period"
                },
                {
                  "name": "principal_portion",
                  "type": "NUMERIC(15,2)",
                  "constraints": "NOT NULL",
                  "comment": "Amount applied to principal"
                },
                {
                  "name": "interest_portion",
                  "type": "NUMERIC(15,2)",
                  "constraints": "NOT NULL",
                  "comment": "Amount applied to interest"
                },
                {
                  "name": "remaining_balance",
                  "type": "NUMERIC(15,2)",
                  "constraints": "NOT NULL CHECK (remaining_balance >= 0)",
                  "comment": "Outstanding principal after this payment"
                },
                {
                  "name": "cumulative_interest",
                  "type": "NUMERIC(15,2)",
                  "constraints": "NOT NULL CHECK (cumulative_interest >= 0)",
                  "comment": "Total interest paid up to this point"
                },
                {
                  "name": "cumulative_principal",
                  "type": "NUMERIC(15,2)",
                  "constraints": "NOT NULL CHECK (cumulative_principal >= 0)",
                  "comment": "Total principal paid up to this point"
                },
                {
                  "name": "created_at",
                  "type": "TIMESTAMP",
                  "constraints": "NOT NULL DEFAULT CURRENT_TIMESTAMP"
                },
                {
                  "name": "updated_at",
                  "type": "TIMESTAMP",
                  "constraints": "NOT NULL DEFAULT CURRENT_TIMESTAMP",
                  "comment": "Set by application or trigger on update"
                }
              ],
              "foreign_keys": [
                {
                  "column": "calculation_id",
                  "references": "slc.loan_calculations(id)",
                  "on_delete": "CASCADE"
                }
              ]
            }
          ]
        }
      ]
    }
  ],
  "assumptions": [
    "The system does not require user authentication or data persistence beyond session.",
    "All calculations are performed client-side without backend processing."
  ],
  "open_questions": [
    "Should the application support additional loan types beyond standard amortization?",
    "Is there a need for multi-currency support in the future?"
  ]
}
