Local Reactive Store (crow-store)
Platform-free reactive key/document persistence with fine-grained Signal keys, reflection-free codecs, transactions, migrations, and atomic file writes.
crow-store gives your app durable, signal-backed local storage with zero reflection, zero annotation processors, and crash-safe atomic persistence.
Defining Keys & Codecs
Declare typed keys with StoreKeys and reflection-free StoreCodecs for structured documents:
object PrefsKeys {
val ThemeMode = StoreKeys.enum("theme_mode", ThemeMode.entries, ThemeMode.System)
val Accent = StoreKeys.enum("accent", AccentOption.entries, AccentOption.Violet)
val CompactDensity = StoreKeys.boolean("compact_density", false)
val BrewCount = StoreKeys.int("brew_count", 0)
}For rich models, implement StoreCodec<T> using StoreCodecs.packFields / unpackFields (length-prefixed, escaping-safe, and reflection-free):
val BeanCodec = object : StoreCodec<CoffeeBean> {
override fun encode(value: CoffeeBean): String = StoreCodecs.packFields(
listOf(value.id.toString(), value.name, value.roaster, value.remainingGrams.toString()),
)
override fun decode(raw: String): CoffeeBean {
val f = StoreCodecs.unpackFields(raw)
return CoffeeBean(
id = f[0].toInt(),
name = f[1],
roaster = f[2],
remainingGrams = f[3].toInt(),
)
}
}Reading & Writing Reactively
Open a crash-safe file-backed store (writes to a temporary file, calls fsync, and performs an atomic move) or an InMemoryStoreBackend for tests:
val store = openFileStore(
file = File(filesDir, "app.crowstore"),
schemaVersion = 1,
)
// Every key is a fine-grained Signal<T> — reading it inside @Ui subscribes directly
val themeSignal = store.state(PrefsKeys.ThemeMode)
val beans = store.collection("beans", idOf = { it.id.toString() }, codec = BeanCodec)
// Atomic multi-key transaction
store.transaction {
store.set(PrefsKeys.BrewCount, currentCount + 1)
beans.upsert(updatedBean)
}Migrations & Testing
- Versioned migrations: Pass
migrations = listOf(StoreMigration(fromVersion = 1, toVersion = 2) { ... })to evolve keys cleanly across app releases. - Process-scoped lifetime: Pair
ReactiveStorewith@CrowApp(process = AppStore::class)so your store opens once per OS process and survives Activity recreations effortlessly. - Instant JVM tests: Swap
FileStoreBackendforInMemoryStoreBackendto test every persistence flow deterministically with zero disk I/O.
How is this guide?
Server Data (crow-query)
Pure-JVM, typed server-state caching inspired by TanStack Query — built natively on Crow resources, held transitions, and optimistic actions.
Schemas & Reactive Forms (crow-schema)
Zod-style Kotlin validation DSL with typed ParseResults, cross-field rules, signal-backed FormState, and JSON Schema export.