From c90a1c22993fbc2a030f16b4cf3c51534d976664 Mon Sep 17 00:00:00 2001
From: Shane Wall <214650244+saworbit@users.noreply.github.com>
Date: Tue, 17 Nov 2026 07:34:57 +1100
Subject: [PATCH] Explain SPACE in the README, with diagrams of its
architecture and data flow
The README listed features but did not say what SPACE is or how its parts
fit together. It now explains capsules, views and segments, and why the
pipeline's order and the content-derived XTS tweak keep deduplication with
encryption on, and what that costs.
Mermaid diagrams show the capsule model, the crates and the files they
write, the write path with its commit point, the read path, and two writers
sharing one segment. A table says which store files are truth and which are
derived, and a section covers reclaim, scrub and shutdown.
The quick start now stores an object through S3, reads it back with
spacectl, and turns on encryption, with a caution about the key. Limits and
trade-offs, a documents table and the project history follow.
The text uses ASD-STE100 Simplified Technical English where it fits: short
sentences, active voice, one instruction per step and no contractions.
---
CHANGELOG.md | 1 +
README.md | 367 ++++++++++++++++++++++++++++++++++++++++++++++-----
2 files changed, 335 insertions(+), 33 deletions(-)
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 1ebf604..54a4b65 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -64,6 +64,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- The Linux release archives are reproducible (#242): the builder image pins the Rust toolchain, paths are remapped, and the archive is sorted with fixed owners and the commit's time. Each archive has a `TOOLCHAIN.txt`. docs/CI_CD_STRATEGY.md says how to rebuild one and compare.
- `docs/capsule.md`, ARCHITECTURE.md, README.md and ROADMAP.md describe what landed with #169, #188, #198 and #201: where the write path takes the pipeline lock, how the content index is kept, multipart upload namespaces and composed capsules, the reclaim pass aborting old uploads, and `spacectl`'s scripting flags and completions.
- docs/capsule.md, CONTRIBUTING.md, SECURITY.md and the S3 quick start describe what landed with #243, #244 and #252: the redb index in place of sled, the fuzz targets, and the release dry run under `Build and test`. The quick start's reset command also removes `space.db.sled-old`.
+- README.md explains what SPACE is and how encryption keeps deduplication, with Mermaid diagrams of the capsule model, the crate architecture, the write and read paths and shared segments. It also has a table of the store files, the background maintenance loops, a quick start that stores an object through S3 and reads it back with `spacectl`, and a list of limits and trade-offs. It uses ASD-STE100 Simplified Technical English where that fits.
### Removed
diff --git a/README.md b/README.md
index 459f20d..8c432eb 100644
--- a/README.md
+++ b/README.md
@@ -5,63 +5,364 @@
[](https://scorecard.dev/viewer/?uri=github.com/saworbit/SPACE)
[](LICENSE)
-Storage Platform for Adaptive Computational Ecosystems
+**Storage Platform for Adaptive Computational Ecosystems**
**One capsule. Multiple views. Zero copies.**
-> Pre-alpha research project. Not production-ready. Single-developer. APIs will change.
+> [!WARNING]
+> SPACE is a pre-alpha research project. Do not keep the only copy of important data in it. One developer maintains SPACE, and the APIs will change.
-## Core reset (2026-10-19)
+## Contents
-This branch is the hard restart. Early exploration produced a lot of crates and experimental features (distributed mesh, extra protocol views, web UI, etc.). That increased cognitive load and made the project hard to ship. The current state keeps only the pieces that still make sense and have been tested:
+- [What SPACE is](#what-space-is)
+- [Architecture](#architecture)
+- [Data flow](#data-flow)
+- [What works today](#what-works-today)
+- [Quick start](#quick-start)
+- [Limits and trade-offs](#limits-and-trade-offs)
+- [Documentation](#documentation)
+- [Project history](#project-history)
+- [Contributing](#contributing)
+- [License](#license)
-- Single-node capsule storage
-- Modular write/read pipeline: compression → BLAKE3 content-addressed dedup → XTS-AES-256 encryption (deterministic tweaks preserve dedup)
-- S3-compatible protocol view
-- spacectl CLI
-- Property-based tests for pipeline invariants
+## What SPACE is
-Everything else is preserved on the `archive/pre-reset-2026-10` branch. See [RESET.md](RESET.md) for the full explainer.
+SPACE is a storage engine for one computer. It keeps all data as **capsules**. A capsule is a stored object with a permanent 128-bit ID.
+
+Clients use **views** to read and write capsules. A view gives names to capsules, but it does not own the bytes. This branch has two views:
+
+- **The S3 view** (`spacectl serve-s3`) is an S3-compatible HTTP server. Each S3 key is a name that points to a capsule.
+- **The `spacectl` command-line tool** reads and writes capsules by their IDs.
+
+`spacectl` can read an object that a client put through S3, because the object is a capsule. SPACE does not make a copy for the second view.
+
+Each capsule is an ordered list of **segments**. A segment holds up to 4 MiB of data by default. When two capsules contain the same segment, SPACE stores that segment one time only. Each stored segment has a reference count.
+
+```mermaid
+flowchart LR
+ subgraph views["Views: names only"]
+ k1["S3 key
photos/cat.jpg"]
+ k2["S3 key
backup/cat-v2.jpg"]
+ cli["spacectl read 9c41"]
+ end
+ subgraph capsules["Capsules"]
+ a["Capsule 3f2a"]
+ b["Capsule 9c41"]
+ end
+ subgraph segments["Stored segments"]
+ s1["Segment 1
1 reference"]
+ s2["Segment 2
2 references"]
+ s3["Segment 3
1 reference"]
+ end
+ k1 --> a
+ k2 --> b
+ cli --> b
+ a --> s1
+ a --> s2
+ b --> s2
+ b --> s3
+```
+
+### How encryption keeps deduplication
+
+The write pipeline compresses, deduplicates and encrypts each segment. Encryption and deduplication usually conflict. If a system encrypts data before it looks for duplicates, two copies of the same data usually give different ciphertext. The system then cannot find the duplicates.
+
+SPACE does the steps in this sequence:
+
+1. It compresses the segment.
+2. It calculates a BLAKE3 hash of the compressed bytes. The hash input also includes the compression algorithm and the encryption mode. Thus segments from different policies never match by mistake.
+3. It looks for the hash in the content index. If the hash is there, the new capsule refers to the stored segment, and SPACE writes nothing.
+4. If the hash is new, SPACE encrypts the segment with XTS-AES-256. The XTS tweak is the first 16 bytes of a BLAKE3 hash of the compressed segment. The same bytes under the same key always give the same ciphertext.
+5. It adds a 16-byte BLAKE3 MAC to the ciphertext, and it appends the segment to the segment log.
+
+Every capsule that refers to a shared segment can decrypt it with the store key. Encryption does not stop deduplication. There is a cost: a person who can read the disk can see which segments are the same. That person cannot read the contents. See [Limits and trade-offs](#limits-and-trade-offs).
+
+## Architecture
+
+SPACE is a Rust workspace. All the parts are in one binary, `spacectl`. The diagram shows how the crates call each other and which files they write.
+
+```mermaid
+flowchart TB
+ subgraph clients["Clients"]
+ sdk["S3 clients
curl, boto3, AWS SDKs"]
+ op["Operator or script"]
+ end
+
+ subgraph bin["spacectl binary"]
+ s3["protocol-s3
S3 view over HTTP"]
+ cmd["CLI commands
create, read, list, delete,
gc, compact, scrub"]
+ end
+
+ subgraph core["Storage core"]
+ reg["capsule-registry
capsules, names, journal
index, reclaim, scrub"]
+ pipe["pipeline
write and read stages"]
+ comp["compression
LZ4, Zstd"]
+ dd["dedup
BLAKE3 content hash"]
+ enc["encryption
XTS-AES-256, BLAKE3 MAC, keys"]
+ st["storage + nvram-sim
segment backends"]
+ end
+
+ subgraph disk["Store directory"]
+ journal[("space.journal
capsule journal")]
+ db[("space.db
redb index")]
+ log[("space.nvram
segment log")]
+ root[("SPACE_STORAGE_ROOT
one file per segment")]
+ end
+
+ sdk -- "HTTP" --> s3
+ op --> cmd
+ s3 --> reg
+ cmd --> reg
+ reg --> pipe
+ pipe --> comp
+ pipe --> dd
+ pipe --> enc
+ pipe --> st
+ reg -- "commit" --> journal
+ reg -- "apply" --> db
+ st -- "default" --> log
+ st -. "optional" .-> root
+```
+
+| Crate | Job |
+|-------|-----|
+| [`common`](crates/common) | Shared types (`CapsuleId`, `SegmentId`, `Policy`) and the `StorageBackend` trait. All other crates use it. |
+| [`compression`](crates/compression) | LZ4 and Zstd. It does not compress data that has high entropy. |
+| [`dedup`](crates/dedup) | BLAKE3 content hashes, separated by algorithm. |
+| [`encryption`](crates/encryption) | XTS-AES-256, the BLAKE3 MAC and the key manager. |
+| [`nvram-sim`](crates/nvram-sim) | The append-only segment log, `space.nvram`. |
+| [`storage`](crates/storage) | Segment backends: the log, one file per segment, memory, and an LRU cache. |
+| [`pipeline`](crates/pipeline) | The write and read stages. It is the only write path. |
+| [`capsule-registry`](crates/capsule-registry) | Capsules and names. It owns the journal, the index, reclaim and scrub. |
+| [`protocol-s3`](crates/protocol-s3) | The S3 view, on axum. |
+| [`spacectl`](crates/spacectl) | The command-line tool and the S3 server. |
+| [`test-support`](crates/test-support) | Helpers for the tests only. |
+
+## Data flow
+
+### Write path
+
+S3 PUT, S3 UploadPart and `spacectl create` all use this path.
+
+```mermaid
+flowchart TD
+ src["Client bytes
S3 PUT, UploadPart or spacectl create"] --> seg["Step 1: Segment
cut into 4 MiB chunks"]
+ seg --> cmp["Step 2: Compress
LZ4 or Zstd, skipped if entropy is high"]
+ cmp --> hash["Step 3: Hash
BLAKE3 of the compressed bytes,
the algorithm and the encryption mode"]
+ hash --> look{"Step 4: Is the hash in
the content index?"}
+ look -- "yes: duplicate" --> reuse["Refer to the stored segment
reference count + 1"]
+ look -- "no: new data" --> encq{"Encryption on?"}
+ encq -- "yes" --> enc["Step 5: Encrypt with XTS-AES-256
tweak from BLAKE3 of the bytes
Step 6: add a 16-byte BLAKE3 MAC"]
+ encq -- "no" --> app
+ enc --> app["Step 7: Append a SEGMENT record
to the segment log, fsync"]
+ reuse --> more{"More data?"}
+ app --> more
+ more -- "yes" --> seg
+ more -- "no" --> commit["Step 8: Commit
append a CAPSULE record to space.journal, fsync,
then apply the record to space.db"]
+```
+
+- **Step 8 is the commit point.** A write that stops before step 8 is not visible to any list or read. Reclaim removes the segments that it stored.
+- **An S3 PUT is atomic.** One journal batch commits the new object, its key and the removal of the old object. After a crash, the key holds the old object or the new object.
+- **Writes overlap.** A streaming write does steps 2, 3, 5 and 6 on a blocking thread before it locks the pipeline. The lock covers only steps 4 and 7, so other writes can continue. If step 4 finds a duplicate, SPACE discards the ciphertext.
+- **Multipart upload does not copy data.** CompleteMultipartUpload makes the object from the segments of its parts. It does not write the parts again.
+
+### Read path
+
+S3 GET and `spacectl read` use this path. SPACE streams the result one segment at a time.
+
+```mermaid
+flowchart TD
+ req["Read request
capsule ID, optional byte range"] --> find["Find the capsule in space.db
skip the segments outside the range"]
+ find --> rd["Read the next segment record"]
+ rd --> encq{"Record says
encrypted?"}
+ encq -- "yes" --> mac["Verify the MAC,
then decrypt with XTS-AES-256"]
+ encq -- "no" --> chk["Verify the content hash"]
+ mac --> cq{"Record says
compressed?"}
+ chk --> cq
+ cq -- "yes" --> unz["Decompress"]
+ cq -- "no" --> out
+ unz --> out["Send the bytes to the client"]
+ out --> more{"More segments?"}
+ more -- "yes" --> rd
+ more -- "no" --> dig["Read of the whole capsule:
check its BLAKE3 digest"]
+```
+
+- **The segment record is the truth.** The read uses the flags in each segment record, not the capsule policy. Because of deduplication, a capsule can refer to segments that a different policy wrote.
+- **The MAC comes first.** SPACE verifies the MAC, with a constant-time compare, before it decrypts. It does not give changed ciphertext to the AES code.
+- **The policy can require encryption.** If the policy of a capsule requires encryption, SPACE refuses a segment that is marked as not encrypted.
+- **A range read reads full segments.** It skips the segments outside the range. It reads each segment in the range completely.
+
+### Shared segments
+
+Two writers send the same chunk. SPACE stores it one time.
+
+```mermaid
+sequenceDiagram
+ participant A as Writer A
+ participant B as Writer B
+ participant P as Pipeline
+ participant I as Content index
+ participant L as Segment log
+ A->>P: chunk X
+ P->>I: look up hash(X)
+ I-->>P: not found
+ P->>L: append encrypt(X) as segment 7
+ P->>I: record hash(X) as segment 7
+ B->>P: chunk X, the same bytes
+ P->>I: look up hash(X)
+ I-->>P: segment 7
+ Note over P,L: SPACE writes nothing.
Segment 7 has 2 references.
+```
+
+When the reference count of a segment goes to zero, reclaim removes it.
+
+### What is on disk
+
+All files are in the store directory. This is the current directory, or the directory that `--store