Files
bernatsamperaandClaude Fable 5 aca7523754 Add workflows API, the marketplace backend (marketplace task 3b)
FastAPI + Postgres service that stores workflow templates as file
bundles with indexed manifest fields, submit-for-review publishing,
and moderation endpoints behind an admin token.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-08-08 13:15:47 +02:00

47 lines
1.7 KiB
Markdown

# workflows API
The marketplace backend for workflow templates. A FastAPI service with a Postgres database. Templates are stored as file bundles (one row per file) plus indexed manifest fields parsed server-side from the bundle's `index.md` frontmatter (see `docs/workflows.md` for the template standard).
Publishing is submit-for-review: anyone can POST a bundle, it lands pending, and it appears publicly only after approval.
## Endpoints
- `GET /api/workflows`: approved directory (id, name, description, tags).
- `GET /api/workflows/{id}`: one approved template with its full file bundle.
- `POST /api/workflows`: submit a bundle for review. Body: `{"files": [{"path": "...", "content": "..."}]}`.
- `GET /api/moderation/workflows`: pending entries (admin token).
- `GET /api/moderation/workflows/{id}`: one pending bundle (admin token).
- `POST /api/moderation/workflows/{id}/approve`: publish (admin token). Approving an id that is already published replaces the published content.
- `POST /api/moderation/workflows/{id}/reject`: hide (admin token).
Moderation auth is a single bearer token: `Authorization: Bearer $ADMIN_TOKEN`.
## Configuration
Env vars: `DATABASE_URL` (postgresql+psycopg://...), `ADMIN_TOKEN`. Optional: `MAX_FILE_BYTES` (default 1000000), `MAX_BUNDLE_BYTES` (default 5000000), `MAX_FILES` (default 200).
Tables are created on startup.
## Run locally
```
cd api
uv sync
DATABASE_URL=postgresql+psycopg://... ADMIN_TOKEN=dev uv run uvicorn app.main:app --reload
```
## Tests
Tests need Docker (they start a throwaway Postgres container):
```
cd api
uv run pytest
```
## Seed
```
ADMIN_TOKEN=... uv run python scripts/seed.py <template-folder> --api-url https://api.gcontext.ai
```