$ show litedb-org/LiteDB
LiteDB is an embedded NoSQL document database library for .NET. In production it is not a server but an in-process database engine that persists BSON documents to a single file with ACID transactions, WAL/checkpointing, MVCC snapshot isolation, B-tree and vector indexes, optional AES-256 encryption, and multi-process shared-file coordination. The public API is built around `LiteDatabase`, `LiteCollection<T>`, and `LiteRepository`, with `BsonMapper` for POCO mapping and both LINQ and SQL-like `Execute` query paths. Internally, `LiteEngine` implements page-based storage, crash recovery, compaction/rebuild, system collections, and an aggressive query optimizer that rewrites predicates, selects indexes, and supports vector similarity search. The repository also ships a CLI shell, a repro runner, stress tools, and a substantial fuzzing harness used to prove durability and recovery correctness under injected faults and power loss. The architecture is a layered monolith: a client/API layer (`LiteDatabase`, mapper, SQL parser, LINQ expression translation), a query execution layer with index selection and predicate optimization, and a storage layer with buffered page cache, WAL recovery, transaction registry, and shared-mutex coordination. Write flows go from POCO through `BsonMapper` into `BsonDocument`, into transaction snapshots and the WAL, then onto data/index pages; reads flow from index seeks/scans through BSON expression evaluation into materialized documents. The core library has no third-party runtime dependencies, relying only on the .NET base class library; supplementary tools add BenchmarkDotNet, Spectre.Console, and Gemini embedding APIs. The code is actively maintained, with a very large regression suite keyed to GitHub issues, continuous fuzzing, and compatibility tooling across file format versions.
The LLM identified 4 files worth highlighting for reuse:
Self-contained CRC32C (Castagnoli) implementation with optional hardware acceleration and a slicing-by-eight software fallback. It takes a byte span and seed, has no LiteDB-specific dependencies, and can be lifted directly into any project needing fast, integrity-checked checksums. Demonstrates low-level performance craftsmanship and safe conditional compilation.
Bounded-memory top-N sorter that uses a heap/priority-queue strategy to avoid sorting an entire collection. It is generic over comparable keys, self-contained, and directly reusable for top-K selection, pagination, or LIMIT-style operations in any .NET codebase. Shows non-obvious algorithmic skill in avoiding full sorts and minimizing allocation.
A compact async synchronization primitive equivalent to a manual reset event that can be awaited without blocking a thread. It has no LiteDB-internal dependencies, supports cancellation, and manages TaskCompletionSource lifecycle carefully. Reusable in any async .NET application needing notify/wait coordination between producers and consumers.
A class-based replacement for ArraySegment<byte> with optional owner/epoch tracking that catches stale or unsafe buffer access in debug builds. It is isolated from database logic and demonstrates a disciplined pattern for handing out borrowed memory slices while preventing use-after-return bugs. Useful for any system that manages pooled byte buffers or zero-copy readers.