MCPcopy Index your code
hub / github.com/clockworklabs/SpacetimeDB

github.com/clockworklabs/SpacetimeDB @v2.7.0-hotfix1

Chat with this repo
repository ↗ · DeepWiki ↗ · release v2.7.0-hotfix1 ↗ · + Follow
37,009 symbols 107,053 edges 3,972 files 6,815 documented · 18% 1 cross-repo links
What it actually does AI analysis from the code graph — generated when you open this
loading…
README
<a href="https://spacetimedb.com#gh-dark-mode-only" target="_blank">
<img width="320" src="https://github.com/clockworklabs/SpacetimeDB/raw/v2.7.0-hotfix1/images/dark/logo.svg" alt="SpacetimeDB Logo">
</a>
<a href="https://spacetimedb.com#gh-light-mode-only" target="_blank">
<img width="320" src="https://github.com/clockworklabs/SpacetimeDB/raw/v2.7.0-hotfix1/images/light/logo.svg" alt="SpacetimeDB Logo">
</a>






<a href="https://spacetimedb.com#gh-dark-mode-only" target="_blank">
    <img width="250" src="https://github.com/clockworklabs/SpacetimeDB/raw/v2.7.0-hotfix1/images/dark/logo-text.svg" alt="SpacetimeDB">
</a>
<a href="https://spacetimedb.com#gh-light-mode-only" target="_blank">
    <img width="250" src="https://github.com/clockworklabs/SpacetimeDB/raw/v2.7.0-hotfix1/images/light/logo-text.svg" alt="SpacetimeDB">
</a>
<h3 align="center">
    Development at the speed of light.
</h3>






<a href="https://github.com/clockworklabs/spacetimedb"><img src="https://img.shields.io/github/v/release/clockworklabs/spacetimedb?color=%23ff00a0&include_prereleases&label=version&sort=semver&style=flat-square"></a>
&nbsp;
<a href="https://github.com/clockworklabs/spacetimedb"><img src="https://img.shields.io/badge/built_with-Rust-dca282.svg?style=flat-square"></a>
&nbsp;
<a href="https://github.com/clockworklabs/spacetimedb/actions"><img src="https://img.shields.io/github/actions/workflow/status/clockworklabs/spacetimedb/ci.yml?style=flat-square&branch=master"></a>
&nbsp;
<a href="https://status.spacetimedb.com"><img src="https://img.shields.io/uptimerobot/ratio/7/m784409192-e472ca350bb615372ededed7?label=cloud%20uptime&style=flat-square"></a>
&nbsp;
<a href="https://hub.docker.com/r/clockworklabs/spacetimedb"><img src="https://img.shields.io/docker/pulls/clockworklabs/spacetimedb?style=flat-square"></a>
&nbsp;
<a href="https://github.com/clockworklabs/spacetimedb/blob/master/LICENSE.txt"><img src="https://img.shields.io/badge/license-BSL_1.1-00bfff.svg?style=flat-square"></a>






<a href="https://crates.io/crates/spacetimedb"><img src="https://img.shields.io/crates/d/spacetimedb?color=e45928&label=Rust%20Crate&style=flat-square"></a>
&nbsp;
<a href="https://www.nuget.org/packages/SpacetimeDB.Runtime"><img src="https://img.shields.io/nuget/dt/spacetimedb.runtime?color=0b6cff&label=NuGet%20Package&style=flat-square"></a>
&nbsp;
<a href="https://www.npmjs.com/package/spacetimedb"><img src="https://img.shields.io/npm/dm/spacetimedb?color=cb0000&label=npm&style=flat-square"></a>






<a href="https://discord.gg/spacetimedb"><img src="https://img.shields.io/discord/1037340874172014652?label=discord&style=flat-square&color=5a66f6"></a>
&nbsp;
<a href="https://twitter.com/spacetime_db"><img src="https://img.shields.io/badge/twitter-Follow_us-1d9bf0.svg?style=flat-square"></a>
&nbsp;
<a href="https://clockworklabs.io/join"><img src="https://img.shields.io/badge/careers-Join_us-86f7b7.svg?style=flat-square"></a>
&nbsp;
<a href="https://www.linkedin.com/company/clockworklabs/"><img src="https://img.shields.io/badge/linkedin-Connect_with_us-0a66c2.svg?style=flat-square"></a>







<a href="https://discord.gg/spacetimedb"><img height="25" src="https://github.com/clockworklabs/SpacetimeDB/raw/v2.7.0-hotfix1/images/social/discord.svg" alt="Discord"></a>
&nbsp;
<a href="https://twitter.com/spacetime_db"><img height="25" src="https://github.com/clockworklabs/SpacetimeDB/raw/v2.7.0-hotfix1/images/social/twitter.svg" alt="Twitter"></a>
&nbsp;
<a href="https://github.com/clockworklabs/spacetimedb"><img height="25" src="https://github.com/clockworklabs/SpacetimeDB/raw/v2.7.0-hotfix1/images/social/github.svg" alt="GitHub"></a>
&nbsp;
<a href="https://twitch.tv/SpacetimeDB"><img height="25" src="https://github.com/clockworklabs/SpacetimeDB/raw/v2.7.0-hotfix1/images/social/twitch.svg" alt="Twitch"></a>
&nbsp;
<a href="https://youtube.com/@SpacetimeDB"><img height="25" src="https://github.com/clockworklabs/SpacetimeDB/raw/v2.7.0-hotfix1/images/social/youtube.svg" alt="YouTube"></a>
&nbsp;
<a href="https://www.linkedin.com/company/clockwork-labs/"><img height="25" src="https://github.com/clockworklabs/SpacetimeDB/raw/v2.7.0-hotfix1/images/social/linkedin.svg" alt="LinkedIn"></a>
&nbsp;
<a href="https://stackoverflow.com/questions/tagged/spacetimedb"><img height="25" src="https://github.com/clockworklabs/SpacetimeDB/raw/v2.7.0-hotfix1/images/social/stackoverflow.svg" alt="StackOverflow"></a>

What is SpacetimeDB?

SpacetimeDB is a relational database that is also a server. You upload your application logic directly into the database, and clients connect to it without any server in between.

Write your schema and business logic as a module in Rust, C#, TypeScript, or C++. SpacetimeDB compiles it, runs it inside the database, and automatically synchronizes state to connected clients in real-time.

Instead of deploying a web or game server that sits in between your clients and your database, your clients connect directly to the database and execute your application logic in your module. You can write all of your permission and authorization logic right inside your module just as you would in a normal server.

This means that you can write your entire application in a single language and deploy it as a single binary. No more separate webserver, no more containers, no more Kubernetes, no more VMs, no more DevOps, no more caching later. Zero infrastructure to manage.

SpacetimeDB Architecture
SpacetimeDB application architecture (elements in white are provided by SpacetimeDB)

SpacetimeDB is optimized for maximum speed and minimum latency. SpacetimeDB provides all the ACID guarantees of a traditional RDBMS, with all the speed of an optimized web server. All application state is held in memory for fast access, while a commit log on disk provides durability and crash recovery. The entire backend of our MMORPG BitCraft Online runs as a single SpacetimeDB module: chat, items, terrain, player positions, everything, synchronized to thousands of players in real-time.

Quick Start

1. Install

# macOS / Linux
curl -sSf https://install.spacetimedb.com | sh

# Windows (PowerShell)
iwr https://windows.spacetimedb.com -useb | iex

2. Log in

spacetime login

This opens a browser to authenticate with GitHub. Your identity is linked to your account so you can publish databases.

3. Start developing

spacetime dev --template chat-react-ts

That is it. This creates a project from a template, publishes it to Maincloud, and watches for file changes, automatically rebuilding and republishing on save. See pricing for details.

How It Works

SpacetimeDB modules define tables (your data) and reducers (your logic). Clients connect, call reducers, and subscribe to tables. When data changes, SpacetimeDB pushes updates to subscribed clients automatically.

// Define a table
#[spacetimedb::table(accessor = messages, public)]
pub struct Message {
    #[primary_key]
    #[auto_inc]
    id: u64,
    sender: Identity,
    text: String,
}

// Define a reducer (your API endpoint)
#[spacetimedb::reducer]
pub fn send_message(ctx: &ReducerContext, text: String) {
    ctx.db.messages().insert(Message {
        id: 0,
        sender: ctx.sender,
        text,
    });
}

On the client side, subscribe and get live updates:

const [messages] = useTable(tables.message);
// messages updates automatically when the server state changes.
// No polling. No refetching.

Language Support

Server Modules

Write your database logic in any of these languages:

Language Quickstart
Rust Get started
C# Get started
TypeScript Get started
C++ Get started

Client SDKs

Connect from any of these platforms:

SDK Quickstart
TypeScript (React, Next.js, Vue, Svelte, Angular, Node.js, Bun, Deno) Get started
Rust Get started
C# (standalone and Unity) Get started
C++ (Unreal Engine) Get started

Running with Docker

docker run --rm --pull always -p 3000:3000 clockworklabs/spacetime start

Building from Source

If you need features from master that have not been released yet:

# Prerequisites: Rust toolchain with wasm32-unknown-unknown target
curl https://sh.rustup.rs -sSf | sh

git clone https://github.com/clockworklabs/SpacetimeDB
cd SpacetimeDB
cargo build --locked --release -p spacetimedb-standalone -p spacetimedb-update -p spacetimedb-cli

Then install the binaries:

macOS / Linux

mkdir -p ~/.local/bin
STDB_VERSION="$(./target/release/spacetimedb-cli --version | sed -n 's/.*spacetimedb tool version \([0-9.]*\);.*/\1/p')"
mkdir -p ~/.local/share/spacetime/bin/$STDB_VERSION

cp target/release/spacetimedb-update ~/.local/bin/spacetime
cp target/release/spacetimedb-cli ~/.local/share/spacetime/bin/$STDB_VERSION
cp target/release/spacetimedb-standalone ~/.local/share/spacetime/bin/$STDB_VERSION

# Add to your shell config if not already present:
export PATH="$HOME/.local/bin:$PATH"

# Set the active version:
spacetime version use $STDB_VERSION

Windows (PowerShell)

$stdbDir = "$HOME\AppData\Local\SpacetimeDB"
$stdbVersion = & ".\target\release\spacetimedb-cli" --version |
    Select-String -Pattern 'spacetimedb tool version ([0-9.]+);' |
    ForEach-Object { $_.Matches.Groups[1].Value }
New-Item -ItemType Directory -Path "$stdbDir\bin\$stdbVersion" -Force | Out-Null

Copy-Item "target\release\spacetimedb-update.exe" "$stdbDir\spacetime.exe"
Copy-Item "target\release\spacetimedb-cli.exe" "$stdbDir\bin\$stdbVersion\"
Copy-Item "target\release\spacetimedb-standalone.exe" "$stdbDir\bin\$stdbVersion\"

# Add to your system PATH: %USERPROFILE%\AppData\Local\SpacetimeDB
# Then in a new shell:
spacetime version use $stdbVersion

Verify with spacetime --version.

Documentation

Full documentation is available at spacetimedb.com/docs, including:

License

SpacetimeDB is licensed under the Business Source License 1.1 (BSL). It converts to the AGPL v3.0 with a linking exception after a few years. The linking exception means you are not required to open-source your own code if you use SpacetimeDB. You only need to contribute back changes to SpacetimeDB itself.

Why did we choose this license? We chose to license SpacetimeDB under the MariaDB Business Source License for 4 years because we can't compete with AWS while also building our products for them.

We chose GPLv3 with linking exception as the open source license because we want contributions merged back into mainline (just like Linux), but we don't want to make anyone else open source their own code (i.e. linking exception).

Extension points exported contracts — how you extend this code

InModule (Interface)
Marker trait for any item defined in a module, to conveniently get the types of various per-module things. [591 implementers]
sdks/rust/src/spacetime_module.rs
CanBeLookupTable (Interface)
Marker trait for tables that can appear as the right/inner/lookup table in a semi-join. Event tables do NOT implement th [6 …
crates/query-builder/src/table.rs
ToProtocol (Interface)
A server-to-client message which can be encoded according to a [`Protocol`], resulting in a [`ToProtocol::Encoded`] mess [9 …
crates/core/src/client/messages.rs
KeySize (Interface)
Index keys whose memory usage we can measure and report. The reported memory usage of an index is based on: - the numb [10 …
crates/table/src/table_index/key_size.rs
MemoryUsage (Interface)
For inspecting how much memory a value is using. This trait specifically measures heap memory. If you want to measure s [126 …
crates/memory-usage/src/lib.rs
Encode (Interface)
A **datatype** which can be encoded. The transaction payload of the commitlog (i.e. individual records in the log) must [7 …
crates/commitlog/src/payload.rs
PrimaryKeyable (Interface)
* Interface for types that can be converted into a column builder with primary key metadata. * * Implementing this int [40 …
crates/bindings-typescript/src/lib/type_builders.ts
DbContext (Interface)
A handle on a database with a particular table schema. [28 implementers]
crates/bindings/src/lib.rs

Core symbols most depended-on inside this repo

new
called by 4195
crates/schema/src/identifier.rs
Ok
called by 3242
crates/bindings-cpp/include/spacetimedb/outcome.h
unwrap
called by 2532
crates/expr/src/expr.rs
map
called by 1826
crates/sats/src/lib.rs
insert
called by 1634
crates/bindings-typescript/src/lib/table.ts
iter
called by 1282
crates/bindings-typescript/src/lib/table.ts
to_string
called by 1018
crates/bindings-cpp/include/spacetimedb/bsatn/uuid.h
filter
called by 877
crates/bindings-typescript/src/lib/indexes.ts

Shape

Method 16,392
Function 11,372
Class 7,610
Interface 1,090
Enum 545

Languages

Rust46%
C++30%
C#15%
TypeScript8%
Python1%
C1%

Modules by API surface

sdks/unreal/tests/TestClient/Source/TestClient/Public/ModuleBindings/SpacetimeDBClient.g.h2,177 symbols
sdks/unreal/tests/TestClient/Source/TestClient/Private/ModuleBindings/SpacetimeDBClient.g.cpp1,011 symbols
crates/bindings-typescript/src/lib/type_builders.ts455 symbols
crates/bindings-csharp/Codegen.Tests/fixtures/diag/snapshots/Module#FFI.verified.cs345 symbols
modules/sdk-test-cs/Lib.cs314 symbols
crates/bindings-csharp/Codegen.Tests/fixtures/server/snapshots/Module#FFI.verified.cs258 symbols
crates/engine/src/relational_db.rs221 symbols
crates/core/src/host/module_host.rs181 symbols
crates/datastore/src/locking_tx_datastore/datastore.rs173 symbols
sdks/unreal/tests/TestProcClient/Source/TestProcClient/Public/ModuleBindings/SpacetimeDBClient.g.h162 symbols
sdks/unreal/tests/TestViewPkClient/Source/TestViewPkClient/Public/ModuleBindings/SpacetimeDBClient.g.h155 symbols
crates/datastore/src/locking_tx_datastore/mut_tx.rs155 symbols

Used by 1 indexed graphs manifest dependencies, hub-wide

Datastores touched

chat-appDatabase · 1 repos
spacetimeDatabase · 1 repos
TestSpaceDatabase · 1 repos
postgresDatabase · 1 repos

For agents

$ claude mcp add SpacetimeDB \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact