Taskbase API — Architecture¶
Kind: reference
Overview¶
The taskbase API is a Go HTTP service under api/ in the skatzi/taskbase repo.
Entry point¶
api/cmd/server/main.go wires the application: connects to Postgres, runs migrations, registers all HTTP routes, and starts the server.
Package layout¶
Each resource is a self-contained package under api/internal/:
api/internal/
organization/ # GET|POST /api/organizations, GET|PUT|DELETE /api/organizations/{id}, PUT /api/organizations/{orgId}/minimum-model, GET /api/organizations/town — the Agent world town map
project/ # GET|POST /api/projects, GET|PUT|DELETE /api/projects/{id}
task/ # GET|POST /api/projects/{id}/tasks, GET|PUT|DELETE /api/tasks/{id}
taskgroup/ # GET /api/projects/{id}/groups — predefined kanban columns
milestone/ # GET|POST /api/organizations/{orgId}/milestones, GET|PUT|DELETE /api/milestones/{id}
epic/ # GET|POST /api/organizations/{orgId}/epics, GET|PUT|DELETE /api/epics/{id}
diagram/ # GET|POST /api/organizations/{orgId}/diagrams, GET|PUT|DELETE /api/diagrams/{id}, ops, positions, check, revisions and restore
routine/ # GET|POST /api/projects/{id}/routines, GET|PUT|DELETE /api/routines/{id}, POST /api/routines/{id}/run — recurring tasks, see Routines
runner/ # runners, runs, claims and the lease sweeper — see Runners and Runs
authz/ # organization grants, route guard, run-scoped agent access
comment/ # GET|POST /api/tasks/{id}/comments — mirrored from Gitea or written in Taskbase
attachment/ # task image upload, download and description binding; run-scoped image download
attention/ # GET /api/attention — the notifications outbox and its event writers (ADR-0010); context header, references, groups (ADR-0015)
attentionaction/ # POST /api/tasks/{id}/requeue-after, POST /api/attention/requeue — Needs attention's multi-step actions, shared with the plan executor (ADR-0015)
pullrequest/ # GET /api/tasks/{id}/pull-request — a task's PR and CI state read from Gitea, cached 60 s (ADR-0015)
session/ # agent sessions: /api/sessions, /api/projects/{id}/sessions, /api/tasks/{id}/sessions, /api/sessions/... — drafts, action plans, confirm, the chosen runner and model (ADR-0013, ADR-0015, ADR-0016)
sessionframe/ # the item context in a task session turn's frame (ADR-0015), and a general turn's organizations and attention summary (ADR-0016)
pipeline/ # GET /api/projects/{id}/pipeline — a project's branch pipeline from Gitea commit statuses, cached 60 s (ADR-0016)
repository/ # GET /api/projects/{id}/repository/tree|file and GET /api/platform-docs/tree|file — a project's repository and the platform docs, read-only, for session agents (ADR 0023); see Agent Sessions — Reading files
notice/ # GET|PUT /api/organizations/{orgId}/mattermost[/test] — settings and the notifier
modelpolicy/ # GET /api/projects/{id}/model-policy — the default model-selection policy plus the project's .taskbase/model-policy.md, read from Gitea and cached 5 min (ADR-0014)
webhook/ # inbound Gitea webhooks
apikey/ # API key management
keycloak/ # Keycloak user search proxy
preference/ # GET|PUT /api/me/preferences — the caller's own preferences (the UI theme), people only
auth/ # OIDC JWT + API key validation middleware
db/ # pgxpool connect + golang-migrate runner
httputil/ # shared JSON helpers
migrations/ # embedded *.sql files
pgtest/ # test-only: per-process migrated Postgres schema for *_pg_test.go
swagger/ # embedded OpenAPI spec + Swagger UI
Each domain package contains:
| File | Purpose |
|------|---------|
| model.go | Struct definition |
| store.go | Store interface |
| store_memory.go | In-memory impl (unit tests, no DB) |
| store_pg.go | PostgreSQL impl |
| handler.go | HTTP handler + RegisterRoutes |
| handler_test.go | Tests using MemoryStore |
diagram/ also has ops.go, the pure op engine that validates and applies an op batch to a diagram
model; both stores share it.
modelpolicy/ has no store. It serves files from Gitea through gitea.FileReader (GetFile,
which returns the content with its blob SHA) and keeps an in-memory cache keyed by repository and
path; a missing file is cached too. When Gitea fails it serves the last cached copy with
stale: true; with no cached copy it answers 502.
Data model¶
- Organization: top-level grouping — projects, milestones, and epics belong to an organization
- Project: belongs to an organization, contains tasks and task groups
- Task: belongs to a project, optionally linked to a task group, milestone, and/or epic. Description supports Markdown
- Task Group: predefined kanban columns within a project (Backlog, In Progress, Test, Review, Done, Blocked)
- Milestone: organization-level time-boxed goal — tasks and epics can optionally be assigned to a milestone. Description supports Markdown
- Epic: organization-level grouping that spans across projects — tasks can optionally be assigned to an epic. Description supports Markdown
- Diagram: organization-level architecture diagram of components and connections. The model changes only through atomic op batches, each bumping the diagram's revision; a separate positions layer holds the layout and is not revisioned. Description supports Markdown
See Database Schema for full table definitions and relationships, and Attention for the attention, Mattermost and comment endpoints.
Task images¶
Task images are stored in task_attachments. Uploads are
unsent until a person saves them on a description or comment. The API sniffs PNG, JPEG, WebP or GIF
from the bytes; one image may be at most 5 MiB. Each description or comment may have at most four
images. A person may have at most 12 unsent uploads per task and 100 uploads per day across tasks.
| Route | Request and response |
|---|---|
POST /api/tasks/{id}/attachments?name= |
A Keycloak-signed-in person sends raw image bytes. Returns 201 with the attachment metadata; the upload remains unsent. name is at most 200 characters with no control characters. |
GET /api/tasks/{id}/attachments/{aid} |
Returns image bytes to a caller admitted to the task's organization. Only the uploader can read an unsent image; other callers get 404. |
PUT /api/tasks/{id}/description/attachments |
A Keycloak-signed-in person sends {"attachment_ids": [...]} (at most 4 KiB). The ids become the description's images; existing description images left out are deleted. Each id must already belong to that description or be the caller's unsent upload on the task. Returns 200 with the resulting list. |
POST /api/tasks/{id}/comments |
Accepts attachment_ids beside body. The ids must be the caller's unsent uploads on this task. A comment may have images without text, but must have at least one of the two. |
GET /api/tasks/{id}/comments |
Each comment includes attachments, an empty array when there are none. |
GET /api/tasks/{id} |
Includes description attachments; task list responses do not. |
The upload refuses empty or unsupported images with 415, images over 5 MiB with 413, and an
exceeded unsent or daily cap with 429. Repeated ids, more than four ids, or ids outside the allowed
set get 400 on binding. The download sets Content-Type, Content-Disposition: inline,
Content-Security-Policy: default-src 'none', X-Content-Type-Options: nosniff,
Cache-Control: private, max-age=3600, and an ETag from the SHA-256 digest.
A run claim also carries the saved images. See Attachments in a claim for the run-scoped URL and access rule.
Source: api/internal/attachment/handler.go, task.go, image.go, and
api/internal/comment/handler.go in Skatzi/taskbase main at
047a302a46f8ea4f05ad8e55c4206247f0bc6a46, reported in task #1861 (read 2026-10-28).
Done column¶
task.Store.Update and UpdateInProject keep a task's column in step with its done flag
(Taskbase PR #353). When a write names no
group_id:
- A task that is done moves to the project's Done column.
- A task that is open and sits in Done (it was reopened) moves to Backlog.
- Otherwise the task keeps its current column, and so does a task whose project has no Done (or Backlog) column.
When a write names a group_id:
- A
group_idthat moves the task to another column wins, even when the same write marks it done. - A task that becomes done (it was not done before the write) and whose
group_idonly repeats its current column still moves to Done (Taskbase PR #434). Full PUT bodies resend the current column: the board's task dialog (api.updateTaskinui/src/App.jsx) and agents that resend the fields fromget_task. - A task that is already done keeps the column it is sent with.
Omitting group_id on PUT /api/tasks/{id} no longer ungroups the task: it keeps its
column, or follows the rules above. The rules are doneColumnGroupID in
api/internal/task/store.go. Every caller gets them because they live in the store: the PUT,
task.Service (Close, Decide, Reassign, Requeue) and the
Gitea webhook. Migration 066 moved the done tasks
that had been left outside Done before the rule existed (Database Schema).
Moving a task to another project¶
PUT /api/tasks/{id} takes an optional project_id that moves the task to another project of the
same organization (Taskbase PR #114).
Omitted, the task stays where it is. Only the REST API offers moves; the UI and the update_task MCP
tool do not send project_id.
- The target must exist, be in the task's organization, and be reachable by the caller; otherwise
403("target project not found, forbidden, or in another organization"). Aproject_idof 0 or less is a400. - A
group_idin the same request must be a column of the target project (400otherwise). Withoutgroup_id, the task lands in the target's Backlog; a target with no Backlog is a400. - The task keeps its ID, so links, comments, runs and references to
#<id>stay valid. - Linked Gitea issues follow the task (Gitea Integration).
When both projects use the same repository, the issue is kept and updated as usual. Otherwise, if
the target project is linked, a new issue is created in its repository before the task is saved
(and deleted again if the save fails; a failed create is a
502) and recorded on the task — closed at once if the task is closed. If the target has no repository, the task's issue link is cleared. The old issue, if any, gets a note appended to its description ("Taskbase task #N moved to project P. New issue: owner/repo#M.") and is closed, so it remains as a pointer.
Task effort¶
A task carries an optional reasoning effort — low, medium or high — beside model, the size
(Taskbase PR #231). Null means the
runner's default. Create, get and list return it, and POST accepts it ("" or omitted for none).
On PUT /api/tasks/{id} it behaves like model: omitted or null keeps it, "" clears it, and any
other value is a 400. A claim records it on the run (Runners and Runs).
Start after¶
A task carries an optional start_after, an RFC 3339 time before which no runner claims it
(Start after, task #2405,
taskbase#689). Null means no wait.
Get and list return it.
| Endpoint | start_after |
|---|---|
POST /api/projects/{id}/tasks |
Optional; omitted means the task can be claimed at once |
PUT /api/tasks/{id} |
Omitted keeps the stored time; null clears it, so the task can be claimed at once |
POST /api/tasks/{id}/requeue |
Optional body {"start_after": "<RFC 3339>"}: the requeued task waits until then. Without it, a stored time is cleared |
The MCP tools map to these: create_task and update_task take start_after, update_task also
clear_start_after, and requeue_task takes start_after
(MCP server).
Task links¶
Typed links between tasks (relates_to, duplicates, depends_on, follow_up_of) are stored in
task_links; who may edit them and how they feed claims is in
Runners and Runs.
GET /api/tasks/{id}/links returns each link with id, source_id, target_id and kind,
plus linked_task: {id, title, project_id, done} — the other end of the link, as seen from task
{id} (Taskbase PR #223).
POST /api/tasks/{id}/links returns the link without linked_task. The MCP tool list_task_links
passes linked_task through.
Across organizations. depends_on and relates_to may join tasks in different organizations
(Taskbase PR #239); there is no schema
change. The organization boundary still holds for content:
- Create: allowed when the caller reaches both organizations — a user with grants on both, an
administrator or a service API key. A target the caller cannot reach answers
400exactly like a missing task, so ids cannot be probed.follow_up_ofandduplicatesstay within one organization (400). Agent runs, the project-manager persona included, may not link across organizations:403, also for a missing target. - Delete: either side may delete the link with access to its own task only. Agents other than the project-manager persona still cannot delete links.
- List:
linked_taskfor a task in another organization hasother_organization: true. A viewer who reaches that organization gets the full summary plusorganization_idandorganization_name; anyone else gets onlyid,doneandother_organization— no title and no project. - Claims: an open cross-organization
depends_onholds the dependent back and raisesblocking_agent_workon a person's blocker like any other (Dependencies), but no digest or decision is imported across it (Run context reuse).
UI. The task dialog's Links section groups links by relation, read from the open task:
| Group | Links |
|---|---|
| Depends on / Blocks | depends_on from / to this task |
| Follow-up of / Followed up by | follow_up_of from / to this task |
| Relates to | relates_to |
| Duplicates | duplicates |
Empty groups are hidden, and a task without links shows "No links yet." Each linked task shows
#id, its title and a Done badge when done, and links to
/organizations/{org}/projects/{project}?task={id}, which opens its dialog — also when it is in
another project (Task deep links). A task in another organization the viewer
reaches links to that organization's board and shows its name; otherwise it shows only its state:
"Blocked by a task in another organization (open)" or "(done)" for an outgoing depends_on, and
"A task in another organization (…)" for the other kinds.
Links on create¶
POST /api/projects/{id}/tasks (MCP create_task) takes the new task's links in the same request
(Taskbase PR #488, task #1137):
| Field | Type | Creates |
|---|---|---|
depends_on |
array of task ids | One depends_on link from the new task to each id |
follow_up_of |
task id | One follow_up_of link from the new task to its predecessor |
The links are stored in the same transaction as the task, and each target is checked as
POST /api/tasks/{id}/links checks it. A refused link creates nothing — no task and no links:
| Status | When |
|---|---|
400 |
A target is missing, or one the caller cannot reach; a follow_up_of target in another organization |
403 |
An agent run names a target outside its run's organization — also when the target is missing |
409 |
The same target is named twice for one kind, e.g. "depends_on": [12, 12] |
A person who reaches both organizations may still make the new task depends_on a task in another
organization (links_test.go, TestCreateTaskWithLinks).
Prefer links on create over creating the task and then calling POST /api/tasks/{id}/links
(MCP create_task_link): the task never sits in the queue without its links, and a refused link
leaves no half-linked task behind. A task an agent creates in a run is
held until that run ends either way, and carries the
read-only held_by_run meanwhile.
Project requests¶
A person can describe what they want in a project, and Taskbase files it as a request for the
project-manager persona, which creates the tasks, epics and milestones it asks for
(Taskbase PR #184).
POST /api/projects/{id}/requests with { "text": "…" } creates a request task and returns it
(201):
- People only: an agent acting for a run gets
403. The MCP toolcreate_project_requestdoes the same (MCP Server). textis trimmed and must be 1–20,000 characters (MaxRequestText, counted as Unicode characters;400otherwise). The API refuses longer text rather than cutting it.- The task lands in the project's Backlog with
kind: "request". Its title isRequest:plus about the first 70 characters of the text, cut at a word. Its description is the text followed by a fixed footer naming who filed it and when. - It is assigned to the
project-managerpersona with no model, so the persona's default model applies at claim. A project whose review persona isproject-managerrefuses requests (400).
GET /api/projects/{id}/requests?limit=20 (limit 1–100, default 20) lists the project's
newest requests first; it too is for people only. Each has the task's id, title, text, dispatch_state, done,
requested_by and created_at, plus:
| Field | Meaning |
|---|---|
latest_run |
The request's most recent run (id, outcome, started_at, finished_at, summary); null before one starts |
question |
The open question the request waits on, if any: its open question event's, else the one its latest run left, unless the request is done or queued again |
attention_id |
The open Needs attention event of that question, if any |
created |
{ tasks, epics, milestones }: the items whose created_by_run_id is one of the request's runs |
Every task carries a read-only kind, task or request (see tasks.kind).
UI. Above the board, the request area starts collapsed to a one-line bar, with + New request, the number of requests, how many are in progress and a link to any that need an answer. It starts collapsed on every page load and opens only on a click (+ New request or the requests count); it is not remembered between visits. Open, it has a request box (Create, or ⌘/Ctrl+Enter) and a collapsible Requests list. The request box never cuts what is typed or pasted: a live counter next to Create shows the count against the limit ("3,950 / 20,000"). Past 20,000 characters it turns into an error ("Too long by 12 characters. Shorten it to 20,000 or fewer — nothing is cut for you."), Create and ⌘/Ctrl+Enter do nothing, and the text stays as it is until the person shortens it. Each request shows a state chip (Queued, Working, Needs your answer, which links to its Needs attention item, Done or Failed) and links to the items its runs created.
Configuration¶
| Env var | Default | Purpose |
|---|---|---|
DATABASE_URL |
postgres://taskbase:taskbase@localhost:5432/taskbase?sslmode=disable |
Postgres connection string |
PORT |
8080 |
HTTP listen port |
METRICS_PORT |
9090 |
Port of GET /metrics (Prometheus), not exposed by any HTTPRoute. Served only when GITEA_TOKEN is set. See API metrics |
KEYCLOAK_ISSUER |
(unset) | OIDC issuer URL — auth is skipped entirely when absent. See Authentication. |
PUBLIC_BASE_URL |
(unset) | Taskbase's external URL, e.g. https://taskbase.skatzi.com. Used for Gitea webhook registration and for the links in Mattermost notices; notices carry no link without it |
TASKBASE_SECRET_KEY |
(unset) | Base64-encoded 32-byte AES-256 key that encrypts Mattermost webhook URLs and runners' Claude API keys set from Taskbase. Without it webhooks and new Claude API keys cannot be saved (503), webhooks are not posted to and waiting keys are not sent. From the tasks-secret-key Secret. See Attention |
MODEL_POLICY_REPO |
Skatzi/platform |
Repository of the default model-selection policy, in owner/name form. An invalid value stops the API at startup |
MODEL_POLICY_PATH |
docs/content/contribution/guides/model-selection-policy.md |
Path of the default model-selection policy in MODEL_POLICY_REPO |
PLATFORM_DOCS_REPO |
Skatzi/platform |
Repository of the platform docs every session reads (Agent Sessions — Reading files), in owner/name form. An invalid value stops the API at startup |
PLATFORM_DOCS_PATH |
docs/content |
Directory of the platform docs in PLATFORM_DOCS_REPO; paths outside it are refused. An invalid value stops the API at startup |
Build¶
From the taskbase repo root:
make build # produces api/bin/api and builds the UI
make test # cd api && go test ./... (no DB required)
make lint # go vet
The Postgres store tests (*_pg_test.go in task, runner, attention and notice) run only
when TASKBASE_TEST_DATABASE_URL is set, and skip otherwise. CI sets it. Each test process then
migrates a uniquely named schema (test_<pid>_<nanos>) in that database, connects with
search_path set to it, and drops it when the package's tests finish. Concurrent go test ./...
runs against one database therefore do not sweep or claim each other's rows:
TASKBASE_TEST_DATABASE_URL=postgres://taskbase:taskbase@localhost:5432/taskbase?sslmode=disable make test
A new Postgres test gets its pool from pgtest.Pool(t) (or a URL from pgtest.URL(t)), and its
package adds func TestMain(m *testing.M) { pgtest.Main(m) }.
Adding a new resource¶
- Create
api/internal/<resource>/withmodel.go,store.go,store_memory.go,store_pg.go,handler.go,handler_test.go - Write a migration in
api/internal/migrations/ - Wire the handler in
api/cmd/server/main.go - Add a
make <resource>-*target if needed