Generated code
On this page

npx globetrotter sync writes the backend from the service file. Every file
has one owner, and the owner decides what a later sync may do to it. The
picture colours each file of fieldops' backend/ by owner.
The four owners
| Owner | Marked by | A later sync |
|---|---|---|
| Generated | @generated-hash in its header |
Overwrites it. |
| Written once (migration) | @globetrotter migration header |
Never touches it. New ones append after the last. |
| Stub | @stub-hash in its header |
Updates it while untouched. Once you edit it, it is yours. |
| Contract | The OpenAPI file and its copies | Rewrites it when it differs. Never edit it. |
Anything else in the folder is yours from the start. A stub file with no marker is written only where the file is absent, and never touched after.
Generated
Rewritten on every sync, and on every studio save. If you edited one by hand,
the sync first keeps your version under backend/.hand-edited/<its path>
(stamped with the time) and then writes the file again. Put structure in the
design, not in these files.
A file the target no longer writes (an entity removed, a service deleted, a target turned off) is removed, after a hand-edited one is kept. A stub you never touched goes with it; a stub you edited is yours and is named until you delete it. A migration is never removed.
Stubs
A stub is written once, with a header saying it follows the design until you edit it. While untouched, a change in the design rewrites it. Edit anything and it is yours: sync stops rewriting it and instead tells you what the design has moved past (see renames).
Migrations
Written by sync only, never by a studio save. See
Data and migrations.
A file is only ever removed when it carries a well-formed generated or stub marker line and its content still matches that marker. A file that merely mentions the marker, or one you edited, is left where it is and named. sync --check lists what a sync would remove without removing it, and every removal is written to the journal.
To turn the sweep off, set GLOBETROTTER_SWEEP=off or "sweep": false under backend in globetrotter.config.json. Files the last sync recorded and no longer writes are still removed.
What is written where (Python)
| Path | Owner | Holds |
|---|---|---|
backend/pyproject.toml |
Yours | The workspace root, written once by init. |
backend/contract/<name>.openapi.json |
Contract | The OpenAPI file the pages and server share. |
backend/migrations/<store>/<engine>/NNNN_*.sql |
Written once | One SQL file per change, per engine. |
backend/migrations/<store>/alembic/ |
Generated | The runner: one revision per SQL file. |
backend/migrations/<store>/mysql-foreign-keys.sql |
Stub, then yours | Only for a mysql store whose migrations were written before 2026-11-13: the foreign keys still owed, for your next migration. Rewritten to what is still owed while untouched; kept once edited; left, and said to be no longer needed, when nothing is owed (Data and migrations). |
packages/<app>_contract |
Generated | The contract as package data, and its schemas as Pydantic models. |
packages/<app>_core |
Generated | Settings, engines, entities, repositories, rules, services, audit, flows, jobs, words; and, when the design has them, shapes.py, machines.py, clients.py, webhooks.py, tenancy.py, files.py, cache.py, search.py, notify.py. |
packages/<app>_fastapi |
Generated | One router per service at the contract's paths, and python -m <app>_fastapi; a service named as a built-in router (Files, Search, Webhooks, Tenancy, Session, Token, Magiclink, Passkey, Apikeys) keeps routers/<name>.py and the built-in one is routers/builtin_<name>.py; routers/ also holds session, token, magiclink, passkey, files, search, tenancy and webhooks when the design has them. |
packages/<app>_impl |
Stub, then yours | One module per service, flows.py, jobs.py, auth.py and wiring.py. A service with one of those names keeps its module, and the other moves: the steps to flow_steps.py, the jobs to scheduled_jobs.py, the key store to key_store.py, the wiring to app_wiring.py. |
backend/tests/conftest.py, test_contract.py |
Stub | The throwaway database and the Schemathesis run. The notices a run sends and the files it uploads are kept in the run's own temporary folder, never in the backend's .globetrotter/sent.jsonl or beside its uploads. |
backend/tests/test_clients.py, test_webhooks.py, test_transitions.py, test_tenancy.py |
Stub | Written when the design has clients, webhooks, a state machine or tenants: the client's policy against a fake transport, each webhook called (signed right, wrong, old, twice, too big, broken), each move called from every state, a person in one organisation and not the other. |
backend/tests/test_given_keys.py, test_update_rules.py |
Stub | Written when a create takes its key or a unique value from the caller (pressed twice: the second is the 409 rowExists), and when an update's params fill a field with a format (a wrong value is a 400 that names the field, a good one is stored, a blank one leaves the field as it was). Neither is written for a design with organisations. |
backend/tests/test_credentials.py |
Stub | A malformed API key or session cookie is the 401 a wrong one is, never a 500. Written when sign-in is on, organisations are off, and a GET that needs someone signed in takes no required param. |
backend/tests/test_still_has.py |
Stub | Written when a generated delete can be refused for rows that still point at the row: the 409 stillHas. |
backend/tests/test_links_stamps.py, test_clears.py |
Stub | Written when a list is kept by a link or ordered by createdAt or updatedAt, and when an update's param says clears, where the test can make the rows through the design's own creates: one key holds only its rows, in both, isNull none of them, a malformed key is a 400; three rows come back in the order made and the other way, and a cursor walk skips and repeats none; null empties the field, left out or blank it stays, null on a param that does not clear is a 400. Neither is written for a design with organisations. |
backend/tests/test_where_clear_link.py |
Stub | Written when a list's own where names a link or a row time, or an update's param empties a link, where the test can press it: the rows answered have that key, none, or another one; the rows changed since a time; a link given, left out (kept), sent null (emptied), and a key that is no key (400). |
backend/tests/test_audit_personal.py |
Stub | Written when an audited entity has a personal field, an update that sets it and a create the test can fill: the audit row holds "[personal]" before and after, null after where the param clears it, and a field beside it keeps its value. |
backend/tests/test_audit_operation.py |
Stub | Written when the design audits an entity on a SQL store (sqlite, or the test database GLOBETROTTER_<STORE>_TEST_URL names) and has a create the test can fill: the create's audit row names Service.operation, a scheduled job's writes name job:<Job>, and a row kept before the column reads empty through the audit's own reader. |
Any other backend/tests/test_*.py |
Yours | Your own tests. Sync never writes them. |
backend/uv.lock |
Lock | uv lock, run by sync. |
backend/.env.example |
Generated | Every variable the code reads for this design. Rewritten; a hand edit is kept in .hand-edited/. |
backend/compose.yaml, ci/github-actions.yml, ruff.toml |
Stub | Follow the design until you edit one. |
backend/compose.rust.yaml |
Stub | The Rust target's compose file, beside Python's compose.yaml: follows the design until you edit it. |
backend/Dockerfile, .dockerignore, pyrightconfig.json, .python-version, .gitignore |
Stub, no marker | Written once, then yours. .python-version and pyright's pythonVersion pin the Python the workspace runs on (3.12): JSON carries no marker, and a Dockerfile has no comment style core knows. |
backend/README.md |
Stub, its marker an HTML comment at the end | Follows the design (stores, port, processes, variables) while it is as generated; once you edit it, it is yours and sync says so once: backend/README.md is yours now; the generated one is at backend/.hand-edited/README.generated.md. That copy is rewritten when the design would change the README, with the same line. A README written before the marker existed has none, so it is yours at the first sync, and the same line says where the current one is. |
State the running backend keeps lives in backend/.globetrotter/ (traces, the
last test run, sent notices, local files). It is this machine's, not the
project's.
<app>_core holds the parts that stay out of your way. The names that matter:
services.py: per service, a Protocol and a Base class with every method the design can write. Your class in<app>_implsubclasses the Base.repositories.py: per entity,get,find,create,update,delete; per store, all of them on one session.rules.py: each entity's rules, andcheck(), which says every wrong value at once by its path.errors.py: what an operation answers when it does not do what was asked, each with its status and words.words.py: the service's own refusal words.audit.py,flows.py,jobs.py,observe.py: the audit rows, the flow and job machinery, and the traces and logs.shapes.py: the query each shape with afromreads.machines.py: the refusal of a move and the check of its own role.clients.py: per client, a Protocol, the real client over httpx and a fake.webhooks.py: verify, parse, the record of events seen, anddelivery()for tests.tenancy.py: the organisation a request is for, and the scope the repositories read.
What is written where (Rust)
| Path | Owner | Holds |
|---|---|---|
crates/<app>-generated |
Generated | The contract's models as serde types, a trait per service with a default method for every operation the design can write, the routers, the stores, error.rs; and, when the design has them, shape.rs, machines.rs, clients.rs, webhooks.rs, tenancy.rs, files.rs, cache.rs, notify.rs, search.rs. |
crates/<app>-generated/tests/contract_examples.rs, clients.rs, webhooks.rs |
Generated | The contract's examples through the models; the client's policy against a fake; each webhook called. |
crates/<app>-generated/tests/machines.rs |
Generated | Written when the design has a state machine: each move pressed through the app's routes from every state on a scratch database, and a guard both ways. A case it cannot make is an #[ignore = "why"] test, shown by cargo test -- --ignored or in the run's ignored count, never an omission. |
crates/<app>-generated/tests/mine.rs |
Generated | Written when a list keeps its rows to the person signed in by a text field of its own (owner=me) and sign-in is on with two roles: nobody signed in is a 401, and two people each get exactly their own rows. The membership form (assignee.userId=me, organisations on) is not pressed here. |
crates/<app>-generated/tests/versions.rs, idempotency.rs, limits.rs, apikeys.rs |
Generated | Written when the design has versions, idempotent commands, limits or managed keys: each pressed through the app on a scratch SQLite file. |
crates/<app>-generated/tests/row_exists.rs, blanks.rs, updates.rs |
Generated | The input rules pressed through the app: a second create with a taken key or unique value is the 409 rowExists; a blank optional value with a shape is not given, and a decimal with a least of 0 or more takes no minus; an update sent one param alone leaves every other field as it was. Each is written only when the design has such an operation. |
crates/<app>-generated/tests/rules.rs |
Generated | The rules beyond a text's, checked without a database: a span whose end may be empty is refused when both ends are there and the end is not after the start, and passes with one empty; a JSON field the row needs refuses null. Written only when the design has one of them (fieldops has the second). |
crates/<app>-generated/tests/still_has.rs |
Generated | A row made, a row that points at it, the delete told 409 stillHas. Written only when the design has such a delete. |
crates/<app>-generated/tests/links.rs, stamps.rs, clears.rs |
Generated | The same three pressed through the app on a scratch SQLite file, the rows written through the repositories: a list kept by a link (eq, in, isNull, a malformed key), a list ordered by a row time with a cursor walk one row a page, an update whose param says clears. Each is written only when the design has such an operation the test can press; none for a design with organisations. |
crates/<app>-generated/tests/where_parts.rs |
Generated | A list's own where on a link or a row time, pressed through the app on a scratch SQLite file: the list holds only the rows its where keeps. A link emptied by null is pressed in clears.rs. Written only when such a list can be pressed. |
crates/<app>-generated/tests/audit_personal.rs |
Generated | The same for the audit: a personal field changed leaves "[personal]" on both sides, the field beside it its values. Written only when the design has an audited entity with a personal field and an update the test can press. |
crates/<app>-generated/tests/audit_operation.rs |
Generated | A row written outside any request names no operation; an update through its route names Service.operation. Written only when the design audits and has an update the test can press. |
crates/<app>-generated/tests/tenancy.rs |
Generated | Tenant isolation, the twin of Python's test_tenancy.py: a row made in one organisation is not read, listed, updated or deleted from another; with managed keys, a key works only in its own organisation, at its maker's role there now (that part only with a uuid organisation key, an API key sign-in and a store on SQLite or, alone, on Postgres: without GLOBETROTTER_<STORE>_TEST_URL it is skipped, or fails under CI: reference). It also presses every list and get of an organisation's rows, for key, session and token sign-in alike: the list holds this organisation's row and not the other's. |
crates/<app>/src/services/<service>.rs |
Stub, then yours | A type per service implementing the trait. |
crates/<app>/src/flows.rs, jobs.rs |
Stub, then yours | The steps and jobs, when the design has them. |
crates/<app>/src/main.rs, lib.rs |
Stub, then yours | Services, and the program that serves them. |
crates/<app>/tests/machines.rs, tenancy.rs |
Stub, then yours | The same presses with your services wired as main.rs wires them. Written when the design has a state machine, or organisations; follow the design until you edit one, then service_status compares their //! Moves:, //! Cases: and //! Presses: lines with the design. |
any other crates/<app>/tests/*.rs |
Yours | Your own tests. Sync never writes them. |
backend/Dockerfile.rust, Dockerfile.rust.dockerignore, rust-toolchain.toml |
Stub | The Rust image, beside the Python one, and the pinned toolchain. The image has never been built here. |
backend/README.md (README.rust.md when the Python target writes README.md) |
Stub, with a marker | The Rust backend's first commands, who owns what, the Processes table the design needs and the environment it reads; follows the design until you edit it, then yours (what the design would write is set aside in .hand-edited/). |
repo_<engine>.rs is written per engine turned on. The contract's copy sits in
the generated crate. The Rust files are written on every sync and studio save;
your files, never. See Targets.
The frontend's side
Beside a backend, sync also writes the pages' binding stub
(src/bindings/<slug>.ts). It calls the page's GET and its actions through
/api, and does what a person expects after each:
- a form whose command answers another page's data (New note, then Notes) goes to that page;
- sign-in goes to the first page;
- anything else says it was done, in a notice;
- a button beside the picked row (Mark done) sends that row's id.
sync writes src/proxy.ts once, where the pages forward /api to a backend
and have none; it is yours after your first edit. See
Connect data.
How a rename reaches your code
Nodes are matched by id, so a rename in the design is a rename, never a drop and an add.
- The database. A renamed field or entity is a
RENAMEin the next migration, so the values stay. - The contract. Callers of a renamed operation are told its new name, and callers of a removed one that it is gone, and by whom.
- Your Python.
syncandservice_statusname each file of yours that still says the old name, by line, and each method of yours whose operation was renamed or removed: it no longer runs. - Your Rust. A method whose operation was renamed or removed stops the
build (
E0407). Sync andservice_statusname it, with the new name when there is one, and each file of yours that still says an old name, by line, as for Python. - A removed service. Its generated trait file and its untouched stub go, with the line saying the service is gone. A
mod <service>;or.<service>(…)in your editedservices/mod.rsormain.rsis named by file (the crate would not build) and never edited by sync; your editedservices/<service>.rsis kept, named as yours and as nothing builds it once themodline is out. - New params. Sync names a param your code does not take yet, with its type.
A renamed or removed operation never silently keeps answering.
Checking it
npx globetrotter sync --check fails when a generated file is out of date, a
design is invalid or lint finds an error. For Python it also checks the lock.
For Rust it runs the toolchain check, cargo clippy -D warnings,
cargo fmt --check and the contract's own examples through the models. A
generated file that the language's own compiler refuses is said on every sync
as the target's bug, by file and line. The generated Python packages type-check
clean in pyright's standard mode, with no # noqa and no # type: ignore line in them. The Protocols and Bases give your editor
every param, answer, repository and the AsyncSession.
Next: Your code to write what is yours, Data and migrations, Targets.