Overview

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 2013 over 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.
Disposable Development Data OnlyKryptonDB is NOT a replacement for production MongoDB or Atlas. It implements a subset of MongoDB commands, stores data in memory by default, and provides no authentication or TLS.

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.

Linux / macOS
curl -fsSL https://raw.githubusercontent.com/nhrbuilds/kryptondb/main/install.sh | bash
kryptondb --version
Windows PowerShell
irm https://raw.githubusercontent.com/nhrbuilds/kryptondb/main/install.ps1 | iex
kryptondb --version
Build from source (Cargo)
cargo install --locked --git https://github.com/nhrbuilds/kryptondb kryptondb-cli
Command Not Found After Install?Open a new shell session or add the installer bin directory printed during installation to your PATH.

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.

Terminal 1 - Start Server
kryptondb run --port 27017 --no-socket
Terminal 2 - Template, Branch & Drop
# 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-1

Loading 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.

Seed Directory Layout
# fixtures/
# └── app/
#     ├── items.json
#     └── users.bson

kryptondb run --port 27017 --no-socket --seed ./fixtures
Documents Only in Seed Files--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.

Branch Lifecycle Helpers
# 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-01

Parallel 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.

ci-branch-wrapper.sh
#!/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 test

Windows PowerShell#

The same CLI commands and connection-string output work natively on Windows PowerShell using standard MongoDB driver URIs.

PowerShell Example
$branchUri = kryptondb branch app test-1 --ttl 30m
mongosh $branchUri --eval 'db.items.findOne()'
kryptondb drop test-1

kryptondb run Flags#

Configure TCP/UDS transports, fixture seeding, connection limits, cursor retention, and memory caps when starting the server.

FlagDefaultDescription
--port <PORT>27017TCP port for MongoDB wire protocol connections.
--no-socketfalseDisable Unix socket / Windows named pipe (useful when running multiple instances).
--socket <PATH>autoCustom Unix socket or Windows named pipe (\\.\pipe\kryptondb).
--bind <IP>127.0.0.1Bind address. Use 0.0.0.0 only on trusted networks (no auth/TLS).
--seed <DIR>noneLoad .json / .bson fixtures into <db>/<collection> on startup.
--max-connections <N>256Process-wide connection limit shared across TCP and local socket.
--io-timeout-secs <S>30Per-operation wire frame read/write timeout in seconds.
--idle-timeout-secs <S>0Idle pooled connection close timeout (0 keeps pooled connections open).
--cursor-ttl-secs <S>600Idle server cursor expiration in seconds.
--max-cursors <N>1000Maximum live cursors retained per connection.
--stage-memory-mb <MB>100Per-operation aggregation stage memory limit in MB (no disk spill).
--mem-limit-db <BYTES>0Per-database estimated byte ceiling (0 = unlimited).
--mem-limit-runtime <BYTES>0Runtime-wide estimated byte ceiling (0 = unlimited).
--rss-limit-mb <MB>0Linux hard process RSS cap in MB at 75% watermark (0 = disabled).
--data-dir <DIR>noneExperimental 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.

CommandPurpose
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 benchRun 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.

CrateResponsibility
kryptondb-cliCLI argument parsing, --seed loader, signal handling, and branch subcommands.
kryptondb-protocolMongoDB OP_MSG / OP_QUERY framing, BSON decoding/encoding, and compression.
kryptondb-serverShared TCP/UDS listeners, command router, sessions, cursors, aggregation, views, and TTL janitor.
kryptondb-coreIn-memory engine (im::OrdMap + HashMap), B-tree/flat secondary indexes, transactions, and CoW forks.
kryptondb-storageOptional 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, cursor getMore / killCursors.
  • Single-field secondary indexes (createIndexes, listIndexes, TTL expireAfterSeconds), $text tokenization, capped collections, and GridFS (fs.files / fs.chunks).
  • Aggregation pipelines ($group, $unwind, $addFields, $replaceRoot, $setWindowFields, $rankFusion, $scoreFusion) and $changeStream watchers.
  • Multi-document transactions with snapshot reads (readConcern: {level: "snapshot"}), WriteConflict detection, and BID128 Decimal128 arithmetic.

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 kryptondb clears all databases and branches.
  • The optional --data-dir WAL mode is experimental: database drops and branch TTL deadlines are not restart-safe.
  • No authentication or TLS is provided; keep --bind 127.0.0.1 or restrict access on trusted build hosts.
  • Release 1.0.0 passed 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 run is active and check that the port in --uri matches --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 --ttl expired during a long pause. Increase --ttl (e.g. --ttl 2h) or touch the branch periodically.
  • Unsupported command (CommandNotFound) - Test your app command set against kryptondb early 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.