docs/docs/00200-core-concepts/00100-databases/00200-spacetime-dev.md
import Tabs from '@theme/Tabs'; import TabItem from '@theme/TabItem'; import { CppModuleVersionNotice } from "@site/src/components/CppModuleVersionNotice";
spacetime devThis guide covers how to create a new SpacetimeDB database module project.
First, install the SpacetimeDB CLI.
spacetime devThe fastest way to get started developing a database module is with spacetime dev. This interactive command guides you through creating a new SpacetimeDB project with hot-reloading - whenever you save changes to your module code, SpacetimeDB automatically rebuilds and republishes your module.
:::caution
spacetime dev is currently an unstable command and may change in the future.
:::
Run the command from your terminal:
spacetime dev
First Time Setup
If no SpacetimeDB project is found in the current directory, you'll be guided through creating a new one:
Step 1: Project Name
Enter a name for your project (e.g., my-project)
Step 2: Project Path
Choose where to create the project files (defaults to ./<project-name>)
Step 3: Select a Client Type Choose how you want to develop:
Existing Projects
If you run spacetime dev in a directory with an existing SpacetimeDB project (containing a spacetimedb/ directory), it will skip setup and enter development mode directly, connecting to your database and watching for file changes.
Creates a full-stack React web application with:
Choose from several built-in templates:
basic-ts - Basic TypeScript client and server stubsbasic-cs - Basic C# client and server stubsbasic-rs - Basic Rust client and server stubsbasic-cpp - Basic C++ server stubsreact-ts - React web app with TypeScript serverchat-console-rs - Complete Rust chat implementationchat-console-cs - Complete C# chat implementationchat-react-ts - Complete TypeScript chat implementationYou can also clone an existing project by entering a GitHub repository (owner/repo) or git URL.
Creates a server module only, without any client code. You'll choose your server language:
The server code will be created in a spacetimedb/ subdirectory within your project.
After completing setup, spacetime dev:
Your database will be available at https://maincloud.spacetimedb.com.
spacetime dev can automatically run your client's development server alongside the SpacetimeDB module. This is configured via the spacetime.json file in your project root:
{
"dev": {
"run": "npm run dev"
}
}
The client command can be:
spacetime.jsonspacetime dev --run "yarn dev"spacetime dev --server-onlyWhen you run spacetime init with a client template, a default client command is automatically configured in spacetime.json based on your project type.
After initialization, your project will contain:
<Tabs groupId="server-language" queryString> <TabItem value="typescript" label="TypeScript">my-project/
├── spacetimedb/ # Server module code
│ ├── package.json
│ ├── tsconfig.json
│ └── src/
│ └── index.ts
├── src/ # Client code
│ └── module_bindings/ # Generated client bindings
├── package.json
├── tsconfig.json
├── spacetime.json # SpacetimeDB configuration
└── README.md
my-project/
├── spacetimedb/ # Server module code
│ ├── StdbModule.csproj
│ └── Lib.cs
├── module_bindings/ # Generated client bindings
├── client.csproj
├── Program.cs
├── spacetime.json # SpacetimeDB configuration
└── README.md
my-project/
├── spacetimedb/ # Server module code
│ ├── Cargo.toml
│ └── src/
│ └── lib.rs
├── src/ # Client code
│ └── module_bindings/ # Generated client bindings
├── Cargo.toml
├── spacetime.json # SpacetimeDB configuration
├── .gitignore
└── README.md
my-project/
├── spacetimedb/ # Server module code (C++)
│ ├── CMakeLists.txt
│ └── src/
│ └── lib.cpp
└── README.md
If you prefer more control over the development workflow, you can create a database module project manually and use the standard build and publish workflow.
spacetime initspacetime init --lang typescript --project-path ./my-project my-project
cd my-project
This creates a new TypeScript project with:
package.json configured for SpacetimeDBsrc/index.ts with a sample modulespacetime init --lang csharp --project-path ./my-project my-project
cd my-project
This creates a new C# project with:
StdbModule.csproj configured for SpacetimeDBLib.cs with a sample modulespacetime init --lang rust --project-path ./my-project my-project
cd my-project
This creates a new Rust project with:
Cargo.toml configured for SpacetimeDBsrc/lib.rs with a sample modulespacetime init --lang cpp --project-path ./my-project my-project
cd my-project
This creates a new C++ project with:
CMakeLists.txt configured for SpacetimeDBsrc/lib.cpp with a sample moduleAfter creating your database module: