2016-10-05 10:33:45 +02:00
# orbit-db
2015-12-26 19:05:51 +02:00
2017-09-15 20:58:18 +02:00
[![ ](https://img.shields.io/badge/freenode-%23orbitdb-blue.svg?style=flat-square )](http://webchat.freenode.net/?channels=%23orbitdb)
2017-03-31 10:54:56 +02:00
[![CircleCI Status ](https://circleci.com/gh/orbitdb/orbit-db.svg?style=shield )](https://circleci.com/gh/orbitdb/orbit-db)
[![npm version ](https://badge.fury.io/js/orbit-db.svg )](https://www.npmjs.com/package/orbit-db)
[![node ](https://img.shields.io/node/v/orbit-db.svg )](https://www.npmjs.com/package/orbit-db)
[![Project Status ](https://badge.waffle.io/orbitdb/orbit-db.svg?columns=In%20Progress&title=In%20Progress )](https://waffle.io/orbitdb/orbit-db)
2016-11-02 13:50:15 +01:00
2017-03-31 10:54:56 +02:00
> A peer-to-peer database for the decentralized web
2016-08-09 16:56:51 +02:00
2016-11-02 13:50:15 +01:00
`orbit-db` is a serverless, distributed, peer-to-peer database. `orbit-db` uses [IPFS ](https://ipfs.io ) as its data storage and [IPFS Pubsub ](https://github.com/ipfs/go-ipfs/blob/master/core/commands/pubsub.go#L23 ) to automatically sync databases with peers. It's an eventually consistent database that uses [CRDTs ](https://en.wikipedia.org/wiki/Conflict-free_replicated_data_type ) for conflict-free database merges making `orbit-db` and excellent choice for offline-first applications.
2015-12-26 19:05:51 +02:00
2016-10-04 22:07:24 +02:00
Data in `orbit-db` can be stored in a
2016-06-08 16:43:09 +02:00
2017-03-31 10:54:56 +02:00
- **[Key-Value Store ](https://github.com/orbitdb/orbit-db/blob/master/API.md#keyvaluenameaddress )**
- **[Log Database ](https://github.com/orbitdb/orbit-db/blob/master/API.md#lognameaddress )** (append-only log)
- **[Feed ](https://github.com/orbitdb/orbit-db/blob/master/API.md#feednameaddress )** (same as log database but entries can be removed)
- **[Document Store ](https://github.com/orbitdb/orbit-db/blob/master/API.md#docsnameaddress-options )** (store indexed JSON documents)
- **[Counters ](https://github.com/orbitdb/orbit-db/blob/master/API.md#counternameaddress )**
2016-06-08 16:44:39 +02:00
2016-10-04 22:07:24 +02:00
This is the Javascript implementation and it works both in **Node.js** and **Browsers** .
2016-10-04 18:40:22 +02:00
2017-03-31 10:54:56 +02:00
To get started, try the ** [OrbitDB CLI ](https://github.com/orbitdb/orbit-db-cli )**, read the ** [Getting Started Guide ](https://github.com/orbitdb/orbit-db/blob/master/GUIDE.md )** or check ** [Live demo 1 ](https://ipfs.io/ipfs/QmRosp97r8GGUEdj5Wvivrn5nBkuyajhRXFUcWCp5Zubbo/ )** and ** [Live demo 2 ](https://ipfs.io/ipfs/QmasHFRj6unJ3nSmtPn97tWDaQWEZw3W9Eh3gUgZktuZDZ/ )**!
2017-09-18 09:11:01 +02:00
2017-03-31 10:54:56 +02:00
< p align = "left" >
< img src = "https://raw.githubusercontent.com/orbitdb/orbit-db/feat/write-access/screenshots/example1.png" width = "28%" >
< a href = "https://asciinema.org/a/JdTmmdBCZarkBkPqbueicwMrG" target = "_blank" > < img src = "https://asciinema.org/a/JdTmmdBCZarkBkPqbueicwMrG.png" width = "50%" / > < / a >
< / p >
2017-03-21 18:27:40 +01:00
2016-10-10 08:49:38 -04:00
## Table of Contents
- [Usage ](#usage )
- [API ](#api )
- [Examples ](#examples )
- [Development ](#development )
- [Background ](#background )
- [Contributing ](#contributing )
- [License ](#license )
2016-10-04 22:07:24 +02:00
## Usage
2016-11-02 13:50:15 +01:00
2017-03-31 10:54:56 +02:00
Read the ** [GETTING STARTED ](https://github.com/orbitdb/orbit-db/blob/master/GUIDE.md )** guide for a more in-depth tutorial and to understand how OrbitDB works.
2017-09-18 09:11:01 +02:00
### CLI
For the CLI tool to manage orbit-db database, see ** [OrbitDB CLI ](https://github.com/orbitdb/orbit-db-cli )**.
It can be installed from Npm with:
```
npm install orbit-db-cli -g
```
2017-03-31 10:54:56 +02:00
### As a library
2017-09-18 09:11:01 +02:00
2017-03-31 10:54:56 +02:00
Install dependencies:
2017-09-18 09:11:01 +02:00
2016-08-09 16:56:51 +02:00
```
2017-03-31 10:54:56 +02:00
npm install orbit-db ipfs
2016-08-09 16:56:51 +02:00
```
2017-03-31 10:54:56 +02:00
Use it as a module:
2016-07-26 11:45:12 +01:00
```javascript
2017-03-31 10:54:56 +02:00
const IPFS = require('ipfs')
2016-08-09 16:56:51 +02:00
const OrbitDB = require('orbit-db')
2016-10-04 18:40:22 +02:00
2017-01-17 09:38:18 +01:00
const ipfs = new IPFS()
ipfs.on('error', (e) => console.error(e))
2017-03-31 10:54:56 +02:00
ipfs.on('ready', async () => {
// Create a database
2017-01-17 09:38:18 +01:00
const orbitdb = new OrbitDB(ipfs)
2017-03-31 10:54:56 +02:00
const db = await orbitdb.log('database name')
// Add an entry to the database
const hash = await db.add('hello world')
// Get last 5 entries
const latest = db.iterator({ limit: 5 }).collect()
console.log(JSON.stringify(latest, null, 2))
2017-01-17 09:38:18 +01:00
})
2016-07-26 11:45:12 +01:00
```
2017-03-31 10:54:56 +02:00
*For more details, see examples for [kvstore ](https://github.com/orbitdb/orbit-db-kvstore#usage ), [eventlog ](https://github.com/haadcode/orbit-db-eventstore#usage ), [feed ](https://github.com/haadcode/orbit-db-feedstore#usage ), [docstore ](https://github.com/shamb0t/orbit-db-docstore#usage ) and [counter ](https://github.com/haadcode/orbit-db-counterstore#usage ).*
2016-11-02 13:50:15 +01:00
2016-10-10 08:49:38 -04:00
## API
2016-10-05 10:33:45 +02:00
2017-03-31 11:53:01 +02:00
See [API documentation ](https://github.com/orbitdb/orbit-db/blob/master/API.md#orbit-db-api-documentation ) for the full documentation.
2016-10-05 10:33:45 +02:00
2017-03-31 11:53:01 +02:00
- [Getting Started ](https://github.com/orbitdb/orbit-db/blob/master/API.md#getting-started )
2017-03-31 10:54:56 +02:00
- [OrbitDB ](https://github.com/orbitdb/orbit-db/blob/master/API.md#orbitdb )
- [keyvalue ](https://github.com/orbitdb/orbit-db/blob/master/API.md#keyvaluenameaddress )
- [log ](https://github.com/orbitdb/orbit-db/blob/master/API.md#lognameaddress )
- [feed ](https://github.com/orbitdb/orbit-db/blob/master/API.md#feednameaddress )
- [docstore ](https://github.com/orbitdb/orbit-db/blob/master/API.md#docsnameaddress-options )
- [counter ](https://github.com/orbitdb/orbit-db/blob/master/API.md#counternameaddress )
- [common ](https://github.com/orbitdb/orbit-db/blob/master/API.md#store )
2016-10-05 10:33:45 +02:00
2016-02-26 13:39:51 +01:00
## Examples
2016-04-15 16:28:56 +02:00
2016-10-05 10:33:45 +02:00
### Install dependencies
2016-07-31 11:43:37 +02:00
2016-10-04 22:07:24 +02:00
```
2017-03-31 11:53:01 +02:00
git clone https://github.com/orbitdb/orbit-db.git
2016-10-04 22:07:24 +02:00
cd orbit-db
2016-07-31 11:11:33 +02:00
npm install
2016-10-04 22:07:24 +02:00
```
### Browser example
```
2017-03-31 10:54:56 +02:00
npm run build
2016-10-04 18:40:22 +02:00
npm run examples:browser
2016-04-15 16:28:56 +02:00
```
2017-03-31 10:54:56 +02:00
< p align = "left" >
< img src = "https://raw.githubusercontent.com/orbitdb/orbit-db/feat/write-access/screenshots/example1.png" width = "33%" >
< / p >
2016-10-04 22:07:24 +02:00
2017-03-31 10:54:56 +02:00
Check the code in [examples/browser/browser.html ](https://github.com/orbitdb/orbit-db/blob/master/examples/browser/browser.html ) and try the [live example ](https://ipfs.io/ipfs/QmRosp97r8GGUEdj5Wvivrn5nBkuyajhRXFUcWCp5Zubbo/ ).
2016-10-04 22:07:24 +02:00
2016-10-04 18:40:22 +02:00
### Node.js example
2016-07-31 11:16:14 +02:00
2016-10-04 22:07:24 +02:00
```
2016-10-04 18:40:22 +02:00
npm run examples:node
2016-07-31 11:16:14 +02:00
```
2017-03-31 11:53:01 +02:00
< img src = "https://raw.githubusercontent.com/orbitdb/orbit-db/feat/ipfs-pubsub/screenshots/orbit-db-demo3.gif" width = "66%" >
2016-10-04 22:07:24 +02:00
2016-10-05 10:33:45 +02:00
**Eventlog**
2016-10-05 10:57:49 +02:00
2017-03-31 10:54:56 +02:00
See the code in [examples/eventlog.js ](https://github.com/orbitdb/orbit-db/blob/master/examples/eventlog.js ) and run it with:
2016-10-04 22:07:24 +02:00
```
2017-03-31 10:54:56 +02:00
node examples/eventlog.js
2016-07-31 11:16:14 +02:00
```
2017-03-31 10:54:56 +02:00
More examples at [examples ](https://github.com/orbitdb/orbit-db/tree/master/examples ).
2016-04-15 15:53:17 +02:00
2016-10-04 18:40:22 +02:00
## Development
2015-12-27 17:27:17 +02:00
2016-10-04 18:40:22 +02:00
#### Run Tests
2016-10-04 22:07:24 +02:00
```
2016-10-04 18:40:22 +02:00
npm test
```
2016-02-12 09:27:57 +01:00
2016-10-04 22:07:24 +02:00
#### Build
```
2016-10-04 18:40:22 +02:00
npm run build
```
2015-12-27 17:27:17 +02:00
2016-10-05 10:33:45 +02:00
#### Benchmark
```
2017-03-31 10:54:56 +02:00
node benchmarks/benchmark-add.js
```
#### Logging
To enable OrbitDB's logging output, set a global ENV variable called `LOG` to `debug` ,`warn` or `error` :
```
LOG=debug node < file >
2016-10-05 10:33:45 +02:00
```
2016-01-19 21:59:53 +08:00
2016-10-05 10:33:45 +02:00
## Background
2015-12-27 17:27:17 +02:00
2017-03-31 10:54:56 +02:00
OrbitDB uses an append-only log as its operations log, implemented in [ipfs-log ](https://github.com/haadcode/ipfs-log ).
2015-12-27 17:27:17 +02:00
2017-03-31 10:54:56 +02:00
To understand a little bit about the architecture, check out a visualization of the data flow at https://github.com/haadcode/proto2 or a live demo: http://celebdil.benet.ai:8080/ipfs/Qmezm7g8mBpWyuPk6D84CNcfLKJwU6mpXuEN5GJZNkX3XK/.
2015-12-27 18:25:23 +02:00
2017-03-31 10:54:56 +02:00
**TODO:**
2016-10-05 10:33:45 +02:00
- list of modules used
- orbit-db-pubsub
- crdts
2016-01-19 21:59:53 +08:00
2016-10-04 18:40:22 +02:00
## Contributing
2016-03-05 12:03:06 +01:00
2017-09-15 20:58:18 +02:00
We would be happy to accept PRs! If you want to work on something, it'd be good to talk beforehand to make sure nobody else is working on it. You can reach us on IRC [#orbitdb ](http://webchat.freenode.net/?channels=%23orbitdb ) on Freenode, or in the comments of the [issues section ](https://github.com/orbitdb/orbit-db/issues ).
2016-10-14 10:32:48 -04:00
2017-03-31 11:53:01 +02:00
A good place to start are the issues labelled ["help wanted" ](https://github.com/orbitdb/orbit-db/issues?q=is%3Aopen+is%3Aissue+label%3A%22help+wanted%22+sort%3Areactions-%2B1-desc ) or the project's [status board ](https://waffle.io/orbitdb/orbit-db ).
2016-10-04 22:07:24 +02:00
2017-03-31 10:54:56 +02:00
## Sponsors
The development of OrbitDB has been sponsored by:
* [Protocol Labs ](https://protocol.ai/ )
If you want to sponsor developers to work on OrbitDB, please reach out to @haadcode .
2016-10-04 18:40:22 +02:00
## License
2016-01-20 16:05:47 +08:00
2017-03-31 10:54:56 +02:00
[MIT ](LICENSE ) ©️ 2017 Haadcode