gitnote has no backend of its own. The user's git repo is the only place notes are kept, the device holds a clone, and a stateless Cloudflare Worker fills the two gaps a browser cannot: GitHub and GitLab do not answer git requests with CORS headers, and GitHub's code exchange needs a client secret.
Browser or Android WebView
|-- static files ------------------> Static Assets (no Worker code runs)
|-- REST: profile, repos, branches -> api.github.com, gitlab.com/api/v4 (direct, CORS)
|-- GitLab sign-in (PKCE) ---------> gitlab.com (direct, CORS)
|-- GitHub code and refresh -------> Worker /api/oauth/* --> github.com
`-- git fetch and push ------------> Worker /api/git/* --> github.com, gitlab.com
- Clone and pull: isomorphic-git runs on the device and fetches through the relay into LightningFS. The clone is shallow; later fetches pass no depth.
- Edit: text goes to a draft in IndexedDB on every change, to the working tree on save, and into git only on a commit.
- Push: the engine checks size limits first, then sends the pack through the relay. Offline, the push waits in a queue on the device.
- Android runs the same app in a WebView at
https://localhostand calls the relay by its full address. See android.md.
Only /api/* runs the Worker; every other path is a static asset, with unknown paths
falling back to index.html. Preview hostnames are off, so the workers.dev hostname
is the only origin.
| Route | Does |
|---|---|
GET /api/health |
Liveness probe |
GET /api/git/<host>/<repo path>.git/info/refs?service=git-upload-pack (or git-receive-pack) |
Git smart-HTTP ref discovery |
POST /api/git/<host>/<repo path>.git/git-upload-pack and .../git-receive-pack |
Fetch and push; needs Content-Length; body uncompressed or Content-Encoding: gzip (415 otherwise) |
POST /api/oauth/github/token |
GitHub App code exchange: JSON { code, code_verifier?, redirect_uri? }, with Content-Length |
POST /api/oauth/github/refresh |
GitHub App token refresh: JSON { refresh_token }, same limits |
- Git hosts come from the
GIT_HOSTSvar:github.com,gitlab.comover https. Loopback entries such aslocalhost:8174use http, for local test servers only. Other hosts, paths, methods and content types answer 403. github.com repos must be exactly<owner>/<repo>.git, and no path segment may be-(GitLab's web-route separator), so the relay never fetches a web page. - Responses. A 2xx passes through only with the git content type for that endpoint
(otherwise a JSON 502
unexpected_upstream_response), and an error status keeps its body only when it istext/plain(otherwise a JSONupstream_errorwith the same status). Every/api/*answer carriesX-Content-Type-Options: nosniffandContent-Security-Policy: default-src 'none'; sandbox; frame-ancestors 'none'. - Headers. Only
Authorization,Content-Type,Accept,Git-ProtocolandUser-Agentgo upstream, and aUser-Agentthat does not start withgit/becomesgit/gitnote-relay. Redirects are never followed: an upstream 3xx (a renamed repo) comes back as a JSON 502repo_moved. - Origins.
/api/*answers the Worker's own origin and the origins inCORS_ORIGINS(https://localhost, the Capacitor WebView, which also gets CORS headers). Requests withoutOriginpass unlessSec-Fetch-Sitesays another site sent them. This stops browsers only; non-browser clients are bounded by the host allowlist and the rate limits. - Errors are JSON:
{ "error": "<code>", "message": "..." }. - Security headers for the app live in
app/static/_headers, because asset responses skip the Worker. The Content Security Policy is generated by SvelteKit (cspinapp/vite.config.js) as a<meta>tag in the builtindex.html, so it also applies inside Capacitor. The Android build allows inline scripts for Capacitor's bridge, so it must never be deployed.
| What | Where | Lifetime |
|---|---|---|
| Clones, one per repo | IndexedDB through LightningFS, named gitnote:<host>/<path> |
Until deleted in the app; the emptied database and its name stay until site data is cleared |
| Drafts | IndexedDB gitnote-drafts |
Until saved or discarded |
| Web tokens | IndexedDB gitnote-auth, encrypted with a non-exportable AES-GCM key |
Until sign-out |
| Android tokens | Android Keystore-backed secure storage | Until sign-out |
| Local copies list, queued pushes, commit author name and email, autosave choice, in-progress sign-in | localStorage | Until replaced or finished |
| Merge in progress | gitnote-merge.json in the clone's git directory |
Until the merge ends |
| Anything about users, on the server | Nothing: no KV, D1, R2 or Durable Objects; logs, traces, Tail Workers and Logpush off | Not applicable |
The Worker's only state is the rate limiter's counters, keyed by client IP.
| Limit | Value | Enforced by |
|---|---|---|
| File: warning | over 50 MB | Engine, before any network call |
| File: block on GitHub | over 100 MiB (GitHub's limit) | Engine |
| File: block on GitLab.com | over 95 MB (relay cap) | Engine |
| Push: block | over 95 MB, estimated from the blobs the unpushed commits add | Engine |
| Git request body | 95 MB, under the 100 MB Workers limit; 413 above it | Relay |
| OAuth request body | 8 KB | Relay |
| Requests per client IP | 300 a minute on /api/*, 10 on /api/oauth/*, per Cloudflare location and approximate |
Relay |
| Repo size: warning before a clone | over 300 MB | App |
| Note opened as text | up to 5 MB, valid UTF-8 | App |
| Network silence | 60 seconds ends a git request | Engine |
The push estimate leaves out trees and commits, so a push just under the cap can still get a 413 from the relay, which is mapped to the same message. There is no cap on downloads through the relay: Workers does not limit response bodies.
npm run e2e:live runs app/e2e/live/ against the domain in routes in
relay/wrangler.jsonc, or GITNOTE_LIVE_URL, with nothing stood in for.
smoke.live.jsneeds no credentials: asset headers, the CSP, deep-link reloads, the relay's refusals, the Android preflight and a nativegit cloneof this public repo.notes.live.jspastes a token, clones, edits, commits, pushes and pulls, checking each result directly against GitHub's API. It skips unless bothGITNOTE_E2E_REPO(<owner>/<repo>) andGITNOTE_E2E_TOKENare set. Use a private repo kept for this, whose default branch holds aREADME.mdfor the test to edit, and a fine-grained token scoped to that repo alone with Contents read and write. For a repo in an organization, the token's resource owner must be the organization, and its policy must allow fine-grained tokens. Each run moves itsgitnote-e2ebranch back to the default branch's tip; the default branch itself never changes.
In .github/workflows/deploy.yml the live-e2e job runs after each deploy. Its smoke
step always runs, with no token in its environment. Its note round trip is skipped while
the GITNOTE_E2E_REPO repository variable is empty. A pull request can never start the
job. It uploads no artifacts, because a Playwright trace would hold the token.