FireLocal is an embedded, offline-first database engine written in Rust that offers a Firestore-style document API for local persistence: documents addressed by collection/doc paths, queries, write batches, transactions, security rules, and optional sync to Firestore.
Status: beta. The core engine is functional and covered by a test suite that includes crash-recovery and restart scenarios, but the project has not yet had production burn-in. Review the limitations before depending on it.
- Document API —
put/get/deleteJSON documents addressed by paths likeusers/alice - Durability — write-ahead log with CRC-framed records; torn writes are detected and discarded on recovery. Choose
Strict(fsync per commit, default) orRelaxed(group commit: deferred fsync with a bounded loss window, never corruption) - LSM-tree storage — memtable with automatic size-triggered flush to SST files; SSTs carry a sparse key index and a bloom filter, so point reads skip files that can't contain the key and scan at most one small block; real compaction merges files and drops tombstones
- Atomic write batches — a batch is one WAL record: after a crash, all of it replays or none of it does
- Transactions — optimistic concurrency control with read-version validation and automatic retry
- Queries — equality queries served by an inverted index; range/
in/array-containsoperators via post-filtered collection scans - Live listeners —
on_snapshot-style callbacks re-run on every write - Security rules — a supported subset of Firestore rules:
matchblocks with path variables and wildcards,allowwithread/write/get/list/create/update/delete, and conditions overrequest.auth/request.auth.uid/ path variables with==,!=,&&,||,!. Unsupported constructs fail at load time instead of silently denying - Single-writer safety — the database directory is protected by an OS file lock; a second process cannot corrupt it
- Optional Firestore sync — push/pull documents with full JSON type fidelity (nested maps, arrays, null); modified documents are tracked and can be pushed manually (
sync_dirty) or by the built-in background sync worker - Multi-platform — Rust core; Node.js (napi), WASM, Python (ctypes), Dart (FFI), and C#/.NET bindings in varying stages of maturity
use firelocal_core::FireLocal;
fn main() -> std::io::Result<()> {
let mut db = FireLocal::new("./mydata")?;
// Write (values must be valid JSON)
db.put("users/alice".to_string(),
br#"{"name":"Alice","age":30}"#.to_vec())?;
// Read
if let Some(data) = db.get("users/alice")? {
println!("User: {}", String::from_utf8_lossy(&data));
}
// Delete
db.delete("users/alice".to_string())?;
Ok(())
}// Atomic batch
let mut batch = db.batch();
batch.set("users/a".to_string(), br#"{"n":1}"#.to_vec());
batch.delete("users/b".to_string());
db.commit_batch(&batch)?;
// OCC transaction with retry
let new_count = db.run_transaction(3, |txn| {
let doc = txn.get("counters/hits")?.unwrap_or(br#"{"n":0}"#.to_vec());
let v: serde_json::Value = serde_json::from_slice(&doc).unwrap();
let n = v["n"].as_i64().unwrap_or(0) + 1;
txn.set("counters/hits".to_string(), format!(r#"{{"n":{n}}}"#).into_bytes());
Ok(n)
})?;db.load_rules(r#"
rules_version = '2';
service cloud.firestore {
match /databases/{database}/documents {
match /users/{userId} {
allow read: if request.auth != null;
allow write: if request.auth.uid == userId;
}
}
}
"#)?;
db.set_auth_uid(Some("alice".to_string()));cargo install --path firelocal-cli
firelocal put users/alice '{"name":"Alice"}' -d ./mydata
firelocal get users/alice -d ./mydata
firelocal shell ./mydata # interactive: put/get/del/flush/compact/stats
firelocal console ./mydata # local web console at http://127.0.0.1:4400firelocal console <path> serves a Firebase-style data browser on
localhost. When the database is idle the console holds the lock and is
fully read-write (edit/create/delete documents, flush, compact). When
your app is running and holds the lock, the console attaches as a live
read-only follower — it tails the WAL, so committed writes appear in the
browser within ~1.5s without touching the running process.
| Platform | Status | Notes |
|---|---|---|
Rust (firelocal-core) |
Beta | Full API; the reference implementation |
CLI (firelocal-cli) |
Beta | put/get/shell/flush/compact/stats + web console |
Node.js (bindings/js) |
Beta | napi-rs; core API incl. batches & compaction |
WASM (firelocal-wasm) |
Experimental | In-memory storage; persist via exportSnapshot() / importSnapshot() |
Python (bindings/python) |
Experimental | ctypes over the C FFI |
Dart (bindings/dart) |
Experimental | dart:ffi; set FIRELOCAL_LIBRARY_PATH |
C#/.NET (bindings/dotnet) |
Experimental | P/Invoke over the C FFI |
None of the packages are published to registries yet; build from source.
Honest notes on where the engine is today:
- Writes fsync per commit by default.
Durability::Strictbounds single-threaded write throughput to your disk's fsync rate.Durability::Relaxeddefers fsync (bounded ~1MB loss window on crash, never corruption) for orders-of-magnitude more throughput; batches amortize the fsync either way. - One writer process at a time. The directory lock makes concurrent multi-process writes fail fast rather than corrupt data. Read-only observers (
reader::DbReader, used byfirelocal console) may attach to a live database without the lock. - Rules support a subset of the Firestore language (documented above).
resource.data, functions, and CEL expressions are rejected atload_rulestime. - Sync is push-based and periodic, via
sync_dirty()or theBackgroundSyncworker; there is no server-push real-time channel, remote deletions are not propagated, and the dirty set is in-memory (not persisted across restarts). - WASM storage is in-memory — persistence is the host app's job via snapshot export/import (e.g. to IndexedDB).
cargo build --workspace
cargo test --workspace
cargo clippy --workspace --all-targets --all-features -- -D warningsThe test suite includes regression tests for crash recovery, restart persistence, tombstone shadowing, atomic batches, index consistency, compaction, transactions, the process lock, and rules enforcement (firelocal-core/tests/regression_tests.rs).
This project is licensed under the MIT License — see the LICENSE file for details.
