Overview
š Try Routier in CodeSandbox
Explore Routier with a live, interactive example. See schemas, live queries, and React integration in action.
Routier is a fast, front-endāfirst data toolkit that augments any datastore with schemas, collections, live queries, optimistic mutations, replication, caching, and moreāwithout locking you into a specific ORM or backend. Itās designed to be extremely thin and fast, staying close to ābareāmetalā JavaScript by avoiding promises/async-await in core hot paths.
Why Routier
Modern apps inevitably build a data abstraction layer: defaults, business rules, computed fields, and adapters for whatever ORM or datastore you start with. That worksāuntil you need to change. You hit performance ceilings, need local-first, or want to adopt a different storage primitive (e.g., SQLite/PGāLite, IndexedDB, OPFS). Rewriting your data layer every time is costly and risky.
Routier solves this by providing a feature-rich, fast, datastoreāagnostic layer you control. Keep your domain model and data API intact; swap the storage plugin beneath it. Get the same developer experience and app behavior, regardless of which frontend datastore youāre running today, or migrate to tomorrow.
Quick Example
Hereās how Routier works in practice:
š” Try it live: Open the CodeSandbox demo to see this code running interactively.
import { DataStore } from "@routier/datastore";
import { s } from "@routier/core/schema";
import { MemoryPlugin } from "@routier/memory-plugin";
const userSchema = s
.define("users", {
id: s.string().key().identity(),
email: s.string().distinct(),
name: s.string(),
createdAt: s.date().default(() => new Date()),
})
.compile();
class Ctx extends DataStore {
users = this.collection(userSchema).create();
constructor() {
super(new MemoryPlugin("app"));
}
}
const ctx = new Ctx();
await ctx.users.addAsync({ name: "Ada", email: "[email protected]" });
await ctx.saveChangesAsync();Target Platform
While Routier works on both frontend and backend, itās primarily designed for client-side applications and modern browser storage technologies:
- IndexedDB
- Local Storage
- SQLite
- Origin Private File System (OPFS)
Philosophy
Routier follows a simple, clear philosophy that guides every design decision.
Toolkit, not an ORM: Routier augments any datastore without forcing a particular approach. Bring your own validation (Zod, AJV) and keep full control of your data layer.
Front-end first: Optimized for client runtimes and local-first patterns, with performance tuned for the browser. Also works beautifully on the backend.
Thin and fast by design: Core hot paths avoid promises/async-await, using minimal abstractions and callbacks for maximum performance.
Portable by plugins: Storage-specific behavior lives in plugins. Swap between IndexedDB, SQLite, Local Storage, or any backend without changing your app code.
Learn about our philosophy ā
Core Features
Routier provides a comprehensive toolkit for managing data in modern applications.
š Schemas
Define your data structure with power and flexibility:
- Defaults: Automatic values for new records (timestamps, statuses)
- Identity: Auto-generated or database-managed primary keys
- Indexes: Fast lookups with single or composite indexes
- Computed Properties: Derived fields that update automatically
- Serialization: Transform data when saving or loading (e.g., dates)
- Property Mapping: Clean up awkward database field names
- Methods: Attach functions to entities (stripped before persistence)
Type checking is handled by libraries like Zod or AJVāRoutier focuses on structure and transformation.
š Live Queries
Reactive data that updates automatically:
- Subscriptions that push updates when data changes
- Zero-config reactivity for real-time UIs
- Built-in change detection and propagation
ā” Performance
Optimized for speed:
- Optimistic Replication: Reads from memory, writes persist asynchronously
- Smart Caching: Predictable invalidation for fast reads
- Database Views: Create views even without native support
š Plugin Architecture
Storage that adapts to your needs:
- Any Backend: Works with IndexedDB, SQLite, Local Storage, OPFS, and more
- Easy Migration: Swap storage without changing your code
- Extensible: Build custom plugins for specialized needs
Performance Philosophy
Routier is built for maximum performance. We intentionally avoided promises and async/await in core hot paths to reduce microtask scheduling overhead. The result is a thin, fast layer that provides powerful data behavior without getting in your way.
Performance isnāt just about speedāitās about predictable, consistent behavior that scales with your application. See how it works ā
How Routier Fits Your Stack
Routier enhances your existing setup rather than replacing it, giving you the benefits you need without the constraints you donāt.
Enhance, donāt replace: Keep your existing datastore. Add structure (schemas, defaults, serialization), speed (indexes, caching), and better ergonomics (live queries, optimistic updates).
Swap without rewrites: Move from IndexedDB to SQLite or adopt OPFS by changing the plugin. Your domain model and app code remain unchanged.
Type checking by choice: Use Zod or AJV for validation. Routier handles transformation and persistence concerns separately.
Client-first, backend-capable: Designed for the browser and local-first workflows, adaptable to backend runtimes as needed.
Getting Started with Routier
Hereās the typical workflow when building with Routier:
1. Define schemas and collections: Describe your data structure with fields, defaults, indexes, and computed properties. Creating schemas ā
2. Choose a storage plugin: Pick IndexedDB, Local Storage, SQLite, OPFS, or build your own. Built-in plugins ā
3. Read with live queries: Subscribe to data changes for reactive UIs that update automatically. Live queries guide ā
4. Write with confidence: Use optimistic replication for fast writes. Changes tracked automatically until you save. State management ā
5. Evolve and scale: Sync data, add more collections, swap storage backendsāall without changing your domain code.
How It Works
Routier provides a simple, consistent API that works across all storage backends.
Define schemas: Type-safe entity definitions with indexes, computed properties, and modifiers. Schema guide ā
Create collections: Typed entity sets backed by your chosen plugin. Collections overview ā
Query your data: Filter, sort, aggregate, and paginate with a fluent query API. Query guide ā
Watch for changes: Subscribe to live queries that update when data changes. Live queries ā
Next Steps
Ready to get started? Choose your path:
Installation - Install packages and dependencies
Quick Start - Build your first app in minutes
React Integration - Use Routier with React
View All Guides - Explore comprehensive guides