$ show fireproof-storage/fireproof
Fireproof is a local-first, real-time document database with CRDT-based conflict resolution, end-to-end encryption, and multi-platform support (browser, Node.js, Deno, Cloudflare Workers). The monorepo contains the core database engine (`@fireproof/core`), a cloud sync backend (Hono + Durable Objects), a dashboard web application for tenant/ledger management, a CLI tool for build and DevOps tasks, and a React hooks library (`use-fireproof`). The architecture is modular with clear separation between storage gateways (IndexedDB, filesystem, memory, cloud), key management (KeyBag with fingerprinting), device identity (X.509-like PKI), and protocol layers (WebSocket/HTTP message dispatch). The codebase exhibits strong engineering practices including extensive TypeScript usage, comprehensive testing (though some tests are skipped or known to fail), and reusable patterns like the Gateway interceptor, Result type, and Evento command pipeline. However, complexity is high due to multiple runtime targets and active refactoring between versions, and there are known critical bugs (e.g., remote sync not triggering subscriptions in React hooks).
The LLM identified 5 files worth highlighting for reuse:
The `KeyBag` class provides a generic, fingerprint-based cryptographic key storage abstraction. It supports multiple provider implementations (memory, file, IndexedDB) and enables key lookup by fingerprint, key import/export, and key migration between versions. This module is isolated with minimal internal dependencies and could be extracted as a standalone key management library for any application requiring secure key storage with flexible backends.
Implements a local Certificate Authority (CA) for device identity management. It generates CA key pairs, signs Certificate Signing Requests (CSRs), and produces X.509-like JWTs for device certificates. The module is self-contained, uses standard cryptographic primitives (JWK, JWT), and demonstrates a clean PKI pattern that can be reused in any system needing decentralized device authentication.
Defines a generic interceptor gateway that wraps a SerdeGateway and allows chaining of interceptors (e.g., logging, encryption, compression). This is a clean implementation of the middleware/interceptor pattern applied to storage gateways, enabling composable transformations on data flow. It is reusable across any project using a similar gateway abstraction for storage or networking.
An async commit queue that manages pending operations with promises, supporting pause, resume, and cancellation. It provides a `CommitQueue` interface with `add`, `flush`, `pause`, `resume`, and `clear` methods. This is a reusable concurrency primitive suitable for any application needing bounded or cancellable async task processing with flow control.
A simple in-memory implementation of the Gateway interface used for testing and ephemeral storage scenarios. It stores key-value pairs in a Map and supports basic `get`, `put`, `delete`, and `subscribe` operations. This is a clean, self-contained mock that can be reused as a test double or lightweight storage backend in any project using a similar gateway abstraction.