AYOUB.*
← ALL PROJECTSREPOS β†—
← All projects
πŸ”₯Database Engine
DatabaseDatabase Enginev4.1.1Rust + DartBSD-3-Clause

PhoenixDB

ACID embedded database β€” Rust core, Dart/Flutter FFI

Read the full case study

Key Facts & Overview

PhoenixDB is an ACID-compliant embedded database engine written in Rust and exposed to Dart/Flutter through a zero-overhead dart:ffi layer. Use it as a key/value store, as typed preferences, for HNSW vector similarity search, or through a small optional SQL front end. It ships B+Tree storage, MVCC transactions, a write-ahead log, and runtime-dispatched SIMD kernels.

  • β€ΊFeature flags: sql, encryption, json, metrics, full β€” opt into what you need.
  • β€ΊFlutter apps need no Rust toolchain; Android ships prebuilt binaries.
  • β€ΊAsync API runs every call on a worker isolate so the UI never blocks.
  • β€ΊSecurity: FFI guardrails, handle tagging, constant-time compares, panic containment.

Core Architectural Features

B+Tree index β€” 4 KiB slotted pages, configurable fill factors
CRC32 integrity on every page; corruption returns Err, never bad data
mmap zero-copy reads + WAL with fsync at commit
MVCC snapshot isolation (many readers, single writer)
Transactions: Begin / Insert / Delete / Commit / Rollback with recovery
Optional SQL: CREATE / INSERT / SELECT / UPDATE / DELETE
HNSW k-NN vector search (cosine / L2 / dot product)
Pure C ABI via cbindgen; NativeFinalizer cleanup in Dart

Installation

flutter pub add phoenixdb

# Or in pubspec.yaml:
# dependencies:
#   phoenixdb: ^4.1.1

# Use `flutter pub`, not `dart pub`:
# PhoenixDB is an FFI plugin, so pub.dev requires the Flutter SDK bound.

Usage

import 'package:phoenixdb/phoenixdb.dart';

// Synchronous key/value
final db = PhoenixDatabase.open('data.pdb');
db.insert(utf8Key('hello'), utf8Value('world'));
print(utf8Decode(db.getOrThrow(utf8Key('hello')))); // world

db.transaction((txn) {
  db.insert(utf8Key('a'), utf8Value('1'), txnId: txn);
  db.insert(utf8Key('b'), utf8Value('2'), txnId: txn);
});
db.close();

// Asynchronous (recommended for Flutter)
final adb = await AsyncPhoenixDB.open('data.pdb');
await adb.insert(utf8Key('k'), utf8Value('v'));
final value = await adb.get(utf8Key('k'));
await adb.close();

API Reference

PhoenixDatabase.open(path)

Open (or create) a synchronous key/value database.

AsyncPhoenixDB.open(path)

Open an async database backed by a worker isolate.

PhoenixPrefs.open(path)

Typed shared_preferences-style facade over the same store.

PhoenixVectorDB.open(path, dimensions, metric)

Open an HNSW vector index for local-first semantic search.

db.query('SQL...')

Run SQL when built with the sql feature; returns rows / scalar / asMaps.

db.transaction((txn) { ... })

Run a block inside an ACID transaction with a txn id.

Hardware & Telemetry Limits

Page size4096 bytes
Max key (FFI)1 MiB
Max value10 MiB
Max vector dimensions65 536
Max k per search4096

Resources & Repositories