{
  "$schema": "mantara.schema.v1",
  "system_name": "Job Management System",
  "schema_name": "ai_sch_20260514_112629",
  "description": "A comprehensive task and workflow management application for organizations to manage jobs efficiently.",
  "menus": [
    {
      "menu_id": 1,
      "menu_name": "User Management",
      "sequence_number": 1,
      "description": "Manage users, roles, and permissions within the system.",
      "submenus": [
        {
          "submenu_id": 101,
          "submenu_name": "User Profiles",
          "sequence_number": 1,
          "description": "Manage user profiles and authentication credentials.",
          "tables": [
            {
              "table_name": "users",
              "comment": "Stores user information including authentication credentials, profile details, and role assignments.",
              "columns": [
                {
                  "name": "id",
                  "type": "UUID",
                  "constraints": "PRIMARY KEY DEFAULT gen_random_uuid()"
                },
                {
                  "name": "submenu_id",
                  "type": "INT",
                  "constraints": "DEFAULT 101 NOT NULL REFERENCES jms.submenu(submenu_id)"
                },
                {
                  "name": "email",
                  "type": "VARCHAR(255)",
                  "constraints": "NOT NULL UNIQUE"
                },
                {
                  "name": "password_hash",
                  "type": "VARCHAR(255)",
                  "constraints": "NOT NULL",
                  "comment": "Stores bcrypt hash, never plain text"
                },
                {
                  "name": "first_name",
                  "type": "VARCHAR(100)",
                  "constraints": "NOT NULL"
                },
                {
                  "name": "last_name",
                  "type": "VARCHAR(100)",
                  "constraints": "NOT NULL"
                },
                {
                  "name": "role",
                  "type": "VARCHAR(50)",
                  "constraints": "NOT NULL CHECK (role IN ('administrator', 'manager', 'team_member', 'viewer'))"
                },
                {
                  "name": "department_id",
                  "type": "UUID",
                  "constraints": "REFERENCES jms.departments(id) ON DELETE SET NULL"
                },
                {
                  "name": "phone",
                  "type": "VARCHAR(50)"
                },
                {
                  "name": "is_active",
                  "type": "BOOLEAN",
                  "constraints": "NOT NULL DEFAULT true"
                },
                {
                  "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": "department_id",
                  "references": "jms.departments(id)",
                  "on_delete": "SET NULL"
                }
              ]
            }
          ]
        },
        {
          "submenu_id": 102,
          "submenu_name": "Team Assignments",
          "sequence_number": 2,
          "description": "Manage user assignments to teams.",
          "tables": [
            {
              "table_name": "user_teams",
              "comment": "Associates users with teams, allowing many-to-many relationships between users and teams.",
              "columns": [
                {
                  "name": "id",
                  "type": "UUID",
                  "constraints": "PRIMARY KEY DEFAULT gen_random_uuid()"
                },
                {
                  "name": "submenu_id",
                  "type": "INT",
                  "constraints": "DEFAULT 102 NOT NULL REFERENCES jms.submenu(submenu_id)"
                },
                {
                  "name": "user_id",
                  "type": "UUID",
                  "constraints": "NOT NULL REFERENCES jms.users(id) ON DELETE CASCADE"
                },
                {
                  "name": "team_id",
                  "type": "UUID",
                  "constraints": "NOT NULL REFERENCES jms.teams(id) ON DELETE CASCADE"
                },
                {
                  "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": "user_id",
                  "references": "jms.users(id)",
                  "on_delete": "CASCADE"
                },
                {
                  "column": "team_id",
                  "references": "jms.teams(id)",
                  "on_delete": "CASCADE"
                }
              ]
            }
          ]
        }
      ]
    },
    {
      "menu_id": 2,
      "menu_name": "Job Management",
      "sequence_number": 2,
      "description": "Create, assign, and track jobs within the organization.",
      "submenus": [
        {
          "submenu_id": 201,
          "submenu_name": "Job Definitions",
          "sequence_number": 1,
          "description": "Define job types, priorities, and statuses.",
          "tables": [
            {
              "table_name": "job_types",
              "comment": "Defines categories for jobs such as 'Maintenance', 'Installation', etc.",
              "columns": [
                {
                  "name": "id",
                  "type": "UUID",
                  "constraints": "PRIMARY KEY DEFAULT gen_random_uuid()"
                },
                {
                  "name": "submenu_id",
                  "type": "INT",
                  "constraints": "DEFAULT 201 NOT NULL REFERENCES jms.submenu(submenu_id)"
                },
                {
                  "name": "name",
                  "type": "VARCHAR(100)",
                  "constraints": "NOT NULL UNIQUE"
                },
                {
                  "name": "description",
                  "type": "TEXT"
                },
                {
                  "name": "is_active",
                  "type": "BOOLEAN",
                  "constraints": "NOT NULL DEFAULT true"
                },
                {
                  "name": "created_at",
                  "type": "TIMESTAMP",
                  "constraints": "NOT NULL DEFAULT CURRENT_TIMESTAMP"
                },
                {
                  "name": "updated_at",
                  "type": "TIMESTAMP",
                  "constraints": "NOT NULL DEFAULT CURRENT_TIMESTAMP"
                }
              ],
              "foreign_keys": []
            },
            {
              "table_name": "job_statuses",
              "comment": "Represents the current state of a job in its lifecycle.",
              "columns": [
                {
                  "name": "id",
                  "type": "UUID",
                  "constraints": "PRIMARY KEY DEFAULT gen_random_uuid()"
                },
                {
                  "name": "submenu_id",
                  "type": "INT",
                  "constraints": "DEFAULT 201 NOT NULL REFERENCES jms.submenu(submenu_id)"
                },
                {
                  "name": "name",
                  "type": "VARCHAR(100)",
                  "constraints": "NOT NULL UNIQUE"
                },
                {
                  "name": "description",
                  "type": "TEXT"
                },
                {
                  "name": "display_order",
                  "type": "INTEGER",
                  "constraints": "NOT NULL DEFAULT 0"
                },
                {
                  "name": "is_active",
                  "type": "BOOLEAN",
                  "constraints": "NOT NULL DEFAULT true"
                },
                {
                  "name": "created_at",
                  "type": "TIMESTAMP",
                  "constraints": "NOT NULL DEFAULT CURRENT_TIMESTAMP"
                },
                {
                  "name": "updated_at",
                  "type": "TIMESTAMP",
                  "constraints": "NOT NULL DEFAULT CURRENT_TIMESTAMP"
                }
              ],
              "foreign_keys": []
            },
            {
              "table_name": "job_priorities",
              "comment": "Defines urgency levels for jobs such as 'Low', 'Medium', 'High', 'Critical'.",
              "columns": [
                {
                  "name": "id",
                  "type": "UUID",
                  "constraints": "PRIMARY KEY DEFAULT gen_random_uuid()"
                },
                {
                  "name": "submenu_id",
                  "type": "INT",
                  "constraints": "DEFAULT 201 NOT NULL REFERENCES jms.submenu(submenu_id)"
                },
                {
                  "name": "name",
                  "type": "VARCHAR(100)",
                  "constraints": "NOT NULL UNIQUE"
                },
                {
                  "name": "level",
                  "type": "INTEGER",
                  "constraints": "NOT NULL"
                },
                {
                  "name": "color",
                  "type": "VARCHAR(7)"
                },
                {
                  "name": "is_active",
                  "type": "BOOLEAN",
                  "constraints": "NOT NULL DEFAULT true"
                },
                {
                  "name": "created_at",
                  "type": "TIMESTAMP",
                  "constraints": "NOT NULL DEFAULT CURRENT_TIMESTAMP"
                },
                {
                  "name": "updated_at",
                  "type": "TIMESTAMP",
                  "constraints": "NOT NULL DEFAULT CURRENT_TIMESTAMP"
                }
              ],
              "foreign_keys": []
            }
          ]
        }
      ]
    },
    {
      "menu_id": 3,
      "menu_name": "Job Execution",
      "sequence_number": 3,
      "description": "Manage the execution and tracking of jobs.",
      "submenus": [
        {
          "submenu_id": 301,
          "submenu_name": "Job Management",
          "sequence_number": 1,
          "description": "Manage job creation, assignment, and tracking.",
          "tables": [
            {
              "table_name": "jobs",
              "comment": "Central entity representing a unit of work with details like title, description, priority, and status.",
              "columns": [
                {
                  "name": "id",
                  "type": "UUID",
                  "constraints": "PRIMARY KEY DEFAULT gen_random_uuid()"
                },
                {
                  "name": "submenu_id",
                  "type": "INT",
                  "constraints": "DEFAULT 301 NOT NULL REFERENCES jms.submenu(submenu_id)"
                },
                {
                  "name": "title",
                  "type": "VARCHAR(500)",
                  "constraints": "NOT NULL"
                },
                {
                  "name": "description",
                  "type": "TEXT"
                },
                {
                  "name": "job_type_id",
                  "type": "UUID",
                  "constraints": "NOT NULL REFERENCES jms.job_types(id) ON DELETE RESTRICT"
                },
                {
                  "name": "job_status_id",
                  "type": "UUID",
                  "constraints": "NOT NULL REFERENCES jms.job_statuses(id) ON DELETE RESTRICT"
                },
                {
                  "name": "job_priority_id",
                  "type": "UUID",
                  "constraints": "NOT NULL REFERENCES jms.job_priorities(id) ON DELETE RESTRICT"
                },
                {
                  "name": "created_by_user_id",
                  "type": "UUID",
                  "constraints": "NOT NULL REFERENCES jms.users(id) ON DELETE RESTRICT"
                },
                {
                  "name": "assigned_to_user_id",
                  "type": "UUID",
                  "constraints": "REFERENCES jms.users(id) ON DELETE SET NULL"
                },
                {
                  "name": "department_id",
                  "type": "UUID",
                  "constraints": "NOT NULL REFERENCES jms.departments(id) ON DELETE RESTRICT"
                },
                {
                  "name": "team_id",
                  "type": "UUID",
                  "constraints": "REFERENCES jms.teams(id) ON DELETE SET NULL"
                },
                {
                  "name": "parent_job_id",
                  "type": "UUID",
                  "constraints": "REFERENCES jms.jobs(id) ON DELETE CASCADE",
                  "comment": "Self-referential for sub-jobs"
                },
                {
                  "name": "due_date",
                  "type": "TIMESTAMP"
                },
                {
                  "name": "started_at",
                  "type": "TIMESTAMP"
                },
                {
                  "name": "completed_at",
                  "type": "TIMESTAMP"
                },
                {
                  "name": "estimated_hours",
                  "type": "NUMERIC(10,2)"
                },
                {
                  "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": "job_type_id",
                  "references": "jms.job_types(id)",
                  "on_delete": "RESTRICT"
                },
                {
                  "column": "job_status_id",
                  "references": "jms.job_statuses(id)",
                  "on_delete": "RESTRICT"
                },
                {
                  "column": "job_priority_id",
                  "references": "jms.job_priorities(id)",
                  "on_delete": "RESTRICT"
                },
                {
                  "column": "created_by_user_id",
                  "references": "jms.users(id)",
                  "on_delete": "RESTRICT"
                },
                {
                  "column": "assigned_to_user_id",
                  "references": "jms.users(id)",
                  "on_delete": "SET NULL"
                },
                {
                  "column": "department_id",
                  "references": "jms.departments(id)",
                  "on_delete": "RESTRICT"
                },
                {
                  "column": "team_id",
                  "references": "jms.teams(id)",
                  "on_delete": "SET NULL"
                },
                {
                  "column": "parent_job_id",
                  "references": "jms.jobs(id)",
                  "on_delete": "CASCADE"
                }
              ]
            }
          ]
        },
        {
          "submenu_id": 302,
          "submenu_name": "Job Comments and Attachments",
          "sequence_number": 2,
          "description": "Manage comments and attachments related to jobs.",
          "tables": [
            {
              "table_name": "comments",
              "comment": "User-generated notes and updates attached to jobs.",
              "columns": [
                {
                  "name": "id",
                  "type": "UUID",
                  "constraints": "PRIMARY KEY DEFAULT gen_random_uuid()"
                },
                {
                  "name": "submenu_id",
                  "type": "INT",
                  "constraints": "DEFAULT 302 NOT NULL REFERENCES jms.submenu(submenu_id)"
                },
                {
                  "name": "job_id",
                  "type": "UUID",
                  "constraints": "NOT NULL REFERENCES jms.jobs(id) ON DELETE CASCADE"
                },
                {
                  "name": "user_id",
                  "type": "UUID",
                  "constraints": "NOT NULL REFERENCES jms.users(id) ON DELETE RESTRICT"
                },
                {
                  "name": "content",
                  "type": "TEXT",
                  "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"
                }
              ],
              "foreign_keys": [
                {
                  "column": "job_id",
                  "references": "jms.jobs(id)",
                  "on_delete": "CASCADE"
                },
                {
                  "column": "user_id",
                  "references": "jms.users(id)",
                  "on_delete": "RESTRICT"
                }
              ]
            },
            {
              "table_name": "attachments",
              "comment": "Files and documents associated with jobs.",
              "columns": [
                {
                  "name": "id",
                  "type": "UUID",
                  "constraints": "PRIMARY KEY DEFAULT gen_random_uuid()"
                },
                {
                  "name": "submenu_id",
                  "type": "INT",
                  "constraints": "DEFAULT 302 NOT NULL REFERENCES jms.submenu(submenu_id)"
                },
                {
                  "name": "job_id",
                  "type": "UUID",
                  "constraints": "NOT NULL REFERENCES jms.jobs(id) ON DELETE CASCADE"
                },
                {
                  "name": "uploaded_by_user_id",
                  "type": "UUID",
                  "constraints": "NOT NULL REFERENCES jms.users(id) ON DELETE RESTRICT"
                },
                {
                  "name": "file_name",
                  "type": "VARCHAR(500)",
                  "constraints": "NOT NULL"
                },
                {
                  "name": "file_path",
                  "type": "VARCHAR(1000)",
                  "constraints": "NOT NULL"
                },
                {
                  "name": "file_type",
                  "type": "VARCHAR(100)"
                },
                {
                  "name": "file_size",
                  "type": "BIGINT",
                  "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"
                }
              ],
              "foreign_keys": [
                {
                  "column": "job_id",
                  "references": "jms.jobs(id)",
                  "on_delete": "CASCADE"
                },
                {
                  "column": "uploaded_by_user_id",
                  "references": "jms.users(id)",
                  "on_delete": "RESTRICT"
                }
              ]
            }
          ]
        }
      ]
    },
    {
      "menu_id": 4,
      "menu_name": "Time and Activity Tracking",
      "sequence_number": 4,
      "description": "Track time and activities related to jobs.",
      "submenus": [
        {
          "submenu_id": 401,
          "submenu_name": "Time Logs",
          "sequence_number": 1,
          "description": "Record time spent by users on jobs.",
          "tables": [
            {
              "table_name": "time_logs",
              "comment": "Records time spent by users working on jobs.",
              "columns": [
                {
                  "name": "id",
                  "type": "UUID",
                  "constraints": "PRIMARY KEY DEFAULT gen_random_uuid()"
                },
                {
                  "name": "submenu_id",
                  "type": "INT",
                  "constraints": "DEFAULT 401 NOT NULL REFERENCES jms.submenu(submenu_id)"
                },
                {
                  "name": "job_id",
                  "type": "UUID",
                  "constraints": "NOT NULL REFERENCES jms.jobs(id) ON DELETE CASCADE"
                },
                {
                  "name": "user_id",
                  "type": "UUID",
                  "constraints": "NOT NULL REFERENCES jms.users(id) ON DELETE RESTRICT"
                },
                {
                  "name": "start_time",
                  "type": "TIMESTAMP",
                  "constraints": "NOT NULL"
                },
                {
                  "name": "end_time",
                  "type": "TIMESTAMP"
                },
                {
                  "name": "duration_minutes",
                  "type": "INTEGER"
                },
                {
                  "name": "notes",
                  "type": "TEXT"
                },
                {
                  "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": "job_id",
                  "references": "jms.jobs(id)",
                  "on_delete": "CASCADE"
                },
                {
                  "column": "user_id",
                  "references": "jms.users(id)",
                  "on_delete": "RESTRICT"
                }
              ]
            }
          ]
        },
        {
          "submenu_id": 402,
          "submenu_name": "Job History",
          "sequence_number": 2,
          "description": "Capture all changes and state transitions for jobs.",
          "tables": [
            {
              "table_name": "job_history",
              "comment": "Audit trail capturing all changes and state transitions for jobs.",
              "columns": [
                {
                  "name": "id",
                  "type": "UUID",
                  "constraints": "PRIMARY KEY DEFAULT gen_random_uuid()"
                },
                {
                  "name": "submenu_id",
                  "type": "INT",
                  "constraints": "DEFAULT 402 NOT NULL REFERENCES jms.submenu(submenu_id)"
                },
                {
                  "name": "job_id",
                  "type": "UUID",
                  "constraints": "NOT NULL REFERENCES jms.jobs(id) ON DELETE CASCADE"
                },
                {
                  "name": "user_id",
                  "type": "UUID",
                  "constraints": "NOT NULL REFERENCES jms.users(id) ON DELETE RESTRICT"
                },
                {
                  "name": "action_type",
                  "type": "VARCHAR(100)",
                  "constraints": "NOT NULL"
                },
                {
                  "name": "field_name",
                  "type": "VARCHAR(255)"
                },
                {
                  "name": "old_value",
                  "type": "TEXT"
                },
                {
                  "name": "new_value",
                  "type": "TEXT"
                },
                {
                  "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": "job_id",
                  "references": "jms.jobs(id)",
                  "on_delete": "CASCADE"
                },
                {
                  "column": "user_id",
                  "references": "jms.users(id)",
                  "on_delete": "RESTRICT"
                }
              ]
            }
          ]
        }
      ]
    },
    {
      "menu_id": 5,
      "menu_name": "Configuration",
      "sequence_number": 5,
      "description": "Configure system settings and job-related parameters.",
      "submenus": [
        {
          "submenu_id": 501,
          "submenu_name": "Departments and Teams",
          "sequence_number": 1,
          "description": "Manage organizational structure including departments and teams.",
          "tables": [
            {
              "table_name": "departments",
              "comment": "Organizational unit grouping users and jobs.",
              "columns": [
                {
                  "name": "id",
                  "type": "UUID",
                  "constraints": "PRIMARY KEY DEFAULT gen_random_uuid()"
                },
                {
                  "name": "submenu_id",
                  "type": "INT",
                  "constraints": "DEFAULT 501 NOT NULL REFERENCES jms.submenu(submenu_id)"
                },
                {
                  "name": "name",
                  "type": "VARCHAR(255)",
                  "constraints": "NOT NULL UNIQUE"
                },
                {
                  "name": "description",
                  "type": "TEXT"
                },
                {
                  "name": "created_at",
                  "type": "TIMESTAMP",
                  "constraints": "NOT NULL DEFAULT CURRENT_TIMESTAMP"
                },
                {
                  "name": "updated_at",
                  "type": "TIMESTAMP",
                  "constraints": "NOT NULL DEFAULT CURRENT_TIMESTAMP"
                }
              ],
              "foreign_keys": []
            },
            {
              "table_name": "teams",
              "comment": "Sub-organizational unit within departments, grouping users working together on related jobs.",
              "columns": [
                {
                  "name": "id",
                  "type": "UUID",
                  "constraints": "PRIMARY KEY DEFAULT gen_random_uuid()"
                },
                {
                  "name": "submenu_id",
                  "type": "INT",
                  "constraints": "DEFAULT 501 NOT NULL REFERENCES jms.submenu(submenu_id)"
                },
                {
                  "name": "department_id",
                  "type": "UUID",
                  "constraints": "NOT NULL REFERENCES jms.departments(id) ON DELETE CASCADE"
                },
                {
                  "name": "name",
                  "type": "VARCHAR(255)",
                  "constraints": "NOT NULL"
                },
                {
                  "name": "description",
                  "type": "TEXT"
                },
                {
                  "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": "department_id",
                  "references": "jms.departments(id)",
                  "on_delete": "CASCADE"
                }
              ]
            }
          ]
        }
      ]
    }
  ],
  "assumptions": [
    "Each job can have only one assignee at a time.",
    "Departments and teams are hierarchical, with teams belonging to departments.",
    "Job types, statuses, and priorities are configurable and can be extended."
  ],
  "open_questions": [
    "Should the system support multi-language job descriptions?",
    "Is there a need for role-based access beyond the predefined roles?"
  ],
  "run_id": "20260514_112629"
}
