rxdb

The local-first database that runs on every JS runtime and replicates with your existing backend - no vendor, no lock-in - https://rxdb.info/

23,335 stars TypeScript Markdown Skills API Spec #angular#browser-database#couchdb#crdt
AI Prompts & Specs

Repository: pubkey/rxdb


Stars: 23147

CLAUDE.md

CLAUDE.md

Build Commands


- Build All: npm run build
- Documentation Build: npm run docs:build

Test Commands


- Run All Tests: npm run test
- Fast Tests (Parallel): npm run test:fast
- Fast Memory Tests: npm run test:fast:memory
- Node Tests: npm run test:node
- Browser Tests: npm run test:browser
- Performance Tests: npm run test:performance
- Lint: npm run lint
- Lint Fix: npm run lint:fix
- Check Types: npm run check-types

Development Scripts


- Unwatch Tests: npm run dev
- Watch Example: npm run dev:example
- Generate Error Messages: npm run generate:error-messages
- Start Docs Server: npm run docs:serve

Code Style & Patterns


- Language: TypeScript
- Database: RxDB (local-first, NoSQL)
- State Management: Reactive (RxJS Observables)
- Formatting: Uses ESLint. Run npm run lint to check and npm run lint:fix to auto-fix.
- Imports: Uses ES modules (import/export).
- Paths: Source code in src/, tests in test/, documentation in docs-src/.
- TypeScript: Do not use enums. Prefer types instead of interfaces.
- Errors: Do not use throw new Error(). Use throw newRxError() or throw newRxTypeError() instead to reduce build size and do not include full error messages in production builds. Use the error codes from src/rx-error.ts and add new error codes if needed like PL1, PL2. Example: throw newRxError('PL1', { plugin });

Development Workflow

sh

1. Make changes

2. Build


npm run build

3. Run tests


npm run test:fast:memory

4. Run lint


npm run lint

5. Check TypeScript types


npm run check-types

Documentation Style


- SHOULD use clear, simple language.
- SHOULD use data and examples to support claims when possible.
- SHOULD be informative.
- SHOULD focus on practical, actionable insights.
- AVOID using em dashes (–) anywhere.
- AVOID constructions like "not just this, but also this".
- AVOID metaphors and cliches.
- AVOID generalizations.
- AVOID upfront warnings or notes, just the output requested.
- AVOID rhetorical questions.
- AVOID specific words like: very, really, literally, actually, certainly, probably, basically, delve, embark, enlightening, esteemed, shed light, craft, creative, imagine, realm, game-changer, unlock, discover, skyrocket, abyss, not alone, in a world where, revolutionize, disruptive, utilize, utilizing, dive deep, tapestry, illuminate, unveil, pivotal, intricate, elucidate, hence, furthermore, realm, however, harness, exciting, groundbreaking, cutting-edge, remarkable, it remains to be seen, glimpse into, navigating, landscape, stark, testament, in summary, in conclusion, moreover, boost, skyrocket, opened up, powerful, inquiries, ever-evolving.
- Review your response and ensure no em dashes.
- MUST format FAQ sections using HTML <details> and <summary> tags. Ensure there is an empty line before and after the inner markdown content so it parses correctly.
- SHOULD try to use components from the docs-src/src/components folder when writing docs.

README.md

<p align="center">
<a href="https://rxdb.info/">
<img src="./docs-src/static/files/logo/logo_text.svg" width="380px" alt="JavaScript Database" />
</a>
<br />
<h3 align="center">A fast, <a href="https://rxdb.info/articles/local-first-future.html">local-first</a>, reactive Database for JavaScript Applications</h3>
</p>
<br />


<p align="center">
<a href="https://github.com/pubkey/rxdb/releases"><img src="https://img.shields.io/github/v/release/pubkey/rxdb?color=%23ff00a0&include_prereleases&label=version&sort=semver&style=flat-square"></a>
&nbsp;
<a href="https://rxdb.info/tutorials/typescript.html"><img src="https://img.shields.io/npm/types/rxdb?style=flat-square"></a>
&nbsp;
<a href="https://github.com/pubkey/rxdb/blob/master/LICENSE.txt"><img src="https://img.shields.io/github/license/pubkey/rxdb?style=flat-square"></a>
&nbsp;
<a href="https://github.com/pubkey/rxdb/stargazers"><img src="https://img.shields.io/github/stars/pubkey/rxdb?color=f6f8fa&style=flat-square"></a>
&nbsp;
<a href="https://www.npmjs.com/package/rxdb"><img src="https://img.shields.io/npm/dm/rxdb?color=c63a3b&style=flat-square"></a>
</p>

<p align="center">
<a href="https://rxdb.info/chat"><img src="https://img.shields.io/discord/969553741705539624?label=discord&style=flat-square&color=5a66f6"></a>
&nbsp;
<a href="https://twitter.com/intent/follow?screen_name=rxdbjs"><img src="https://img.shields.io/badge/twitter-%40rxdbjs-1DA1F2?style=flat-square"></a>
&nbsp;
<a href="https://www.linkedin.com/company/rxdb"><img src="https://img.shields.io/badge/linkedin-%40rxdb-0e76a8?style=flat-square"></a>
&nbsp;
<a href="https://rxdb.info/newsletter"><img src="https://img.shields.io/badge/newsletter-subscribe-e05b29?style=flat-square"></a>
</p>


<br />

<h2>
<img height="16" width="16" src="./docs-src/static/files/logo/logo.svg">&nbsp;&nbsp;What is RxDB?
</h2>

<p align="justify">
RxDB (short for <b>R</b>eactive <b>D</b>ata<b>b</b>ase) is a <a href="https://rxdb.info/articles/local-first-future.html">local-first</a>, NoSQL-database for JavaScript Applications.
Reactive means that you can not only query the current state, but <b>subscribe</b> to all state changes like the result of a query or even a single field of a document.
This is great for UI-based <b>realtime</b> applications in a way that makes it easy to develop and also has great performance benefits.
</p>

Use the quickstart, read the documentation or explore the example projects.


<h2>
<img height="16" width="16" src="./docs-src/static/files/icons/with-gradient/people.svg">&nbsp;&nbsp;Used by <b style="color: #e6008d;">many</b>
</h2>

RxDB is a proven technology used by thousands of developers worldwide. With its flexibility, RxDB is used in a diverse range of apps and services.

<a href="https://rxdb.info/#reviews" target="_blank">
<img src="./docs-src/static/files/used-by-many.png" />
</a>
<br />
(<a href="https://forms.gle/7taae27VqLXqd4sF6">add yours</a>)

<h2>
<img height="16" width="16" src="./docs-src/static/files/icons/with-gradient/multiplayer.svg">&nbsp;&nbsp;Multiplayer realtime applications
<img height="36" src="./docs-src/static/files/icons/with-gradient/text/made-easy.svg">
</h2>

!realtime.gif


<h2>
<img height="16" width="16" src="./docs-src/static/files/icons/with-gradient/replication.svg">&nbsp;&nbsp;Replicate with your <b style="color: #e6008d;">existing infrastructure</b>
</h2>

RxDB provides an easy to implement, <b>battle-tested</b> <a href="https://rxdb.info/replication.html">Sync Engine</a> for <a href="https://rxdb.info/articles/realtime-database.html">realtime</a> replication with your existing infrastructure.<br />
You do not have to use a specific cloud or backend database. The protocol works by implementing three simple HTTP endpoints.
There are also production-ready plugins to easily replicate with <a href="https://rxdb.info/replication-graphql.html">GraphQL</a>, <a href="https://rxdb.info/replication-couchdb.html">CouchDB</a>, <a href="https://rxdb.info/replication-websocket.html">Websocket</a>, <a href="https://rxdb.info/replication-webrtc.html">WebRTC (P2P)</a>, <a href="https://rxdb.info/replication-supabase.html">Supabase</a>, <a href="https://rxdb.info/replication-firestore.html">Firestore</a>, <a href="https://rxdb.info/replication-nats.html">NATS</a> or <a href="https://rxdb.info/replication-google-drive.html">Google Drive</a>.


<h2>
<img height="16" width="16" src="./docs-src/static/files/icons/with-gradient/storage-layer.svg">&nbsp;&nbsp;<b style="color: #8D2089;">Flexible</b> storage layer
</h2>

RxDB is based on a storage interface that enables you to swap out the underlying storage engine. This increases code reuse because the same database code can be used in different JavaScript environments by just switching out the storage settings.

You can use RxDB on top of LocalStorage, IndexedDB, OPFS, LokiJS, Dexie.js, in-memory, SQLite, in a WebWorker thread and even on top of FoundationDB and DenoKV.

No matter what kind of runtime you have, as long as it runs JavaScript, it can run RxDB:

<h4>
<img height="13" src="https://cdnjs.cloudflare.com/ajax/libs/browser-logos/39.2.2/chrome/chrome_24x24.png" />
<img height="13" src="https://cdnjs.cloudflare.com/ajax/libs/browser-logos/39.2.2/firefox/firefox_24x24.png" />
<img height="13" src="https://cdnjs.cloudflare.com/ajax/libs/browser-logos/39.2.2/safari/safari_24x24.png" />
<img height="13" src="https://cdnjs.cloudflare.com/ajax/libs/browser-logos/39.2.2/edge/edge_24x24.png" />
<a href="./examples/angular">Browsers</a>
<img height="13" src="docs-src/static/files/icons/nodejs.svg" />
<a href="./examples/node">Node.js</a>
<img height="13" src="docs-src/static/files/icons/react.svg" />
<a href="https://rxdb.info/react-native-database.html">React Native</a>
<img height="13" src="docs-src/static/files/icons/capacitor.svg" />
<a href="https://rxdb.info/capacitor-database.html">Capacitor</a>
<img height="13" src="docs-src/static/files/icons/nativescript.svg" />
<a href="https://github.com/herefishyfish/rxdb-nativescript">NativeScript</a>
<img height="13" src="docs-src/static/files/icons/flutter.svg" />
<a href="./examples/flutter">Flutter</a>
or as an <img height="13" src="docs-src/static/files/icons/electron.svg" />
<a href="https://rxdb.info/electron-database.html">Electron Database</a>
</h4>


<h2>
All the features that you need
</h2>

Since its beginning in 2018, RxDB has gained a huge set of features and plugins which makes it a flexible full solution regardless of which type of application you are building. Every feature that you need now or might need in the future is already there.


<table>
<tr>
<td>
<a href="https://rxdb.info/logger.html">Logging</a><br>
<a href="https://rxdb.info/rx-attachment.html">Attachments</a><br>
<a href="https://rxdb.info/orm.html">ORM</a><br>
<a href="https://rxdb.info/transactions-conflicts-revisions.html">Conflict Handling</a><br>
<a href="https://rxdb.info/middleware.html">Middleware</a><br>
<a href="https://rxdb.info/reactivity.html">Signals</a>
</td>
<td>
<a href="https://rxdb.info/rx-state.html">State</a><br>
<a href="https://rxdb.info/backup.html">Backup</a><br>
<a href="https://rxdb.info/replication.html">Replication</a><br>
<a href="https://rxdb.info/rx-server.html">Server</a><br>
<a href="https://rxdb.info/rx-storage.html">Storages</a><br>
<a href="https://rxdb.info/rx-local-document.html">Local Documents</a>
</td>
<td>
<a href="https://rxdb.info/schema-validation.html">Schema Validation</a><br>
<a href="https://rxdb.info/key-compression.html">Compression</a><br>
<a href="https://rxdb.info/migration-schema.html">Migration</a><br>
<a href="https://rxdb.info/encryption.html">Encryption</a><br>
<a href="https://rxdb.info/crdt.html">CRDT</a><br>
<a href="https://rxdb.info/population.html">Population</a>
</td>
</tr>
</table>


<h2>
<img height="16" width="16" src="./docs-src/static/files/icons/with-gradient/rocket.svg">&nbsp;&nbsp;Quick start
</h2>


#### Install

sh
npm install rxdb rxjs --save

#### Store data

javascript
import { 
createRxDatabase
} from 'rxdb/plugins/core';

/
* For browsers, we use the localstorage based storage.
* In other JavaScript runtimes, we can use different storages:
* @link https://rxdb.info/rx-storage.html
*/
import { getRxStorageLocalstorage } from 'rxdb/plugins/storage-localstorage';

// create a database
const db = await createRxDatabase({
name: 'heroesdb', // the name of the database
storage: getRxStorageLocalstorage()
});

// add collections with a schema
await db.addCollections({
heroes: {
schema: {
version: 0,
primaryKey: 'name',
type: 'object',
properties: {
name: {
type: 'string',
maxLength: 100
},
healthpoints: {
type: 'number'
}
},
required: ['name', 'healthpoints']
}
}
});

// insert a document
await db.heroes.insert({
name: 'Bob',
healthpoints: 100
});

#### Query data once

javascript
const aliveHeroes = await db.heroes.find({
selector: {
healthpoints: {
$gt: 0
}
}
}).exec(); // the exec() returns the result once

#### Observe a Query

javascript
await db.heroes.find({
selector: {
healthpoints: {
$gt: 0
}
}
})
.$ // the $ returns an observable that emits each time the result set of the query changes
.subscribe(aliveHeroes => console.dir(aliveHeroes));


<h2>
<img height="16" width="16" src="./docs-src/static/files/icons/with-gradient/rocket.svg">&nbsp;&nbsp;Get started
</h2>


Get started now by reading the docs or exploring the example-projects.

<h2>
<img height="16" width="16" src="./docs-src/static/files/icons/with-gradient/contribute.svg">&nbsp;&nbsp;Support and Contribute
</h2>

- Leave a Star ☝️
- Check out how you can contribute to this project.
- Read this when you have found a bug
- Buy access to the premium plugins
- Join us at discord to get help
- Follow us at LinkedIn

<!--
There are many websites that just exact-copy the readme of github projects.
This generates free backlinks so we add some links here to pages
that we need to rank better.
-->

#### More content
Angular Database, Frontend Database, localStorage, React Database, Browser Database, React Native Database, PWA Database, In-memory NoSQL database, JSON database, Angular IndexedDB, React IndexedDB, Optimistic UI, local database, React Native Encryption, Vue Database, jQuery Database, Vue IndexedDB, Firestore Alternative, Firebase Realtime Database Alternative, Ionic Storage

----------------

View llms.txt