moltendb-core
๐ The Pure Engine Crate
In-memory document store ยท Append-only WAL ยท Query evaluator ยท Analytics (๐ง WIP)
Zero knowledge of HTTP, auth, JWT, or WASM bindings.
What is this crate?
moltendb-core is the heart of MoltenDB. It contains every piece of logic that is shared between the HTTP server (moltendb-server) and the browser WASM adapter (moltendb-wasm):
- In-memory store โ
DashMap-backed document collections, keyed by(collection, key). - Append-only WAL โ every write is appended to a log file (
LogEntry: INSERT, DELETE, DROP, INDEX, ENC). On startup the log is replayed into memory. - Storage backends โ
DiskStorage(sync/async),TieredStorage(hot + cold log),EncryptedStorage(ChaCha20-Poly1305),OpfsStorage(WASM / browser OPFS). - Query evaluator โ
$eq,$ne,$gt,$gte,$lt,$lte,$in,$nin,$contains,$or,$and, field projection (include / exclude), dot-notation for nested fields, joins, sort, count, offset. - Analytics engine โ COUNT, SUM, AVG, MIN, MAX with optional WHERE filtering. โ ๏ธ Under active development โ not ready for production use.
- Auto-indexing โ
query_heatmaptracks hot fields and builds indexes automatically. - Handler pipeline โ
process_get,process_set,process_update,process_delete,process_analyticsโ the single source of truth consumed by both the server and the WASM adapter. - Input validation โ collection name, key, and field name rules enforced before any operation reaches the engine.
Crate type
[]
= ["rlib"]
moltendb-core compiles to a native rlib. It is not a cdylib โ WASM bindings live in the separate moltendb-wasm crate. This keeps the native dependency tree clean (no wasm-bindgen, no web-sys).
WASM-specific code (OpfsStorage, Db::open_wasm) is gated behind #[cfg(target_arch = "wasm32")] and only compiled when the crate is used as a dependency of moltendb-wasm.
Add to your project
[]
= "0.3.0-beta.2"
Minimal example
use Db;
async
Using the handler pipeline (same API as the HTTP server)
use ;
use json;
let db = open.await?;
let payload = json!;
let = process_get;
println!;
Module overview
| Module | Responsibility |
|---|---|
engine |
Db struct, storage backends, WAL replay, operations |
engine::storage |
DiskStorage, TieredStorage, EncryptedStorage, OpfsStorage |
query |
Query condition evaluation, field projection, joins, sort, pagination |
analytics |
Aggregate functions: COUNT, SUM, AVG, MIN, MAX โ โ ๏ธ under development, not ready for use |
handlers |
process_get, process_set, process_update, process_delete, process_analytics |
validation |
Collection / key / field name validation rules |
Storage modes
| Mode | Use case |
|---|---|
DiskStorage (sync) |
Low-latency writes, small datasets |
DiskStorage (async) |
High-throughput writes, background flush |
TieredStorage |
100k+ documents โ separates hot and cold log files |
EncryptedStorage |
At-rest encryption with ChaCha20-Poly1305 |
OpfsStorage |
Browser WASM โ Origin Private File System |
Design constraints
- RAM is the hard limit. All documents are kept in memory for the lifetime of the process. There is no eviction, TTL, or page cache. A 100 000-document collection of typical JSON objects occupies roughly 100โ200 MB of RAM.
- No HTTP, no auth, no JWT. This crate has zero knowledge of the network layer. It is safe to embed in any Rust application without pulling in Axum, Tokio TLS, or any auth dependency.
- Single writer, many readers. The
DashMapstore is safe for concurrent reads. Writes are serialised through the storage backend.
Part of the MoltenDB workspace
MoltenDB/
โโโ moltendb-core/ โ you are here
โโโ moltendb-wasm/ โ browser adapter (wasm-bindgen glue, WorkerDb, OPFS)
โโโ moltendb-auth/ โ identity layer (JWT, Argon2, UserStore)
โโโ moltendb-server/ โ network layer (Axum, TLS, CORS, CLI config)
See the root README for the full architecture overview and feature list.