GitDB treats a GitHub repository as database storage. Application code talks to GitDB tables and SQL; GitDB persists committed state into repository files and advances Git history with non-force ref updates.
The design is intentionally small: no DB server, no ORM compatibility layer, no wire protocol service. The repository is the durable store.
-
App API
GitDb.openopenGitDbdefineTableinsert,insertMany,upsertMany,select,first,deleteWhere- raw SQL through
executeandquery
-
Client runtime
- Local SQL execution after open/replay
- Serialized mutation queue
- Isolated transaction copies
- Rebuildable equality indexes
-
Store contract
- Manifest read/write
- Mutation append/replay
- Additive batch commit boundary
- Optional local snapshots, locks, compaction, and tree commits
-
GitHub database repository
- Plaintext manifest/log files for reviewable repositories
- Encrypted manifest/log files for opaque repositories
- Git commits as durable history
The manifest is the committed boundary. A mutation becomes database state only when the manifest references its segment. Unreferenced files may exist after a crash or failed commit, but they are not replayed.
For GitHub stores, a batch write creates a tree containing the new log segments
and manifest, creates a commit, and updates the branch ref with force: false.
If the branch moved, GitDB retries from the latest ref.
read ref -> read base commit -> create tree -> create commit -> update ref
The browser entrypoint avoids Node-only imports. It uses:
fetchfor GitHub REST calls- GitHub contents API for reads
- GitHub Git Database API for tree commits
- Web Crypto AES-GCM for encrypted mode
This lets extension service workers, static apps, and other serverless clients use GitHub as the backing database. The client still needs a user-scoped GitHub token or OAuth flow with repository contents access.
On open:
- Read the manifest from the configured store.
- Read a visible snapshot only if the store supports it.
- Use the snapshot only when its checkpoint sequence equals the manifest sequence.
- Otherwise replay manifest-listed mutation segments in order.
- Rebuild equality indexes from recovered rows.
This is why stale page files, stale indexes.json, and orphan mutation files do
not corrupt query results.
| Area | What GitDB guarantees | What it does not claim |
|---|---|---|
| GitHub storage | Manifest and log files are committed into a repository through Git history. | Low-latency server database behavior |
| Transactions | Successful mutations advance one manifest sequence boundary. Failed mutations restore previous committed state. | Cross-device distributed transactions |
| Concurrency | One opened runtime serializes its own writes; GitHub ref conflicts trigger retry. | Mature multi-writer OLTP coordination |
| Durability | Manifest-listed mutation logs replay on open. Matching snapshots can replace replay. | Trusting uncheckpointed snapshot files |
| Indexes | Equality indexes rebuild from committed rows and accelerate safe equality lookups. | Full SQL optimizer or range indexes |
| Compaction | Local plaintext compaction writes checkpoint first, manifest second, deletes old logs last. | Browser or encrypted compaction |
gitdb/v1/
manifest.json
log/
00000000000000000001.json
Node plaintext stores may also write visible review snapshots:
gitdb/v1/
snapshot.json
todos/
schema.json
pages.json
pages/
000000.json
indexes.json
indexes.json is derived data. It is useful for inspection and future tooling,
but the runtime does not trust it over committed rows.
gitdb/v1/
manifest.enc
log/
00000000000000000001.enc
Node encrypted stores use the Node crypto implementation. Browser encrypted stores use Web Crypto while preserving the same packed AES-GCM payload shape.
GitDbEngine.compact() currently targets local plaintext stores:
- Write a visible page snapshot at the current manifest sequence.
- Advance the manifest to an empty
logSegmentslist. - Delete obsolete mutation segment files.
Crash behavior:
- Before checkpoint: old manifest and old logs remain usable.
- After checkpoint before manifest: old manifest can still reopen safely.
- After manifest before deletion: new manifest reopens from the checkpoint while old logs are harmless.
GitDB is a good fit when slow GitHub writes are acceptable and a repository is the desired durable record. It is not a replacement for Postgres, SQLite, or a hosted transactional database when latency, throughput, large query planning, or multi-writer coordination matters.