DEV Community

Dharan Ganesan
Dharan Ganesan

Posted on

Internal of RXDB: Plugins, Storages Adapters 🚀

RXDB (short for Reactive Database) is an open-source client-side database that utilizes reactive programming and offline-first principles.

🏛️ Architecture

RXDB follows a modular architecture, which is divided into multiple layers. Each layer has a specific responsibility, making the codebase easy to maintain and extend. The main layers of RXDB are:

  1. 📑 Core Layer: This layer provides the basic functionality of RXDB, such as document CRUD operations and query execution.

  2. 🧩 Plugin Layer: Plugins are building blocks that helps to extend the functionality of RXDB. They can be used to provide encryption, sync, and validation features, among others. This layer is responsible for the communication between RXDB and the underlying database system. Currently, RXDB supports multiple adapters, including PouchDB, MongoDB, and SQLite.

🗃️ Data Structures

RXDB uses the JSON data format to store and retrieve data. Each document in RXDB is represented as a JSON object, which can be easily manipulated using JavaScript. Documents can have arbitrary nesting, allowing for complex data structures to be stored in the database.

In addition to the JSON data format, RXDB also supports binary data storage using the Blob data type. This can be useful when working with large files or binary data, such as images or videos.

🧩 Plugins

RXDB's plugin system allows developers to extend the functionality of the database by adding additional features. Some popular plugins include:

  1. Encryption Plugin: This plugin provides transparent encryption for data stored in RXDB. It uses the Web Cryptography API to encrypt and decrypt data on the client-side, ensuring that sensitive data remains secure.

  2. Replication Plugin: This plugin enables data synchronization between multiple instances of RXDB. It uses a variety of synchronization protocols, including PouchDB's Sync Protocol, to keep data consistent across different devices and platforms.

  3. Validation Plugin: This plugin provides data validation and schema enforcement for RXDB. It can be used to ensure that data stored in the database conforms to a specific schema, preventing data corruption and other issues.

Storage

RXDB supports multiple storage options, including:

  1. IndexedDB: This is the default storage backend for RXDB. It is a key-value store that is built into most modern web browsers, making it a good choice for web-based applications.

  2. LocalStorage: This storage backend is also built into most modern web browsers. It provides a simple key-value store, but has a smaller storage capacity than IndexedDB.

  3. Memory: This storage backend stores data in memory, making it useful for testing and debugging purposes.

  4. Custom: RXDB also allows developers to create their own custom storage backends by implementing the RxStorage interface.

Angular + ngrx + rxdb example:

https://github.com/dhrn/rxdb-ngrx-example or https://stackblitz.com/edit/angular-1zvpdc

Top comments (0)