# Kanban Board Module

The Kanban board organises tasks into columns so teams can visualise work in progress.
Each board belongs to a tenant and may be scoped to a department using the
`tenant_id` and `department_id` columns on the main tables.

## Database Tables

### kanban_boards
- `id` INT PRIMARY KEY
- `tenant_id` INT nullable
- `department_id` INT nullable
- `name` VARCHAR NOT NULL
- `description` TEXT nullable
- `created_at` DATETIME
- `updated_at` DATETIME

### kanban_columns
- `id` INT PRIMARY KEY
- `board_id` INT FOREIGN KEY
- `title` VARCHAR NOT NULL
- `column_order` INT
- `created_at` DATETIME
- `updated_at` DATETIME

### kanban_tasks
- `id` INT PRIMARY KEY
- `column_id` INT FOREIGN KEY
- `title` VARCHAR NOT NULL
- `description` TEXT nullable
- `assignee_id` INT nullable
- `due_date` DATE nullable
- `position` INT
- `created_at` DATETIME
- `updated_at` DATETIME

## API Endpoints

Boards and tasks follow standard CRUD routes under `/api`.

```text
GET    /api/kanban_boards
POST   /api/kanban_boards
GET    /api/kanban_boards/{id}
PUT    /api/kanban_boards/{id}
DELETE /api/kanban_boards/{id}

GET    /api/kanban_tasks?board_id={id}
POST   /api/kanban_tasks
GET    /api/kanban_tasks/{id}
PUT    /api/kanban_tasks/{id}
DELETE /api/kanban_tasks/{id}
```

## Attaching Tasks to Workflow Events

Workflow steps can create tasks automatically using the
`create_task` step type. Define the step in a workflow’s JSON as shown in
[`docs/WorkflowEngine.md`](WorkflowEngine.md) to insert a row into
`kanban_tasks` when the workflow runs.

Example snippet:
```json
{
  "type": "create_task",
  "title": "Review {document}",
  "column_id": 2,
  "assignee_id": 7
}
```

## Multi-Tenant Behaviour and Custom Forms

All board and task tables include `tenant_id` and optional `department_id` so
records are isolated between counsels. Administrators can customise task forms
per tenant or department using the Form Builder described in
[`docs/FormBuilder.md`](FormBuilder.md). When a customised form exists the
Kanban UI loads those field definitions instead of the global version so each
organisation can capture the data relevant to their processes.

