No description
  • Rust 99.1%
  • Shell 0.8%
  • Dockerfile 0.1%
Find a file
Repository files (latest commit first)
Filename Latest commit message Latest commit date
Tim Janke 0d9dd5c1eb
All checks were successful
CI / check (push) Successful in 5m17s
CI / publish (push) Successful in 2m49s
🐛 (aircraft): Refuse an empty patch and read a patched airport code like a created one
2026-10-16 11:13:12 +02:00
.github/workflows 👷 (ci): Publish the backend image to the Forgejo registry 2026-08-06 07:04:00 +02:00
.omp 🐛 (skill): Read X-Plane 11 and 12 jet and turboprop engine types as Jet A 2026-10-16 10:53:29 +02:00
crates 🐛 (aircraft): Refuse an empty patch and read a patched airport code like a created one 2026-10-16 11:13:12 +02:00
docs 🐛 (aircraft): Refuse setting a rental state by hand 2026-10-16 10:52:40 +02:00
migrations 🗃️ (aircraft): Record the administrator behind every fleet write 2026-10-16 10:07:19 +02:00
proto@da4893eb3e ✨ (sim): Verify a chunk as it was sent, then decode it 2026-09-07 01:06:29 +01:00
scripts ✨ (web): Serve the contract this build implements 2026-08-03 08:08:25 +02:00
.dockerignore 👷 (ci): Fail on warnings and on contract drift 2026-08-03 08:08:27 +02:00
.env.example ✨ (meta): Serve the plugin release from a manifest 2026-08-31 07:57:53 +02:00
.gitignore 🙈 Add the .idea folder to the ignore list 2026-10-16 09:27:31 +02:00
.gitmodules 💚 (ci): Use a relative URL for the proto submodule 2026-08-06 06:42:26 +02:00
Cargo.lock 🐛 (import): Recognise the body limit by its error type, not its message 2026-10-15 13:46:34 +02:00
Cargo.toml 🐛 (import): Parse snapshot floats exactly so a file-filled elevation keeps following the file 2026-10-16 09:17:48 +02:00
clippy.toml 🎉 (workspace): Add the Cargo workspace and the domain crate 2026-08-03 06:47:52 +02:00
docker-compose.yml 👷 (ci): Fail on warnings and on contract drift 2026-08-03 08:08:27 +02:00
Dockerfile 👷 (ci): Fail on warnings and on contract drift 2026-08-03 08:08:27 +02:00
README.md 📝 (docs): Describe the shared fleet rules and the fleet MCP tools 2026-10-16 10:33:46 +02:00
rustfmt.toml 🎉 (workspace): Add the Cargo workspace and the domain crate 2026-08-03 06:47:52 +02:00

flyg-backend

The backend for the flyg platform: a virtual-aviation service where pilots rent aircraft, fly orders in X-Plane 12, and earn money for verified flights.

One process serves three surfaces.

Surface Path Format Client Credential
Website /api/v1 JSON, RFC 9457 errors, SSE flyg-frontend Session cookie plus a double-submit CSRF header
Simulator /v1 Protobuf over HTTP and WebSocket flyg-plugin-xplane12 Bearer device token
Administration /api/mcp MCP (JSON-RPC over Streamable HTTP) An administrator's AI client Bearer admin access token

This repository invents neither of the first two contracts. The website's belongs to flyg-frontend/openapi.yaml, and the simulator's to the flyg-proto schemas. This repository implements both and bridges them: a preflight set on the website reaches the sim, and telemetry from the sim reaches the browser. The MCP tools are this repository's own; their names and JSON Schemas are the contract.

The plugin is a sensor and an actuator. Every judgement — whether an order was delivered, whether a recording is trustworthy, what a flight earned — is made here, from what was persisted rather than from what the client asserted.

Running it

cp .env.example .env          # then set DATABASE_URL if you are not using compose
docker compose up -d db       # Postgres on 5433, to stay out of a local one's way
cargo run                     # migrates at startup, then serves

Point the website at it with VITE_API_PROXY=http://localhost:8080 in flyg-frontend.

The whole stack in containers:

docker compose up --build

First run

A migrated database holds seeded airports and nothing else. There are no aircraft and no orders, and both are created through /api/v1/admin, which needs the admin role — a role only an administrator can grant. So the platform would have no way to reach its first order, and the first account to register becomes the administrator. Every account after it is a pilot.

In order, on a fresh deployment:

  1. Open the website. While no account exists, GET /api/v1/setup reports setup_required and the website shows its setup screen instead of the usual entry pages. It asks for a first and last name, a callsign — letters and digits only, three to twenty-four of them — and whether anyone else may register afterwards. The account created there is the administrator.
  2. Create aircraft (/admin/aircraft) and orders (/admin/orders). Until both exist, the market and the order board are empty for every pilot.
  3. Pair a simulator: the plugin shows a code, and /pair on the website approves it. FLYG_PUBLIC_ORIGIN is what the plugin is told to send the pilot to, so it has to be the website's own origin.

Whether registration is open is a switch in platform_settings. The first account sets it, /admin/settings changes it later, and GET /api/v1/setup reports it as registration_open. While it is off, a newcomer's registration is answered with 403 registration_closed; pilots who are signed in are not affected and can still add passkeys. Signing in takes no callsign: the passkey is discoverable and names the account by itself.

The bootstrap fires only while the users table is empty, so it cannot hand the role to a latecomer. A database that already has pilots but no administrator is the one case it cannot help with, and is corrected directly:

psql "$DATABASE_URL" -c "UPDATE users SET roles = ARRAY['pilot','admin'] WHERE display_name = 'Nordwind'"

MCP

Administrators can let an AI client manage the platform's reference data: airports and the fleet. Create a token under MCP access on the website (admin area), then point the client at /api/mcp on the website's origin, for example with Claude Code:

claude mcp add --transport http flyg https://<site>/api/mcp --header "Authorization: Bearer <token>"

The token acts with its owner's admin rights and stops working when it expires, is revoked, or its owner is no longer an administrator. The tools describe themselves; docs/BACKEND_PLAN.md has the rules they enforce.

The airport tools list, read, create, update, delete and batch-upsert airports, and report what still refers to one that cannot be deleted (airport_usage). An airport carries more than its code, position and fuel price: a status (ACTIVE or DISABLED; a disabled field takes no new orders), the default arrival_radius_m new orders to it measure their arrival against, the landing_fee_cents charged on arrival, the fuel_types it sells (JET_A, AVGAS_100LL, or both — an aircraft whose fuel is not among them is refused fuel there), an IATA code, city and ISO 3166-1 alpha-2 country.

import_airport_layout reads one airport's apt.dat (at most 900 000 bytes; a larger file goes through the website's upload) and applies its values under the import's override rule: a field follows the file only while it still equals what the last import wrote; an administrator's edit ends the file's say over that field. Runways are the website's to edit, and the whole-scenery bulk import (X-Plane's global apt.dat, plain or gzip) happens there too.

The omp skill flyg-airport (.omp/skills/, found when omp runs inside this repository) drives these tools for named airports: it cuts them out of a supplied apt.dat, creates missing ones after confirmation, imports them and offers to overwrite fields that still differ from the file.

The fleet tools list, read, create, update and delete aircraft, and report what still refers to one that cannot be deleted (aircraft_usage). They enforce the website's fleet rules and refuse with the website's codes.

The omp skill flyg-aircraft drives the fleet tools: it reads specs out of a supplied X-Plane .acf (or asks for them), checks that the target airport sells the aircraft's fuel, confirms and creates the aircraft.

Layout

Crate Holds
flyg-core Domain rules with no IO: payouts, verdicts, flight summaries, readiness, track thinning, chunk signatures, cursors, airport validation
flyg-proto Types generated from the proto/ submodule by prost
flyg-server The binary: axum routers for every surface, sqlx repositories, and the hub that joins the website and the simulator

proto/ is the shared schema repository at ssh://git@git.janke.biz:2222/flyg/proto.git, which the plugin uses too. Clone with submodules, or run git submodule update --init --recursive afterwards. Either way needs an SSH key that git.janke.biz accepts.

The hub lives in memory, so it describes this process alone. A second instance would report only its own simulator connections. Running more than one requires a shared channel first.

Tests

cargo test --workspace

flyg-core is tested on its own. flyg-server starts a real server on an ephemeral port, gives each test its own database, and drives both surfaces over real HTTP and real WebSockets: a test signs chunks the way the plugin does, and the server verifies them the way it will in production.

DATABASE_URL must point at a Postgres that may create databases.

Documents

  • docs/BACKEND_PLAN.md — the architecture, the milestones, and the policy questions still open.
  • docs/openapi.yaml — the web contract, copied from flyg-frontend, served at /api/v1/openapi.yaml. scripts/check-contract.sh catches the two drifting apart.
  • docs/ASSEMBLY_RUN.md — flying one order end to end, from registering to the payout. The part of the system no suite can reach on its own.