Memories architecture
Memories shares one Rust service across local and hosted clients. A local store, a hosted Center and a relay have different trust boundaries: where the operation runs determines who can see plaintext. This overview describes the current code; Design explains the trade-offs and Roadmap separates implemented features from validation gaps and candidates.
Components
| Component | Responsibility |
|---|---|
crates/core |
Cryptography, encrypted SQLite Store, identities, signed policies/revisions, authorization, retrieval, cloud sync and shared Service dispatch. |
crates/cli |
Cargo package/binary memories: CLI, daemon, OS-authenticated IPC, MCP, relay/HTTP clients, desktop integrations and credential custody. |
crates/center |
memories-center: signed enrollment/MCP/unlock tickets; optional hosted storage, accounts, grants, requests, device registry and sealed-envelope delivery. |
crates/relay |
memories-relay: bounded, in-memory WebSocket rooms and forwarding of automation webhooks to an online host; no offline asset store. |
crates/ffi |
C ABI in memories.h; local service handles and the Rust hosted client used by Flutter. |
mobile/lib |
Flutter UI: Standalone library or Center/SaaS hosted client, secure profiles, device pairing, editors and lifecycle locking. Storage and cryptography remain in Rust. |
| Desktop | crates/cli/src/desktop/ and bin/memories-tray.rs: Windows tray/macOS menu bar and loopback dashboard with restricted card editing. Linux supports the dashboard, without a native tray. |
website/app |
Browser client of a hosted Center, also embedded by Center at /app/; no browser-local encrypted vault. |
deploy/ |
SaaS Hosted Center deployment templates and a same-domain API proxy; the backend is the same hosted Center, not a separate storage protocol. |
Data flow and transports
flowchart LR
CLI[CLI and local MCP] -->|OS-authenticated IPC| D[Daemon]
Desk[Desktop dashboard] -->|Restricted CLI operations| D
D --> Core[Core Service]
Mobile[Flutter Standalone] --> FFI[C FFI]
FFI --> Core
Core --> Local[Device-local encrypted Store]
Core -->|Recipient-encrypted vault envelopes| Transport[Files / relay sync / cloud objects]
Transport --> Peer[Authorized peer Store]
Hosted[Web / Flutter hosted / SaaS daemon] -->|HTTPS bearer requests| Center[Hosted Center]
Center --> Server[Operator-keyed Store]
Phone[Approving phone] -->|Recipient-sealed ciphertext| Center
Center -->|Sealed envelope| Device[Paired recipient device]
Ticket[Ticket-only Center] -->|Signed tickets, no vault keys| D
service::Request is typed JSON with a snake-case op; unknown top-level fields
are rejected. Local IPC uses a version-1 Wire wrapper and a big-endian 32-bit
length prefix. Unix sockets/Windows named pipes authenticate the OS account.
The daemon must run with the same dedicated home as its clients.
Direct daemon /v1/rpc is a WebSocket transport: binary JSON AuthFrame then
Wire. Relay RPC uses /v1/rpc/{room}/{slot} with the same frames. Desktop RPC
can reach the full daemon operation surface subject to its authorization checks;
remote elevation uses ws:remote / relay:remote, separately from cli:{pid}.
Tokens are constant-time checked and cleared on lock. Non-loopback listening
requires explicit opt-in; remote relay connections require WSS by default.
Relay RPC is not end-to-end encrypted: its relay/TLS terminator can read the
listen token and RPC payloads. Vault sync at /v1/channel/{room}/{slot} instead
carries recipient-encrypted envelopes. Hosted Center /v1/rpc is a separate
HTTP JSON content API, with a closed per-vault grant dispatcher; it is not the
daemon WebSocket protocol. The loopback desktop WebUI is another restricted
surface, never a generic Request bridge. See remote daemon
and protocol reference.
FFI handles are numeric registry IDs, not pointers. Callers free returned strings
once with memories_free. memories_lock_all advances the lock generation and
suppresses late responses; network work runs outside registry/service locks.
Mobile FFI/Share reject desktop process execution, remote/proxy operations and
local grant management. Hosted hosted_* calls have their own allowlist.
Storage and revision DAGs
The base Store has header, state and checkpoints tables; optional unattended
custody adds auxiliary records. Argon2id derives the password wrapping key for a
random master key. XChaCha20-Poly1305 encrypts state/checkpoints; each policy epoch
has a vault key, and each revision has a random wrapped data key. Serialized
content uses authenticated 256 KiB chunks with position/count binding.
One cooperating writer holds an OS lock. Mutations prepare a candidate state,
then atomically commit encrypted state and a signed encrypted checkpoint with
SQLite synchronous=FULL. Audited content delivery commits its intent before
returning plaintext. Failure to persist denies delivery. Each device owns a
separate database; cloud-synchronizing live SQLite files is unsupported.
Memory, cards, files and credentials share a signed, content-addressed revision DAG. Concurrent heads remain conflicts until an explicit resolution consumes all visible parents. Sync verifies policies, revisions, audit chains and deletion records before replacing local state. Unknown stale-epoch writes, including local offline edits absent from a newer policy snapshot, enter quarantine. Policy forks require an Owner valid on both branches to sign the selected head and discarded chain; incompatible resolutions fail closed.
Full-vault envelopes travel through files, online relay sync or durable OneDrive/Google Drive object queues. Cloud jobs persist exact ciphertext bytes before I/O, deduplicate by hash and recheck session/authorization before import. OAuth tokens, grants and run bindings stay device-local. See cloud sync and deletion.
Soft deletion preserves recoverable encrypted content. Version/vault trash uses signed lifecycle DAGs; hard deletion removes selected payloads and retains signed erasure receipts to prevent resurrection. Hosted admin compaction only prunes eligible legacy hard-tombstone ancestors with Owner-signed audited receipts. It preserves heads, live history, quarantine, policies and audits; it does not collect cloud history or erase backups. Ordinary saves never auto-prune history.
End-to-end sealed envelopes
crypto::Envelope authenticates the version, sender Ed25519 key, recipient
X25519 key, ephemeral X25519 key and encrypted payload. The sender derives a
transport key with X25519/HKDF-SHA256, encrypts with XChaCha20-Poly1305 and signs
with Ed25519. The intended recipient decrypts with its private exchange key
and verifies the expected sender.
Local sync seals the vault package for an approved peer. Hosted secret delivery
is separate: the approving phone seals a body for each attested recipient.
DeviceKeys::seal_card also binds purpose, vault, card, recipient and version
inside the authenticated payload; open_card checks that context. Sensitive
structured fields travel inside this client-created ciphertext, not ordinary
hosted card metadata. The sticky e2e flag rejects plaintext secret writes;
clearing it requires a direct Owner grant and a secret-free transition.
A ticket-only Center receives no device vault keys. A hosted Center stores these sealed bodies without their private decryption keys, but sees device/card identifiers, public keys, versions, timing and ordinary metadata. Its operator can decrypt ordinary unsealed hosted content, including protected content permitted through hosted grants. A sync relay sees ciphertext and traffic metadata; an RPC relay has the broader visibility described above.
Trust and key rotation
Local user Ed25519 keys certify device signing/exchange keys. A certificate alone does not grant vault access: the signed policy must include the member and exact device certificate and exclude the device from revocation. Current approval APIs require Admin/Owner authority; only Owners revoke vault devices or transfer ownership. Policy changes advance the epoch and create a fresh vault key. Local joining uses expiring request/approval files and full invitation-fingerprint verification, plus an independently verified approving-device key.
Hosted pairing uses a five-minute code, optional camera QR and a six-digit SAS comparison. The phone signs the recipient's keys, scope, expiry, pairing identity, Center origin and canonical vault UUID. The phone pins that vault identity and checks the canonical identity endpoint before approval/sealing and again before uploads; a device list cannot silently replace a pin.
Phone key rotation is a linear chain signed by both old and new keys. New approvals/sealing and freshly fetched envelopes require its active tip; retired signatures remain historical evidence. Re-pair recipients after rotation. Phone secure storage retains trust/pins/local revocations; CLI/hosted MCP retain learned rotation checkpoints. Forks, cycles and known rollback fail closed. A compromised active key requires independently verified root replacement. Center ticket-signing keys are separate configured trust anchors; replacing one requires updating endpoint pins, not using the phone rotation chain.
Authorization and revocation
Only Admin/Owner can issue or delegate grants, bounded by role, scope, vault,
parent expiry and a maximum delegation depth of two. Omitted scope is read.
Direct grant issuance needs an unlocked service but no terminal elevation or
second approver. Membership changes retain elevation checks. Requests can be
broadcast to eligible Admin/Owner members or directed to selected IDs; approval
records bounds and the requester claims the token once. Access lists are
Admin/Owner-only. See authorization.
Revocation is pull-based where remote evidence is needed, with no fleet push:
| Surface | Current mechanism and latency |
|---|---|
| Local vault policy | Effective after commit/import on that device; offline peers learn through sync, with no fixed delivery bound. Local grant revocation also invalidates descendants. |
| Hosted grants/devices | Center checks current authority/generations on requests. Member/device revocation invalidates affected grants and removes recipient envelopes; affected cards need secret rotation/re-sealing. |
| Hosted MCP | Polls authenticated GET /v1/devices before identity-key custody and again before delivery on every call; no background interval. Definitive denial persists a local revoke marker. Transport/5xx/malformed responses deny the attempt without inventing a permanent revoke. |
| Phone devices page | Refreshes every 30 seconds while current and not busy, including canonical vault-identity checks. Approval/sealing also checks on use; this timer is not a universal revocation deadline. |
The revoked_devices response is an authenticated Center projection of its
persisted log, not an independently signed revocation-list protocol. Center's
60-second expired-grant cleanup and daemon's one-second maintenance tick are
local maintenance, not revocation push. There is a final-check/delivery race;
partitions deny new hosted MCP calls but do not invalidate an offline local copy.
Neither signatures nor polling recall plaintext already delivered or provide an
independent witness against a malicious Center withholding evidence.
Deployment shapes
- Standalone: CLI/daemon or Flutter/FFI owns a local encrypted Store. Optional file/relay/cloud sync joins authorized replicas; device-only vaults are excluded from sync and exported backups.
- Ticket-managed devices: configured Centers sign bootstrap/MCP/unlock tickets; local self-bootstrap and local MCP minting are disabled. Password unlock and vault keys remain local. An unlock ticket grants no sudo authority.
- Self-hosted Center:
memories-center --data DIRowns an operator-keyed Store plus account/grant/device metadata. Serve it behind HTTPS; its listener does not implement native TLS. Web, mobile and daemon SaaS attachment use scoped content bearers; admin controls are separate. - SaaS Hosted Center: the same server behind the
deploy/service/container templates. The API Worker forwards only/v1/*and/healthto a fixed HTTPS upstream, strips cookies, disables caching, and does not retry or follow redirects. Static website/docs/Web assets are served separately. The proxy does not mint authority or add end-to-end encryption. - Remote daemon/relay host: operations run on the host Store; attachment does not create a client replica. Mobile Share is foreground-only and stops on lock.
Flutter's Center and SaaS modes share the hosted Rust client and keep separate secure URL/token profiles. Switching locks/disposes the active session; it does not migrate data. SaaS daemon attachment uses exactly one configured hosted backend and fails unsupported operations without local fallback. Web keeps tokens and content in page memory, clears its session on background/disconnect or five minutes idle, and trusts the host supplying its scripts.
Further reading
Use the documentation index, Design, security boundaries, Center guide, mobile guide and Web guide. The protocol and implementation reference retains detailed IPC, retrieval, jobs, cloud-worker, remote-session, backup and protected-card notes from the previous architecture document. These are implemented boundaries, not claims of independent security review or completed platform acceptance.