Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion doc/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ This page says where each kind of document lives in this repository and how it c

They change in place, through PRs.

- **Package docs.** A component's living docs stay with its code and change with it. Examples: [`pkgs/id/ARCHITECTURE.md`](../pkgs/id/ARCHITECTURE.md), [`pkgs/id/AGENTS.md`](../pkgs/id/AGENTS.md), [`pkgs/id/TODO.md`](../pkgs/id/TODO.md), [`pkgs/mcpx/docs/`](../pkgs/mcpx/docs/) and [`pkgs/mcpx/TODO.md`](../pkgs/mcpx/TODO.md).
- **Package docs.** A component's living docs stay with its code and change with it. Examples: [`pkgs/id/ARCHITECTURE.md`](../pkgs/id/ARCHITECTURE.md), [`pkgs/id/AGENTS.md`](../pkgs/id/AGENTS.md), [`pkgs/id/book/`](../pkgs/id/book/) and [`pkgs/mcpx/docs/`](../pkgs/mcpx/docs/).

`TODO.md` files are not living docs: `pkgs/id/TODO.md` says of itself that it is idle future planning that must not ground decisions, so it is not cited as a component's documentation.
- **Agent skills.** `.agents/skills/` holds the workflow lifecycle skills and the shared skills. `.opencode/skills/` holds the OpenCode skill set.

## Dated records vs living documents
Expand Down
6 changes: 3 additions & 3 deletions pkgs/id/AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,8 @@ just serve # Serve with web UI [requires bun]
just run # Run CLI with arguments
just test # All fast tests (Rust + TypeScript unit + typecheck)
just test-unit # Unit tests only (fast)
just test-e2e # Playwright E2E (146 tests, chromium + firefox)
just test-nix # nix flake check (27 checks — runs everything)
just test-e2e # Playwright E2E (chromium + firefox)
just test-nix # nix flake check (all checks — runs everything)
```

**Testing architecture:** See [`doc/testing-architecture`](../../doc/2026-03-29T00-00-00Z_reference_testing_architecture/2026-03-29T00-00-00Z_reference_testing_architecture.md) for the complete 6-layer testing reference, browser coverage matrix, environment comparison, and "when to add tests where" decision tree.
Expand All @@ -118,7 +118,7 @@ Adding or updating dependencies is allowed. Inform the user of each one (name, v

## CLI Commands

Run `id --help` for command list, `id <command> --help` for options. See `src/cli.rs` for full definitions.
Run `id --help` for command list, `id <command> --help` for options. See `crates/id-cli/src/cli/mod.rs` for full definitions.

## Project Structure

Expand Down
78 changes: 42 additions & 36 deletions pkgs/id/ARCHITECTURE.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ System architecture for the `id` peer-to-peer platform and Rust facade.

## Overview

`id` is built on [Iroh](https://iroh.computer). The workspace separates the facade and command application from core, capability/policy, sync, world, directory, web, and other service crates. The facade retains historical `id::` paths by re-exporting the split modules.
`id` is a peer-to-peer collaboration platform built on [Iroh](https://iroh.computer). It composes a workspace of crates through the root facade: an Iroh-based file core (blob storage, metadata documents and peer networking) plus signed events, groups, the directory, currency services and the world runtime. The CLI, REPL and optional web UI consume those layers. The facade retains historical `id::` paths by re-exporting the split modules. The diagram below shows the file-core path, not the entire platform; the crate table and store-port boundaries describe the wider workspace.

```
┌──────────────────────────────────────────────────────────────────┐
Expand All @@ -22,7 +22,7 @@ System architecture for the `id` peer-to-peer platform and Rust facade.
│ Core Services │
│ ┌───────────┐ ┌───────────┐ ┌───────────┐ ┌──────────────┐ │
│ │ Protocol │ │ Store │ │ TagStore │ │ Discovery │ │
│ │ (P2P RPC) │ │ (blobs) │ │ (metadata) │ │ (mDNS/DHT) │ │
│ │ (P2P RPC) │ │ (blobs) │ │ (metadata) │ │(gossip/mDNS) │ │
│ └─────┬─────┘ └─────┬─────┘ └─────┬─────┘ └──────┬───────┘ │
├────────┴──────────────┴──────────────┴───────────────┴───────────┤
│ Iroh Runtime │
Expand All @@ -40,35 +40,39 @@ crate is consumed outside `pkgs/id/`).
| Crate | Classification | Notes |
|-------|----------------|-------|
| `id` (root, `src/`) | Public facade and binary | Re-exports the workspace API at historical `id::` paths; command parsing and dispatch are implemented in `id-cli`. |
| `id-core` | Shared core | Depended on by workspace crates. The facade re-exports a selected subset; it also includes `admission_gate`, `migration_control`, `petname`, `world_presentation`, and feature-gated `qr`. See `src/lib.rs` for the authoritative list. |
| `id-core` | Shared core | Depended on by nine sibling crates and the root. The facade re-exports a selected subset; it also includes `admission_gate`, `migration_control`, `petname`, `world_presentation`, and feature-gated `qr`. See `src/lib.rs` for the authoritative list. |
| `id-caps`, `id-store`, `id-events`, `id-groups`, `id-sync`, `id-worlds`, `id-directory`, `id-web` | Internal | Used only by sibling crates and the root. |
| `id-cli` | Internal (binary) | Only the root depends on it. |
| `id-config` | Internal | The facade lists it as a dev-dependency for invariant tests; it has no production dependent. |
| `id-config` | Internal (dev only) | The facade lists it as a dev-dependency for invariant tests (`tests/config_invariants.rs`); it has no production dependent. |
| `id-currency-registry` | Internal | Only the root depends on it. |
| `id-native-shell`, `id-hw-shell` | Internal (app) | Workspace members, not default members; both production-depend on the facade. `id-native-shell` rejects `--help` and unknown flags; it has no `--version` option. |
| `id-render` | Internal compiler library | Rendering-pipeline compiler core: semantic-markup parsing and vocabulary validation, with composition/lowering/emission stages. |
| `id-import-notion` | Internal importer library | Notion importer manifest and inventory primitives, with maintained integration tests. |
| `id-native-shell`, `id-hw-shell` | Internal (app) | Workspace members, but not default members; both production-depend on the facade, and nothing depends on them. `id-native-shell` rejects `--help` and unknown flags; it has no `--version` option. |
| `id-render` | Internal compiler library | Rendering-pipeline compiler core: semantic-markup parsing and vocabulary validation, with composition/lowering/emission stages. Nothing depends on it. |
| `id-import-notion` | Internal importer library | Notion importer manifest and inventory primitives, with maintained integration tests. Nothing depends on it. |

Standalone examples and benchmarks (`examples/`, `benchmarks`) are not
public API. Vendored crates (`vendor/p2panda-sync`, `vendor/p2panda-encryption`)
are third-party code.

Rustdoc coverage on public items is about 99% in `id-core` and the root
crate. `missing_docs = "warn"` is set in both `Cargo.toml` files.
crate. `missing_docs = "warn"` is set in both `Cargo.toml` files. DES-3: this chapter's module map once followed the pre-split single-crate layout and pointed at paths that no longer exist; it now follows the workspace layout at `06450991e33` (`crates/id-cli/src/cli/`, `crates/id-sync/src/protocol.rs`, `crates/id-store/src/store.rs`, `crates/id-core/src/tuple.rs`, `crates/id-web/src/`, `web/src/`).

## Core Modules

### Entry Point (`main.rs`, `lib.rs`)
### Entry Point (`src/main.rs`, `src/lib.rs`)

`main.rs` starts the facade binary; command parsing and dispatch are implemented in `id-cli` and re-exported at the historical facade paths. Node services are composed by the current command/server layers.

### CLI (`cli.rs`)
### CLI (`crates/id-cli/src/cli/`)

Defines the command-line interface using [clap](https://docs.rs/clap). All commands, subcommands, options, and aliases are declared here. The `tag` command accepts aliases `label` and `link`.
Defines the command-line interface using [clap](https://docs.rs/clap). All commands, subcommands, options, and aliases are declared here (`mod.rs` plus one module per command group, such as `world.rs`, `groups.rs` and `walk.rs`). The `tag` command accepts aliases `label` and `link`.

### Protocol (`protocol.rs`)
### Commands (`crates/id-cli/src/commands/`)

Defines the P2P request/response protocol between nodes. Uses Iroh's RPC mechanism with custom `MetaRequest`/`MetaResponse` types serialized as postcard-encoded bytes.
Implements the command handlers the parser dispatches to; see [Command Layer](#command-layer).

### Protocol (`crates/id-sync/src/protocol.rs`)

Defines the P2P request/response protocol between nodes. Uses Iroh's RPC mechanism with custom `MetaRequest`/`MetaResponse` types serialized as postcard-encoded bytes. The ALPN is `/iroh-meta/3` (`META_ALPN`).

Key message types:

Expand All @@ -79,11 +83,11 @@ Key message types:
- `SetTag`/`DelTag`/`GetTags`/`SearchTags` — metadata operations (SearchTags uses structured query syntax)
- `MigrateTags` — add name/file auto-tags to all existing files

### Store (`store.rs`)
### Store (`crates/id-store/src/store.rs`)

Wraps Iroh's blob store for named file operations. Maps human-readable names to content hashes via Iroh tags. Handles import from filesystem, export, and content retrieval.

### Tags (`tags.rs`, `tuple.rs`)
### Tags (`crates/id-store/src/tags.rs`, `crates/id-core/src/tuple.rs`)

The metadata tag system uses a dual-index architecture for efficient queries:

Expand All @@ -110,17 +114,17 @@ Operations: `set_tag`, `del_tag`, `get_tags`, `search_by_query` (structured synt

Display: Values truncated at 256 bytes by default. CLI supports `--hex`, `--binary`, `--no-truncate` flags. Web UI shows `name`/`file`/`path` tags as display names and deduplicates files with identical (hash, display_name, tags).

### Discovery (`discovery.rs`)
### Discovery (`crates/id-core/src/discovery.rs`)

Peer discovery using mDNS for local network and Iroh's DHT for global discovery. Maintains a peer list and provides lookup by node ID prefix.
Peer discovery with three mechanisms that coexist: gossip over a shared topic (the wide-area default), mDNS on the local network (on by default), and mainline DHT address lookup and publishing (off by default, enabled with `id serve --dht` behind the `dht` cargo feature). The module holds the announcement types and the in-memory peer table; the hardcoded fallbacks are `DEFAULT_TOPIC` (`id-peer-discovery-v1`) and `DEFAULT_TOPIC_SECRET` (`id-public-discovery-v1`), with `defaults.json` the operative source on a stock serve. It maintains a peer list and provides lookup by node ID prefix.

### Helpers (`helpers.rs`)
### Helpers (`crates/id-cli/src/helpers.rs`)

Utility functions for hash parsing, node ID validation, file size formatting, timestamp handling, and output formatting.

## Command Layer

Each command in `src/commands/` follows a consistent pattern:
Each command in `crates/id-cli/src/commands/` follows a consistent pattern:

1. Parse arguments (from CLI or REPL)
2. Determine local vs. remote operation (check if first arg is a 64-char hex node ID)
Expand All @@ -139,19 +143,19 @@ id list a1b2c3d4... # Remote (64-char hex node ID)

Remote operations serialize the request via `protocol.rs` and send it over Iroh's QUIC transport.

## REPL (`repl/`)
## REPL (`crates/id-cli/src/repl/`)

The interactive REPL (`runner.rs`) provides a shell-like experience:

- **Command dispatch**: Maps input to command handlers with alias resolution
- **Shell features** (`input.rs`): Pipe to shell (`|>`), subshell capture (`$()`), backtick expansion, heredocs (`<<<`, `<<EOF`), input redirection
- **Alias groups**: `tag`/`label`/`link` are interchangeable prefixes; `tags`/`labels`/`links` for listing

## Web UI (`src/web/`, `web/`)
## Web UI (`crates/id-web/src/`, `web/src/`)

Feature-gated behind `--features web`. Embeds a full browser UI in the binary.

### Backend (`src/web/`)
### Backend (`crates/id-web/src/`)

| Module | Purpose |
| ----------------- | -------------------------------------------------- |
Expand All @@ -163,7 +167,7 @@ Feature-gated behind `--features web`. Embeds a full browser UI in the binary.
| `content_mode.rs` | Content type detection and rendering mode |
| `markdown.rs` | Markdown → HTML rendering with syntax highlighting |

### Frontend (`web/`)
### Frontend (`web/src/`)

TypeScript bundled with Bun, producing a single JS file and CSS file embedded in the binary.

Expand Down Expand Up @@ -304,7 +308,7 @@ flattening, and `tests/store_port_boundary.rs` rejects it.

The project uses Nix flakes for reproducible builds:

- `flake.nix` — packages (`id-web`, `id-lib`), checks (11 CI checks), apps (all justfile commands)
- `flake.nix` — packages (`id-web`, `id-lib`), checks (the CI set plus the NixOS VM checks; 50 attributes under `checks.x86_64-linux` when measured on 2026-11-23 at `06450991e33` with `nix eval '.#checks.x86_64-linux' --apply 'x: builtins.length (builtins.attrNames x)'` in `pkgs/id`), apps (all justfile commands)
- `nix-common.nix` — shared build inputs and dev shell packages
- `rust-toolchain.toml` — Rust version pinning (read by rust-overlay)
- `web/bun.nix` — offline npm dependency fetching via bun2nix
Expand All @@ -320,15 +324,17 @@ The build script (`scripts/build.sh`) tracks the current variant beside its Carg

## Testing

| Layer | Framework | Command | Count |
| ----------------------- | ----------------- | -------------------------------- | ----- |
| Unit | `cargo test` | `just test-unit` | ~408 |
| Integration | `cargo test` | `just test-int` | ~93 |
| TypeScript | vitest | `just test-web-unit` | ~304 |
| E2E | Playwright | `just test-e2e` | 208 |
| NixOS VM (API) | curl/Python | `just test-nixos-serve` | ~15 |
| NixOS VM (DOM) | Chromium | `just test-nixos-e2e` | ~10 |
| NixOS VM (Integration) | cargo test binary | `just test-nixos-integration` | ~93 |
| NixOS 4-VM (Playwright) | Playwright | `just test-nixos-playwright-e2e` | 208 |

`just test-nix` (`nix flake check`, 27 checks) runs everything — all test layers above are included. See [`doc/testing-architecture`](../../doc/2026-03-29T00-00-00Z_reference_testing_architecture/2026-03-29T00-00-00Z_reference_testing_architecture.md) for the complete testing reference.
| Layer | Framework | Command |
| ----------------------- | ----------------- | -------------------------------- |
| Unit | `cargo test` | `just test-unit` |
| Integration | `cargo test` | `just test-int` |
| TypeScript | vitest | `just test-web-unit` |
| E2E | Playwright | `just test-e2e` |
| NixOS VM (API) | curl/Python | `just test-nixos-serve` |
| NixOS VM (DOM) | Chromium | `just test-nixos-e2e` |
| NixOS VM (Integration) | cargo test binary | `just test-nixos-integration` |
| NixOS 4-VM (Playwright) | Playwright | `just test-nixos-playwright-e2e` |

Test totals are deliberately not stated: a count is a measurement of one run on one date, and this file records it with its date or not at all. To produce a current count for one layer, run its command and record the summary line with the date and the commit.

`just test-nix` (`nix flake check`, 50 checks on `x86_64-linux` when measured on 2026-11-23 by the method above) runs everything — all test layers above are included. See [`doc/testing-architecture`](../../doc/2026-03-29T00-00-00Z_reference_testing_architecture/2026-03-29T00-00-00Z_reference_testing_architecture.md) for the complete testing reference.
Loading