Skip to content
Merged
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
9 changes: 8 additions & 1 deletion templates/angular-ts/.template.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,12 @@
"description": "Angular web app with TypeScript server",
"client_framework": "Angular",
"client_lang": "typescript",
"server_lang": "typescript"
"server_lang": "typescript",
"builtWith": [
"angular",
"rxjs",
"tslib",
"typescript",
"spacetimedb"
]
}
117 changes: 117 additions & 0 deletions templates/angular-ts/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
Get a SpacetimeDB Angular app running in under 5 minutes.

## Prerequisites

- [Node.js](https://nodejs.org/) 18+ installed
- [SpacetimeDB CLI](https://spacetimedb.com/install) installed

Install the [SpacetimeDB CLI](https://spacetimedb.com/install) before continuing.

---

## Create your project

Run the `spacetime dev` command to create a new project with a SpacetimeDB module and Angular client.

This will start the local SpacetimeDB server, publish your module, generate TypeScript bindings, and start the Angular development server.

```bash
spacetime dev --template angular-ts
```



## Open your app

Navigate to [http://localhost:4200](http://localhost:4200) to see your app running.

The template includes a basic Angular app connected to SpacetimeDB.



## Explore the project structure

Your project contains both server and client code.

Edit `spacetimedb/src/index.ts` to add tables and reducers. Edit `src/app/app.component.ts` to build your UI.

```
my-spacetime-app/
├── spacetimedb/ # Your SpacetimeDB module
│ └── src/
│ └── index.ts # Server-side logic
├── src/ # Angular frontend
│ └── app/
│ ├── app.component.ts
│ ├── app.config.ts
│ └── module_bindings/ # Auto-generated types
├── angular.json
└── package.json
```



## Understand tables and reducers

Open `spacetimedb/src/index.ts` to see the module code. The template includes a `person` table and two reducers: `add` to insert a person, and `sayHello` to greet everyone.

Tables store your data. Reducers are functions that modify data — they're the only way to write to the database.

```typescript
import { schema, table, t } from 'spacetimedb/server';

const spacetimedb = schema({
person: table(
{ public: true },
{
name: t.string(),
}
),
});
export default spacetimedb;

export const add = spacetimedb.reducer(
{ name: t.string() },
(ctx, { name }) => {
ctx.db.person.insert({ name });
}
);

export const sayHello = spacetimedb.reducer(ctx => {
for (const person of ctx.db.person.iter()) {
console.info(`Hello, ${person.name}!`);
}
console.info('Hello, World!');
});
```



## Test with the CLI

Open a new terminal and navigate to your project directory. Then use the SpacetimeDB CLI to call reducers and query your data directly.

```bash
cd my-spacetime-app

# Call the add reducer to insert a person
spacetime call add Alice

# Query the person table
spacetime sql "SELECT * FROM person"
name
---------
"Alice"

# Call sayHello to greet everyone
spacetime call say_hello

# View the module logs
spacetime logs
2025-01-13T12:00:00.000000Z INFO: Hello, Alice!
2025-01-13T12:00:00.000000Z INFO: Hello, World!
```

## Next steps

- Read the [TypeScript SDK Reference](https://spacetimedb.com/docs/intro/core-concepts/clients/typescript-reference) for detailed API docs
5 changes: 4 additions & 1 deletion templates/basic-cpp/.template.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
{
"description": "A basic C++ server template with only stubs for code",
"server_lang": "cpp",
"client_lang": "rust"
"client_lang": "rust",
"builtWith": [
"spacetimedb-sdk"
]
}
118 changes: 118 additions & 0 deletions templates/basic-cpp/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
Get a SpacetimeDB C++ app running in under 5 minutes.

## Prerequisites

- [SpacetimeDB CLI](https://spacetimedb.com/install) installed
- [Emscripten SDK](https://emscripten.org/docs/getting_started/downloads.html) 4.0.21+ installed
- CMake 3.20+ and a make/ninja backend
- C++20 toolchain (host) — build targets WASM via Emscripten

After installing the SDK, run the appropriate `emsdk_env` script (PowerShell or Bash) so `emcc` and the CMake toolchain file are available on `PATH`.

Install the [SpacetimeDB CLI](https://spacetimedb.com/install) before continuing.

---

## Install Emscripten

Use the official SDK (see [Emscripten downloads](https://emscripten.org/docs/getting_started/downloads.html)) and activate the environment so `emcc` and the CMake toolchain file are on PATH. We recommend Emscripten 4.0.21+.

```bash
# From your emsdk directory (after downloading/cloning)
# Windows PowerShell
./emsdk install 4.0.21
./emsdk activate 4.0.21
./emsdk_env.ps1

# macOS/Linux
./emsdk install 4.0.21
./emsdk activate 4.0.21
source ./emsdk_env.sh
```



## Create your project

Use the CLI-managed workflow with `spacetime build`, which wraps CMake + `emcc` for you, starts the local server, builds/publishes your module, and generates client bindings.

```bash
spacetime dev --template basic-cpp
```


Need manual control? You can still drive CMake+emcc directly (see `spacetimedb/CMakeLists.txt`), but the recommended path is `spacetime build`/`spacetime dev`.





Server code lives in the `spacetimedb` folder; the template uses CMake and the SpacetimeDB C++ SDK.


```
my-spacetime-app/
├── spacetimedb/ # Your C++ module
│ ├── CMakeLists.txt
│ └── src/
│ └── lib.cpp # Server-side logic
├── Cargo.toml
└── src/
└── main.rs # Rust client application
```



## Understand tables and reducers

The template includes a `Person` table and two reducers: `add` to insert, `say_hello` to iterate and log.

```cpp
#include "spacetimedb.h"
using namespace SpacetimeDB;

struct Person { std::string name; };
SPACETIMEDB_STRUCT(Person, name)
SPACETIMEDB_TABLE(Person, person, Public)

SPACETIMEDB_REDUCER(add, ReducerContext ctx, std::string name) {
ctx.db[person].insert(Person{name});
return Ok();
}

SPACETIMEDB_REDUCER(say_hello, ReducerContext ctx) {
for (const auto& person : ctx.db[person]) {
LOG_INFO("Hello, " + person.name + "!");
}
LOG_INFO("Hello, World!");
return Ok();
}
```



## Test with the CLI

Open a new terminal and navigate to your project directory. Then call reducers and inspect data right from the CLI.

```bash
cd my-spacetime-app

# Insert a person
spacetime call add Alice

# Query the person table
spacetime sql "SELECT * FROM person"

# Call say_hello to greet everyone
spacetime call say_hello

# View the module logs
spacetime logs
```

## Notes

- To use a local SDK clone instead of the fetched archive, set `SPACETIMEDB_CPP_SDK_DIR` before running `spacetime dev`/`spacetime build`.
- The template builds to WebAssembly with exceptions disabled (`-fno-exceptions`).
- If `emcc` is not found, re-run the appropriate `emsdk_env` script to populate environment variables.
6 changes: 5 additions & 1 deletion templates/basic-cs/.template.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
{
"description": "A basic C# client and server template with only stubs for code",
"client_lang": "csharp",
"server_lang": "csharp"
"server_lang": "csharp",
"builtWith": [
"SpacetimeDB.ClientSDK",
"SpacetimeDB.Runtime"
]
}
117 changes: 117 additions & 0 deletions templates/basic-cs/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
Get a SpacetimeDB C# app running in under 5 minutes.

## Prerequisites

- [.NET 8 SDK](https://dotnet.microsoft.com/download/dotnet/8.0) installed
- [SpacetimeDB CLI](https://spacetimedb.com/install) installed

Install the [SpacetimeDB CLI](https://spacetimedb.com/install) before continuing.

---

## Install .NET WASI workload

SpacetimeDB C# modules compile to WebAssembly using the WASI experimental workload.

```bash
dotnet workload install wasi-experimental
```



## Create your project

Run the `spacetime dev` command to create a new project with a C# SpacetimeDB module.

This will start the local SpacetimeDB server, compile and publish your module, and generate C# client bindings.

```bash
spacetime dev --template basic-cs
```



## Explore the project structure

Your project contains both server and client code.

Edit `spacetimedb/Lib.cs` to add tables and reducers. Use the generated bindings in the client project.

```
my-spacetime-app/
├── spacetimedb/ # Your SpacetimeDB module
│ ├── StdbModule.csproj
│ └── Lib.cs # Server-side logic
├── client.csproj
├── Program.cs # Client application
└── module_bindings/ # Auto-generated types
```



## Understand tables and reducers

Open `spacetimedb/Lib.cs` to see the module code. The template includes a `Person` table and two reducers: `Add` to insert a person, and `SayHello` to greet everyone.

Tables store your data. Reducers are functions that modify data — they're the only way to write to the database.

```csharp
using SpacetimeDB;

public static partial class Module
{
[SpacetimeDB.Table(Accessor = "Person", Public = true)]
public partial struct Person
{
public string Name;
}

[SpacetimeDB.Reducer]
public static void Add(ReducerContext ctx, string name)
{
ctx.Db.Person.Insert(new Person { Name = name });
}

[SpacetimeDB.Reducer]
public static void SayHello(ReducerContext ctx)
{
foreach (var person in ctx.Db.Person.Iter())
{
Log.Info($"Hello, {person.Name}!");
}
Log.Info("Hello, World!");
}
}
```



## Test with the CLI

Open a new terminal and navigate to your project directory. Then use the SpacetimeDB CLI to call reducers and query your data directly.

```bash
cd my-spacetime-app

# Call the add reducer to insert a person
spacetime call add Alice

# Query the person table
spacetime sql "SELECT * FROM Person"
name
---------
"Alice"

# Call say_hello to greet everyone
spacetime call say_hello

# View the module logs
spacetime logs
2025-01-13T12:00:00.000000Z INFO: Hello, Alice!
2025-01-13T12:00:00.000000Z INFO: Hello, World!
```

## Next steps

- See the [Chat App Tutorial](https://spacetimedb.com/docs/intro/tutorials/chat-app) for a complete example
- Read the [C# SDK Reference](https://spacetimedb.com/docs/intro/core-concepts/clients/csharp-reference) for detailed API docs
Loading
Loading