2026-02-11 12:59:37 +00:00
# API / auth
2026-02-11 06:15:54 +00:00
2026-02-11 12:59:37 +00:00
This page documents how Mission Control’ s API surface is organized and how authentication works.
2026-02-11 06:30:08 +00:00
2026-02-11 12:59:37 +00:00
For deeper backend architecture context, see:
2026-02-11 06:33:03 +00:00
- [Architecture ](05-architecture.md )
2026-02-11 06:30:08 +00:00
2026-02-11 12:59:37 +00:00
## Base path
2026-02-11 06:15:54 +00:00
2026-02-11 12:59:37 +00:00
Evidence: `backend/app/main.py` .
2026-02-11 06:33:03 +00:00
2026-02-11 12:59:37 +00:00
- All API routes are mounted under: `/api/v1/*`
2026-02-11 06:33:03 +00:00
2026-02-11 12:59:37 +00:00
## Auth model (two callers)
2026-02-11 06:33:03 +00:00
2026-02-11 12:59:37 +00:00
Mission Control has two primary actor types:
2026-02-11 06:33:03 +00:00
2026-02-11 12:59:37 +00:00
1) **User (Clerk) ** — human UI/admin
2) **Agent (`X-Agent-Token`) ** — automation
2026-02-11 06:33:03 +00:00
2026-02-11 12:59:37 +00:00
### User auth (Clerk)
2026-02-11 06:33:03 +00:00
2026-02-11 12:59:37 +00:00
Evidence:
- backend: `backend/app/core/auth.py`
- config: `backend/app/core/config.py`
2026-02-11 06:33:03 +00:00
2026-02-11 12:59:37 +00:00
- Frontend calls backend using `Authorization: Bearer <token>` .
- Backend validates requests using the Clerk Backend API SDK with `CLERK_SECRET_KEY` .
2026-02-11 06:33:03 +00:00
2026-02-11 12:59:37 +00:00
### Agent auth (`X-Agent-Token`)
2026-02-11 06:33:03 +00:00
2026-02-11 12:59:37 +00:00
Evidence:
- `backend/app/core/agent_auth.py`
- agent API surface: `backend/app/api/agent.py`
2026-02-11 06:33:03 +00:00
2026-02-11 12:59:37 +00:00
- Agents authenticate with `X-Agent-Token: <token>` .
- Token is verified against the agent’ s stored `agent_token_hash` .
2026-02-11 06:33:03 +00:00
2026-02-11 12:59:37 +00:00
## Route groups (modules)
2026-02-11 06:33:03 +00:00
2026-02-11 12:59:37 +00:00
Evidence: `backend/app/main.py` includes routers from `backend/app/api/*` .
2026-02-11 06:33:03 +00:00
2026-02-11 12:59:37 +00:00
| Module | Prefix (under `/api/v1` ) | Purpose |
|---|---|---|
| `activity.py` | `/activity` | Activity listing and task-comment feed endpoints. |
| `agent.py` | `/agent` | Agent-scoped API routes for board operations and gateway coordination. |
2026-02-11 06:33:03 +00:00
| `agents.py` | `/agents` | Thin API wrappers for async agent lifecycle operations. |
| `approvals.py` | `/boards/{board_id}/approvals` | Approval listing, streaming, creation, and update endpoints. |
| `auth.py` | `/auth` | Authentication bootstrap endpoints for the Mission Control API. |
2026-02-11 12:48:18 +00:00
| `board_group_memory.py` | `/board-groups/{group_id}/memory` and `/boards/{board_id}/group-memory` | Board-group memory CRUD and streaming endpoints. |
2026-02-11 06:33:03 +00:00
| `board_groups.py` | `/board-groups` | Board group CRUD, snapshot, and heartbeat endpoints. |
| `board_memory.py` | `/boards/{board_id}/memory` | Board memory CRUD and streaming endpoints. |
| `board_onboarding.py` | `/boards/{board_id}/onboarding` | Board onboarding endpoints for user/agent collaboration. |
| `boards.py` | `/boards` | Board CRUD and snapshot endpoints. |
| `gateway.py` | `/gateways` | Thin gateway session-inspection API wrappers. |
| `gateways.py` | `/gateways` | Thin API wrappers for gateway CRUD and template synchronization. |
| `metrics.py` | `/metrics` | Dashboard metric aggregation endpoints. |
| `organizations.py` | `/organizations` | Organization management endpoints and membership/invite flows. |
| `souls_directory.py` | `/souls-directory` | API routes for searching and fetching souls-directory markdown entries. |
| `tasks.py` | `/boards/{board_id}/tasks` | Task API routes for listing, streaming, and mutating board tasks. |
| `users.py` | `/users` | User self-service API endpoints for profile retrieval and updates. |
2026-02-11 12:48:18 +00:00
## Backend API layer notes (how modules are organized)
Evidence: `backend/app/main.py` , `backend/app/api/*` , `backend/app/api/deps.py` .
### Conventions
- Each file under `backend/app/api/*` typically declares an `APIRouter` (`router = APIRouter(...)` ) and defines endpoints with decorators like `@router.get(...)` , `@router.post(...)` , etc.
- Board-scoped modules embed `{board_id}` in the prefix (e.g. `/boards/{board_id}/tasks` ).
- Streaming endpoints usually expose **SSE ** endpoints at `.../stream` (see `sse-starlette` usage).
### Where key behaviors live
- **Router wiring / base prefix**: `backend/app/main.py` mounts these routers under `/api/v1/*` .
- **Auth / access control** is mostly expressed through dependencies (see `backend/app/api/deps.py` ):
- `require_admin_auth` — require an authenticated * admin user * .
- `require_admin_or_agent` — allow either an admin user or an authenticated agent.
- `get_board_for_actor_read` / `get_board_for_actor_write` — enforce board access for the calling actor.
- `require_org_member` / `require_org_admin` — enforce org membership/admin for user callers.
- **Agent-only surface**: `backend/app/api/agent.py` uses `get_agent_auth_context` (X-Agent-Token) and contains board/task/memory endpoints specifically for automation.
### Module-by-module map (prefix, key endpoints, and pointers)
This is a “where to look” index, not a full OpenAPI dump. For exact parameters and response shapes, see:
- route module file (`backend/app/api/<module>.py` )
- schemas (`backend/app/schemas/*` )
- models (`backend/app/models/*` )
- services (`backend/app/services/*` )
| Module | Prefix (under `/api/v1` ) | Key endpoints (examples) | Main deps / auth | Pointers (schemas/models/services) |
|---|---|---|---|---|
| `activity.py` | `/activity` | `GET /activity` (events); `GET /activity/task-comments` + `/stream` | `require_admin_or_agent` , `require_org_member` | `app/models/activity_events.py` , `app/schemas/activity_events.py` |
| `agent.py` | `/agent` | agent automation surface: boards/tasks/memory + gateway coordination | `get_agent_auth_context` (X-Agent-Token) | `backend/app/core/agent_auth.py` , `backend/app/services/openclaw/*` |
| `agents.py` | `/agents` | agent lifecycle + SSE stream + heartbeat | org-admin gated for user callers; some endpoints allow agent access via deps | `app/schemas/agents.py` , `app/services/openclaw/provisioning_db.py` |
| `approvals.py` | `/boards/{board_id}/approvals` | list/create/update approvals + `/stream` | `require_admin_or_agent` + board access deps | `app/models/approvals.py` , `app/schemas/approvals.py` |
2026-02-11 12:59:37 +00:00
## Where authorization is enforced
Evidence: `backend/app/api/deps.py` .
Most route modules don’ t “hand roll” access checks; they declare dependencies:
- `require_admin_auth` — admin user only.
- `require_admin_or_agent` — admin user OR authenticated agent.
- `get_board_for_actor_read` / `get_board_for_actor_write` — board access for user/agent.
- `require_org_member` / `require_org_admin` — org membership/admin for user callers.
## “Start here” pointers for maintainers
- Router wiring: `backend/app/main.py`
- Access dependencies: `backend/app/api/deps.py`
- User auth: `backend/app/core/auth.py`
- Agent auth: `backend/app/core/agent_auth.py`
- Agent automation surface: `backend/app/api/agent.py`