Storage layout
The files each device keeps in OPFS and the objects the API keeps in its object store: names, layout, and bytes.
The API keeps bytes in its Postgres database and in an S3-compatible object store beside it (Cloudflare R2 in production). Each device keeps an encrypted SQLite database and a directory of encrypted files, both in the browser’s origin private file system (OPFS), and beside them its keyring in IndexedDB and preferences in local and session storage. Every table in the two databases is in the Postgres and SQLite schema references. This page covers the rest: which files and objects exist, how they are named, and the bytes inside them.
No user content here is readable by a server. Object-store blobs are encrypted on the device under keys the server never sees, and the database pages and blob files in OPFS are encrypted under keys from the device’s local keyring. Cipher suites gives the primitives. What stays in plaintext is structure: object keys, envelope headers, each pool slot’s 4096-byte header, and the public desktop installers in the downloads bucket.
On the device
Every shell (the web app, Capacitor on iOS and Android, and Electrobun on the desktop) keeps its data in its WebView’s origin storage. Each identity on the device gets its own database and its own blob namespace, both named by the identity’s signing fingerprint.
| Path | What it holds | Written by |
|---|---|---|
/tearleads-sqlite/app-identity-<fingerprint>.db/ |
The identity’s SQLite database, in a pool of slot files | sahPoolStorage.ts, sqliteDbName.ts |
/tearleads/<fingerprint>/ |
The identity’s blob namespace: one .blob file per storage key |
opfsBlobStore.ts |
The SQLite pool
The SQLite worker opens each database through SQLite’s
SyncAccessHandle Pool VFS,
registered as tearleads-opfs-sahpool-<segment> over the directory
/tearleads-sqlite/<segment>. The segment is the database’s file name with
surrounding whitespace and its leading / removed, each run of characters other
than letters, digits, ., _, and - replaced by one _, and underscores
trimmed from both ends; a name that leaves nothing, ., or .. uses default
(sahPoolStorage.ts).
A separate pool per database lets separate workers open separate databases
without contending for the same access handles
(SQLite setup).
The VFS does not store files under their own names. It keeps a fixed set of
slot files with random names in the pool’s .opaque/ directory, at least 12
(SAHPOOL_MINIMUM_CAPACITY), holds a SyncAccessHandle open on each, and maps
each file SQLite opens (the database and its rollback journal) onto a free
slot. Each slot starts with a 4096-byte header:
| Bytes | Field |
|---|---|
| 0–511 | The SQLite file name the slot holds, such as /app-identity-<fingerprint>.db; empty when the slot is free |
| 512–515 | The flags SQLite opened the file with |
| 516–523 | A digest of bytes 0–515, checked when the pool is loaded |
| 4096 onward | The file’s bytes |
The database’s pages are encrypted by SQLite3MultipleCiphers with the ChaCha20 codec, under a key derived from the local keyring (at-rest database), so a slot file holds a plaintext slot header and ciphertext pages.
The blob namespace
Attachment bytes and a few app files live as one file each under
/tearleads/<fingerprint>/, named by the storage key, URI-encoded, with
.blob appended:
| Storage key | File | What it is |
|---|---|---|
<localId>-<slotId>-<uuid> |
<localId>-<slotId>-<uuid>.blob |
An attachment added on this device; each new version of a slot gets a fresh key (attachments/index.ts) |
blob-<blobId> |
blob-<blobId>.blob |
An attachment downloaded from the server, named by its blob (hydrate.ts) |
shell/desktop-state.json |
shell%2Fdesktop-state.json.blob |
The app’s window layout (usePaneDesktopStateStorage.ts) |
The document rows that point at these keys are in the SQLite reference. Writes
to one key are serialized by a Web Lock named for the namespace and key, and a
write lands through a writable stream that OPFS commits only when it closes, so
a failed write leaves the previous file or none
(opfsBlobFile.ts).
Each file is in the local encrypted blob format, version 2
(encryptedBlobEnvelope.ts):
- The 39-byte magic
tearleads.local-blob-store.encrypted.v2. - The JSON header’s length, a 4-byte big-endian integer, at most 64 KiB.
- The JSON header:
format,version,cipher(aes-256-gcm),chunkSize,chunkCount,plaintextByteLength, the baseiv, andkeyDerivation, which isnullfor the keyring-derived keys the app uses. - The chunks: the plaintext in 5 MiB pieces (the last shorter), each encrypted with AES-256-GCM and followed by its 16-byte tag.
A chunk’s IV is the base IV combined with the chunk index, and its additional
data binds the namespace, the storage key, the chunk index, and the header, so
a file moved to another key, or a chunk moved within a file, fails to decrypt.
The key is derived from the local keyring for the purpose
blob-store:<fingerprint>, one per namespace.
Outside OPFS
| Storage | Name | What it holds |
|---|---|---|
| IndexedDB | tearleads-local-keyring, store wrappingKeys |
Non-extractable wrapping keys, by key id; raw key bytes on WKWebView (soft limits) |
| IndexedDB | tearleads-local-keyring-manifests, store manifests |
Keyring manifests, by scope: each scope’s root key wrapped by a wrapping key; in localStorage where IndexedDB is unavailable |
| localStorage and sessionStorage | Many keys | Preferences and UI state, none of it content |
The local keyring describes the key hierarchy, and soft limits gives each platform’s quota and eviction rules. The keyring and the OPFS files share an origin, so a browser that evicts the origin removes both together.
When it is removed
| Event | What goes |
|---|---|
| Log out | The identity’s database pool and its blob namespace |
| Destroy an identity on this device | The same, then the identity’s saved keys |
| Reset this device | Every entry in the OPFS root, the IndexedDB databases, and local and session storage (resetting this device) |
| An unreadable database | That database’s pool, recreated empty (useUnreadableDatabaseRecovery.ts) |
In the object store
The API keeps attachment bytes in an S3-compatible bucket and never reads them:
clients upload and download through presigned URLs, and the API keeps the rows
that say which objects exist and who may read them (blob_stages, blobs, and
blob_audit_objects in the Postgres reference).
| Bucket | What it holds | Defined in |
|---|---|---|
tearleads-blobs-<tier> |
Encrypted attachment bytes, one object per blob | stacks/prod/storage, r2-object-storage |
tearleads-downloads-<tier> |
Desktop installers, update archives, and their manifests (public) | stacks/prod/downloads |
Locally the API uses an in-process S3 server in memory, or LocalStack (blob object store).
Blob keys
A blob’s object key is
organizations/<organization id>/blob-stages/<stage id>
with both ids URI-encoded
(storageKeys.ts). The
API chooses it when a client opens a blob stage
and records it in blob_stages.storage_key; the bind that promotes the stage to
a blob copies the same key to blobs.storage_key, so the object is never
copied or renamed. Before it opens a stage’s upload or deletes an object, the
API checks that the key lies under the stage’s organization. An
s3 store can wrap every key in a BLOB_OBJECT_STORE_S3_KEY_PREFIX; the
deployed tiers set none.
Object format
An object is the blob envelope, version 2
(blobEnvelopeV2.ts):
- The 23-byte magic
tearleads.blob.bytes.v2. - The header’s length, a 4-byte big-endian integer, at most 64 KiB.
- The header, canonical JSON:
blobId,byteLength(the plaintext’s),chunkCount,chunkSize,contentKeyEpoch,contentRecordId,encryptionSuite,format, the baseiv,metadataHash,nonceDomainHash, andversion. - The chunks: the plaintext in 5 MiB pieces, at most 10,000, each encrypted with AES-256-GCM and followed by its 16-byte tag.
Each chunk is encrypted under a record key derived from the blob’s
content key for the organization, blob,
content record, and key epoch. Its IV is the base IV with the chunk index
XORed into the last four bytes. Its additional data binds those names, the
chunk’s index and length, the chunk size and count, the plaintext length, and
the header’s metadata and nonce-domain hashes
(chunkedBlobCrypto.ts).
The object’s length is
the header’s plus the plaintext’s plus 16 bytes per chunk; blobs.byte_length
records it, and blobs.sha256 is the SHA-256 of the whole object.
A client uploads the object as a multipart upload. Every part but the last is
the length of the header plus one encrypted chunk, because R2 needs equal
nonfinal parts and that size keeps even a 10,000-chunk object within 10,000
parts. Part 1 is therefore exactly the header and chunk 0, and each later part
is an equal slice of the rest, crossing chunk boundaries
(encryptedUploadParts.ts).
The blob protocol gives the upload,
completion, and read rules, and hard limits the
bounds.
Object lifecycle
| Stage | Object |
|---|---|
| Stage opened | A multipart upload begins at the stage’s key; the stage expires an hour later. |
| Stage expired or abandoned | Cleanup aborts the upload and deletes the key, in case the parts were already assembled. R2 also aborts any upload still incomplete after seven days. |
| Bound | The stage becomes a blob at the same key. |
| Dereferenced | Detach, replacement, or purge leaves the blob unbound; after a 24-hour grace period the collector deletes the object and records the deletion in blob_audit_objects. |
Attachment retention explains when a blob stops being referenced and how long history keeps it.
Download keys
The downloads bucket is public and flat. Each desktop release writes, per
channel (stable or canary) and target (such as macos-arm64):
| Key | Contents | Overwritten |
|---|---|---|
<channel>-<target>-<sha256>-<app>.dmg, -Setup.zip, or -Setup.tar.gz |
The installer, named by its own SHA-256 | Never: the name changes with the bytes |
<installer key>.sha256 |
The installer’s checksum line | Never |
<channel>-<target>-<sha256>-<app>.app.tar.zst or .tar.zst |
The update archive, named by its own SHA-256 | Never |
<channel>-<target>-update.json |
The updater’s manifest, naming the current archive | Each release |
<channel>-<target>-download.json |
The download page’s manifest, naming the current installer | Each release |
A release uploads the content-addressed files first, then switches the two
manifests (publishDesktopRelease.ts).