SSyncropel Docs

Your First Multi-Namespace Setup

Set up two isolated environments under one organization, write records into each and check that a child namespace can only narrow its parent. About 15 minutes.

What you'll learn

By the end of this tutorial you'll have:

  • Created an ORG-level namespace and two ENV-level children
  • Written records into each environment through the HTTP API
  • Confirmed that records from one environment can't accidentally claim the other's namespace
  • Triggered the 403 NAMESPACE_REJECTED error and recovered from it
  • Archived an environment and seen that new writes under it are blocked
  • Used spl debug replay to inspect records in a specific namespace

You'll need: a running spl serve (the Quickstart covers this), and curl. About 15 minutes.

If you skipped the Namespaces concept page, read its first three sections before you start. They explain the reasoning this tutorial demonstrates.

Step 1: confirm your workspace is healthy

spl doctor

You should see 7 PASS checks. If instance reachable fails, run spl serve first.

spl namespace list

On a fresh install this shows only default (the implicit root). That's the starting point.

Step 2: create the ORG

You'll set up a fictional company called "tutorial" with staging and prod environments under a web project.

spl namespace create tutorial --description "Tutorial walkthrough tenant"
✓ namespace 'tutorial' → active

Try creating a child without its project parent. You should get a clear refusal:

spl namespace create tutorial/web/staging
error: parent namespace 'tutorial/web' does not exist or is not Active.
  Create the parent first:
    spl namespace create tutorial/web

The CLI checks the parent first, so it catches this before anything is saved.

Step 3: build the tree

spl namespace create tutorial/web --description "Web project"
spl namespace create tutorial/web/staging --description "Staging environment"
spl namespace create tutorial/web/prod --description "Production environment"

Verify the structure:

spl namespace list
  ID                                  STATUS     LEVEL      DESCRIPTION
  default                             active     DEFAULT    System default namespace (implicit)
  tutorial                            active     ORG        Tutorial walkthrough tenant
  tutorial/web                        active     PROJECT    Web project
  tutorial/web/prod                   active     ENV        Production environment
  tutorial/web/staging                active     ENV        Staging environment

  4 explicit + 1 implicit (default)

Inspect the staging environment to see its full chain of ancestors:

spl namespace show tutorial/web/staging
Namespace: tutorial/web/staging
  Status:      active
  Level:       ENV
  Depth:       3
  Description: Staging environment

  Ancestor chain (root last):
    ✓ tutorial/web/staging
    ✓ tutorial/web
    ✓ tutorial
    ✓ default

Every ancestor is Active (✓). Records claiming tutorial/web/staging will be accepted.

Step 4: write your first namespace-scoped record

curl -X POST http://localhost:9100/v1/records \
  -H "Content-Type: application/json" \
  -d '{
    "act": "INTEND",
    "actor": "did:sync:user:tutorial",
    "thread": "th_tutorial_staging",
    "body": {
      "namespace": "tutorial/web/staging",
      "goal": "Deploy v1.0 to staging"
    },
    "clock": 0,
    "data_type": "VOID"
  }'

You should see a successful response with the new record ID:

{
  "object": "record",
  "id": "abc123...",
  "thread": "th_tutorial_staging",
  "actor": "did:sync:user:tutorial",
  "act": "INTEND",
  ...
}

Now write a follow-up DO record:

curl -X POST http://localhost:9100/v1/records \
  -H "Content-Type: application/json" \
  -d '{
    "act": "DO",
    "actor": "did:sync:user:tutorial",
    "thread": "th_tutorial_staging",
    "body": {
      "namespace": "tutorial/web/staging",
      "topic": "task_started",
      "action": "deploy"
    },
    "clock": 1,
    "data_type": "VOID"
  }'

Step 5: trigger the namespace rejection

Now try to write a record claiming a namespace that doesn't exist:

curl -X POST http://localhost:9100/v1/records \
  -H "Content-Type: application/json" \
  -d '{
    "act": "INTEND",
    "actor": "did:sync:user:tutorial",
    "thread": "th_tutorial_test",
    "body": {
      "namespace": "fake-corp",
      "goal": "should fail"
    },
    "clock": 0,
    "data_type": "VOID"
  }'

You should get a 403 with an error message that explains the fix:

{
  "object": "error",
  "type": "invalid_request_error",
  "code": "NAMESPACE_REJECTED",
  "message": "namespace 'fake-corp' rejected: ancestor 'fake-corp' is not Active in the registry. Create it first with `spl namespace create fake-corp`."
}

The error tells you exactly what's wrong and how to fix it. This is the narrowing rule in action: Syncropel checked each ancestor, found fake-corp missing, and refused the write.

Step 6: try a namespace you didn't create

Now try something more interesting. Write a record claiming tutorial/web/staging/job-99: a JOB-level namespace under your existing staging environment, but one you didn't create:

curl -X POST http://localhost:9100/v1/records \
  -H "Content-Type: application/json" \
  -d '{
    "act": "INTEND",
    "actor": "did:sync:user:tutorial",
    "thread": "th_tutorial_jobtest",
    "body": {
      "namespace": "tutorial/web/staging/job-99",
      "goal": "should also fail"
    },
    "clock": 0,
    "data_type": "VOID"
  }'
{
  "object": "error",
  "code": "NAMESPACE_REJECTED",
  "message": "namespace 'tutorial/web/staging/job-99' rejected: ancestor 'tutorial/web/staging/job-99' is not Active in the registry. Create it first with `spl namespace create tutorial/web/staging/job-99`."
}

This is important: a parent namespace doesn't automatically grant access to its descendants. Because tutorial/web/staging is Active doesn't mean any child namespace under it is allowed. Each namespace must be created explicitly. This makes namespaces a real boundary instead of a wildcard.

To allow job-99, create it:

spl namespace create tutorial/web/staging/job-99

Now retry the curl. It should succeed.

Step 7: archive an environment

Imagine staging is being retired. Archive it:

spl namespace archive tutorial/web/staging
✓ namespace 'tutorial/web/staging' → archived

Now any new write claiming tutorial/web/staging (or any descendant, including the job-99 you just created) is rejected:

curl -X POST http://localhost:9100/v1/records \
  -H "Content-Type: application/json" \
  -d '{
    "act": "INTEND",
    "actor": "did:sync:user:tutorial",
    "thread": "th_tutorial_postarchive",
    "body": {"namespace": "tutorial/web/staging", "goal": "should fail"},
    "clock": 0, "data_type": "VOID"
  }'
{
  "code": "NAMESPACE_REJECTED",
  "message": "namespace 'tutorial/web/staging' rejected: ancestor 'tutorial/web/staging' is not Active in the registry."
}

The descendant is rejected too:

curl -X POST http://localhost:9100/v1/records \
  -H "Content-Type: application/json" \
  -d '{
    "act": "INTEND",
    "actor": "did:sync:user:tutorial",
    "thread": "th_tutorial_postarchive2",
    "body": {"namespace": "tutorial/web/staging/job-99", "goal": "cascade test"},
    "clock": 0, "data_type": "VOID"
  }'
{
  "code": "NAMESPACE_REJECTED",
  "message": "namespace 'tutorial/web/staging/job-99' rejected: ancestor 'tutorial/web/staging' is not Active in the registry."
}

The error names tutorial/web/staging (the archived ancestor) as the failing link, not job-99 itself. The descendant inherits its parent's archived state instantly.

tutorial/web/prod is still fine because its ancestor chain (tutorial/web/prod → tutorial/web → tutorial → default) is still all Active. Try writing to it:

curl -X POST http://localhost:9100/v1/records \
  -H "Content-Type: application/json" \
  -d '{
    "act": "INTEND",
    "actor": "did:sync:user:tutorial",
    "thread": "th_tutorial_prod",
    "body": {"namespace": "tutorial/web/prod", "goal": "still works"},
    "clock": 0, "data_type": "VOID"
  }'

Success. Sibling environments are isolated: archiving staging doesn't touch prod.

Step 8: re-activate by re-creating

Need staging back? Re-create it:

spl namespace create tutorial/web/staging --description "Revived"
namespace 'tutorial/web/staging' already exists and is Active — overriding
✓ namespace 'tutorial/web/staging' → active

The CLI tells you it's overriding the prior state (which was Archived). The latest record for each namespace wins, so the new Active one replaces the Archived one.

Note: re-activating the parent does NOT re-activate descendants. If you also archive tutorial/web/staging/job-99 and want it back, you have to re-create it separately:

spl namespace show tutorial/web/staging/job-99
# Status: archived
spl namespace create tutorial/web/staging/job-99
# Now active

Step 9: inspect the records you just created

Use spl debug replay to see the records on the staging thread:

spl debug replay th_tutorial_staging
spl debug replay th_tutorial_staging

  CLOCK  ACT    ACTOR                               STATUS       BODY
      0  INTEND did:sync:user:tutorial              inbox        goal=Deploy v1.0 to staging
→     1  DO     did:sync:user:tutorial              active       topic=task_started

  Final status: active (2 records)

The replay walks the records in order and shows the status after each one. The → arrow marks status changes.

Step 10: clean up

When you're done with the tutorial, archive (or delete) the namespaces you created:

spl namespace archive tutorial/web/staging/job-99
spl namespace archive tutorial/web/staging
spl namespace archive tutorial/web/prod
spl namespace archive tutorial/web
spl namespace archive tutorial

Or, for a full cleanup (the audit trail is still kept):

spl namespace delete tutorial/web/staging/job-99
spl namespace delete tutorial/web/staging
spl namespace delete tutorial/web/prod
spl namespace delete tutorial/web
spl namespace delete tutorial

The records you wrote during the tutorial (in th_tutorial_staging, th_tutorial_prod, etc.) remain in your workspace. Archiving a namespace stops new writes but does not delete anything.

What you learned

In this tutorial you've used:

  1. Parent check. A child needs an Active parent, which catches typos.
  2. Explicit creation. Descendants don't get access automatically.
  3. Clear errors. Every rejection names the failing ancestor and the command to fix it.
  4. Archiving reaches down. Archiving a parent stops writes to everything under it immediately.
  5. Isolation between siblings. Archiving one environment doesn't touch the others.
  6. Re-activation. Re-creating a namespace brings it back, and the CLI tells you it is overriding.
  7. Inspection. spl namespace show shows the ancestors and spl debug replay shows the records.

For real setups, see the Namespaces guide, which covers rules scoped to namespaces, a checklist before turning on enforcement, and recovery.

Next steps

On this page