Skip to content

Commit 8c72c2f

Browse files
committed
Migrate docs to docusaurus
1 parent 2f9554c commit 8c72c2f

63 files changed

Lines changed: 30502 additions & 20131 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

docs/.gitignore

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,20 @@
1-
**/.vscode
2-
.idea
3-
*.log
4-
node_modules
5-
.DS_store
1+
# Dependencies
2+
/node_modules
3+
4+
# Production
5+
/build
6+
7+
# Generated files
8+
.docusaurus
9+
.cache-loader
10+
11+
# Misc
12+
.DS_Store
13+
.env.local
14+
.env.development.local
15+
.env.test.local
16+
.env.production.local
17+
18+
npm-debug.log*
19+
yarn-debug.log*
20+
yarn-error.log*

docs/.prettierignore

Lines changed: 0 additions & 2 deletions
This file was deleted.

docs/LICENSE.txt

Lines changed: 0 additions & 1 deletion
This file was deleted.

docs/README.md

Lines changed: 24 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,41 @@
1-
## Migration note
2-
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.
1+
# Website
32

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

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

8-
### Making Edits
9-
10-
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:
11-
12-
1. Fork our repository
13-
2. Clone your fork:
14-
15-
```bash
16-
git clone ssh://git@github.com/<username>/SpacetimeDB
17-
cd SpacetimeDB/docs
7+
```
8+
$ yarn
189
```
1910

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

23-
```bash
24-
git add .
25-
git commit -m "A specific description of the changes I made and why"
2613
```
14+
$ yarn start
15+
```
16+
17+
This command starts a local development server and opens up a browser window. Most changes are reflected live without having to restart the server.
2718

28-
5. Push your changes to your fork as a branch
19+
### Build
2920

30-
```bash
31-
git checkout -b a-branch-name-that-describes-my-change
32-
git push -u origin a-branch-name-that-describes-my-change
21+
```
22+
$ yarn build
3323
```
3424

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

37-
> 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.
27+
### Deployment
3828

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

43-
### Checking Links
31+
```
32+
$ USE_SSH=true yarn deploy
33+
```
4434

45-
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).
35+
Not using SSH:
4636

47-
## License
37+
```
38+
$ GIT_USER=<Your GitHub username> yarn deploy
39+
```
4840

49-
This documentation repository is licensed under Apache 2.0. See LICENSE.txt for more details.
41+
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.

docs/STYLE.md

Lines changed: 0 additions & 412 deletions
This file was deleted.
Lines changed: 77 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,21 @@
1+
---
2+
title: Overview
3+
slug: /
4+
---
5+
6+
import Tabs from "@theme/Tabs";
7+
import TabItem from "@theme/TabItem";
8+
19
# SpacetimeDB Documentation
210

311
## Installation
412

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

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

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

13-
<button to="/docs/getting-started">Getting Started</button>
14-
1519
## What is SpacetimeDB?
1620

1721
SpacetimeDB is a database that is also a server.
@@ -21,11 +25,18 @@ SpacetimeDB is a full-featured relational database system that lets you run your
2125
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.
2226

2327
<figure>
24-
<img src="/images/basic-architecture-diagram.png" alt="SpacetimeDB Architecture" style="width:100%">
25-
<figcaption style="margin-top: 10px;" align="center">
26-
<b align="center">SpacetimeDB application architecture</b>
27-
<span style="font-size: 14px">(elements in white are provided by SpacetimeDB)</span>
28-
</figcaption>
28+
<img
29+
src="/images/basic-architecture-diagram.png"
30+
alt="SpacetimeDB Architecture"
31+
style={{ width: "100%" }}
32+
/>
33+
<figcaption style={{ marginTop: "10px", textAlign: "center" }} align="center">
34+
<b align="center">SpacetimeDB application architecture</b>
35+
<span style={{ fontSize: "14px" }}>
36+
{" "}
37+
(elements in white are provided by SpacetimeDB)
38+
</span>
39+
</figcaption>
2940
</figure>
3041

3142
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.
@@ -36,23 +47,6 @@ SpacetimeDB is optimized for maximum speed and minimum latency, rather than batc
3647

3748
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.
3849

39-
## Application Workflow Preview
40-
41-
<figure>
42-
<img src="/images/workflow-preview-diagram.png" alt="SpacetimeDB Application Workflow Preview" style="width:100%">
43-
<figcaption style="margin-top: 10px;" align="center">
44-
<b align="center">SpacetimeDB Application Workflow Preview</b>
45-
</figcaption>
46-
</figure>
47-
48-
49-
The above illustrates the workflow when using SpacetimeDB.
50-
51-
* All client-side reads happen with the data view that is cached locally.
52-
* 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.
53-
* RLS filters restrict the data view server-side before subscriptions are evaluated. These filters can be used for access control or client scoping.
54-
* 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.
55-
5650
## State Mirroring
5751

5852
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.
@@ -83,9 +77,11 @@ SpacetimeDB was designed first and foremost as the backend for multiplayer Unity
8377
## Key architectural concepts
8478

8579
### Host
80+
8681
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.
8782

8883
### Database
84+
8985
A SpacetimeDB **database** is an application that runs on a [host](#host).
9086

9187
A database exports [tables](#table), which store data, and [reducers](#reducer), which allow [clients](#client) to make requests.
@@ -95,8 +91,27 @@ A database's schema and business logic is specified by a piece of software calle
9591
(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.)
9692

9793
### Table
94+
9895
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:
9996

97+
<Tabs groupId="syntax" queryString>
98+
99+
<TabItem value="rust" label="Rust">
100+
101+
```rust
102+
#[spacetimedb::table(name = players, public)]
103+
pub struct Player {
104+
#[primary_key]
105+
id: u64,
106+
name: String,
107+
age: u32,
108+
user: Identity,
109+
}
110+
```
111+
112+
</TabItem>
113+
<TabItem value="csharp" label="C#">
114+
100115
```csharp
101116
[SpacetimeDB.Table(Name = "players", Public = true)]
102117
public partial struct Player
@@ -108,28 +123,23 @@ public partial struct Player
108123
Identity user;
109124
}
110125
```
111-
<!-- TODO: switchable language widget.
112-
```rust
113-
#[spacetimedb::table(name = players, public)]
114-
pub struct Player {
115-
#[primary_key]
116-
id: u64,
117-
name: String,
118-
age: u32,
119-
user: Identity,
120-
}
121-
```
122-
-->
126+
127+
</TabItem>
128+
129+
</Tabs>
123130

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

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

132-
:::server-rust
140+
<Tabs groupId="syntax" queryString>
141+
<TabItem value="rust" label="Rust">
142+
133143
A reducer can be written in Rust like so:
134144

135145
```rust
@@ -147,8 +157,10 @@ fn main() {
147157
ctx.reducers.set_player_name(57, "Marceline".into());
148158
}
149159
```
150-
:::
151-
:::server-csharp
160+
161+
</TabItem>
162+
<TabItem value="csharp" label="C#">
163+
152164
A reducer can be written in C# like so:
153165

154166
```csharp
@@ -167,7 +179,9 @@ void Main() {
167179
Connection.Reducer.SetPlayerName(57, "Marceline");
168180
}
169181
```
170-
:::
182+
183+
</TabItem>
184+
</Tabs>
171185

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

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

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

194-
:::server-rust
208+
<Tabs groupId="syntax" queryString>
209+
210+
<TabItem value="rust" label="Rust">
211+
195212
```rust
196213
#[spacetimedb::reducer]
197214
pub fn hello(ctx: &spacetimedb::ReducerContext) -> Result<(), String> {
@@ -202,14 +219,18 @@ pub fn hello(ctx: &spacetimedb::ReducerContext) -> Result<(), String> {
202219

203220
#[spacetimedb::reducer]
204221
pub fn world(ctx: &spacetimedb::ReducerContext) -> Result<(), String> {
205-
clear_all_tables(ctx);
222+
clear_all_tables(ctx);
206223
}
224+
207225
```
226+
208227
While SpacetimeDB doesn't support nested transactions,
209228
a reducer can [schedule another reducer](https://docs.rs/spacetimedb/latest/spacetimedb/attr.reducer.html#scheduled-reducers) to run at an interval,
210229
or at a specific time.
211-
:::
212-
:::server-csharp
230+
231+
</TabItem>
232+
<TabItem value="csharp" label="C#">
233+
213234
```csharp
214235
[SpacetimeDB.Reducer]
215236
public static void Hello(ReducerContext ctx)
@@ -227,13 +248,16 @@ public static void World(ReducerContext ctx)
227248
// ...
228249
}
229250
```
251+
230252
While SpacetimeDB doesn't support nested transactions,
231253
a reducer can [schedule another reducer](/docs/modules/c-sharp#scheduled-reducers) to run at an interval,
232254
or at a specific time.
233-
:::
234255

256+
</TabItem>
257+
</Tabs>
235258

236259
### Client
260+
237261
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).
238262

239263
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.
@@ -262,7 +286,7 @@ def identity_from_claims(issuer: str, subject: str) -> [u8; 32]:
262286
*id_hash
263287
])
264288
identity_big_endian_bytes: [u8; 32] = [
265-
0xC2,
289+
0xC2,
266290
0x00,
267291
*checksum_hash[:4],
268292
*id_hash
@@ -279,6 +303,7 @@ A `ConnectionId` identifies client connections to a SpacetimeDB database.
279303
A user has a single [`Identity`](#identity), but may open multiple connections to your database. Each of these will receive a unique `ConnectionId`.
280304

281305
### Energy
306+
282307
**Energy** is the currency used to pay for data storage and compute operations in a SpacetimeDB host.
283308

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

300-
5. How do I create a Unity game with SpacetimeDB?
325+
1. How do I create a Unity game with SpacetimeDB?
301326
Follow our [Unity Tutorial](/docs/unity) guide!
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
---
2+
slug: /getting-started
3+
---
4+
15
# Getting Started
26

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

0 commit comments

Comments
 (0)