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 }
- remove the container from
{from}/layout.json(rev + 1) - add it to
{to}/layout.jsonat the requested position (rev + 1) - the instance file is untouched, so every prop moves with it
widgets/settings/{widgetId}.jsonis 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:
- Duplicate space must deep-copy: new instance ids, new files.
- Delete space removes the containers, then trashes each of their instances.
- Uninstall a widget type deletes only
widgets/{widgetId}/{version}/…and its installed.jsonentry. Every instance stays, in every space, so reinstalling restores them.- Uninstall a built-in only adds its id to
widgets/library.json → disabled. The code - ships with the client and never moves; its placements still show the restore placeholder, and
- installing it again removes the id from that list. Removing every built-in is allowed.
- Remove from space moves the instance to
spaces/trash/and removes the container. Undo - (client-side) writes the instance back. Trash is pruned after 7 days.
- Forget a type's settings is a separate, explicit action; it is not part of uninstall.
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
- One owner of geometry. Position and size live only in
layout.json. - One owner of identity.
type,version,propslive only in the instance file. - One owner of secrets. Only
private/holds credentials;data/never does. - Join key is the container id, and a filled container's id is its instance id. A container
- without an instance file is empty. An instance file referenced by no layout is an orphan:
- ignored on load and trashed after a grace period (only uninstall deliberately leaves them).
- One home per instance. An instance id belongs to one layout at a time. Moving it changes
- ownership by editing two layouts; it never copies or rewrites the values.
- Two revisions per space:
layout.revand each instance file's ownrev. Editing a - position never conflicts with editing a prop.
- Square invariant: every container satisfies
floor(x/4) === floor((x+w−1)/4)andy+h <= 4.- Ids:
c_+ 12 hex for containers,u+ base32 uuid for users, uuid for spaces and - views and tokens. Ids are validated against
^[a-z0-9_]{3,40}$before they touch a path.
Concurrency and sync
- Writes:
File.WriteAllText(tmp)→File.Move(tmp, target, overwrite: true). A rolling .prevcopy is kept per file.- Requests carry
If-Match: <rev>. Stale writes get409and the current document back. - On a synced folder, a conflicted copy (
layout (conflicted copy).json) is detected at load - by mtime + rev mismatch and surfaced as "this space was edited elsewhere" rather than merged.
- One writer per space at a time (soft lock in the UI) until realtime collaboration exists.
Sizes and limits
| Thing | Limit |
|---|---|
layout.json | 64 KB (a 100-block space is ~8 KB) |
| widget instance | 16 KB |
| common widget settings | 16 KB |
| wallpaper | 2 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
scripts/backup.sh/publish.shzippublished/intoarchive/(last 10 kept).App_Datais not part of a release. Its backup story is the user's sync folder, plus an- export (
/api/export) that containsdata/only — neverprivate/. scripts/backup-data.sharchives the livedata/+private/trees (notApp_Data/backups)- with a SHA-256 sidecar.
scripts/restore-data.sh <archive> --yesverifies the archive, - copies the current trees to
App_Data/backups/pre-restore-…, and requires the API to be - stopped. Use
BENTO_STORAGE_ROOTwhen production points outside the repo.
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"] }
- It is read when an account is created; the new account's
widgets/library.jsonrecords the - complement as
disabled. - A missing file means every built-in, which is also the behaviour for accounts created
- before the setting existed.
- Changing it never rewrites an existing account. Users own their library and may remove every
- widget; the add-widget picker then points at the marketplace.
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.