Skip to content
This repository has been archived by the owner on Oct 5, 2023. It is now read-only.

Peer-to-Peer Databases for the Decentralized Web

License

Notifications You must be signed in to change notification settings

orbitdb-archive/orbit-db-nextgen

 
 

Repository files navigation

OrbitDB

Matrix npm version node

OrbitDB is a serverless, distributed, peer-to-peer database. OrbitDB uses IPFS as its data storage and Libp2p Pubsub to automatically sync databases with peers. It's an eventually consistent database that uses Merkle-CRDTs for conflict-free database writes and merges making OrbitDB an excellent choice for p2p and decentralized apps, blockchain applications and local-first web applications.

OrbitDB provides various types of databases for different data models and use cases:

  • events: an immutable (append-only) log with traversable history. Useful for "latest N" use cases or as a message queue.
  • documents: a document database to which JSON documents can be stored and indexed by a specified key. Useful for building search indices or version controlling documents and data.
  • keyvalue: a key-value database just like your favourite key-value database.
  • keyvalue-indexed: key-value data indexed in a Level key-value database.

All databases are implemented on top of OrbitDB's OpLog, an immutable, cryptographically verifiable, operation-based conflict-free replicated data structure (CRDT) for distributed systems. OpLog is formalized in the paper Merkle-CRDTs. You can also easily extend OrbitDB by implementing and using a custom data model benefitting from the same properties as the default data models provided by the underlying Merkle-CRDTs.

Project status & support

  • Status: in active development
  • Compatible with ipfs-core versions >= 0.18.0

NOTE! js-ipfs and related packages are now superseded by IPFS's Helia project and are no longer being maintained. As part of this migration, OrbitDB will be switching to Helia.

This is the Javascript implementation and it works both in Browsers and Node.js with support for Linux, OS X, and Windows. Node version 16 is supported.

A Go implementation is developed and maintained by the Berty project at berty/go-orbit-db.

Table of Contents

Installation

Note! The upcoming version 1.0.0 is currently in testing and needs to be installed as version "next" as described below.

npm install @orbitdb/core@next

Browser <script> tag

OrbitDB can be loaded in the browser using the distributed js file with the <script/> tag. OrbitDB is the global namespace and all external functions are available via this namespace:

<script>/path/to/orbitdb.min.js</script>

Usage

If you're using @orbitdb/core to develop browser or Node.js applications, use it as a module with the javascript instance of IPFS.

import IPFS from 'ipfs-core'
import { createOrbitDB } from '@orbitdb/core'

;(async function () {
  const ipfs = await IPFS.create()
  const orbitdb = await createOrbitDB({ ipfs })

  // Create / Open a database. Defaults to db type "events".
  const db = await orbitdb.open("hello")
  
  const address = db.address
  console.log(address)
  // "/orbitdb/hash"
  // The above address can be used on another peer to open the same database

  // Listen for updates from peers
  db.events.on("update", entry => {
    console.log(entry)
    const all = await db.all()
    console.log(all)
  })

  // Add an entry
  const hash = await db.add("world")
  console.log(hash)

  // Query
  for await (const record of db.iterator()) {
    console.log(record)
  }
  
  await db.close()
  await orbitdb.stop()
})()

Documentation

Use the Getting Started guide for an initial introduction to OrbitDB and you can find more advanced topics covered in our docs.

API

See api.orbitdb.org for the full API documentation.

Development

Run Tests

npm run test

Build

npm run build

Benchmark

node benchmarks/benchmark-add.js

See benchmarks/ for more benchmarks.

API

To build the API documentation, run:

npm run build:docs

Documentation is output to ./docs/api.

Other implementations

If you know of any other repos that ought to be included in this section, please open a PR and add them.

Contributing

Take a look at our organization-wide Contributing Guide. You'll find most of your questions answered there. Some questions may be answered in the FAQ, as well.

If you want to code but don't know where to start, check out the issues labelled "help wanted".

Sponsors

The development of OrbitDB has been sponsored by:

If you want to sponsor developers to work on OrbitDB, please reach out to @haadcode.

License

MIT © 2015-2023 Protocol Labs Inc., Haja Networks Oy, OrbitDB Community

About

Peer-to-Peer Databases for the Decentralized Web

Resources

License

Code of conduct

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • JavaScript 97.3%
  • HTML 2.5%
  • Makefile 0.2%