Files
bradleyshep 7454329a08 Template README + template.json generation tool (#4570)
# Description of Changes

Adds `tools/templates/` scripts to derive template metadata from
manifests and generate READMEs from quickstart docs. Replaces slug-based
`builtWith` with manifest-derived data and hardcoded quickstart mappings
with discovery from docs.

**Manifest-based `builtWith`** (`update-template-jsons.ts`)

- Reads `package.json`, `Cargo.toml`, and `.csproj` to populate
`builtWith` in `.template.json`.
- Scoped npm packages normalize to scope (`@angular/core` → `angular`).
Excludes `@types/*`. Adds `nodejs` only for nodejs-ts when `@types/node`
is present.
- Root manifests processed before subdirs; primary framework first (e.g.
`react` before `spacetimedb` in react-ts). Dependencies reordered in
package.json where needed.

**Dynamic quickstart discovery** (`generate-template-readmes.ts`)

- Discovers template → quickstart by parsing `--template X` from files
in `docs/docs/00100-intro/00200-quickstarts/`.
- Optional `quickstart` override in `.template.json`; must resolve under
quickstarts dir.
- chat-react-ts has no quickstart; uses manual README.

**New:** `tools/templates/` (update-template-jsons.ts,
generate-template-readmes.ts, README, package.json, pnpm-lock).
**Modified:** all `templates/*/.template.json` (added `builtWith`),
new/generated `templates/*/README.md`.

# API and ABI breaking changes

None.

# Expected complexity level and risk

**1** – Dev tooling only. No runtime or API changes. Scripts are
isolated; failures only affect generated metadata and READMEs.

# Testing

- [ ] `cd tools/templates && pnpm run generate` completes without errors
- [ ] Spot-check `builtWith` and generated READMEs for a few templates
2026-03-20 13:01:58 +00:00

2.9 KiB

Get a SpacetimeDB C# app running in under 5 minutes.

Prerequisites

Install the SpacetimeDB CLI before continuing.


Install .NET WASI workload

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

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.

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.

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.

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