# Why we built it this way

> The main design decisions behind screw-bugs and screw-bugs Cloud, with the reason, the cost and where each lives.

Source: https://docs.screwbugs.dev/decisions

Each decision below has its reason, what it cost us and where to read the code. The most important come first.

## `screw-bugs` has no AI of its own

- **Why:** the user's own coding agent decides what to test, writes the cases and judges the results; `screw-bugs` only runs them.
- **Trade-off:** `screw-bugs` can't plan a test by itself, so Cloud needs a planner of its own (see below).
- **Where:** screw-bugs `AGENTS.md` (screw-bugs), Product, `README.md` (screw-bugs)

## Tests are structured steps, not free-form scripts

- **Why:** every job is checked against one schema (`JobSpec`), so a job runs the same locally and in Cloud and makes the same report.
- **Trade-off:** a test can only use the step vocabulary, and that vocabulary is too large a union for a model provider's strict structured output, so Cloud's planner hands its plan in as a tool call and fixes what the check rejects.
- **Where:** "Jobs, cases and steps" in the screw-bugs README, `packages/core/src/schema` (screw-bugs), `apps/web/src/server/jobs/planner.ts` (Cloud)

## Uploaded content never runs on the login domain

- **Why:** the session cookie lives on `screwbugs.dev`, so reports render only on `reports.screwbugs.dev` (no cookies at all) and files come only from `media.screwbugs.dev`.
- **Trade-off:** three hosts to run instead of one, and report pages carry their own Content Security Policy.
- **Where:** `README.md` (Cloud), `apps/web/src/server/reports.ts` (Cloud), `docs/upload-protocol.md` (Cloud)

## Cloud depends on `screw-bugs`, never the other way

- **Why:** `@screw-bugs/core` (schema, engine core, report) depends only on `effect` and uses only Web APIs Workers have, so Cloud pulls in no Playwright or Node code.
- **Trade-off:** core can't use Node built-ins or other packages; a lint rule and a Workers build check (`check:workers`) enforce it.
- **Where:** screw-bugs `AGENTS.md` (screw-bugs), Module boundaries, `packages/core/scripts/check-workers.ts` (screw-bugs)

## Shared reports render with their own version line's renderer

- **Why:** each version line writes its own bundle format, and any renderer of a line reads any bundle of it; a report also shows with the exact version that made it at its own address, such as `/v0-1-10/<slug>/report`.
- **Trade-off:** Cloud carries one npm alias of `@screw-bugs/core` per release (`report-0-1-12`) until that release's shares expire; reports from before 0.1.10 show with their line's newest renderer, and their own version's address shows the not-found page.
- **Where:** `apps/web/src/server/renderers.ts` (Cloud), `docs/deploy.md` (Cloud), Adding a renderer

## Cloud plans tests with Claude, on our model account

- **Why:** a Cloud job has no coding agent to write its cases, so Claude writes `screw-bugs`' own job, which the engine runs as it would a local one.
- **Trade-off:** we pay for the tokens, so every run has caps (next).
- **Where:** `apps/web/src/server/jobs/planner.ts` (Cloud)

## Every run and every person has a cost cap

- **Why:** so one busy repository can't run up a big bill; model tokens and Browser Run time both count.
- **Trade-off:** a run stops at its cap (tool calls, tokens, wall time, dollars), and once a person's monthly cap is used up, new runs are refused.
- **Where:** `packages/shares/src/caps.ts` (Cloud)

## Bot runs start on a comment, from someone who can push

- **Why:** each run costs us a model and a browser.
- **Trade-off:** no run on every push, and people without push access to the repository can't start one.
- **Where:** `apps/web/src/server/github/webhook.ts` (Cloud), `apps/web/src/server/github/pulls.ts` (Cloud)

## Test accounts are each person's own, signed in once by hand

- **Why:** a run reuses a saved session, as test accounts work locally; sessions are sealed with AES-GCM and opened only inside a run.
- **Trade-off:** no fresh account per run; a run without a saved session waits for its requester to sign in through a live view.
- **Where:** `apps/web/src/server/accounts` (Cloud), `packages/shares/src/secrets.ts` (Cloud)

## Preview headers go only to the preview's own origin

- **Why:** setting them for the whole browser would send the secrets to every site the page loads from (analytics, fonts, a login provider).
- **Trade-off:** a preview that redirects to another site still takes the headers there; routing every request ourselves avoided that but loaded pages 3x slower on Browser Run.
- **Where:** `apps/web/src/server/browser/access.ts` (Cloud)

## Slack (coming soon) is linked to the GitHub account, never matched by email

- **Why:** a person's GitHub email is often not their work email.
- **Trade-off:** each person connects Slack once on `/account`, and nobody can sign in to Cloud with Slack.
- **Where:** `docs/slack.md` (Cloud)

## A Cloudflare Workflow runs each job

- **Why:** it keeps the run alive from start to finish, retries each step, and after a crash or timeout resumes from the last finished step.
- **Trade-off:** a run is split into steps (plan, run, review, finish), and a step cut short starts over.
- **Where:** `apps/web/src/server/jobs/workflow.ts` (Cloud), `apps/web/src/server/jobs/run.ts` (Cloud)

## Videos are encoded in a Container

- **Why:** Browser Run has no ffmpeg, so each recorded session streams to a Cloudflare Container that encodes it as `screw-bugs` does (VP9 WebM).
- **Trade-off:** a second Worker to deploy before the app, and containers are billed while they run, so each is stopped when its video is done.
- **Where:** `apps/encoder/src/index.ts` (Cloud)

## Database connections and auth are per request

- **Why:** on Workers a database connection can't outlive the request that opened it, and the auth instance uses that connection.
- **Trade-off:** every request, and every Workflow step, opens its own connection (through Hyperdrive) and closes it after.
- **Where:** `apps/web/src/server/scope.ts` (Cloud)

## One `effect` version for Cloud and the renderers

- **Why:** with one copy of `effect`, Cloud's schemas and the `screw-bugs` renderers' are the same classes.
- **Trade-off:** Cloud upgrades `effect` only in step with `screw-bugs`.
- **Where:** `pnpm-workspace.yaml` (Cloud)

**Next:** [Back to the overview](/index.md)