Contributing & architecture
How the agents work — vendor/ as the spec, the judge, levels, commits and the design rule.
Read GOAL.md and MANIFESTO.md first. This page is a short map, not a substitute.
Architecture
One Cargo workspace, one final binary: megabase. One crate per Supabase-authored service (megabase-rest, megabase-auth, megabase-realtime, megabase-storage, megabase-functions, megabase-pooler, megabase-meta, megabase-studio), plus megabase-core (config, errors, HS256 JWT) and megabase-server (gateway). HTTP: axum on tokio. PostgreSQL stays external. JWT verification lives only in megabase-core; component crates must not copy it. With DATABASE_URL set, the binary installs the Auth SQL objects it implements.
The loop
- Read GOAL.md, PROGRESS.md, coverage/summary.json.
- Take one Ready issue.
- Spec the unit from
vendor/if the spec file is missing. - Implement in Rust.
- Run the judge (
just judge). Mutating cases also compare database
side-effects; judge harness changes stay on review/*. The held-out suite (just judge-hidden) is weekly and is not part of this loop.
- Keep the commit only if total conformance does not fall.
- Record: PR, coverage, and a new
docs/decisions/NNNN-slug.mdwhen the
decision outlives one issue. PROGRESS.md stays current state only.
Failures return HTTP 501 with {"code":"MEGABASE_NOT_IMPLEMENTED",...}. Never a plausible but unverified answer.
Hard rules (short)
- Rust only, with the exceptions in GOAL.md (configuration, compatibility SQL, Studio assets).
- Never modify
vendor/orjudge/on a feature branch. - Never disable a test to make a score go up.
- Credit upstream in a header comment; keep NOTICE current.
- Conventional Commits for the site and docs; component unit commits follow GOAL.md.
Checked queries
Auth DML is sqlx::query! / sqlx::query_as!. .cargo/config.toml sets SQLX_OFFLINE=true, and .sqlx/ is the committed query metadata. After changing a query string, install sqlx-cli 0.8.6 (the sqlx pin in the workspace Cargo.toml) and refresh the cache against a database that already has the Auth schema:
cargo install sqlx-cli --version 0.8.6 --locked --no-default-features --features native-tls,postgres
SQLX_OFFLINE=false DATABASE_URL=postgres://… cargo sqlx prepare --workspace -- --all-targetsCommit the .sqlx files the command writes. A CI cargo sqlx prepare --check step would live in .github/ and needs its own review/* pull request.
Pull request checks
Protected paths and Conventional Commits title run on every pull request.
The other workflows call .github/actions/pr-paths instead of paths / paths-ignore on the trigger. A workflow that never starts leaves a required check at "Expected — waiting". Each job keeps its check name. When the diff does not apply, the job's first step succeeds and the remaining steps are skipped, so the check is success. An empty output runs the job. An empty diff, a failed base fetch, or a failed path-filter job (checkout or action error) runs the full suite. A skipped job is not used as a success for that case.
A diff is site-only when every path is `site/`, `devlog/`, `MANIFESTO.md`, `HUMAN_LOG.md`, or anything under `docs/` except `docs/COMPATIBILITY.md` and `docs/epics/ (coverage-tool output). A site-only pull request does not compile the server. These checks report success without their usual work: Build, MSRV 1.89, Coverage check, Container image, Judge, the cargo-fuzz matrix, Bencher, cargo-deny, cargo-vet, cargo-machete, cargo-hack, and Codecov. The cargo-audit matrix still scans site/Cargo.lock when the diff changes a site-generator input, because that lockfile can change on a site-only pull request. The workspace Cargo.lock leg reports success without scanning. A pull request that changes neither the server nor a site-generator input (for example docs/decisions/ only) reports both legs as success without scanning. Push to main` audits both lockfiles.
Generate site (`pages.yml`) runs when a path is a generator input: `site/`, `devlog/, MANIFESTO.md, HUMAN_LOG.md, the workspace Cargo.toml (the version badge), a top-level docs/*.md file, coverage/summary.json, coverage/units.json, coverage/badge-coverage.json, coverage/badge-conformance.json, coverage/judge-results.json, coverage/judge-history.json, coverage/treemap.svg, or coverage/treemap-light.svg. That job formats, lints (clippy -D warnings), tests, and builds site/. Cargo.toml and the coverage/ inputs are not site-only, so those diffs also run the server suite. A pull request with none of those paths (for example docs/decisions/` alone) reports Generate site as success without building.
Judge shards (judge.yml) use the same classification. A pull request that only changes one component crate runs that shard and the other shard checks succeed without starting the reference stack:
| Crate | Shard |
|---|---|
crates/megabase-auth | Judge (auth) |
crates/megabase-rest | Judge (rest) |
crates/megabase-storage | Judge (storage) |
crates/megabase-realtime | Judge (realtime) |
crates/megabase-meta | Judge (meta) |
crates/megabase-functions | Judge (functions) |
Two component crates run those two shards. Shared inputs run every shard: `crates/megabase-server` (the gateway), `crates/megabase-core`, the `crates/megabase` binary, root `Cargo.toml` and `Cargo.lock`, `judge/`, `.github/`, `coverage/judge-results.json` (the baseline the harness reads), and any Dockerfile or compose file. A path that is none of those and is not site content, `docs/`, `coverage/, README.md, or PROGRESS.md is unclassifiable and also runs every shard. No component crate and no shared input (for example a site-only diff, or docs/decisions/ alone) skips the Judge build. The mapping is the COMPONENT_SHARDS list in .github/actions/pr-paths. Add a line when studio or pooler gets judge/cases/<shard>.toml`. Until that file exists, those crates run every shard.
A diff that touches both a site path and a server path runs both suites. Push to main, the fuzz schedule, the hidden judge, Scorecard, Release, and workflow_dispatch (including release lockfile sync) are not filtered and run every Judge shard.
CodeQL is GitHub code scanning default setup. There is no codeql.yml, so this filter does not skip it.
Real app smoke test
.github/workflows/realapp.yml (check Real app (supabase-js)) runs the nextjs-todo-list scenario from issue #320 with the official @supabase/supabase-js client, at the tag vendor.toml pins for vendor/supabase-js, against a Megabase built from the pull request (0038). The job starts the reference stack's PostgreSQL image, creates a realapp database, starts Megabase against it (which installs auth.users and auth.uid()), applies the example's migration, then signs up two users and walks sign-in, sign-out, wrong password, getSession / getUser, insert().select().single(), a check violation (23514), an RLS-denied insert (42501), order('id'), update().select().single(), the other user and anon seeing no rows, PGRST116 on a foreign update, a no-op foreign delete, delete, and sign-out, plus the two browser preflights. The job summary lists every step. The scenario is a heredoc in the workflow: the Protected paths guard rejects a .js or .mjs file outside vendor/ (the only other exception is site/static/db-dither.js).
While REALAPP_REQUIRED in the workflow is "false", a failed scenario is a warning annotation and the check stays green. Set it to "true" once the client bugs #320 lists are closed. Site-only pull requests report success without building.
Fuzzing
OpenSSF Scorecard's Fuzzing check treats a Rust repo as fuzzed when a *.rs file contains libfuzzer_sys (checks/raw/fuzzing.go, tool RustCargoFuzz). fuzz/ is a standalone cargo-fuzz workspace (not a member of the root workspace) with three targets:
| Target | Exercises |
|---|---|
jwt | megabase-core HS256 verify_at and bearer_token |
gateway_http | gateway request-target parse and Kong prefix matching |
rest_query | PostgREST query walker and the served horizontal-filter parser (interpret_query); both stay panic-free |
Needs a nightly toolchain and cargo-fuzz 0.13.2 (the root rust-toolchain.toml is stable; pass +nightly):
rustup toolchain install nightly
cargo install cargo-fuzz --locked --version 0.13.2
just fuzz jwt # or gateway_http / rest_query; default 60s
just fuzz jwt 600
cargo +nightly fuzz list
# just fuzz pins --target to the host triple so a musl-built cargo-fuzz
# does not pick x86_64-unknown-linux-musl (ASan cannot link static musl)..github/workflows/fuzz.yml runs each target for 60 seconds on pull requests that are not site-only, and 600 seconds by default on a nightly schedule and workflow_dispatch (the seconds input can override that duration). A crash uploads fuzz/artifacts/. Seed inputs live in fuzz/corpus/<target>/. Do not commit fuzz/target/, fuzz/artifacts/, or fuzz/coverage/.
Design
Mockups live in the Kite identity file. The public site is generated from site/ in Rust. No JavaScript framework.
Supply chain
Megabase owns two Rust lockfiles: the workspace Cargo.lock and site/Cargo.lock (the static generator is a standalone crate). just audit and the CI cargo-audit matrix each run cargo audit --file once per owned lockfile. A workspace-only cargo audit misses site/. A site-only pull request audits site/Cargo.lock when the change affects a site-generator input, and skips the workspace leg; every push to main audits both lockfiles. There is no advisory ignore. Cargo still records optional sqlx-mysql in the workspace lockfile when only the postgres feature is on; [patch.crates-io] replaces that crate with third_party/sqlx-mysql, which leaves the rsa feature off so RUSTSEC-2023-0071 is not in the lockfile (0033). OpenSSF Scorecard's OSV check walks every Cargo.lock in the tree, including site/.
Lockfiles under vendor/ belong to the pinned upstream spec. Agents never edit them (ADR 0003). Report issues in those trees upstream; do not add an OSV ignore unless a Scorecard finding is only in vendor/ and cannot be fixed without bumping a pin.
cargo vet --locked checks the workspace graph against imported audits from Mozilla, Google, and the Bytecode Alliance (supply-chain/). Crates those imports do not cover are exemptions. cargo-machete fails CI on an unused dependency in crates/, tools/, judge/, site/, and fuzz/ (cargo-udeps needs nightly). cargo-hack check --locked --each-feature runs only for workspace crates that declare features; today none do, so that job does not rebuild the workspace.
site/ used resvg 0.45, which pulled in unmaintained rustybuzz (RUSTSEC-2026-0206) and ttf-parser (RUSTSEC-2026-0192). resvg 0.48 shapes text with harfrust and skrifa instead. Workspace cargo audit did not see those crates because site/ is excluded from the workspace.
CI
Compiling jobs use sccache (0035). Same-repository runs write the R2 bucket named by SCCACHE_BUCKET. Fork pull requests have no repository secrets, so sccache uses its local disk and the job still passes. Swatinem/rust-cache caches the registry and git database, not target/. The image build compiles inside Docker and does not use sccache.
CI runs workspace tests with cargo nextest (cargo-nextest from taiki-e/install-action). Profile ci in .config/nextest.toml retries a failed test twice, prints every attempt, and fails the job if the test never passes or exceeds three 60s slow-timeout periods. Doctests stay on cargo test --doc. Codecov runs cargo +nightly llvm-cov --no-report --workspace --locked nextest --profile ci, then cargo +nightly llvm-cov --no-report --workspace --locked --doc, then cargo +nightly llvm-cov report --doctests --lcov --output-path lcov.info. Doctest coverage needs nightly. Local just test remains cargo test.
What a human does
Humans wrote the manifesto, GOAL.md and the initial setup. Every later human action is logged in HUMAN_LOG.md. The count is part of the result.
Wrong or unfinished? Open an issue or edit docs/contributing.md on GitHub.