Plugin Compositions

Routier’s plugin system is fully composable. Plugins implement IDbPlugin and can wrap or be wrapped by other plugins. This page maps common combinations to their use cases and guides.

Quick Navigation

How Composition Works

Every plugin implements IDbPlugin (query, bulkPersist, destroy). Composition means passing one plugin as the “store” to another:

YourApp → PluginA(PluginB(PluginC))

Plugins are interchangeable at each layer. Choose the combination that fits your architecture.

HttpSwrDbPlugin Combinations

HttpSwrDbPlugin does stale-while-revalidate over HTTP: cache-first reads, background revalidate when stale, POST writes to your API. It accepts any IDbPlugin as its store.

These combinations give users a local-first experience: the app works offline using the local cache and syncs when back online. See Local-First Apps for the full picture.

Store Use Case Guide
DexiePlugin IndexedDB-backed cache, simple setup Syncing
MemoryPlugin In-memory cache, no persistence Syncing
PouchDB PouchDB as local cache Syncing
LocalStoragePlugin localStorage-backed cache Syncing
OptimisticUpdatesDbPlugin(Dexie) IndexedDB + in-memory reads, maximum speed HttpSwrDbPlugin with Optimistic Replication
OptimisticUpdatesDbPlugin(any) Any backend + in-memory reads HttpSwrDbPlugin with Optimistic Replication

OptimisticUpdatesDbPlugin Combinations

OptimisticUpdatesDbPlugin uses an in-memory store for reads and a source plugin for writes. Reads are instant; writes persist to the source and replicate back to memory.

Source Use Case Guide
DexiePlugin IndexedDB persistence, fast reads Optimistic Replication
MemoryPlugin Pure in-memory (rare) Optimistic Replication
PouchDB PouchDB as write backend Optimistic Replication
Any IDbPlugin Custom or third-party backend Optimistic Replication

OptimisticUpdatesDbPlugin can be used with or without HttpSwrDbPlugin. Use it alone when you have a local-only or custom sync flow.

Storage-Only Combinations

Use a single storage plugin when you don’t need HTTP sync or an extra memory layer:

Plugin Use Case Link
DexiePlugin IndexedDB in the browser Dexie Plugin
MemoryPlugin In-memory, tests, prototypes Memory Plugin
PouchDB PouchDB with CouchDB sync PouchDB Plugin
LocalStoragePlugin localStorage Local Storage Plugin
FileSystemPlugin File-based (Node.js) File System Plugin
SQLitePlugin SQLite SQLite Plugin

Quick Reference

I want… Composition Guide
HTTP sync with IndexedDB cache HttpSwrDbPlugin(DexiePlugin) Syncing
HTTP sync with in-memory cache HttpSwrDbPlugin(MemoryPlugin) Syncing
HTTP sync + fastest possible reads HttpSwrDbPlugin(OptimisticUpdatesDbPlugin(DexiePlugin)) HttpSwrDbPlugin with Optimistic
Local-only, instant reads from memory OptimisticUpdatesDbPlugin(DexiePlugin) Optimistic Replication
Local-only, IndexedDB DexiePlugin Dexie Plugin
Local-only, in-memory MemoryPlugin Memory Plugin

This site uses Just the Docs, a documentation theme for Jekyll.