Bento Spaces docs

Bento Spaces documentation

Storage

Everything is JSON files on disk. No database. Writes are atomic: temp file, then rename.

The split that matters

App_Data/
  private/                          ← never synced, never exported, never published
    api-tokens/{hash}.json          ← SHA-256 hashes of personal API tokens
    pairing/{code}.json             ← one-time bridge pairing codes (ten minutes)
    health/{userId}.json            ← cached connector health, pruned to live connectors
    push/vapid.json                 ← self-hosted VAPID private/public key pair
    push/subscriptions/{userId}.json ← browser push endpoints and their keys
    push/outbox.json                ← fake transport only (disposable storage)
    billing/checkouts/{token}.json  ← short-lived, user-bound checkout tokens
    billing/events/{eventId}.json   ← idempotent provider event receipts
    reports/{reportId}.json         ← operator-only reader reports
    users/{userId}/
      account.json                  ← username, pbkdf2 hash, plan, created
      views/{viewId}.json           ← hashed view token, space, idle policy, PIN hash
    sessions/{tokenHash}.json
    throttles.json
  data/                             ← safe to point at a synced folder (iCloud/Dropbox/OneDrive)
    config/
      default-widgets.json          ← operator defaults for new accounts (/manage)
    publishers/
      handles.json                  ← global publisher handle index
      {userId}/
        profile.json                ← handle, display name, bio, tier
        feedback/{threadId}.json    ← user messages and developer replies
        widgets/{widgetHandle}/
          icon.png                  ← optional 1:1 artwork (png/jpeg/webp)
          draft.json                ← mutable Studio draft
          releases/{version}/       ← immutable manifest + hash/meta
    users/{userId}/
      workspaces.json               ← dock: order, name, letter, colour, wallpaper, widgetTint
      registries.json               ← widget sources (URL + name)
      notifications.json            ← per-user feed, capped at 100
      notification-settings.json    ← muted notification groups
      widgets/                      ← the library
        library.json                ← built-ins this account removed
        installed.json              ← downloaded widgets (hash-pinned)
        {widgetId}/{version}/manifest.json
        settings/{widgetId}.json    ← shared defaults for that type (never secrets)
      spaces/
        widgets/{instanceId}.json   ← one instance's type, version, props — no space
        trash/{instanceId}.json     ← removed placement, kept 7 days for undo
        {spaceId}/
          layout.json               ← positions and which instance fills each container
          wallpaper.jpg

Rule: if a file can leak a person's data, it lives in private/. data/ must be safe to hand to any sync client without thinking.

Instances are not owned by a space

A widget's values live once per account, outside every space:

spaces/widgets/{instanceId}.json     values: type, version, props
spaces/{spaceId}/layout.json         placement: x, y, w, h and the instance id

container.id is the instance id when a container is filled; an empty container has an id and no instance file. This is what makes moving a widget between spaces cheap:

POST /api/spaces/{from}/widgets/{instanceId}/move { "toSpaceId": "…", "x": 6, "y": 2 }
  1. remove the container from {from}/layout.json (rev + 1)
  2. add it to {to}/layout.json at the requested position (rev + 1)
  3. the instance file is untouched, so every prop moves with it
  4. widgets/settings/{widgetId}.json is account-wide and also untouched

The target is written first, so a crash can leave a duplicate reference but never a lost widget. copy creates a new instance id and clones the props; two spaces never share one instance. An instance id should appear in exactly one layout at a time.

Because instance files are global:

GET /api/spaces/{id} always returns layout joined with its instances; a placement whose type is neither built in nor installed comes back with missing: true so the shelf can show "Widget removed — reinstall to restore" instead of an empty box. Export and share use the same joined document; a raw layout.json is never self-contained.

File shapes

// data/…/spaces/{spaceId}/layout.json  — positions only, no widget identity
{
  "schemaVersion": 3,
  "shelfUnits": 4,
  "rev": 12,
  "containers": [
    { "id": "c_7f3a", "x": 0, "y": 0, "w": 2, "h": 2, "group": "g_1" },
    { "id": "c_91bd", "x": 2, "y": 0, "w": 2, "h": 3 }
  ]
}
// data/…/spaces/widgets/{instanceId}.json — what lives there, never where
{
  "schemaVersion": 1,
  "type": "clock",
  "version": "1.2.0",
  "props": { "tz": "Europe/Malta" },
  "vars": { "token": "{{var:crmToken}}" },
  "rev": 4
}
// data/…/widgets/settings/{widgetId}.json — defaults shared by every instance
{
  "settingsVersion": 1,
  "values": { "connectorId": "c_51ee…" },
  "updatedAt": "2026-11-26T15:25:40Z"
}

Resolution order is instance props > common values > manifest defaults. An instance always wins, so two Gree widgets can share a connector default and still point at different rooms. Secrets never appear here: a connector is referenced by id, its token lives in private/secrets/.

// data/…/spaces/trash/{instanceId}.json — undo after "Remove widget"
{
  "instance": { "type": "clock", "version": "1.2.0", "props": {…}, "rev": 3 },
  "container": { "id": "c_7f3a", "x": 0, "y": 0, "w": 2, "h": 2 },
  "spaceId": "…",
  "deletedAt": "2026-11-26T16:00:00Z"
}
// private/…/views/{viewId}.json — a shared link or a paired display
{
  "id": "9f2c…",
  "spaceId": "s_work",
  "tokenHash": "sha256…",
  "idle": "60s",
  "wake": "pin",
  "actions": false,
  "display": false,
  "pinHash": "…",
  "createdAt": "2026-11-25T09:00:00Z",
  "lastOpenedAt": "2026-11-25T09:04:00Z",
  "revokedAt": null
}
// display: true → read-only pairing, no PIN, 30-day session, /display/{token}

Invariants

  1. One owner of geometry. Position and size live only in layout.json.
  2. One owner of identity. type, version, props live only in the instance file.
  3. One owner of secrets. Only private/ holds credentials; data/ never does.
  4. Join key is the container id, and a filled container's id is its instance id. A container
  5. without an instance file is empty. An instance file referenced by no layout is an orphan:
  6. ignored on load and trashed after a grace period (only uninstall deliberately leaves them).
  7. One home per instance. An instance id belongs to one layout at a time. Moving it changes
  8. ownership by editing two layouts; it never copies or rewrites the values.
  9. Two revisions per space: layout.rev and each instance file's own rev. Editing a
  10. position never conflicts with editing a prop.
  11. Square invariant: every container satisfies
  12. floor(x/4) === floor((x+w−1)/4) and y+h <= 4.
  13. Ids: c_ + 12 hex for containers, u + base32 uuid for users, uuid for spaces and
  14. views and tokens. Ids are validated against ^[a-z0-9_]{3,40}$ before they touch a path.

Concurrency and sync

Sizes and limits

ThingLimit
layout.json64 KB (a 100-block space is ~8 KB)
widget instance16 KB
common widget settings16 KB
wallpaper2 MB per space, jpg/webp only
request body (JSON APIs)64 KB

Where App_Data lives in production

publish.sh replaces published/ wholesale, so production must point Storage:Root at a folder outside it (for example D:\bento-data). Locally, published/App_Data is disposable. Archives exclude App_Data/** either way.

Backups

Publishers and releases

A publisher handle is permanent and names a developer registry. A widget handle is unique inside that publisher, so the install id is <publisher>--<widget> (for example ren--weather). Built-in ids stay reserved; legacy registry ids keep working unchanged.

A release directory is never edited. Publishing validates the draft, injects the qualified id and developer, hashes the exact JSON bytes into meta.json, and refuses a version that already exists or is lower than the latest. Test installs copy a release into the developer's own installed.json; the personal and market registries are read models over these directories.

The default library

data/config/default-widgets.json is operator data, not a user preference:

{ "schemaVersion": 1, "widgets": ["clock", "note", "weather"] }

widgets/library.json is created lazily for existing accounts with {"disabled": []}, so the first read after an upgrade keeps everything enabled. That write also marks the account as migrated: a later default change cannot retroactively hide widgets.

Migration from per-space widget files

Before the account-level instance store, values lived at spaces/{spaceId}/widgets/{containerId}.json. Container ids are already instance ids, so the move needs no layout rewrite:

node scripts/migrate-storage-v2.mjs --user <userId> --dry-run   # counts only
node scripts/migrate-storage-v2.mjs --user <userId>             # move + create gree settings

The script backs nothing up itself — copy App_Data first. It also seeds widgets/settings/gree.json from the first Gree instance's connectorId; instance props stay in place and still win.

The server reads legacy files too: the first read of an instance writes it to the new path and deletes the old one, so a half-migrated folder keeps working.

Test storage root

Browser suites and smoke tests register real accounts. Point them at a disposable root so they never fill the live App_Data:

Storage__Root="$TMPDIR/bento-tests" dotnet run --project source/Bento.Api --urls http://127.0.0.1:5080

scripts/dev-test.sh starts exactly that. The browser suites import scripts/e2e/_guard.mjs and refuse a non-temporary root (/api/health reports test: true only then); BENTO_ALLOW_REAL=1 overrides it. scripts/cleanup-accounts.mjs --keep <userId> prunes stray accounts.