Nov 17, 2026 · Clint Lewis
1. Purpose and scope
The Kestrel simulator is a web app in which a pilot powers up the KF-07 Kestrel Mk II, flies one mission, and has the result recorded. This document is the single set of requirements the build is checked against.
It covers the simulator as a product (flight rules, cockpit, server, data) and the way it is built and run (tests, pipeline, deployment, monitoring). It does not cover the artwork of the suit, which is reused from the tutorials.
Every requirement has an ID so code, tests and commits can point at it.
| Prefix |
Area |
| FLT |
Flight rules (the business logic) |
| CKP |
Cockpit (the browser app) |
| API |
Server and API |
| DAT |
Data |
| IAM |
Identity and access |
| QA |
Testing |
| OPS |
Build, containers, deployment, networking |
| OBS |
Observability |
| DSN |
Design and repository conventions |
"Must" marks a requirement the build fails without. "Should" marks one that can be deferred with a note in the progress log.
2. Sources
All 19 tutorials in the series were read for this document. Ten of them tell part of the Kestrel story; the other nine teach the stack with a different example and contribute conventions only.
| Tutorial |
Kestrel content |
Contributes |
| Observability from Zero |
The Aster retrieval mission: phases, orders, 25 kW budget, the bottle |
Flight rules, logs, metrics, traces, health checks, alerts |
| Test Cases from Zero |
Nine subsystems, rules R1 to R6, 21 test cases |
Preflight rules, test-case format |
| Playwright + pytest from Zero |
The Kestrel Console: every page, label and message |
Console contract, test tooling |
| React + TypeScript from Zero |
The cockpit's four screens; Ilse and Tomo |
Cockpit structure, front-end stack |
| SQLAlchemy + Alembic from Zero |
kestrel-control, pilots and sorties tables |
Data model, migration rules |
| HTTP + Networking from Zero |
Routes, roles, waypoints, CORS and TLS for the suit |
API behaviour, status codes, CORS, TLS |
| Cloud Deploy from Zero |
The Mk II blueprint; releases 1.0.0 to 1.2.0; the gantry |
Deployment, configuration, rollback |
| Docker from Zero |
Reactor control service and its log store |
Containers, Compose, volumes |
| NGINX from Zero |
Compute cores, the gate, the 25 kW compute budget |
Reverse proxy, rate limit, cache |
| Kubernetes from Zero |
Sections, nine services, recon / assault / orbital loadouts |
Orchestration (not needed for version 1) |
| FastAPI from Zero |
None (shop example) |
API structure, validation, dependencies, tests |
| Postgres from Zero |
None (shop example) |
Types, constraints, roles, backups |
| OAuth from Zero |
None (shop example) |
Sign-in flows, token rules |
| Tailwind + shadcn/ui from Zero |
None (Projects page) |
Styling, components, tokens |
| CI from Zero |
None (shop example) |
Pipeline, branch protection |
| Git Basics Sandbox |
None (hello-api) |
Branch and pull-request workflow, secrets |
| Agent Files Tutor |
None (hello-api) |
AGENTS.md, DESIGN.md, tokens.json, specs |
| OpenAPI Design Tutor |
None (Tally Desk) |
API design rules, openapi.yaml |
| MCP Interface Design Tutor |
None (Tally Desk) |
Not needed for version 1 |
The business-logic tutorial now in progress will implement section 5 and cite its requirement IDs.
3. The Kestrel canon
These are the names and numbers the simulator must use, taken as written from the tutorials. Where two tutorials disagree, this section gives the ruling and section 13 records the disagreement.
The suit and its people
| Item |
Canon |
From |
| Designation |
KF-07 Kestrel Mk II, a 17-metre piloted frame |
Cloud Deploy, Docker, Kubernetes |
| Home |
Hangar 7, standing in the gantry |
Docker, Cloud Deploy |
| Designer |
Ilse Varga, mobile suit designer |
React + TypeScript |
| Cockpit tech |
Tomo Reyes |
React + TypeScript |
| Console pilot |
Ada, ada@example.com, "pilot of KF-07" |
Test Cases, Playwright |
| Squadron roster |
Wren (captain), Ibis (lieutenant), Heron (ensign), Kite |
SQLAlchemy + Alembic |
| Mission control |
The operator on the downlink, user ops |
Observability |
| Roles |
pilot and tech (hangar tech) |
HTTP + Networking |
| Past missions |
M-041 (2 Nov 2026, Complete), M-058 (9 Nov 2026, Complete) |
Playwright |
Subsystems
The simulator uses the nine subsystems of the preflight console. The draw is the load each one puts on the test bench during its check.
| Subsystem |
Category |
Check draw (kW) |
| Sensors |
nav |
6.5 |
| Reactor |
power |
12 |
| Defense systems |
defense |
14 |
| Guidance |
nav |
7.5 |
| Limbs |
motion |
9 |
| Locomotion |
motion |
16 |
| Propulsion |
power |
22 |
| Communication array |
comms |
4 |
| Cockpit |
crew |
3 |
Other tutorials name services rather than subsystems. Each service belongs to one of the nine.
| Subsystem |
Services that belong to it |
| Reactor |
reactor |
| Propulsion |
thrusters |
| Guidance |
nav, navigation, targeting |
| Sensors |
sensors |
| Communication array |
comms |
| Cockpit |
flight computer, cockpit computer, life-support |
| Defense systems |
shield, railgun |
| Locomotion |
stabiliser |
| Limbs |
containment (the magnetic bottle, carried on the right arm) |
The mission
The simulator flies one mission, the Kestrel's first: Aster retrieval.
| Item |
Canon |
| Objective |
Retrieve 40 nanograms of antimatter (antihydrogen) from the unmanned trap station orbiting Aster |
| Distance |
Aster is 12 light-years from Hangar 7 |
| Route |
Hangar 7, gate-alpha, jump, Aster, trap station, and back the same way |
| Cargo |
One magnetic bottle; its field must hold without a break from capture to hand-over |
| Hand-over |
The Hangar 7 vault |
| Phases |
hangar, transit, aster, trap, captured, return, docked |
| Mission clock |
Shown as T+HH:MM:SS |
Flight numbers
| Quantity |
Value |
| Reactor power budget |
25 kW, a hard limit |
| Normal reactor output |
13 kW |
| Jump surge |
24 kW for under 20 seconds |
| Flight computer draw |
1 kW |
| Navigation draw |
1 kW |
| Sensors draw in flight |
2 kW |
| Containment draw |
6 kW while a sample is aboard, otherwise 0 |
| Thrusters draw |
9 kW at cruise, 21 kW at sprint, 0 in the hangar or docked |
| Bottle field |
5.2 T normal, 3.1 T degraded, pre-cool to 4 K |
| Backup cells |
Hold the field for 45 minutes |
| Sample |
40 ng |
| Starter cell |
Gives 5 kW when a preflight load is under 50 kW |
4. System overview
The simulator is a browser app that runs the flight, backed by a small API that signs pilots in and keeps the mission log. This is the hybrid architecture chosen for the business logic: rules that run every second live in the browser, and rules that must be trusted or remembered live on the server.
| Part |
Built with |
Runs on |
Owns |
| Flight core |
TypeScript, pure functions in src/core |
The pilot's browser |
Every flight rule in section 5 while a mission is being flown |
| Cockpit |
React, TypeScript, Vite |
GitHub Pages |
Showing the state and sending orders to the flight core |
Kestrel control (kestrel-control) |
Python, FastAPI |
One container on a server |
Sign-in, the roster, the mission log, re-checking every mission it is sent |
Database (kestrel) |
PostgreSQL on Neon |
Neon |
Pilots and sorties, with constraints as the last line of defence |
| Pipeline |
GitHub Actions |
GitHub |
Lint, tests, build and deploy on every change |
What a pilot does
- Signs in.
- Runs preflight: queues subsystem checks on the console and starts the preflight.
- Flies Aster retrieval: gives orders that move the suit through the seven phases while the flight core enforces the power budget.
- Docks. The cockpit sends the mission to Kestrel control, which re-checks it and writes it to the mission log.
- Reads the mission log.
Ground rules
- The flight core has no React, no network and no storage code in it, so it can be tested without a screen.
- A screen may decide what to show. It may not decide what is allowed.
- The server never trusts a result the browser reports. It replays the orders through its own copy of the rules.
- Out of scope for version 1: Kubernetes, an NGINX balancer in front of several copies, and an MCP server. Their Kestrel details stay in their tutorials.
5. Flight rules (FLT)
These are the rules the business-logic tutorial implements. Each is written so one or more test cases can be derived from it. "New" in the source column marks a rule no tutorial states, added here because the simulator needs an answer.
Preflight
| ID |
Requirement |
Source |
| FLT-01 |
The total draw must be the sum of every load switched on, in kW. With nothing on it is 0 kW. |
Test Cases R1 |
| FLT-02 |
Throttling back must take a percentage off the total draw. Throttle back is a whole number from 0 to 100: at 0 nothing is taken off, at 100 the draw is 0 kW. |
Test Cases R2 |
| FLT-03 |
A throttle-back value outside 0 to 100, or not a whole number, must be refused with a reason. |
New (R2 leaves it open) |
| FLT-04 |
A total draw of 50 kW or more must take 0 kW from the starter cell. Less than 50 kW must take 5 kW. An empty queue takes none. |
Test Cases R3, R5 |
| FLT-05 |
The check queue must report load (sum of queued draws), starter cell (FLT-04) and total draw (load plus starter cell), each to one decimal with the unit kW. |
Test Cases R5 |
| FLT-06 |
A preflight must only start for a signed-in pilot. |
Test Cases, Playwright |
| FLT-07 |
The launch order must be refused until a preflight has been started for this mission. |
New |
Mission phases and orders
The mission starts in hangar. An order is the only thing that can move it.
| Order |
Allowed in |
Moves the suit to |
launch |
hangar |
transit |
align |
transit, return |
no move |
jump |
transit |
aster |
jump |
captured |
return |
approach |
aster |
trap |
scan |
trap |
no move |
capture |
trap |
captured |
hold |
captured, return |
no move |
trim |
every phase except hangar and docked |
no move |
dock |
return |
docked |
| ID |
Requirement |
Source |
| FLT-10 |
The flight state must hold: phase, burn profile, antimatter aboard in ng, bottle field, mission clock, the order log, and the last alert. |
Observability, new |
| FLT-11 |
The phases must be exactly the seven in section 3, in that order. |
Observability |
| FLT-12 |
An order must be accepted only in the phases the table above lists for it, and must move the suit only as the table says. |
Observability |
| FLT-13 |
An order given in any other phase must be refused with "cannot NAME: the Kestrel is" followed by the phase text (for example "parked in Hangar 7"). |
Observability |
| FLT-14 |
An order name that is not in the table must be refused as an unknown order. |
Observability |
| FLT-15 |
dock must be refused at sprint with "cannot dock at sprint burn: set the thrusters to cruise first". |
Observability |
| FLT-16 |
docked is the end of the mission. No order is accepted after it. |
Observability |
| FLT-17 |
capture must be refused until at least one scan has been accepted in trap (the scan pre-cools the bottle). |
New |
| FLT-18 |
capture must put 40 ng aboard. dock must deliver whatever is aboard and leave 0 ng aboard. |
Observability |
| FLT-19 |
Each accepted order must advance the mission clock by 15 seconds. |
Observability |
| FLT-20 |
The mission result must be Complete when the suit is docked and 40 ng were delivered. |
Observability, Playwright |
Power
| ID |
Requirement |
Source |
| FLT-30 |
The burn profile must be cruise or sprint. Any other value must be refused. |
Observability |
| FLT-31 |
The flight draw must be the sum of: flight computer 1 kW, navigation 1 kW, sensors 2 kW, containment 6 kW while antimatter is aboard, and thrusters 9 kW at cruise or 21 kW at sprint. Thrusters draw 0 kW in hangar and docked. |
Observability |
| FLT-32 |
The flight draw must never exceed the 25 kW budget. A draw of exactly 25 kW is allowed. |
Observability, Docker, NGINX |
| FLT-33 |
Any order or burn change that would take the draw over budget must be refused at once, naming the budget and the draw asked for. This covers switching to sprint with a sample aboard (31 kW) and capture at sprint. |
Observability postmortem |
| FLT-34 |
A jump must show the reactor peaking at 24 kW for under 20 seconds. The surge is displayed, not charged against FLT-32. |
Observability |
Promises that hold after every order
| ID |
Requirement |
Source |
| FLT-40 |
Flight draw is at most 25 kW. |
FLT-32 |
| FLT-41 |
Antimatter aboard is 0 ng or 40 ng, and is 40 ng only in captured and return. |
Observability |
| FLT-42 |
While antimatter is aboard, the bottle is on its main field at 5.2 T. It must not drop from capture to hand-over. |
Observability |
| FLT-43 |
The phase is one of the seven. |
FLT-11 |
How the rules behave
| ID |
Requirement |
Source |
| FLT-50 |
Every rule must be a pure function: the same state and order always give the same answer, and the state passed in is never changed. |
New |
| FLT-51 |
A rule must answer with either the new state or a refusal and its reason. A refusal is an ordinary answer, not an exception. |
New |
| FLT-52 |
A refused order must change nothing except the alert. The next accepted order must clear the alert. |
New |
| FLT-53 |
Every change to the flight state must go through one function that takes the state and an order and returns the new state. |
New |
| FLT-54 |
Every order given, accepted or refused, must be appended to the order log with its result. |
New |
| FLT-55 |
The flight rules must exist twice with the same results: in TypeScript in the browser and in Python on the server. |
New |
6. Cockpit (CKP)
The browser app has two halves: the Kestrel Console for preflight, whose wording is already fixed by the Playwright tutorial, and the cockpit for flight, whose four screens come from the React tutorial.
Pages
| Route |
Page title |
Heading |
Signed out |
/ |
Kestrel Console · KF-07 preflight |
Kestrel Console |
Open |
/queue |
Check queue · Kestrel Console |
Check queue |
Open |
/login |
Sign in · Kestrel Console |
Sign in |
Open |
/account |
Pilot account · Kestrel Console |
Welcome back, Ada |
Goes to /login |
/missions |
Mission log · Kestrel Console |
Mission log |
Goes to /login |
/cockpit (new) |
Cockpit · Kestrel Console |
Kestrel cockpit |
Goes to /login |
| anything else |
Not found · Kestrel Console |
404 |
"There is no page at this address." |
Console
| ID |
Requirement |
Source |
| CKP-01 |
Every page must have the route, title and heading in the table above. |
Playwright |
| CKP-02 |
Every page must show the menu: Home, "Queue (n)" with the number of queued checks, then "Sign in" when signed out or "Mission log" when signed in. |
Playwright |
| CKP-03 |
Home must list the nine subsystems under the heading "Subsystems", each with its name, category, draw (as "6.5 kW") and a "Queue check" button. |
Test Cases R4, Playwright |
| CKP-04 |
Typing in "Search systems" must keep the subsystems whose name or category contains the text, ignoring capitals. An empty search lists all nine. No match shows No systems match "text". The list updates about 300 ms after typing stops. |
Test Cases R4, Playwright |
| CKP-05 |
"Queue check" must add the subsystem to the queue and show the status "Queued the NAME check". |
Test Cases R5 |
| CKP-06 |
The queue page must show a table of System and Draw, or "The queue is empty", with Load, Starter cell and Total draw per FLT-05, and a "Start preflight" button. |
Playwright |
| CKP-07 |
"Start preflight" must go to /login when signed out and show "Preflight started" when signed in. |
Playwright |
| CKP-08 |
A failed sign-in must stay on /login and show the alert "Wrong email or password". A successful one must open /account with "Signed in as EMAIL, pilot of KF-07" and a link to the mission log. |
Test Cases R6, Playwright |
| CKP-09 |
The mission log must be a table of Mission, Date and Result, newest last, read from the API. |
Playwright |
| CKP-10 |
A fresh session must start signed out with an empty queue. Moving between pages must clear status lines, errors, form fields and the search. |
Playwright |
Cockpit
| ID |
Requirement |
Source |
| CKP-20 |
The cockpit must be built from one component per screen: alert bar, systems, main display, comms. A mission screen is added for phase and orders. |
React + TypeScript, new |
| CKP-21 |
The alert bar must show the last alert in its danger style, and "All systems nominal" when there is none. |
React + TypeScript |
| CKP-22 |
The systems screen must show each flight load from FLT-31 with its draw, the total, and the 25 kW budget. |
Observability, new |
| CKP-23 |
The main display must show reactor output and the burn profile, with a control to switch between cruise and sprint. |
React + TypeScript, Observability |
| CKP-24 |
The mission screen must show the phase, the mission clock as T+HH:MM:SS, the antimatter aboard, and one control per order. |
Observability, new |
| CKP-25 |
The comms screen must show the order log, newest last. |
React + TypeScript, new |
| CKP-26 |
No component may contain a flight rule. Components read the state and send orders; a refusal's reason comes from the flight core and is shown as it is. |
Section 4 |
| CKP-27 |
The Mk II blueprint from the tutorials must be reused and must change with the state: gantry, burn, antimatter aboard, and an over-budget refusal. |
Cloud Deploy, kestrel-simulator notes |
| CKP-28 |
When the suit docks, the cockpit must send the mission to the API and show whether it was recorded. |
Section 4 |
For every page
| ID |
Requirement |
Source |
| CKP-40 |
Every control must be reachable by its role and visible name, and usable with the keyboard alone. Status lines use role=status; errors use role=alert. |
Playwright |
| CKP-41 |
Every page must work at 375 px and 1280 px wide, designed small screen first. |
Tailwind + shadcn/ui |
| CKP-42 |
The app must show a different message for each of: not signed in (401), not allowed (403), not found (404), invalid input (422), and a server fault (5xx). |
HTTP + Networking |
| CKP-43 |
Text fields must accept accented letters such as é, à and ç. |
Test Cases |
| CKP-44 |
A direct visit or a refresh on any route must load that page when hosted on GitHub Pages. |
New |
| CKP-45 |
A mission in progress should survive a page reload. |
Tailwind + shadcn/ui (next step) |
7. Server and API (API)
Kestrel control is one FastAPI application, titled kestrel-control, listening on port 8000. It has three jobs: sign pilots in, keep the roster, and keep a mission log it can vouch for.
Endpoints
| Method and path |
Who |
Does |
Answers |
GET /healthz |
Anyone |
Says the process is alive |
200 {"status":"ok"} |
GET /readyz |
Anyone |
Says whether the database answers |
200 ready, or 503 naming the failed check |
GET /version |
Anyone |
Gives the release number |
200 {"version":"1.0.0"} |
GET /status |
Anyone |
Names the frame and mission |
200 with frame "KF-07 Kestrel Mk II", mission "Aster retrieval" |
GET /pilots |
Tech |
Lists the roster |
200, a page of pilots |
POST /pilots |
Tech |
Enlists a pilot |
201, or 409 "Callsign already taken" |
GET /pilots/{pilot_id} |
Tech, or the pilot themself |
Shows one pilot |
200, or 404 "No such pilot" |
GET /missions |
Signed-in pilot |
Lists that pilot's missions |
200, a page of missions |
POST /missions |
Signed-in pilot |
Submits a flown mission's order log |
201, or 422 when the log does not replay |
GET /missions/{mission_id} |
The pilot who flew it, or a tech |
Shows one mission |
200, 403 or 404 |
Sign-in adds two endpoints from the FastAPI tutorial: POST /token takes an email and password as form fields and answers with an access token, and GET /pilots/me returns the signed-in pilot.
Requirements
| ID |
Requirement |
Source |
| API-01 |
The API must provide the endpoints in the table above, with those answers. |
SQLAlchemy, Observability, Cloud Deploy |
| API-02 |
POST /missions must replay the submitted order log through the server's own flight rules (FLT-55). If any order would be answered differently, the mission must be refused with 422 and nothing stored. The result that is stored is the server's, not the browser's. |
Section 4 |
| API-03 |
The pilot a mission belongs to must come from the sign-in token, never from the request body, path or query. |
OpenAPI Design, OAuth |
| API-04 |
POST /missions must accept an Idempotency-Key header so that a retry does not record the mission twice. |
OpenAPI Design |
| API-05 |
Every input must be typed and validated by the framework. Invalid input answers 422 with a message naming the field. |
FastAPI, HTTP + Networking |
| API-06 |
Every endpoint must declare a response model, so internal fields such as password hashes never leave the server. |
FastAPI, SQLAlchemy |
| API-07 |
Status codes must be used as follows: 201 for a create, 204 when nothing is returned, 401 not signed in, 403 signed in but not allowed, 404 missing, 405 wrong method, 409 conflict, 422 invalid input. A 500 always means a bug. |
FastAPI, HTTP + Networking |
| API-08 |
List endpoints must take limit (default 25, at most 100) and an opaque cursor, and return data and next_cursor. |
OpenAPI Design, FastAPI |
| API-09 |
/healthz must check only the process. /readyz must check the database and name what failed. |
Observability |
| API-10 |
The API must be stateless: nothing a request needs later is kept in a Python variable. |
FastAPI, HTTP + Networking |
| API-11 |
Each request must get its own database session through a dependency, closed when the request ends. |
FastAPI, SQLAlchemy |
| API-12 |
CORS must allow exactly the cockpit's origin for each environment. No wildcard origin. |
HTTP + Networking |
| API-13 |
Configuration must come from environment variables (KESTREL_ENV, DATABASE_URL, LOG_LEVEL, and the signing key or identity-provider settings). The app must refuse to start, saying which one, if a setting is missing. |
Cloud Deploy |
| API-14 |
The code must be laid out as a package: app/main.py, app/config.py, app/db.py, app/models.py, one file per resource under app/routers/, and the flight rules in their own module with no FastAPI or database code in it. |
FastAPI, SQLAlchemy, section 4 |
| API-15 |
The API must only be served over HTTPS, and must send the strict-transport-security header. |
HTTP + Networking, Cloud Deploy |
| API-16 |
The contract should be written first as openapi.yaml (OpenAPI 3.1), kept in the repository, and checked against what the app generates. |
OpenAPI Design |
| API-17 |
Field and query names must be snake_case. Dates are 2026-11-09; timestamps are UTC with Z. |
OpenAPI Design |
8. Data (DAT)
The database is PostgreSQL, named kestrel, hosted on Neon. It keeps two tables from the SQLAlchemy tutorial, extended so a sortie can hold a flown mission. Columns marked new are added by this document.
pilots
| Column |
Type |
Rule |
id |
integer, identity |
Primary key |
callsign |
varchar(30) |
Required, unique |
joined_at |
timestamp with time zone |
Required, defaults to now |
grade |
varchar(20) |
Optional (renamed from rank) |
clearance |
integer |
Required; existing pilots backfilled with 1 |
email (new) |
text |
Required, unique; what the pilot signs in with |
role (new) |
text |
Required; pilot or tech |
sorties
| Column |
Type |
Rule |
id |
integer, identity |
Primary key |
pilot_id |
integer |
Required, references pilots.id, indexed |
mission |
varchar(40) |
Required; "Aster retrieval" |
launched_at |
timestamp with time zone |
Required, defaults to now |
code (new) |
text |
Required, unique; the mission number shown in the log, such as M-058 |
result (new) |
text |
Required; Complete or Incomplete |
delivered_ng (new) |
integer |
Required; 0 or 40 |
order_log (new) |
jsonb |
Required; the orders as replayed by the server |
idempotency_key (new) |
text |
Unique; from API-04 |
Requirements
| ID |
Requirement |
Source |
| DAT-01 |
The schema must contain the two tables above, plus Alembic's alembic_version. |
SQLAlchemy + Alembic |
| DAT-02 |
Every rule in the tables must be enforced by the database itself (unique, foreign key, not null, and check constraints on role, result and delivered_ng), as well as by the API. |
Postgres, section 4 |
| DAT-03 |
Models must use SQLAlchemy 2.0 typed mapping (Mapped, mapped_column) with psycopg 3, one engine for the app. |
SQLAlchemy + Alembic |
| DAT-04 |
The schema must only ever be changed by an Alembic migration. create_all, drop_all and hand-typed ALTER must not be run against a migrated database. |
SQLAlchemy + Alembic |
| DAT-05 |
A model change and its migration must be committed together. A revision already applied to a shared database must not be edited. |
SQLAlchemy + Alembic |
| DAT-06 |
Every autogenerated migration must be read before it is applied. A required column on a table with rows is added in three steps (add as optional, backfill, make required). A rename uses a rename, never drop and add. |
SQLAlchemy + Alembic |
| DAT-07 |
Time columns must be timestamp with time zone. Primary keys must be identity columns. Foreign-key columns must be indexed. Table names are plural, lower-case, with underscores. |
Postgres |
| DAT-08 |
The API must connect as a role that is not the owner or a superuser. |
Postgres |
| DAT-09 |
The connection string is a secret, supplied as DATABASE_URL, and must require TLS (sslmode=require). |
Postgres, Cloud Deploy |
| DAT-10 |
A write that touches more than one row or table must happen inside one transaction. |
Postgres |
| DAT-11 |
A fresh database must be seeded with the roster (Wren, Ibis, Heron), the pilot Ada, and missions M-041 and M-058. |
SQLAlchemy, Playwright |
| DAT-12 |
A backup should be taken before any release that migrates, and proven once by restoring it. |
Postgres, SQLAlchemy |
9. Identity and access (IAM)
There are two roles, pilot and tech. Version 1 signs pilots in the way the FastAPI tutorial teaches: an email and password form, answered with a short-lived token the API signs itself.
| ID |
Requirement |
Source |
| IAM-01 |
Every user must have exactly one role: pilot or tech. |
HTTP + Networking |
| IAM-02 |
A pilot must be able to see and record only their own missions. A tech must be able to see the roster and every mission, and enlist pilots. |
FastAPI, HTTP + Networking |
| IAM-03 |
The console's mission log, account page, cockpit and "Start preflight" must require a signed-in user (FLT-06, section 6). |
Test Cases, Playwright |
| IAM-04 |
A request without a valid token must answer 401 with www-authenticate: Bearer. A valid token without the needed role must answer 403. The two must never be swapped. |
HTTP + Networking, OAuth |
| IAM-05 |
A failed sign-in must give one message, "Wrong email or password", whichever of the two was wrong. |
Test Cases R6, FastAPI |
| IAM-06 |
If the API stores passwords, it must store only a hash made with a maintained library (Argon2). |
FastAPI |
| IAM-07 |
Access tokens must be short-lived (30 minutes at most) and sent as a Bearer token on every request, over HTTPS only. |
FastAPI, OAuth, HTTP + Networking |
| IAM-08 |
The API must verify every token's signature and expiry with a fixed algorithm set in configuration. It must never trust a token it has only decoded. |
OAuth |
| IAM-09 |
Tokens must not be kept in localStorage or sessionStorage. They are held in memory, or behind an HttpOnly, Secure, SameSite cookie. |
OAuth |
| IAM-10 |
No secret, token or password may appear in a URL, a log line, the repository, or the browser bundle. |
HTTP + Networking, Git Basics, Observability |
| IAM-11 |
The test pilot for automated tests is ada@example.com. Her password must come from a CI secret, not from the test code. |
Test Cases, CI |
10. Quality and operations (QA, OPS, OBS)
A change is done when its tests pass in the pipeline, it is deployed from a numbered release, and the running system can explain itself.
Testing
| ID |
Requirement |
Source |
| QA-01 |
Test cases must be written before the feature, as a Markdown sheet at docs/test-cases.md, changed in the same pull request as the behaviour. |
Test Cases |
| QA-02 |
Each case must have an ID (TC-AREA-NN), a priority (P1 smoke, P2 regression, P3 nice to have), a level (unit or browser), and Given / When / Then with a Then that can be observed. |
Test Cases |
| QA-03 |
The 21 cases of the tutorial's model sheet (TC-PWR, TC-CON, TC-SRCH, TC-QUE, TC-AUTH) must pass against the simulator. |
Test Cases |
| QA-04 |
Every FLT requirement must have at least one case, and every limit must be tested just below, at and just above it (49.99, 50 and 120 kW for the starter cell; 25 kW for the budget). |
Test Cases |
| QA-05 |
The flight core must be tested with Vitest, with no browser. Its tests must include one that fires several hundred random orders and checks FLT-40 to FLT-43 after each. |
Business-logic tutorial |
| QA-06 |
The server's flight rules must be tested with pytest, and one shared set of order logs must give the same results in both languages (FLT-55). |
FastAPI, new |
| QA-07 |
API tests must use FastAPI's TestClient and run without a server. Database rules must be tested against real PostgreSQL, not SQLite. |
FastAPI, Postgres |
| QA-08 |
Browser tests must use Playwright with pytest. Each test starts signed out with an empty queue, finds elements by role and visible name, and waits with expect, never with a sleep. |
Playwright + pytest |
| QA-09 |
One case must become one test, named for what it promises, with the case ID in a comment above it. A Then must not be weakened to make a test pass. |
Test Cases |
| QA-10 |
A smoke set marked smoke must cover: the console lists nine subsystems, a check can be queued, a pilot can sign in, and the starter-cell limit. |
Test Cases, Playwright |
Build and deployment
| ID |
Requirement |
Source |
| OPS-01 |
All work must reach main through a branch and a pull request. Nothing is pushed to main directly. |
Git Basics, CI |
| OPS-02 |
The pipeline must run on every pull request and on main: lint, unit tests, then browser tests (which wait for the first two). All must be required checks. |
CI |
| OPS-03 |
The pipeline must also run alembic upgrade head on an empty PostgreSQL and then alembic check. |
SQLAlchemy + Alembic |
| OPS-04 |
A failing browser test must upload its trace and screenshot. |
Playwright, CI |
| OPS-05 |
The pipeline's token must be read-only by default. Secrets come from GitHub secrets; .env is ignored and .env.example is committed. |
CI, Git Basics |
| OPS-06 |
The API must ship as a container image built from a Dockerfile, with a pinned base image, dependencies installed before the code is copied, and no secret baked in. |
Docker |
| OPS-07 |
Each release must have a version number and an image tagged with it. latest must not be deployed. |
Cloud Deploy, Kubernetes |
| OPS-08 |
The container must have a health check and a restart policy. A release counts as live only once its health check passes. |
Cloud Deploy, Docker |
| OPS-09 |
A deploy must keep the previous release ready, and go back to it automatically if the new one fails its health check. |
Cloud Deploy |
| OPS-10 |
Migrations must be applied before a new release takes traffic (DAT-04). |
SQLAlchemy + Alembic |
| OPS-11 |
The cockpit must be built with npm run build (type check, then bundle) and published to GitHub Pages by the pipeline. |
React + TypeScript, kestrel-simulator notes |
| OPS-12 |
The API must sit behind a proxy that terminates HTTPS and redirects HTTP to HTTPS. The database must not be reachable from the public internet except by the API's own connection. |
Cloud Deploy, Docker, NGINX |
| OPS-13 |
Pushing a version tag should build, publish and deploy that release with no manual step. |
Cloud Deploy |
Observability
| ID |
Requirement |
Source |
| OBS-01 |
The API must log one JSON object per line to standard output with ts (UTC), level, service, msg and a trace_id. |
Observability |
| OBS-02 |
Every response must carry an x-trace-id header matching the log lines of that request. |
Observability |
| OBS-03 |
A recorded mission must log the pilot, the mission code and the result. A refused mission must log the order that failed to replay. |
Observability, API-02 |
| OBS-04 |
The API must expose /metrics with request counts by method, route and status, and request duration. |
Observability |
| OBS-05 |
The API should count missions by result (kestrel_orders_total with order and result labels is the tutorial's pattern) and keep label values few. |
Observability |
| OBS-06 |
Two alerts should exist: the service has stopped answering for 1 minute, and more than 5% of requests are failing for 1 minute. |
Observability |
| OBS-07 |
Logs must never contain a secret, token, password or email address. |
Observability, OpenAPI Design |
11. Design and repository conventions (DSN)
The repository is kestrel-simulator on GitHub, and it must be readable by a person or a coding agent arriving cold.
| ID |
Requirement |
Source |
| DSN-01 |
The repository must have main as its default branch, a .gitignore covering .env before the first commit, and a committed .env.example with names and no values. |
Git Basics |
| DSN-02 |
README.md must say what the simulator is, how to run each part, how to get a local sign-in, and which environment variables exist. |
Git Basics, OpenAPI Design |
| DSN-03 |
AGENTS.md must contain: Project (with stack versions), Commands (install, run, test, lint, each exact), Project structure, Code style, Testing, Git workflow, and Boundaries (Always, Ask first, Never). CLAUDE.md contains the single line @AGENTS.md. |
Agent Files |
| DSN-04 |
DESIGN.md and tokens.json must describe the look. Tokens are named for their purpose, not their value. One of the two files is the source and the other is generated from it. |
Agent Files |
| DSN-05 |
Text on its background must reach a contrast of at least 4.5 to 1, and the primary colour on its surface at least 3 to 1. |
Agent Files |
| DSN-06 |
Each feature must have a spec at specs/NAME.md with Goal, Context, Acceptance criteria, Out of scope, Constraints, How to verify, and Open questions. Acceptance criteria must cite the requirement IDs in this document. |
Agent Files |
| DSN-07 |
Commit messages must be imperative and cover one idea each. Branches are named for what they do and are deleted after merging. |
Git Basics |
| DSN-08 |
Screens must use the design tokens only: no hard-coded colour values, and no class names built at run time. |
Tailwind + shadcn/ui |
| DSN-09 |
The cockpit must be React with TypeScript in strict mode, built by Vite, on Node.js 20 or newer. |
React + TypeScript, Tailwind + shadcn/ui |
| DSN-10 |
The cockpit and the API should live in separate top-level folders of the one repository, each with its own install, run and test commands. |
New |
| DSN-11 |
The simulator's look is its own. It need not match the tutorials' palette, and the token file already in the repository stands. |
kestrel-simulator notes |
12. Where each rule is enforced
A rule that matters is checked in more than one place, so one mistake cannot break it. This table is the map the two business-logic tutorials follow: the browser column is part 1, the API and database columns are part 2.
| Rule |
Flight core (browser) |
API |
Database |
Tutorial that teaches it |
| Draw never exceeds 25 kW (FLT-32) |
Refuses the order at once |
Refuses the mission on replay |
Not stored, so nothing to check |
Business logic, FastAPI |
| Orders only in their phases (FLT-12) |
Transition table |
Same table in Python, on replay |
Not applicable |
Business logic, FastAPI |
| Antimatter is 0 or 40 ng (FLT-41) |
Checked after every order |
Result computed by the server |
Check constraint on delivered_ng |
Business logic, Postgres |
| Mission result (FLT-20) |
Shown to the pilot |
Decided by the server |
Check constraint on result |
FastAPI, SQLAlchemy |
| A mission belongs to its pilot (API-03) |
Not decided here |
Taken from the token |
Foreign key on pilot_id |
OAuth, FastAPI, Postgres |
| A mission is recorded once (API-04) |
Sends one key per mission |
Checks the key |
Unique idempotency_key |
OpenAPI Design, Postgres |
| Callsigns are unique |
Not decided here |
Answers 409 |
Unique constraint |
SQLAlchemy + Alembic |
| Preflight needs a sign-in (FLT-06) |
Sends the pilot to /login |
Refuses without a token |
Not applicable |
Playwright, OAuth |
| Starter cell limit (FLT-04) |
Pure function |
Not needed: nothing is stored |
Not applicable |
Test Cases, Playwright |
13. Conflicts and rulings
The tutorials were written one at a time and disagree in 18 places. All are ruled below.
Decided on 17 November 2026
| Topic |
What the tutorials say |
Ruling |
| Two power scales |
Preflight loads add up to 94 kW and the starter cell cuts in under 50 kW (Test Cases). In flight the reactor budget is 25 kW (Observability, Docker). |
Both stand. Preflight figures are test-bench loads on the hangar's ground supply; flight figures are reactor power. |
| Sign-in flow |
FastAPI teaches a password form and a token the API signs itself. OAuth teaches an identity provider with authorization code and PKCE. |
Version 1 follows the FastAPI tutorial under the IAM rules. An identity provider is version 2. |
| Styling |
The React tutorial's cockpit uses a hand-written stylesheet. The Tailwind tutorial uses Tailwind 4 with shadcn/ui. |
Tailwind with shadcn/ui, fed by the repository's tokens. |
| Where the API runs |
Cloud Deploy uses a rented server with Docker Compose and a Caddy gateway. The database is on Neon and the cockpit on GitHub Pages. |
One small rented server running the API container behind Caddy, as Cloud Deploy teaches, with no database container because the database is on Neon. It needs an address on a domain you own. |
| Host names in the story |
kestrel.test (HTTP, Observability) and kestrel.hangar-7.dev (Cloud Deploy) |
Both stand: kestrel.test is the hangar network, kestrel.hangar-7.dev is the public address. |
| New rules in this document |
FLT-03, FLT-07, FLT-17, the /cockpit route, and the new columns in section 8 are in no tutorial. |
Accepted. |
Ruled here
| Topic |
What the tutorials say |
Ruling |
| Designation |
"KF-07 Kestrel Mk II" in the newer tutorials, "KF-07 Kestrel" in Kubernetes, NGINX and the Observability status reply |
KF-07 Kestrel Mk II everywhere |
| Reactor figures |
13 kW output and 25 kW limit (Docker, Observability); 1380 MW (Kubernetes); 25 kW at idle (HTTP) |
25 kW budget, 13 kW normal output |
| Subsystem names |
Nine in the console; a different nine in Kubernetes (with railgun, shield, life-support); seven services in Observability; "navigation" in Docker |
The Test Cases nine are the subsystems. Every other name is a service inside one of them, mapped in section 3 |
| Mission log or sorties |
"Mission log" with M-041 on the console; a sorties table with missions like "recon sweep" in the database |
Screens and API say missions; the table stays sorties |
| Health check path |
/health (Cloud Deploy, Docker); /healthz and /readyz (Observability) |
/healthz and /readyz |
| ORM |
SQLModel on SQLite (FastAPI); SQLAlchemy 2.0 on PostgreSQL (SQLAlchemy + Alembic) |
SQLAlchemy 2.0 on PostgreSQL |
| PostgreSQL version |
16 (Docker, Postgres); 17 (Cloud Deploy, SQLAlchemy) |
17. Neon offers it, but new projects default to 18, so pick 17 when creating the project |
| Python version |
3.12 (Docker, Agent Files); 3.13 (Cloud Deploy); 3.14 (FastAPI, Playwright) |
3.14, stated once in AGENTS.md |
| Port |
8000 (most); 8080 (Kubernetes) |
8000 |
| Error body |
{"detail": ...} (FastAPI, HTTP, SQLAlchemy); RFC 9457 problem documents (OpenAPI Design) |
detail for version 1 |
| Pipeline file |
tests.yml with older action versions (Playwright); ci.yml with lint, unit and browser jobs (CI) |
ci.yml from the CI tutorial |
| Test password |
"skyward" (Test Cases, Playwright); "teatime" (FastAPI, CI) |
Neither in code: a CI secret (IAM-11) |
| Image and registry names |
hangar7/kestrel-reactor, hangar/NAME, ghcr.io/hangar-7/control, ghcr.io/hangar7/kestrel-flight |
In the tutorials the registry account is hangar-7 everywhere. The real build has one API image, named for the real repository |
| Waypoints, loadouts, compute cores |
Waypoints (HTTP), recon / assault / orbital loadouts (Kubernetes) and compute cores (NGINX) are part of the story |
Not in version 1 |