{
  "$schema": "mantara.schema.v1",
  "system_name": "Airlines Management System",
  "schema_name": "ai_sch_20260512_081000",
  "description": "A lightweight web application for managing core airline operations including flight scheduling, aircraft management, passenger bookings, and crew assignments.",
  "menus": [
    {
      "menu_id": 1,
      "menu_name": "Flight Management",
      "sequence_number": 1,
      "description": "Manage flight operations including scheduling, assignments, and status updates.",
      "submenus": [
        {
          "submenu_id": 101,
          "submenu_name": "Flight Scheduling",
          "sequence_number": 1,
          "description": "Create and manage flight schedules.",
          "tables": [
            {
              "table_name": "flights",
              "comment": "Stores scheduled flight operations including route, schedule, assigned aircraft, and operational status.",
              "columns": [
                {
                  "name": "id",
                  "type": "UUID",
                  "constraints": "PRIMARY KEY DEFAULT gen_random_uuid()"
                },
                {
                  "name": "submenu_id",
                  "type": "INT",
                  "constraints": "DEFAULT 101 NOT NULL REFERENCES ams.submenu(submenu_id)"
                },
                {
                  "name": "flight_number",
                  "type": "VARCHAR(20)",
                  "constraints": "NOT NULL"
                },
                {
                  "name": "origin_airport_id",
                  "type": "UUID",
                  "constraints": "NOT NULL REFERENCES ams.airports(id) ON DELETE RESTRICT"
                },
                {
                  "name": "destination_airport_id",
                  "type": "UUID",
                  "constraints": "NOT NULL REFERENCES ams.airports(id) ON DELETE RESTRICT"
                },
                {
                  "name": "aircraft_id",
                  "type": "UUID",
                  "constraints": "NOT NULL REFERENCES ams.aircraft(id) ON DELETE RESTRICT"
                },
                {
                  "name": "departure_time",
                  "type": "TIMESTAMP",
                  "constraints": "NOT NULL"
                },
                {
                  "name": "arrival_time",
                  "type": "TIMESTAMP",
                  "constraints": "NOT NULL"
                },
                {
                  "name": "base_price",
                  "type": "NUMERIC(12,2)",
                  "constraints": "NOT NULL CHECK (base_price >= 0)"
                },
                {
                  "name": "status",
                  "type": "VARCHAR(50)",
                  "constraints": "NOT NULL CHECK (status IN ('Scheduled', 'Active', 'Completed', 'Cancelled'))"
                },
                {
                  "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": "origin_airport_id",
                  "references": "ams.airports(id)",
                  "on_delete": "RESTRICT"
                },
                {
                  "column": "destination_airport_id",
                  "references": "ams.airports(id)",
                  "on_delete": "RESTRICT"
                },
                {
                  "column": "aircraft_id",
                  "references": "ams.aircraft(id)",
                  "on_delete": "RESTRICT"
                }
              ]
            }
          ]
        },
        {
          "submenu_id": 102,
          "submenu_name": "Flight Assignments",
          "sequence_number": 2,
          "description": "Manage crew assignments for flights.",
          "tables": [
            {
              "table_name": "flight_assignments",
              "comment": "Links crew members to flights with their assigned role for that flight.",
              "columns": [
                {
                  "name": "id",
                  "type": "UUID",
                  "constraints": "PRIMARY KEY DEFAULT gen_random_uuid()"
                },
                {
                  "name": "submenu_id",
                  "type": "INT",
                  "constraints": "DEFAULT 102 NOT NULL REFERENCES ams.submenu(submenu_id)"
                },
                {
                  "name": "flight_id",
                  "type": "UUID",
                  "constraints": "NOT NULL REFERENCES ams.flights(id) ON DELETE CASCADE"
                },
                {
                  "name": "crew_member_id",
                  "type": "UUID",
                  "constraints": "NOT NULL REFERENCES ams.crew_members(id) ON DELETE CASCADE"
                },
                {
                  "name": "assigned_role",
                  "type": "VARCHAR(50)",
                  "constraints": "NOT NULL CHECK (assigned_role IN ('Captain', 'First Officer', 'Flight Attendant', 'Purser'))"
                },
                {
                  "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": "flight_id",
                  "references": "ams.flights(id)",
                  "on_delete": "CASCADE"
                },
                {
                  "column": "crew_member_id",
                  "references": "ams.crew_members(id)",
                  "on_delete": "CASCADE"
                }
              ]
            }
          ]
        }
      ]
    },
    {
      "menu_id": 2,
      "menu_name": "Aircraft Management",
      "sequence_number": 2,
      "description": "Manage aircraft inventory and operational status.",
      "submenus": [
        {
          "submenu_id": 201,
          "submenu_name": "Aircraft Inventory",
          "sequence_number": 1,
          "description": "Manage aircraft details and status.",
          "tables": [
            {
              "table_name": "aircraft",
              "comment": "Stores information about each aircraft including model, capacity, and operational status.",
              "columns": [
                {
                  "name": "id",
                  "type": "UUID",
                  "constraints": "PRIMARY KEY DEFAULT gen_random_uuid()"
                },
                {
                  "name": "submenu_id",
                  "type": "INT",
                  "constraints": "DEFAULT 201 NOT NULL REFERENCES ams.submenu(submenu_id)"
                },
                {
                  "name": "registration_number",
                  "type": "VARCHAR(50)",
                  "constraints": "NOT NULL UNIQUE"
                },
                {
                  "name": "model",
                  "type": "VARCHAR(100)",
                  "constraints": "NOT NULL"
                },
                {
                  "name": "manufacturer",
                  "type": "VARCHAR(100)",
                  "constraints": "NOT NULL"
                },
                {
                  "name": "total_seats",
                  "type": "INTEGER",
                  "constraints": "NOT NULL CHECK (total_seats > 0)"
                },
                {
                  "name": "status",
                  "type": "VARCHAR(50)",
                  "constraints": "NOT NULL CHECK (status IN ('Active', 'Maintenance', 'Retired'))"
                },
                {
                  "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": "Passenger Management",
      "sequence_number": 3,
      "description": "Manage passenger information and bookings.",
      "submenus": [
        {
          "submenu_id": 301,
          "submenu_name": "Passenger Records",
          "sequence_number": 1,
          "description": "Store and manage passenger personal information.",
          "tables": [
            {
              "table_name": "passengers",
              "comment": "Stores passenger personal information and contact details.",
              "columns": [
                {
                  "name": "id",
                  "type": "UUID",
                  "constraints": "PRIMARY KEY DEFAULT gen_random_uuid()"
                },
                {
                  "name": "submenu_id",
                  "type": "INT",
                  "constraints": "DEFAULT 301 NOT NULL REFERENCES ams.submenu(submenu_id)"
                },
                {
                  "name": "first_name",
                  "type": "VARCHAR(100)",
                  "constraints": "NOT NULL"
                },
                {
                  "name": "last_name",
                  "type": "VARCHAR(100)",
                  "constraints": "NOT NULL"
                },
                {
                  "name": "email",
                  "type": "VARCHAR(255)",
                  "constraints": "NOT NULL"
                },
                {
                  "name": "phone",
                  "type": "VARCHAR(20)",
                  "constraints": "NOT NULL"
                },
                {
                  "name": "passport_number",
                  "type": "VARCHAR(50)",
                  "constraints": "NOT NULL UNIQUE"
                },
                {
                  "name": "date_of_birth",
                  "type": "DATE",
                  "constraints": "NOT NULL"
                },
                {
                  "name": "nationality",
                  "type": "VARCHAR(100)",
                  "constraints": "NOT NULL"
                },
                {
                  "name": "created_at",
                  "type": "TIMESTAMP",
                  "constraints": "NOT NULL DEFAULT CURRENT_TIMESTAMP"
                },
                {
                  "name": "updated_at",
                  "type": "TIMESTAMP",
                  "constraints": "NOT NULL DEFAULT CURRENT_TIMESTAMP"
                }
              ]
            }
          ]
        },
        {
          "submenu_id": 302,
          "submenu_name": "Bookings",
          "sequence_number": 2,
          "description": "Manage passenger bookings for flights.",
          "tables": [
            {
              "table_name": "bookings",
              "comment": "Links passengers to flights with booking details, seat assignments, and payment status.",
              "columns": [
                {
                  "name": "id",
                  "type": "UUID",
                  "constraints": "PRIMARY KEY DEFAULT gen_random_uuid()"
                },
                {
                  "name": "submenu_id",
                  "type": "INT",
                  "constraints": "DEFAULT 302 NOT NULL REFERENCES ams.submenu(submenu_id)"
                },
                {
                  "name": "booking_reference",
                  "type": "VARCHAR(20)",
                  "constraints": "NOT NULL UNIQUE"
                },
                {
                  "name": "passenger_id",
                  "type": "UUID",
                  "constraints": "NOT NULL REFERENCES ams.passengers(id) ON DELETE CASCADE"
                },
                {
                  "name": "flight_id",
                  "type": "UUID",
                  "constraints": "NOT NULL REFERENCES ams.flights(id) ON DELETE CASCADE"
                },
                {
                  "name": "seat_number",
                  "type": "VARCHAR(10)",
                  "constraints": "NOT NULL"
                },
                {
                  "name": "booking_class",
                  "type": "VARCHAR(50)",
                  "constraints": "NOT NULL CHECK (booking_class IN ('Economy', 'Business', 'First Class'))"
                },
                {
                  "name": "total_price",
                  "type": "NUMERIC(12,2)",
                  "constraints": "NOT NULL CHECK (total_price >= 0)"
                },
                {
                  "name": "booking_status",
                  "type": "VARCHAR(50)",
                  "constraints": "NOT NULL CHECK (booking_status IN ('Confirmed', 'Cancelled', 'Completed'))"
                },
                {
                  "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": "passenger_id",
                  "references": "ams.passengers(id)",
                  "on_delete": "CASCADE"
                },
                {
                  "column": "flight_id",
                  "references": "ams.flights(id)",
                  "on_delete": "CASCADE"
                }
              ]
            }
          ]
        },
        {
          "submenu_id": 303,
          "submenu_name": "Booking Payments",
          "sequence_number": 3,
          "description": "Manage payment transactions for bookings.",
          "tables": [
            {
              "table_name": "booking_payments",
              "comment": "Tracks payment amount, method, status, and transaction details for bookings.",
              "columns": [
                {
                  "name": "id",
                  "type": "UUID",
                  "constraints": "PRIMARY KEY DEFAULT gen_random_uuid()"
                },
                {
                  "name": "submenu_id",
                  "type": "INT",
                  "constraints": "DEFAULT 303 NOT NULL REFERENCES ams.submenu(submenu_id)"
                },
                {
                  "name": "booking_id",
                  "type": "UUID",
                  "constraints": "NOT NULL REFERENCES ams.bookings(id) ON DELETE CASCADE"
                },
                {
                  "name": "amount",
                  "type": "NUMERIC(12,2)",
                  "constraints": "NOT NULL CHECK (amount >= 0)"
                },
                {
                  "name": "payment_method",
                  "type": "VARCHAR(50)",
                  "constraints": "NOT NULL CHECK (payment_method IN ('Credit Card', 'Debit Card', 'Cash', 'Bank Transfer', 'Online Payment'))"
                },
                {
                  "name": "payment_status",
                  "type": "VARCHAR(50)",
                  "constraints": "NOT NULL CHECK (payment_status IN ('Pending', 'Completed', 'Failed', 'Refunded'))"
                },
                {
                  "name": "transaction_id",
                  "type": "VARCHAR(100)"
                },
                {
                  "name": "payment_date",
                  "type": "TIMESTAMP",
                  "constraints": "NOT NULL DEFAULT CURRENT_TIMESTAMP"
                },
                {
                  "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": "booking_id",
                  "references": "ams.bookings(id)",
                  "on_delete": "CASCADE"
                }
              ]
            }
          ]
        }
      ]
    },
    {
      "menu_id": 4,
      "menu_name": "Crew Management",
      "sequence_number": 4,
      "description": "Manage crew member information and assignments.",
      "submenus": [
        {
          "submenu_id": 401,
          "submenu_name": "Crew Records",
          "sequence_number": 1,
          "description": "Store and manage crew member information.",
          "tables": [
            {
              "table_name": "crew_members",
              "comment": "Stores crew member information, role, and certification details.",
              "columns": [
                {
                  "name": "id",
                  "type": "UUID",
                  "constraints": "PRIMARY KEY DEFAULT gen_random_uuid()"
                },
                {
                  "name": "submenu_id",
                  "type": "INT",
                  "constraints": "DEFAULT 401 NOT NULL REFERENCES ams.submenu(submenu_id)"
                },
                {
                  "name": "employee_id",
                  "type": "VARCHAR(50)",
                  "constraints": "NOT NULL UNIQUE"
                },
                {
                  "name": "first_name",
                  "type": "VARCHAR(100)",
                  "constraints": "NOT NULL"
                },
                {
                  "name": "last_name",
                  "type": "VARCHAR(100)",
                  "constraints": "NOT NULL"
                },
                {
                  "name": "email",
                  "type": "VARCHAR(255)",
                  "constraints": "NOT NULL UNIQUE"
                },
                {
                  "name": "phone",
                  "type": "VARCHAR(20)",
                  "constraints": "NOT NULL"
                },
                {
                  "name": "role",
                  "type": "VARCHAR(50)",
                  "constraints": "NOT NULL CHECK (role IN ('Captain', 'First Officer', 'Flight Attendant', 'Purser'))"
                },
                {
                  "name": "certification_number",
                  "type": "VARCHAR(100)",
                  "constraints": "NOT NULL"
                },
                {
                  "name": "certification_expiry",
                  "type": "DATE",
                  "constraints": "NOT NULL"
                },
                {
                  "name": "status",
                  "type": "VARCHAR(50)",
                  "constraints": "NOT NULL CHECK (status IN ('Active', 'On Leave', 'Inactive'))"
                },
                {
                  "name": "created_at",
                  "type": "TIMESTAMP",
                  "constraints": "NOT NULL DEFAULT CURRENT_TIMESTAMP"
                },
                {
                  "name": "updated_at",
                  "type": "TIMESTAMP",
                  "constraints": "NOT NULL DEFAULT CURRENT_TIMESTAMP"
                }
              ]
            }
          ]
        }
      ]
    },
    {
      "menu_id": 5,
      "menu_name": "Airport Management",
      "sequence_number": 5,
      "description": "Manage airport information used in flight operations.",
      "submenus": [
        {
          "submenu_id": 501,
          "submenu_name": "Airport Records",
          "sequence_number": 1,
          "description": "Store and manage airport information.",
          "tables": [
            {
              "table_name": "airports",
              "comment": "Stores airport codes, names, locations, and timezone information.",
              "columns": [
                {
                  "name": "id",
                  "type": "UUID",
                  "constraints": "PRIMARY KEY DEFAULT gen_random_uuid()"
                },
                {
                  "name": "submenu_id",
                  "type": "INT",
                  "constraints": "DEFAULT 501 NOT NULL REFERENCES ams.submenu(submenu_id)"
                },
                {
                  "name": "code",
                  "type": "VARCHAR(10)",
                  "constraints": "NOT NULL UNIQUE"
                },
                {
                  "name": "name",
                  "type": "VARCHAR(255)",
                  "constraints": "NOT NULL"
                },
                {
                  "name": "city",
                  "type": "VARCHAR(100)",
                  "constraints": "NOT NULL"
                },
                {
                  "name": "country",
                  "type": "VARCHAR(100)",
                  "constraints": "NOT NULL"
                },
                {
                  "name": "timezone",
                  "type": "VARCHAR(50)",
                  "constraints": "NOT NULL"
                },
                {
                  "name": "created_at",
                  "type": "TIMESTAMP",
                  "constraints": "NOT NULL DEFAULT CURRENT_TIMESTAMP"
                },
                {
                  "name": "updated_at",
                  "type": "TIMESTAMP",
                  "constraints": "NOT NULL DEFAULT CURRENT_TIMESTAMP"
                }
              ]
            }
          ]
        }
      ]
    }
  ],
  "assumptions": [
    "The system does not require user authentication, all users have full access.",
    "Each flight is assigned to exactly one aircraft, and each aircraft can be scheduled for multiple flights at different times.",
    "Payments are processed externally, and the system only tracks payment records."
  ],
  "open_questions": [
    "Should the system support multi-currency payments?",
    "Is there a need for role-based access control in the future?"
  ]
}
