# paste-bin (FastAPI port) A minimal, security-focused paste bin: share text, images, and files with expiring links. This branch is the **arch-llm/FastAPI port** of the Flask app that still lives on `main`. It is built spec-first: a signed `.arch` spec is the single source of truth, the backend is generated + verified against frozen owner tests, and the frontend client is generated from the emitted OpenAPI contract. Wiki: the full port report (ability matrix, bugs fixed, build history, live probe) is on the repo wiki — **FastAPI port (arch-llm pipeline)**. ## The pipeline ``` schema.arch (signed spec) <- source of truth | | arch-llm build --session paste-bin (LLM generation, deterministic glue, v pytest verification, 80% coverage gate) paste_bin/ (generated backend) <- verified: 51/51 owner tests, 92.5% coverage | | arch-llm openapi paste-bin --client --out ui v ui/openapi.json + ui/client.js <- deterministic contract emission (no LLM) | v ui/index.html + ui/app.js <- SPA; calls ONLY window.PasteBinAPI ``` Nothing here is hand-maintained against a drifting API: the backend is verified from the spec, the client is generated from the OpenAPI projection of the same spec, and the SPA only touches the generated client's exported surface. Drift becomes a build failure instead of a silent runtime break. ## Layout | Path | What | |---|---| | `schema.arch` | the signed spec (single source of truth) | | `signoff.yaml` | owner signoff hashes over spec + tests (provenance) | | `paste_bin/` | generated FastAPI backend (7 modules + glue) | | `tests/` | owner-authored ground-truth tests (51 tests, **frozen**) + freeze manifest | | `ui/` | SPA + emitted contract artifacts (`openapi.json`, `client.js`) + Caddyfile | | `Dockerfile` / `requirements.txt` | canonical image (python:3.14-slim, uvicorn) | ## Quick start ```sh # backend (canonical image; data in volumes) docker build -t paste-bin . docker run -d --name paste-bin -p 18900:8080 \ -v paste-bin-data:/app/data paste-bin # API on http://127.0.0.1:18900 (GET / -> JSON index, GET /health, /pastes/...) # tests pip install -r requirements.txt pytest # 51 tests # UI + API same-origin (Caddy reverse proxy; run from the ui/ directory) cd ui && caddy run --config Caddyfile # http://127.0.0.1:18901/index.html ``` `ui/Caddyfile` proxies every path the OpenAPI doc declares (`/`, `/health`, `/pastes*`) to the backend on `127.0.0.1:18900` and serves the SPA + contract artifacts same-origin. ## The API (contract) `GET /` JSON index · `GET /health` · `POST /pastes` (multipart: `paste_type`, `title`, `expiry`, `content` or `file`) · `GET /pastes/{paste_id}` view · `GET /pastes/{paste_id}/raw` · `GET /pastes/{paste_id}/download`. Errors are JSON `{error: str}` with **pinned literals** (see `x-error-literals` in `ui/openapi.json`): `Content cannot be empty`, `Invalid expiry`, `Invalid paste type`, `No file selected`, `Invalid image format`, `File content does not match image type.`, `File too large. Maximum size is 20 MB.`, `Too many uploads. Please wait.`, `Paste not found`. Paste IDs match `^[a-f0-9]{16}$` (exported as `PasteBinAPI.PASTE_ID_RE`). ## Editing the project The spec is the project. To change behavior: edit `schema.arch` (or the arch-llm design session `paste-bin`), re-sign, rebuild, re-emit. Do **not** hand-edit `paste_bin/` or `ui/client.js` — the next build/emission overwrites them. See `AGENTS.md` for the agent-facing rules and `../wiki` for the port history. ## Differences from the Flask original - JSON API instead of HTML templates (the old form posts map 1:1 onto the multipart contract); routes namespaced `/pastes/...`; create returns `201` JSON (was 302). - `/health` + JSON index added (the old app had no `/health`). - 7 old bugs fixed, not duped (file-type `/raw` 500, silent expiry default, AVI-as-webp, stripped text content, leaking rate-limit state, trusted client mimetype, orphaned `.tmp.*` files) — details on the wiki. - 62/62 live probe assertions green on the final build (r3).