{
  "$schema": "mantara.schema.v1",
  "system_name": "Todo Task Management Application",
  "schema_name": "ai_sch_20260513_094958",
  "description": "A comprehensive task organization system for managing personal and professional tasks.",
  "menus": [
    {
      "menu_id": 1,
      "menu_name": "User Management",
      "sequence_number": 1,
      "description": "Manage user accounts, profiles, and permissions.",
      "submenus": [
        {
          "submenu_id": 101,
          "submenu_name": "User Registration",
          "sequence_number": 1,
          "description": "Handles user registration and account creation.",
          "tables": [
            {
              "table_name": "users",
              "comment": "Stores user account information and preferences.",
              "columns": [
                {
                  "name": "id",
                  "type": "UUID",
                  "constraints": "PRIMARY KEY DEFAULT gen_random_uuid()"
                },
                {
                  "name": "submenu_id",
                  "type": "INT",
                  "constraints": "DEFAULT 101 NOT NULL REFERENCES ttma.submenu(submenu_id)"
                },
                {
                  "name": "email",
                  "type": "VARCHAR(255)",
                  "constraints": "NOT NULL UNIQUE",
                  "comment": "User's email address, used for login and notifications."
                },
                {
                  "name": "password_hash",
                  "type": "VARCHAR(255)",
                  "constraints": "NOT NULL",
                  "comment": "Stores bcrypt hash of the user's password."
                },
                {
                  "name": "full_name",
                  "type": "VARCHAR(255)",
                  "constraints": "NOT NULL",
                  "comment": "User's full name."
                },
                {
                  "name": "is_active",
                  "type": "BOOLEAN",
                  "constraints": "NOT NULL DEFAULT true",
                  "comment": "Indicates if the user's account is active."
                },
                {
                  "name": "is_admin",
                  "type": "BOOLEAN",
                  "constraints": "NOT NULL DEFAULT false",
                  "comment": "Indicates if the user has admin privileges."
                },
                {
                  "name": "email_verified",
                  "type": "BOOLEAN",
                  "constraints": "NOT NULL DEFAULT false",
                  "comment": "Indicates if the user's email has been verified."
                },
                {
                  "name": "email_verified_at",
                  "type": "TIMESTAMP",
                  "comment": "Timestamp when the user's email was verified."
                },
                {
                  "name": "last_login_at",
                  "type": "TIMESTAMP",
                  "comment": "Timestamp of the user's last login."
                },
                {
                  "name": "preferences",
                  "type": "JSONB",
                  "comment": "User's preferences stored in JSON format."
                },
                {
                  "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": "User Profile Management",
          "sequence_number": 2,
          "description": "Allows users to manage their profile information and settings."
        }
      ]
    },
    {
      "menu_id": 2,
      "menu_name": "Task Management",
      "sequence_number": 2,
      "description": "Manage tasks, subtasks, and task-related operations.",
      "submenus": [
        {
          "submenu_id": 201,
          "submenu_name": "Task Creation",
          "sequence_number": 1,
          "description": "Handles the creation of new tasks.",
          "tables": [
            {
              "table_name": "tasks",
              "comment": "Stores task details and metadata.",
              "columns": [
                {
                  "name": "id",
                  "type": "UUID",
                  "constraints": "PRIMARY KEY DEFAULT gen_random_uuid()"
                },
                {
                  "name": "submenu_id",
                  "type": "INT",
                  "constraints": "DEFAULT 201 NOT NULL REFERENCES ttma.submenu(submenu_id)"
                },
                {
                  "name": "user_id",
                  "type": "UUID",
                  "constraints": "NOT NULL REFERENCES ttma.users(id) ON DELETE CASCADE",
                  "comment": "References the user who owns the task."
                },
                {
                  "name": "list_id",
                  "type": "UUID",
                  "constraints": "REFERENCES ttma.lists(id) ON DELETE SET NULL",
                  "comment": "References the list to which the task belongs."
                },
                {
                  "name": "title",
                  "type": "VARCHAR(500)",
                  "constraints": "NOT NULL",
                  "comment": "Title of the task."
                },
                {
                  "name": "description",
                  "type": "TEXT",
                  "comment": "Detailed description of the task."
                },
                {
                  "name": "status",
                  "type": "VARCHAR(50)",
                  "constraints": "NOT NULL DEFAULT 'not_started' CHECK (status IN ('not_started', 'in_progress', 'completed', 'cancelled', 'on_hold'))",
                  "comment": "Current status of the task."
                },
                {
                  "name": "priority",
                  "type": "VARCHAR(50)",
                  "constraints": "NOT NULL DEFAULT 'medium' CHECK (priority IN ('low', 'medium', 'high', 'urgent'))",
                  "comment": "Priority level of the task."
                },
                {
                  "name": "due_date",
                  "type": "TIMESTAMP",
                  "comment": "Due date and time for the task."
                },
                {
                  "name": "completed_at",
                  "type": "TIMESTAMP",
                  "comment": "Timestamp when the task was completed."
                },
                {
                  "name": "is_completed",
                  "type": "BOOLEAN",
                  "constraints": "NOT NULL DEFAULT false",
                  "comment": "Indicates if the task is completed."
                },
                {
                  "name": "sort_order",
                  "type": "INTEGER",
                  "constraints": "NOT NULL DEFAULT 0",
                  "comment": "Order of the task in the list."
                },
                {
                  "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": "ttma.users(id)",
                  "on_delete": "CASCADE"
                },
                {
                  "column": "list_id",
                  "references": "ttma.lists(id)",
                  "on_delete": "SET NULL"
                }
              ]
            }
          ]
        },
        {
          "submenu_id": 202,
          "submenu_name": "Subtask Management",
          "sequence_number": 2,
          "description": "Handles the creation and management of subtasks.",
          "tables": [
            {
              "table_name": "subtasks",
              "comment": "Stores subtask details and metadata.",
              "columns": [
                {
                  "name": "id",
                  "type": "UUID",
                  "constraints": "PRIMARY KEY DEFAULT gen_random_uuid()"
                },
                {
                  "name": "submenu_id",
                  "type": "INT",
                  "constraints": "DEFAULT 202 NOT NULL REFERENCES ttma.submenu(submenu_id)"
                },
                {
                  "name": "parent_task_id",
                  "type": "UUID",
                  "constraints": "NOT NULL REFERENCES ttma.tasks(id) ON DELETE CASCADE",
                  "comment": "References the parent task to which the subtask belongs."
                },
                {
                  "name": "title",
                  "type": "VARCHAR(500)",
                  "constraints": "NOT NULL",
                  "comment": "Title of the subtask."
                },
                {
                  "name": "description",
                  "type": "TEXT",
                  "comment": "Detailed description of the subtask."
                },
                {
                  "name": "is_completed",
                  "type": "BOOLEAN",
                  "constraints": "NOT NULL DEFAULT false",
                  "comment": "Indicates if the subtask is completed."
                },
                {
                  "name": "completed_at",
                  "type": "TIMESTAMP",
                  "comment": "Timestamp when the subtask was completed."
                },
                {
                  "name": "sort_order",
                  "type": "INTEGER",
                  "constraints": "NOT NULL DEFAULT 0",
                  "comment": "Order of the subtask in the parent task."
                },
                {
                  "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": "parent_task_id",
                  "references": "ttma.tasks(id)",
                  "on_delete": "CASCADE"
                }
              ]
            }
          ]
        },
        {
          "submenu_id": 203,
          "submenu_name": "Task Tagging",
          "sequence_number": 3,
          "description": "Manages the association of tags with tasks.",
          "tables": [
            {
              "table_name": "task_tags",
              "comment": "Associates tags with tasks for categorization.",
              "columns": [
                {
                  "name": "id",
                  "type": "UUID",
                  "constraints": "PRIMARY KEY DEFAULT gen_random_uuid()"
                },
                {
                  "name": "submenu_id",
                  "type": "INT",
                  "constraints": "DEFAULT 203 NOT NULL REFERENCES ttma.submenu(submenu_id)"
                },
                {
                  "name": "task_id",
                  "type": "UUID",
                  "constraints": "NOT NULL REFERENCES ttma.tasks(id) ON DELETE CASCADE",
                  "comment": "References the task to which the tag is applied."
                },
                {
                  "name": "tag_id",
                  "type": "UUID",
                  "constraints": "NOT NULL REFERENCES ttma.tags(id) ON DELETE CASCADE",
                  "comment": "References the tag applied to the task."
                },
                {
                  "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": "task_id",
                  "references": "ttma.tasks(id)",
                  "on_delete": "CASCADE"
                },
                {
                  "column": "tag_id",
                  "references": "ttma.tags(id)",
                  "on_delete": "CASCADE"
                }
              ]
            }
          ]
        }
      ]
    },
    {
      "menu_id": 3,
      "menu_name": "Collaboration",
      "sequence_number": 3,
      "description": "Facilitates task sharing and collaborative features.",
      "submenus": [
        {
          "submenu_id": 301,
          "submenu_name": "Task Sharing",
          "sequence_number": 1,
          "description": "Manages sharing of tasks between users.",
          "tables": [
            {
              "table_name": "shares",
              "comment": "Stores information about task sharing between users.",
              "columns": [
                {
                  "name": "id",
                  "type": "UUID",
                  "constraints": "PRIMARY KEY DEFAULT gen_random_uuid()"
                },
                {
                  "name": "submenu_id",
                  "type": "INT",
                  "constraints": "DEFAULT 301 NOT NULL REFERENCES ttma.submenu(submenu_id)"
                },
                {
                  "name": "task_id",
                  "type": "UUID",
                  "constraints": "NOT NULL REFERENCES ttma.tasks(id) ON DELETE CASCADE",
                  "comment": "References the task being shared."
                },
                {
                  "name": "owner_user_id",
                  "type": "UUID",
                  "constraints": "NOT NULL REFERENCES ttma.users(id) ON DELETE CASCADE",
                  "comment": "References the user who owns the task."
                },
                {
                  "name": "shared_with_user_id",
                  "type": "UUID",
                  "constraints": "NOT NULL REFERENCES ttma.users(id) ON DELETE CASCADE",
                  "comment": "References the user with whom the task is shared."
                },
                {
                  "name": "permission_level",
                  "type": "VARCHAR(50)",
                  "constraints": "NOT NULL DEFAULT 'view' CHECK (permission_level IN ('view', 'comment', 'edit'))",
                  "comment": "Level of access granted to the shared user."
                },
                {
                  "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": "task_id",
                  "references": "ttma.tasks(id)",
                  "on_delete": "CASCADE"
                },
                {
                  "column": "owner_user_id",
                  "references": "ttma.users(id)",
                  "on_delete": "CASCADE"
                },
                {
                  "column": "shared_with_user_id",
                  "references": "ttma.users(id)",
                  "on_delete": "CASCADE"
                }
              ]
            }
          ]
        },
        {
          "submenu_id": 302,
          "submenu_name": "Comments",
          "sequence_number": 2,
          "description": "Handles comments on tasks for collaboration.",
          "tables": [
            {
              "table_name": "comments",
              "comment": "Stores comments made on tasks by users.",
              "columns": [
                {
                  "name": "id",
                  "type": "UUID",
                  "constraints": "PRIMARY KEY DEFAULT gen_random_uuid()"
                },
                {
                  "name": "submenu_id",
                  "type": "INT",
                  "constraints": "DEFAULT 302 NOT NULL REFERENCES ttma.submenu(submenu_id)"
                },
                {
                  "name": "task_id",
                  "type": "UUID",
                  "constraints": "NOT NULL REFERENCES ttma.tasks(id) ON DELETE CASCADE",
                  "comment": "References the task to which the comment is attached."
                },
                {
                  "name": "user_id",
                  "type": "UUID",
                  "constraints": "NOT NULL REFERENCES ttma.users(id) ON DELETE CASCADE",
                  "comment": "References the user who made the comment."
                },
                {
                  "name": "content",
                  "type": "TEXT",
                  "constraints": "NOT NULL",
                  "comment": "Content of the comment."
                },
                {
                  "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": "task_id",
                  "references": "ttma.tasks(id)",
                  "on_delete": "CASCADE"
                },
                {
                  "column": "user_id",
                  "references": "ttma.users(id)",
                  "on_delete": "CASCADE"
                }
              ]
            }
          ]
        }
      ]
    },
    {
      "menu_id": 4,
      "menu_name": "Notifications and Activity",
      "sequence_number": 4,
      "description": "Manage notifications and activity logs for user actions.",
      "submenus": [
        {
          "submenu_id": 401,
          "submenu_name": "Notifications",
          "sequence_number": 1,
          "description": "Handles user notifications for task-related events.",
          "tables": [
            {
              "table_name": "notifications",
              "comment": "Stores notifications sent to users about task events.",
              "columns": [
                {
                  "name": "id",
                  "type": "UUID",
                  "constraints": "PRIMARY KEY DEFAULT gen_random_uuid()"
                },
                {
                  "name": "submenu_id",
                  "type": "INT",
                  "constraints": "DEFAULT 401 NOT NULL REFERENCES ttma.submenu(submenu_id)"
                },
                {
                  "name": "user_id",
                  "type": "UUID",
                  "constraints": "NOT NULL REFERENCES ttma.users(id) ON DELETE CASCADE",
                  "comment": "References the user receiving the notification."
                },
                {
                  "name": "task_id",
                  "type": "UUID",
                  "constraints": "REFERENCES ttma.tasks(id) ON DELETE CASCADE",
                  "comment": "References the task related to the notification."
                },
                {
                  "name": "notification_type",
                  "type": "VARCHAR(100)",
                  "constraints": "NOT NULL CHECK (notification_type IN ('task_assigned', 'task_shared', 'task_due_soon', 'task_overdue', 'comment_added', 'task_completed', 'task_updated', 'mention'))",
                  "comment": "Type of notification event."
                },
                {
                  "name": "title",
                  "type": "VARCHAR(500)",
                  "constraints": "NOT NULL",
                  "comment": "Title of the notification."
                },
                {
                  "name": "message",
                  "type": "TEXT",
                  "constraints": "NOT NULL",
                  "comment": "Detailed message of the notification."
                },
                {
                  "name": "is_read",
                  "type": "BOOLEAN",
                  "constraints": "NOT NULL DEFAULT false",
                  "comment": "Indicates if the notification has been read."
                },
                {
                  "name": "read_at",
                  "type": "TIMESTAMP",
                  "comment": "Timestamp when the notification was read."
                },
                {
                  "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": "ttma.users(id)",
                  "on_delete": "CASCADE"
                },
                {
                  "column": "task_id",
                  "references": "ttma.tasks(id)",
                  "on_delete": "CASCADE"
                }
              ]
            }
          ]
        },
        {
          "submenu_id": 402,
          "submenu_name": "Activity Logs",
          "sequence_number": 2,
          "description": "Records actions performed on tasks for audit purposes.",
          "tables": [
            {
              "table_name": "activity_logs",
              "comment": "Stores logs of actions performed on tasks by users.",
              "columns": [
                {
                  "name": "id",
                  "type": "UUID",
                  "constraints": "PRIMARY KEY DEFAULT gen_random_uuid()"
                },
                {
                  "name": "submenu_id",
                  "type": "INT",
                  "constraints": "DEFAULT 402 NOT NULL REFERENCES ttma.submenu(submenu_id)"
                },
                {
                  "name": "task_id",
                  "type": "UUID",
                  "constraints": "NOT NULL REFERENCES ttma.tasks(id) ON DELETE CASCADE",
                  "comment": "References the task related to the activity."
                },
                {
                  "name": "user_id",
                  "type": "UUID",
                  "constraints": "NOT NULL REFERENCES ttma.users(id) ON DELETE CASCADE",
                  "comment": "References the user who performed the action."
                },
                {
                  "name": "action_type",
                  "type": "VARCHAR(100)",
                  "constraints": "NOT NULL CHECK (action_type IN ('created', 'updated', 'deleted', 'completed', 'reopened', 'commented', 'shared', 'status_changed', 'priority_changed', 'due_date_changed', 'assigned', 'attachment_added', 'attachment_removed'))",
                  "comment": "Type of action performed."
                },
                {
                  "name": "description",
                  "type": "TEXT",
                  "constraints": "NOT NULL",
                  "comment": "Description of the action performed."
                },
                {
                  "name": "metadata",
                  "type": "JSONB",
                  "comment": "Additional metadata related to the action."
                },
                {
                  "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": "task_id",
                  "references": "ttma.tasks(id)",
                  "on_delete": "CASCADE"
                },
                {
                  "column": "user_id",
                  "references": "ttma.users(id)",
                  "on_delete": "CASCADE"
                }
              ]
            }
          ]
        }
      ]
    },
    {
      "menu_id": 5,
      "menu_name": "Organization",
      "sequence_number": 5,
      "description": "Manage lists, tags, and task organization features.",
      "submenus": [
        {
          "submenu_id": 501,
          "submenu_name": "List Management",
          "sequence_number": 1,
          "description": "Handles creation and management of task lists.",
          "tables": [
            {
              "table_name": "lists",
              "comment": "Stores lists for organizing tasks.",
              "columns": [
                {
                  "name": "id",
                  "type": "UUID",
                  "constraints": "PRIMARY KEY DEFAULT gen_random_uuid()"
                },
                {
                  "name": "submenu_id",
                  "type": "INT",
                  "constraints": "DEFAULT 501 NOT NULL REFERENCES ttma.submenu(submenu_id)"
                },
                {
                  "name": "user_id",
                  "type": "UUID",
                  "constraints": "NOT NULL REFERENCES ttma.users(id) ON DELETE CASCADE",
                  "comment": "References the user who owns the list."
                },
                {
                  "name": "name",
                  "type": "VARCHAR(255)",
                  "constraints": "NOT NULL",
                  "comment": "Name of the list."
                },
                {
                  "name": "description",
                  "type": "TEXT",
                  "comment": "Description of the list."
                },
                {
                  "name": "color",
                  "type": "VARCHAR(50)",
                  "comment": "Color associated with the list for UI purposes."
                },
                {
                  "name": "sort_order",
                  "type": "INTEGER",
                  "constraints": "NOT NULL DEFAULT 0",
                  "comment": "Order of the list in the user's sidebar."
                },
                {
                  "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": "ttma.users(id)",
                  "on_delete": "CASCADE"
                }
              ]
            }
          ]
        },
        {
          "submenu_id": 502,
          "submenu_name": "Tag Management",
          "sequence_number": 2,
          "description": "Handles creation and management of tags for tasks.",
          "tables": [
            {
              "table_name": "tags",
              "comment": "Stores tags for categorizing tasks.",
              "columns": [
                {
                  "name": "id",
                  "type": "UUID",
                  "constraints": "PRIMARY KEY DEFAULT gen_random_uuid()"
                },
                {
                  "name": "submenu_id",
                  "type": "INT",
                  "constraints": "DEFAULT 502 NOT NULL REFERENCES ttma.submenu(submenu_id)"
                },
                {
                  "name": "user_id",
                  "type": "UUID",
                  "constraints": "NOT NULL REFERENCES ttma.users(id) ON DELETE CASCADE",
                  "comment": "References the user who owns the tag."
                },
                {
                  "name": "name",
                  "type": "VARCHAR(100)",
                  "constraints": "NOT NULL",
                  "comment": "Name of the tag."
                },
                {
                  "name": "color",
                  "type": "VARCHAR(50)",
                  "comment": "Color associated with the tag for UI purposes."
                },
                {
                  "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": "ttma.users(id)",
                  "on_delete": "CASCADE"
                }
              ]
            }
          ]
        }
      ]
    }
  ],
  "assumptions": [
    "Each user can create multiple lists and tags for task organization.",
    "Tasks can be shared with multiple users with varying permission levels.",
    "Notifications are triggered by task-related events and user actions."
  ],
  "open_questions": [
    "Should the system support recurring tasks?",
    "Is there a need for role-based access control beyond admin and standard user?"
  ]
}
