Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 20 additions & 5 deletions docs/.gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,20 @@
**/.vscode
.idea
*.log
node_modules
.DS_store
# Dependencies
/node_modules

# Production
/build

# Generated files
.docusaurus
.cache-loader

# Misc
.DS_Store
.env.local
.env.development.local
.env.test.local
.env.production.local

npm-debug.log*
yarn-debug.log*
yarn-error.log*
2 changes: 0 additions & 2 deletions docs/.prettierignore

This file was deleted.

1 change: 0 additions & 1 deletion docs/LICENSE.txt

This file was deleted.

56 changes: 24 additions & 32 deletions docs/README.md
Original file line number Diff line number Diff line change
@@ -1,49 +1,41 @@
## Migration note
We are in the process of moving from the `spacetimedb-docs` repo to the `docs` subdirectory of [SpacetimeDB](https://github.com/clockworklabs/SpacetimeDB). **Any new changes should be made there**. The `spacetimedb-docs` repo will only be updated on release. Apologies in advance for any sharp edges while the migration is in progress.
# Website

## SpacetimeDB Documentation
This website is built using [Docusaurus](https://docusaurus.io/), a modern static website generator.

This repository contains the markdown files which are used to display documentation on our [website](https://spacetimedb.com/docs).
### Installation

### Making Edits

To make changes to our docs, you can open a pull request in this repository. You can typically edit the files directly using the GitHub web interface, but you can also clone our repository and make your edits locally. To do this you can follow these instructions:

1. Fork our repository
2. Clone your fork:

```bash
git clone ssh://git@github.com/<username>/SpacetimeDB
cd SpacetimeDB/docs
```
$ yarn
```

3. Make your edits to the docs that you want to make + test them locally
4. Commit your changes:
### Local Development

```bash
git add .
git commit -m "A specific description of the changes I made and why"
```
$ yarn start
```

This command starts a local development server and opens up a browser window. Most changes are reflected live without having to restart the server.

5. Push your changes to your fork as a branch
### Build

```bash
git checkout -b a-branch-name-that-describes-my-change
git push -u origin a-branch-name-that-describes-my-change
```
$ yarn build
```

6. Go to our GitHub and open a PR that references your branch in your fork on your GitHub
This command generates static content into the `build` directory and can be served using any static contents hosting service.

> NOTE! If you make a change to `nav.ts` you will have to run `npm run build` to generate a new `docs/nav.js` file.
### Deployment

#### CLI Reference Section
1. Run `cargo run --features markdown-docs -p spacetimedb-cli > docs/cli-reference.md`
2. Run `pnpm format`
Using SSH:

### Checking Links
```
$ USE_SSH=true yarn deploy
```

We have a CI job which validates internal links. You can run it locally with `npm run check-links`. This will print any internal links (i.e. links to other docs pages) whose targets do not exist, including fragment links (i.e. `#`-ey links to anchors).
Not using SSH:

## License
```
$ GIT_USER=<Your GitHub username> yarn deploy
```

This documentation repository is licensed under Apache 2.0. See LICENSE.txt for more details.
If you are using GitHub pages for hosting, this command is a convenient way to build the website and push to the `gh-pages` branch.
412 changes: 0 additions & 412 deletions docs/STYLE.md

This file was deleted.

129 changes: 77 additions & 52 deletions docs/docs/index.md → docs/docs/01-Intro/01-overview.mdx
Original file line number Diff line number Diff line change
@@ -1,17 +1,21 @@
---
title: Overview
slug: /
---

import Tabs from "@theme/Tabs";
import TabItem from "@theme/TabItem";

# SpacetimeDB Documentation

## Installation

You can run SpacetimeDB as a standalone database server via the `spacetime` CLI tool.

You can find the instructions to install the CLI tool for your platform [here](/install).

<button to="/install">Click here to install</button>
You can find the instructions to install the CLI tool for your platform [here](https://spacetimedb.com/install).

To get started running your own standalone instance of SpacetimeDB check out our [Getting Started Guide](/docs/getting-started).

<button to="/docs/getting-started">Getting Started</button>

## What is SpacetimeDB?

SpacetimeDB is a database that is also a server.
Expand All @@ -21,11 +25,18 @@ SpacetimeDB is a full-featured relational database system that lets you run your
This means that you can write your entire application in a single language and deploy it as a single binary. No more microservices, no more containers, no more Kubernetes, no more Docker, no more VMs, no more DevOps, no more infrastructure, no more ops, no more servers.

<figure>
<img src="/images/basic-architecture-diagram.png" alt="SpacetimeDB Architecture" style="width:100%">
<figcaption style="margin-top: 10px;" align="center">
<b align="center">SpacetimeDB application architecture</b>
<span style="font-size: 14px">(elements in white are provided by SpacetimeDB)</span>
</figcaption>
<img
src="/images/basic-architecture-diagram.png"
alt="SpacetimeDB Architecture"
style={{ width: "100%" }}
/>
<figcaption style={{ marginTop: "10px", textAlign: "center" }} align="center">
<b align="center">SpacetimeDB application architecture</b>
<span style={{ fontSize: "14px" }}>
{" "}
(elements in white are provided by SpacetimeDB)
</span>
</figcaption>
</figure>

This is similar to ["smart contracts"](https://en.wikipedia.org/wiki/Smart_contract), except that SpacetimeDB is a **database** and has nothing to do with blockchain. Because it isn't a blockchain, it can be dramatically faster than many "smart contract" systems.
Expand All @@ -36,23 +47,6 @@ SpacetimeDB is optimized for maximum speed and minimum latency, rather than batc

Speed and latency is achieved by holding all of your application state in memory, while persisting data to a commit log which is used to recover data after restarts and system crashes.

## Application Workflow Preview

<figure>
<img src="/images/workflow-preview-diagram.png" alt="SpacetimeDB Application Workflow Preview" style="width:100%">
<figcaption style="margin-top: 10px;" align="center">
<b align="center">SpacetimeDB Application Workflow Preview</b>
</figcaption>
</figure>


The above illustrates the workflow when using SpacetimeDB.

* All client-side reads happen with the data view that is cached locally.
* Client-side subscriptions tell the server what data client cares about and wants to be synced within its data view. Changes to data will be pushed by the server to the client cache.
* RLS filters restrict the data view server-side before subscriptions are evaluated. These filters can be used for access control or client scoping.
* Reducers are effectively async RPC's. The request is sent off and if the results of that reducer makes changes to data, it will be written to the database directly. As a result of that, if those changes make it through the two layers above, then the client will see the result when it queries its local cache.

## State Mirroring

SpacetimeDB can generate client code in a [variety of languages](#client-side-sdks). This creates a client library custom-designed to talk to your database. It provides easy-to-use interfaces for connecting to the database and submitting requests. It can also **automatically mirror state** from your database to client applications.
Expand Down Expand Up @@ -83,9 +77,11 @@ SpacetimeDB was designed first and foremost as the backend for multiplayer Unity
## Key architectural concepts

### Host

A SpacetimeDB **host** is a server that hosts [databases](#database). You can run your own host, or use the SpacetimeDB maincloud. Many databases can run on a single host.

### Database

A SpacetimeDB **database** is an application that runs on a [host](#host).

A database exports [tables](#table), which store data, and [reducers](#reducer), which allow [clients](#client) to make requests.
Expand All @@ -95,8 +91,27 @@ A database's schema and business logic is specified by a piece of software calle
(Technically, a SpacetimeDB module is a [WebAssembly module](https://developer.mozilla.org/en-US/docs/WebAssembly) that imports a specific low-level [WebAssembly ABI](/docs/webassembly-abi) and exports a small number of special functions. However, the SpacetimeDB [server-side libraries](#module-libraries) hide these low-level details. As a developer, writing a module is mostly like writing any other C# or Rust application, except for the fact that a [special CLI tool](/install) is used to deploy the application.)

### Table

A SpacetimeDB **table** is a SQL database table. Tables are declared in a module's native language. For instance, in C#, a table is declared like so:

<Tabs groupId="syntax" queryString>

<TabItem value="rust" label="Rust">

```rust
#[spacetimedb::table(name = players, public)]
pub struct Player {
#[primary_key]
id: u64,
name: String,
age: u32,
user: Identity,
}
```

</TabItem>
<TabItem value="csharp" label="C#">

```csharp
[SpacetimeDB.Table(Name = "players", Public = true)]
public partial struct Player
Expand All @@ -108,28 +123,23 @@ public partial struct Player
Identity user;
}
```
<!-- TODO: switchable language widget.
```rust
#[spacetimedb::table(name = players, public)]
pub struct Player {
#[primary_key]
id: u64,
name: String,
age: u32,
user: Identity,
}
```
-->

</TabItem>

</Tabs>

The contents of a table can be read and updated by [reducers](#reducer).
Tables marked `public` can also be read by [clients](#client).

### Reducer

A **reducer** is a function exported by a [database](#database).
Connected [clients](#client-side-sdks) can call reducers to interact with the database.
This is a form of [remote procedure call](https://en.wikipedia.org/wiki/Remote_procedure_call).

:::server-rust
<Tabs groupId="syntax" queryString>
<TabItem value="rust" label="Rust">

A reducer can be written in Rust like so:

```rust
Expand All @@ -147,8 +157,10 @@ fn main() {
ctx.reducers.set_player_name(57, "Marceline".into());
}
```
:::
:::server-csharp

</TabItem>
<TabItem value="csharp" label="C#">

A reducer can be written in C# like so:

```csharp
Expand All @@ -167,7 +179,9 @@ void Main() {
Connection.Reducer.SetPlayerName(57, "Marceline");
}
```
:::

</TabItem>
</Tabs>

These look mostly like regular function calls, but under the hood,
the client sends a request over the internet, which the database processes and responds to.
Expand All @@ -178,9 +192,9 @@ This can be used to authenticate the caller.

Reducers are run in their own separate and atomic [database transactions](https://en.wikipedia.org/wiki/Database_transaction).
When a reducer completes successfully, the changes the reducer has made,
such as inserting a table row, are *committed* to the database.
such as inserting a table row, are _committed_ to the database.
However, if the reducer instead returns an error, or throws an exception,
the database will instead reject the request and *revert* all those changes.
the database will instead reject the request and _revert_ all those changes.
That is, reducers and transactions are all-or-nothing requests.
It's not possible to keep the first half of a reducer's changes and discard the last.

Expand All @@ -191,7 +205,10 @@ Instead, when the nested reducer gracefully errors,
and the overall reducer completes successfully,
the changes in the nested one are still persisted.

:::server-rust
<Tabs groupId="syntax" queryString>

<TabItem value="rust" label="Rust">

```rust
#[spacetimedb::reducer]
pub fn hello(ctx: &spacetimedb::ReducerContext) -> Result<(), String> {
Expand All @@ -202,14 +219,18 @@ pub fn hello(ctx: &spacetimedb::ReducerContext) -> Result<(), String> {

#[spacetimedb::reducer]
pub fn world(ctx: &spacetimedb::ReducerContext) -> Result<(), String> {
clear_all_tables(ctx);
clear_all_tables(ctx);
}

```

While SpacetimeDB doesn't support nested transactions,
a reducer can [schedule another reducer](https://docs.rs/spacetimedb/latest/spacetimedb/attr.reducer.html#scheduled-reducers) to run at an interval,
or at a specific time.
:::
:::server-csharp

</TabItem>
<TabItem value="csharp" label="C#">

```csharp
[SpacetimeDB.Reducer]
public static void Hello(ReducerContext ctx)
Expand All @@ -227,13 +248,16 @@ public static void World(ReducerContext ctx)
// ...
}
```

While SpacetimeDB doesn't support nested transactions,
a reducer can [schedule another reducer](/docs/modules/c-sharp#scheduled-reducers) to run at an interval,
or at a specific time.
:::

</TabItem>
</Tabs>

### Client

A **client** is an application that connects to a [database](#database). A client logs in using an [identity](#identity) and receives an [connection id](#connectionid) to identify the connection. After that, it can call [reducers](#reducer) and query public [tables](#table).

Clients are written using the [client-side SDKs](#client-side-sdks). The `spacetime` CLI tool allows automatically generating code that works with the client-side SDKs to talk to a particular database.
Expand Down Expand Up @@ -262,7 +286,7 @@ def identity_from_claims(issuer: str, subject: str) -> [u8; 32]:
*id_hash
])
identity_big_endian_bytes: [u8; 32] = [
0xC2,
0xC2,
0x00,
*checksum_hash[:4],
*id_hash
Expand All @@ -279,6 +303,7 @@ A `ConnectionId` identifies client connections to a SpacetimeDB database.
A user has a single [`Identity`](#identity), but may open multiple connections to your database. Each of these will receive a unique `ConnectionId`.

### Energy

**Energy** is the currency used to pay for data storage and compute operations in a SpacetimeDB host.

<!-- TODO(1.0): Rewrite this section after finalizing energy SKUs. -->
Expand All @@ -297,5 +322,5 @@ A user has a single [`Identity`](#identity), but may open multiple connections t
1. How do I create a new database with SpacetimeDB?
Follow our [Quick Start](/docs/getting-started) guide!

5. How do I create a Unity game with SpacetimeDB?
1. How do I create a Unity game with SpacetimeDB?
Follow our [Unity Tutorial](/docs/unity) guide!
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
---
slug: /getting-started
---

# Getting Started

To develop SpacetimeDB databases locally, you will need to run the Standalone version of the server.
Expand Down
Loading
Loading