Skip to content

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.

StoreUse CaseGuide
DexiePluginIndexedDB-backed cache, simple setupSyncing
MemoryPluginIn-memory cache, no persistenceSyncing
PouchDBPouchDB as local cacheSyncing
BrowserStoragePluginlocalStorage-backed cacheSyncing
OptimisticUpdatesDbPlugin(Dexie)IndexedDB + in-memory reads, maximum speedHttpSwrDbPlugin with Optimistic Replication
OptimisticUpdatesDbPlugin(any)Any backend + in-memory readsHttpSwrDbPlugin 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.

SourceUse CaseGuide
DexiePluginIndexedDB persistence, fast readsOptimistic Replication
MemoryPluginPure in-memory (rare)Optimistic Replication
PouchDBPouchDB as write backendOptimistic Replication
Any IDbPluginCustom or third-party backendOptimistic 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:

PluginUse CaseLink
DexiePluginIndexedDB in the browserDexie Plugin
MemoryPluginIn-memory, tests, prototypesMemory Plugin
PouchDBPouchDB with CouchDB syncPouchDB Plugin
BrowserStoragePluginlocalStorage or sessionStorageBrowser Storage Plugin
FileSystemPluginFile-based (Node.js)File System Plugin
SqliteDbPluginSQLite in Node or a browserSQLite Plugin
PostgresDbPluginPostgreSQLServer Databases
MysqlDbPluginMySQLServer Databases
MongoDbPluginMongoDBServer Databases

Quick Reference

I want...CompositionGuide
HTTP sync with IndexedDB cacheHttpSwrDbPlugin(DexiePlugin)Syncing
HTTP sync with in-memory cacheHttpSwrDbPlugin(MemoryPlugin)Syncing
HTTP sync + fastest possible readsHttpSwrDbPlugin(OptimisticUpdatesDbPlugin(DexiePlugin))HttpSwrDbPlugin with Optimistic
Local-only, instant reads from memoryOptimisticUpdatesDbPlugin(DexiePlugin)Optimistic Replication
Local-only, IndexedDBDexiePluginDexie Plugin
Local-only, in-memoryMemoryPluginMemory Plugin

Released under the MIT License.