Documentation · v1.0.0
KryptonDB Reference
Installation, copy-on-write branching, CI isolation wrappers, kryptondb run flags, workspace crates, and scope boundaries.
Introduction#
KryptonDB is a local MongoDB-wire-compatible document database written in Rust for temporary development data, parallel test suites, CI jobs, and coding agents.
Start one local server process, load a starting template database (either via --seed or your MongoDB driver), create isolated O(1) copy-on-write branches whenever a job or agent starts, and let idle time limits or explicit drop clean them up.
- Single-process local server speaking MongoDB
OP_MSG 2013over TCP and local Unix socket / named pipe. - O(1) copy-on-write branching (
forkDatabase) sharing unchanged documents and secondary indexes across branches. - No Rust toolchain or Docker daemon required for end users - prebuilt binaries include SHA-256 checksum verification.
Installation#
Install the latest prebuilt release binary using the platform installer scripts (which download the release archive and verify its .sha256 sidecar), or compile from source with Cargo.
curl -fsSL https://raw.githubusercontent.com/nhrbuilds/kryptondb/main/install.sh | bash
kryptondb --versionirm https://raw.githubusercontent.com/nhrbuilds/kryptondb/main/install.ps1 | iex
kryptondb --versioncargo install --locked --git https://github.com/nhrbuilds/kryptondb kryptondb-cliPATH.Quickstart#
Start KryptonDB in one terminal, populate a starter app template database with mongosh, create an isolated branch, verify isolation, and drop it when finished.
kryptondb run --port 27017 --no-socket# Seed the template database
mongosh "mongodb://127.0.0.1:27017/app" --eval \
'db.items.insertOne({_id: "welcome", message: "Hello from the template"})'
# Create an isolated branch with a 30-minute idle TTL
BRANCH_URI="$(kryptondb branch app test-1 --ttl 30m)"
# Connect with mongosh or any MongoDB driver
mongosh "$BRANCH_URI" --eval 'db.items.findOne()'
# Remove branch when done
kryptondb drop test-1Loading Seed Data#
Pass --seed <directory> when launching kryptondb run to pre-load .json (Extended JSON, one document per line or pretty-printed) or .bson collection fixtures under directories named after their target database.
# fixtures/
# └── app/
# ├── items.json
# └── users.bson
kryptondb run --port 27017 --no-socket --seed ./fixtures--seed imports documents into collections; it does not import dump metadata, indexes, schema validators, or collection options. Create required indexes on the template database before creating branches.Branches & Idle TTL#
Each branch created via kryptondb branch <template> <name> shares unchanged state with the template database and tracks its own writes and TTL independently.
The branch TTL (--ttl, default 2h) acts as a sliding idle timer: database activity resets the countdown, while inactive branches are reaped automatically by the background janitor.
# Supported TTL units: s, m, h, d (e.g. 90s, 30m, 2h, 1d)
URI="$(kryptondb branch app agent-01 --ttl 30m)"
# List active databases with TTL and estimated size
kryptondb ls
# Emit structured JSON for CI or agent orchestrators
kryptondb ls --json
# Print connection URI for an existing database
kryptondb url agent-01Parallel Tests & CI Fan-out#
Because writes inside one branch never leak into siblings or the template, parallel Jest/Vitest/Playwright workers and autonomous coding agents can share one running kryptondb process.
Use unique branch names per worker and pair an explicit trap cleanup EXIT handler with --ttl as a safety net for aborted jobs.
#!/usr/bin/env bash
set -euo pipefail
branch="ci-${CI_JOB_ID:-local}"
uri="$(kryptondb branch app "$branch" --ttl 1h)"
cleanup() {
kryptondb drop "$branch" >/dev/null 2>&1 || true
}
trap cleanup EXIT
MONGODB_URI="$uri" npm testWindows PowerShell#
The same CLI commands and connection-string output work natively on Windows PowerShell using standard MongoDB driver URIs.
$branchUri = kryptondb branch app test-1 --ttl 30m
mongosh $branchUri --eval 'db.items.findOne()'
kryptondb drop test-1kryptondb run Flags#
Configure TCP/UDS transports, fixture seeding, connection limits, cursor retention, and memory caps when starting the server.
| Flag | Default | Description |
|---|---|---|
--port <PORT> | 27017 | TCP port for MongoDB wire protocol connections. |
--no-socket | false | Disable Unix socket / Windows named pipe (useful when running multiple instances). |
--socket <PATH> | auto | Custom Unix socket or Windows named pipe (\\.\pipe\kryptondb). |
--bind <IP> | 127.0.0.1 | Bind address. Use 0.0.0.0 only on trusted networks (no auth/TLS). |
--seed <DIR> | none | Load .json / .bson fixtures into <db>/<collection> on startup. |
--max-connections <N> | 256 | Process-wide connection limit shared across TCP and local socket. |
--io-timeout-secs <S> | 30 | Per-operation wire frame read/write timeout in seconds. |
--idle-timeout-secs <S> | 0 | Idle pooled connection close timeout (0 keeps pooled connections open). |
--cursor-ttl-secs <S> | 600 | Idle server cursor expiration in seconds. |
--max-cursors <N> | 1000 | Maximum live cursors retained per connection. |
--stage-memory-mb <MB> | 100 | Per-operation aggregation stage memory limit in MB (no disk spill). |
--mem-limit-db <BYTES> | 0 | Per-database estimated byte ceiling (0 = unlimited). |
--mem-limit-runtime <BYTES> | 0 | Runtime-wide estimated byte ceiling (0 = unlimited). |
--rss-limit-mb <MB> | 0 | Linux hard process RSS cap in MB at 75% watermark (0 = disabled). |
--data-dir <DIR> | none | Experimental WAL directory (drop & TTL lifecycle are not restart-safe). |
CLI Subcommands#
All management commands default to --uri mongodb://127.0.0.1:27017 and accept custom --uri endpoints.
| Command | Purpose |
|---|---|
kryptondb run [OPTIONS] | Start the MongoDB-compatible database server. |
kryptondb branch <TEMPLATE> <NAME> [--ttl 2h] [--json] | Create an isolated branch from <TEMPLATE> and print its connection URI. |
kryptondb fork <SOURCE> <TARGET> [--ttl TTL] | Fork an existing database directly via forkDatabase. |
kryptondb ls [--json] | List active databases along with their remaining TTL and size. |
kryptondb url <DB_NAME> | Print the mongodb:// connection string for <DB_NAME>. |
kryptondb drop <DB_NAME> | Drop a branch or database immediately. |
kryptondb bench | Run the built-in in-memory engine micro-benchmark. |
Workspace Crates#
KryptonDB is structured as a modular Cargo workspace isolating wire framing, connection lifecycle, and copy-on-write document state.
| Crate | Responsibility |
|---|---|
kryptondb-cli | CLI argument parsing, --seed loader, signal handling, and branch subcommands. |
kryptondb-protocol | MongoDB OP_MSG / OP_QUERY framing, BSON decoding/encoding, and compression. |
kryptondb-server | Shared TCP/UDS listeners, command router, sessions, cursors, aggregation, views, and TTL janitor. |
kryptondb-core | In-memory engine (im::OrdMap + HashMap), B-tree/flat secondary indexes, transactions, and CoW forks. |
kryptondb-storage | Optional experimental WAL & checkpoint recovery crate (outside disposable contract). |
Supported Feature Surface#
While intentionally scoped to disposable workflows rather than full Atlas parity, KryptonDB supports a broad set of core MongoDB driver operations.
- CRUD (
insert,find,update,delete,count,distinct,findAndModify,bulkWrite) with projection, sorting, cursorgetMore/killCursors. - Single-field secondary indexes (
createIndexes,listIndexes, TTLexpireAfterSeconds),$texttokenization, capped collections, and GridFS (fs.files/fs.chunks). - Aggregation pipelines (
$group,$unwind,$addFields,$replaceRoot,$setWindowFields,$rankFusion,$scoreFusion) and$changeStreamwatchers. - Multi-document transactions with snapshot reads (
readConcern: {level: "snapshot"}),WriteConflictdetection, and BID128Decimal128arithmetic.
Scope & Known Limits#
Review these operational boundaries before adopting KryptonDB in your test or agent pipeline.
- Default mode is purely in-memory: stopping or restarting
kryptondbclears all databases and branches. - The optional
--data-dirWAL mode is experimental: database drops and branch TTL deadlines are not restart-safe. - No authentication or TLS is provided; keep
--bind 127.0.0.1or restrict access on trusted build hosts. - Release
1.0.0passed 830 workspace tests on Linux x64 (with CI runner/macOS/Windows verification ongoing - check releases before upgrading).
Troubleshooting#
Common setup and branch issues when integrating KryptonDB into local tests or CI:
- Client cannot connect - Ensure
kryptondb runis active and check that the port in--urimatches--port. - Template database missing - Verify you started with
--seed ./fixtures(matching directory names) or inserted at least one document into the template DB first. - Branch disappeared mid-run - Its sliding idle
--ttlexpired during a long pause. Increase--ttl(e.g.--ttl 2h) or touch the branch periodically. - Unsupported command (
CommandNotFound) - Test your app command set againstkryptondbearly and report reproducible examples in GitHub Issues.
License & Trademark#
KryptonDB is open source software licensed under AGPL-3.0-only.
MongoDB is a registered trademark of MongoDB Inc. KryptonDB is an independent project and is not affiliated with, endorsed by, or sponsored by MongoDB Inc.