# Architecture
## Components
```mermaid
flowchart LR
U[Browser: consultant, QA approver, admin] -->|HTTPS, session cookie + CSRF header| API
subgraph Container [One Docker image, non-root, tini]
API[FastAPI app
coworker/api] --> RM[Run manager
api/runner.py, run_jobs queue]
RM --> G[LangGraph workflow
coworker/graph]
G --> PW[Playwright executor
automation/, adapters/playwright.py]
G --> RR[QA rule C1-C6
reports/generate_report.py, qa/audit.py]
G --> TR[Triage
triage/classifier.py]
API --> DB[(SQLite: runs, events, users, sessions,
pods, schedules, audit chain)]
API --> V[(Vault: secrets/vault.json
+ FPT_SECRET_* env)]
SCH[Scheduler
platform/scheduler.py] --> RM
SYNC[State sync
platform/statesync.py] --> DB
MOCK[Practice pod
mock-app :3100]
end
G -->|EgressGate| LLM[AI model
llm/router.py]
G -->|EgressGate: REST| FUS[Oracle Fusion test pod]
PW -->|browser| FUS
PW --> MOCK
API -->|EgressGate| SB[Supabase: identity, encrypted backup]
API -->|EgressGate, optional| H[Hermes assistant]
```
## A test run, step by step
| Step | Node (`coworker/graph/nodes/`) | What happens |
|---|---|---|
| 1 | `research.scout` | Reads the pod; stops on a production pod. On a Fusion pod it first discovers which business areas the pod uses and samples their test data from the pod's own records (`platform/discovery.py`, docs/DISCOVERY.md) |
| 2 | `research.*` | Reads what the patch changes; the AI model summarises (public or redacted data only) |
| 3 | `design.*` | Chooses scenarios from the library (`tests/cases`), coverage maps (`analysis/`); AI may draft extra scenarios, which are dry-run |
| 4 | `design.approval_gate` | Pauses; a consultant approves or skips each scenario (one answer per gate, atomic) |
| 5 | `data.*` | Plans test data |
| 6 | `execute.executor` | Runs Playwright in chunks; live view frames; retries a crashed attempt once |
| 7 | `triage.*` | Classifies failures (UI change, data, timing, real defect) |
| 8 | human review gate | A QA approver confirms real defects or waives |
| 9 | `report.*` | Go / no-go by the QA rule, PDF/HTML/Excel; test data clean-up summary |
The run manager persists queued jobs (`run_jobs`) so answers survive a restart; LangGraph checkpoints (SQLite) let a
paused run continue. Temporal is an alternative orchestrator (`FPT_ORCHESTRATOR=temporal`) for long runs on a
dedicated server.
## Boundaries that matter
- **Egress gate** (`platform/egress.py`): the only module that makes HTTP calls. It checks the kill switch, writes an
audit record per call, pins each call to the configured host, and allows writes to Fusion only for seeding test
data (with `SEED_ALLOWED=1`) and cancelling it.
- **Vault** (`platform/vault.py`): secrets live in the environment (`FPT_SECRET_*`) or the encrypted vault file; API
answers never contain them; child processes get a scrubbed environment (`platform/procs.child_env`).
- **LLM router** (`llm/router.py`): client data never goes to an external model; only public or redacted payloads.
- **QA rule**: the decision is computed by `reports/generate_report.py`, never by the AI.
## Data
SQLite at `$FPT_HOME/fpt.sqlite`, migrations in `coworker/platform/migrations/*.sql` (forward-only, applied by
`python -m coworker setup` at every start). Evidence (screenshots, videos, traces) encrypted under `$FPT_HOME/evidence`
with retention. Without a persistent disk, the whole data folder is saved encrypted to Supabase Storage every 60 s and
restored at boot.
## Web app
React 18, Mantine 7, TanStack Query, React Router; typed API client generated from the backend's OpenAPI
(`npm run gen:api`). Less-used pages are loaded on demand. Errors are mapped to plain language in
`web/src/api/errors.ts`; a screen that crashes shows a recovery page (`components/ErrorPages.tsx`).