|
1 | | -# astradb |
2 | | -Database for astrawiki & astrachat ipfs using orbitdb & libp2p |
| 1 | +# AstraDB |
| 2 | + |
| 3 | +**AstraDB** is a distributed database infrastructure designed to power **dynamic, community-driven, and decentralized applications**. |
| 4 | +Built as a higher-level layer over [OrbitDB](https://github.com/orbitdb/orbitdb) and [LibP2P](https://github.com/libp2p/js-libp2p), it provides the core mechanisms for **data synchronization**, **replication**, and **collaboration** between nodes in a peer-to-peer environment. |
| 5 | + |
| 6 | +Unlike traditional databases, AstraDB is specifically designed for **mutable-state applications** operating on top of [IPFS](https://ipfs.tech), such as knowledge repositories or real-time messaging systems. |
| 7 | +It automates the fundamental tasks required for decentralized operation — including **node discovery**, **eventual consistency**, and **data persistence** — allowing developers to build responsive and fault-tolerant systems without centralized servers. |
| 8 | + |
| 9 | +Each AstraDB instance behaves as a fully independent, self-replicating node that can interconnect with others to share data. |
| 10 | +Its **key–value event model** allows every entity (for example, an article or a chat) to evolve as a chronological sequence of updates, making it possible to reconstruct or audit any state at any point in time. |
| 11 | + |
| 12 | +This approach makes AstraDB ideal for applications that rely on **real-time collaboration** and **community ownership**, where users contribute directly to data availability and integrity. |
| 13 | + |
| 14 | +## Applications |
| 15 | + |
| 16 | +AstraDB serves as the data layer for Bitxenia’s decentralized applications: |
| 17 | + |
| 18 | +- **[Astrawiki](https://github.com/bitxenia/astrawiki)** — a collaborative knowledge repository that allows users to create and edit articles distributed across the IPFS network. |
| 19 | +- **[Astrachat](https://github.com/bitxenia/astrachat)** — a real-time messenger where all messages are stored and synchronized through AstraDB using event-based updates. |
| 20 | + |
| 21 | +Both applications demonstrate how AstraDB abstracts away the complexity of peer-to-peer networks, enabling developers to focus on the logic of their decentralized systems. |
| 22 | + |
| 23 | +## Overview |
| 24 | + |
| 25 | +- Built on **IPFS**, **OrbitDB**, and **LibP2P** |
| 26 | +- Event-based **key–value data model** |
| 27 | +- Supports **append-only** structures and **real-time updates** |
| 28 | +- Provides **node discovery** and **collaborator replication** |
| 29 | +- Fully decentralized — no central servers or authorities |
| 30 | +- Designed for **distributed, community-oriented applications** |
| 31 | + |
| 32 | +## Install |
| 33 | + |
| 34 | +```sh |
| 35 | +npm install @bitxenia/astradb |
| 36 | +``` |
| 37 | + |
| 38 | +## Usage |
| 39 | + |
| 40 | +Using the `createAstradb` init function you can create and connect the node to a database. |
| 41 | + |
| 42 | +```ts |
| 43 | +import { createAstradb } from "@bitxenia/astradb"; |
| 44 | + |
| 45 | +const node = await createAstradb({ |
| 46 | + dbName: "bitxenia-db", |
| 47 | +}); |
| 48 | + |
| 49 | +const keyList = await node.getAllKeys(); |
| 50 | +console.log(keyList); |
| 51 | +``` |
| 52 | + |
| 53 | +## Documentation |
| 54 | + |
| 55 | +You can find more advanced topics, such as a detailed explanation of AstraDB’s architecture and internal components in our [docs](https://github.com/bitxenia/docs/tree/main/ipfs/application). |
| 56 | + |
| 57 | +## Development |
| 58 | + |
| 59 | +**Clone and install dependencies:** |
| 60 | + |
| 61 | +```sh |
| 62 | +git clone git@github.com:bitxenia/astradb.git |
| 63 | +cd astradb |
| 64 | +npm install |
| 65 | +``` |
| 66 | + |
| 67 | +### Run Tests |
| 68 | + |
| 69 | +```sh |
| 70 | +npm run test |
| 71 | +``` |
| 72 | + |
| 73 | +### Build |
| 74 | + |
| 75 | +```sh |
| 76 | +npm run build |
| 77 | +``` |
| 78 | + |
| 79 | +## Contribute |
| 80 | + |
| 81 | +Contributions welcome! Please check out the issues. |
| 82 | + |
| 83 | +## Troubleshooting |
| 84 | + |
| 85 | +### The node cannot receive incoming connections and, as a result, cannot collaborate. |
| 86 | + |
| 87 | +If the node is set to collaborate and it fails to do so, the reason should most likely be a port issue. The `LibP2P` implementation uses `UPnP` to automatically open ports and detect the public IP. If the modem is outdated, you will need to manually open the ports and specify the public IP when creating the node in the `createAstradb` init function. |
| 88 | + |
| 89 | +The default ports that need to be opened manually, if not changed on the options, are: |
| 90 | + |
| 91 | +- `40001` TCP port, used to receive `TCP` incoming connections. |
| 92 | +- `40001` UDP port, used to receive `WebRTC-Direct` incoming connections. |
| 93 | + |
| 94 | +If this does not work, your ISP may be using Double NAT, which prevents incoming connections. In this case, you may need to contact your ISP to request a solution. |
| 95 | + |
| 96 | +## License |
| 97 | + |
| 98 | +MIT (LICENSE-MIT / http://opensource.org/licenses/MIT) |
| 99 | + |
0 commit comments