I will implement the User Group Management System as follows:

### 1. Database Schema Changes
*   **New Table `user_groups`**: Stores group info (id, name, description, is_system, created_at).
*   **New Table `user_group_members`**: Links users to groups (group_id, user_id, created_at).
*   **Update `exam_tasks`**: Add `selection_config` column to store the original assignment logic (e.g., which groups were selected).
*   **Migration Script**: Create `scripts/migrate_user_groups.ts` to initialize tables and the default "All Users" group, adding all existing users to it.

### 2. Backend Implementation (Node.js/Express)
*   **Models**:
    *   `UserGroupModel`: CRUD for groups, membership management, and "All Users" logic.
    *   Update `UserModel`: Methods to fetch user's groups.
    *   Update `ExamTaskModel`: Handle `selection_config`.
*   **Controllers**:
    *   `UserGroupController`: API endpoints for group management.
    *   Update `UserController`:
        *   Auto-add new users to "All Users" group.
        *   Handle group assignment updates.
    *   Update `ExamTaskController`:
        *   Support assigning tasks by `groupIds`.
        *   Logic to flatten groups + users and remove duplicates.
*   **API Routes**: Register new `/api/user-groups` endpoints.

### 3. Frontend Implementation (React)
*   **User Management (`UserManagePage`)**:
    *   Add a **Tab Interface**: "User List" vs "User Group Management".
    *   **Group Management Tab**: List groups, Create/Edit/Delete groups (with "All Users" protection).
    *   **User List**: Show assigned groups in the table.
    *   **User Edit Modal**: Add a Multi-select component to manage user's groups.
*   **Exam Task Assignment (`ExamTaskPage`)**:
    *   Update Assignment Modal.
    *   Add **User Group Selection** (Multi-select).
    *   Show "Selected Users" count and "Selected Groups" count.
    *   Implement logic to calculate total unique users before saving.

### 4. Business Logic & Constraints
*   **"All Users" Group**:
    *   Created automatically.
    *   Cannot be deleted or renamed.
    *   All new users join automatically.
    *   Users cannot be removed from it manually.
*   **Audit**: Record group membership changes (log to database/console as appropriate).
*   **Permissions**: Ensure only admins can manage groups (reusing existing Admin middleware).

I will start by creating the migration script and updating the backend models.