# ephemeral-ai-lab/layerfs architecture

> Architecture diagram of the GitHub repository ephemeral-ai-lab/layerfs, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-19). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/ephemeral-ai-lab/layerfs
- Repository: https://github.com/ephemeral-ai-lab/layerfs

## Overview

LayerFS is a versioned filesystem for AI agents: agents fork branches, work in isolated writable Workspaces, commit changes into durable shared history, merge, and publish. The README documents both direct Store-backed file/branch operations and Sandbox-backed command execution; compute is separate from durable state. The graph follows those documented capabilities and the sampled content/overlay internals. Some implementation links are inferred from the documented product flow and are marked dashed where the excerpts do not establish the call directly.

Main entry points: [`core/crates/layerfs-api/src/lib.rs`](https://github.com/ephemeral-ai-lab/layerfs/blob/main/core/crates/layerfs-api/src/lib.rs) (Rust API), [`core/crates/layerfs-api/src/branch/merge.rs`](https://github.com/ephemeral-ai-lab/layerfs/blob/main/core/crates/layerfs-api/src/branch/merge.rs) (Branch operations), [`core/crates/layerfs-api/src/sandbox/exec.rs`](https://github.com/ephemeral-ai-lab/layerfs/blob/main/core/crates/layerfs-api/src/sandbox/exec.rs) (Sandbox commands), [`core/crates/layerfs-workspace/src/lib.rs`](https://github.com/ephemeral-ai-lab/layerfs/blob/main/core/crates/layerfs-workspace/src/lib.rs) (Workspace semantics)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_agent["Agent interface"]
  node_api["Rust API<br/>[lib.rs]"]
  node_dispatch["Daemon dispatch<br/>[dispatch.rs]"]
end

subgraph group_history["Branches and history"]
  node_branch["Branch operations<br/>[merge.rs]"]
  node_historyquery["History queries<br/>[query.rs]"]
end

subgraph group_workspace["Workspace operations"]
  node_fsapi["Filesystem calls<br/>[write.rs]"]
  node_workspacecore["Workspace semantics<br/>[lib.rs]"]
  node_overlay[("Workspace overlay<br/>[lib.rs]")]
end

subgraph group_runtime["Sandbox and mount"]
  node_sandbox["Sandbox commands<br/>[exec.rs]"]
  node_fuse["FUSE operations<br/>[read.rs]"]
  node_bridge["Daemon bridge<br/>[control_reply.rs]"]
end

subgraph group_storage["Content and storage"]
  node_contentfs["Filesystem construction<br/>[update.rs]"]
  node_fileedit["File edits<br/>[engine.rs]"]
  node_mapping["File mapping<br/>[build.rs]"]
  node_objects["Canonical objects<br/>[codec.rs]"]
  node_mergecontent["Content merge<br/>[build.rs]"]
  node_store["Store service<br/>[store_service.rs]"]
  node_persistence[("SQLite persistence<br/>[query.rs]")]
end

node_user(("Agent or caller"))

node_user -->|"calls"| node_api
node_api -.->|"routes branch calls"| node_branch
node_api -.->|"routes file calls"| node_fsapi
node_api -->|"manages sandboxes"| node_sandbox
node_api -.->|"dispatches"| node_dispatch
node_branch -.->|"reads history"| node_historyquery
node_branch -->|"updates shared Store"| node_store
node_fsapi -->|"uses shared Store"| node_store
node_store -->|"binds private Workspace"| node_workspacecore
node_workspacecore -.->|"uses overlay jobs"| node_overlay
node_workspacecore -.->|"constructs filesystem state"| node_contentfs
node_contentfs -.->|"applies file edits"| node_fileedit
node_fileedit -->|"uses mapping codec"| node_mapping
node_mapping -.->|"encodes objects"| node_objects
node_branch -->|"merges changes"| node_mergecontent
node_store -.->|"persists state"| node_persistence
node_sandbox -.->|"controls daemon"| node_bridge
node_sandbox -->|"mounts Workspace"| node_fuse
node_fuse -.->|"serves filesystem requests"| node_workspacecore
node_sandbox -->|"commits Workspace"| node_branch

click node_api "https://github.com/ephemeral-ai-lab/layerfs/blob/main/core/crates/layerfs-api/src/lib.rs"
click node_dispatch "https://github.com/ephemeral-ai-lab/layerfs/blob/main/core/crates/layerfs-daemon/src/operator/dispatch.rs"
click node_branch "https://github.com/ephemeral-ai-lab/layerfs/blob/main/core/crates/layerfs-api/src/branch/merge.rs"
click node_historyquery "https://github.com/ephemeral-ai-lab/layerfs/blob/main/core/crates/layerfs-history/src/contract/query.rs"
click node_fsapi "https://github.com/ephemeral-ai-lab/layerfs/blob/main/core/crates/layerfs-api/src/fs/write.rs"
click node_workspacecore "https://github.com/ephemeral-ai-lab/layerfs/blob/main/core/crates/layerfs-workspace/src/lib.rs"
click node_overlay "https://github.com/ephemeral-ai-lab/layerfs/blob/main/core/crates/layerfs-overlay/src/lib.rs"
click node_contentfs "https://github.com/ephemeral-ai-lab/layerfs/blob/main/core/crates/layerfs-content/src/filesystem/update.rs"
click node_fileedit "https://github.com/ephemeral-ai-lab/layerfs/blob/main/core/crates/layerfs-content/src/file/edit/engine.rs"
click node_mapping "https://github.com/ephemeral-ai-lab/layerfs/blob/main/core/crates/layerfs-content/src/file/mapping/build.rs"
click node_objects "https://github.com/ephemeral-ai-lab/layerfs/blob/main/core/crates/layerfs-content/src/object/codec.rs"
click node_mergecontent "https://github.com/ephemeral-ai-lab/layerfs/blob/main/core/crates/layerfs-content/src/merge/build.rs"
click node_store "https://github.com/ephemeral-ai-lab/layerfs/blob/main/core/crates/layerfs-store-service/src/store_service.rs"
click node_persistence "https://github.com/ephemeral-ai-lab/layerfs/blob/main/core/crates/layerfs-persistence/src/backend/sqlite/query.rs"
click node_sandbox "https://github.com/ephemeral-ai-lab/layerfs/blob/main/core/crates/layerfs-api/src/sandbox/exec.rs"
click node_fuse "https://github.com/ephemeral-ai-lab/layerfs/blob/main/core/crates/layerfs-fuse/src/operations/read.rs"
click node_bridge "https://github.com/ephemeral-ai-lab/layerfs/blob/main/core/crates/layerfs-bridge/src/control_reply.rs"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_api,node_dispatch toneBlue
class node_branch,node_historyquery toneAmber
class node_fsapi,node_workspacecore,node_overlay toneMint
class node_sandbox,node_fuse,node_bridge toneRose
class node_contentfs,node_fileedit,node_mapping,node_objects,node_mergecontent,node_store,node_persistence,node_user toneIndigo
```

## Components

### Agent interface

- [Rust API](https://github.com/ephemeral-ai-lab/layerfs/blob/main/core/crates/layerfs-api/src/lib.rs): `core/crates/layerfs-api/src/lib.rs`
- [Daemon dispatch](https://github.com/ephemeral-ai-lab/layerfs/blob/main/core/crates/layerfs-daemon/src/operator/dispatch.rs): `core/crates/layerfs-daemon/src/operator/dispatch.rs`

### Branches and history

- [Branch operations](https://github.com/ephemeral-ai-lab/layerfs/blob/main/core/crates/layerfs-api/src/branch/merge.rs): `core/crates/layerfs-api/src/branch/merge.rs`
- [History queries](https://github.com/ephemeral-ai-lab/layerfs/blob/main/core/crates/layerfs-history/src/contract/query.rs): `core/crates/layerfs-history/src/contract/query.rs`

### Workspace operations

- [Filesystem calls](https://github.com/ephemeral-ai-lab/layerfs/blob/main/core/crates/layerfs-api/src/fs/write.rs): `core/crates/layerfs-api/src/fs/write.rs`
- [Workspace semantics](https://github.com/ephemeral-ai-lab/layerfs/blob/main/core/crates/layerfs-workspace/src/lib.rs): `core/crates/layerfs-workspace/src/lib.rs`
- [Workspace overlay](https://github.com/ephemeral-ai-lab/layerfs/blob/main/core/crates/layerfs-overlay/src/lib.rs): `core/crates/layerfs-overlay/src/lib.rs`

### Sandbox and mount

- [Sandbox commands](https://github.com/ephemeral-ai-lab/layerfs/blob/main/core/crates/layerfs-api/src/sandbox/exec.rs): `core/crates/layerfs-api/src/sandbox/exec.rs`
- [FUSE operations](https://github.com/ephemeral-ai-lab/layerfs/blob/main/core/crates/layerfs-fuse/src/operations/read.rs): `core/crates/layerfs-fuse/src/operations/read.rs`
- [Daemon bridge](https://github.com/ephemeral-ai-lab/layerfs/blob/main/core/crates/layerfs-bridge/src/control_reply.rs): `core/crates/layerfs-bridge/src/control_reply.rs`

### Content and storage

- [Filesystem construction](https://github.com/ephemeral-ai-lab/layerfs/blob/main/core/crates/layerfs-content/src/filesystem/update.rs): `core/crates/layerfs-content/src/filesystem/update.rs`
- [File edits](https://github.com/ephemeral-ai-lab/layerfs/blob/main/core/crates/layerfs-content/src/file/edit/engine.rs): `core/crates/layerfs-content/src/file/edit/engine.rs`
- [File mapping](https://github.com/ephemeral-ai-lab/layerfs/blob/main/core/crates/layerfs-content/src/file/mapping/build.rs): `core/crates/layerfs-content/src/file/mapping/build.rs`
- [Canonical objects](https://github.com/ephemeral-ai-lab/layerfs/blob/main/core/crates/layerfs-content/src/object/codec.rs): `core/crates/layerfs-content/src/object/codec.rs`
- [Content merge](https://github.com/ephemeral-ai-lab/layerfs/blob/main/core/crates/layerfs-content/src/merge/build.rs): `core/crates/layerfs-content/src/merge/build.rs`
- [Store service](https://github.com/ephemeral-ai-lab/layerfs/blob/main/core/crates/layerfs-store-service/src/store_service.rs): `core/crates/layerfs-store-service/src/store_service.rs`
- [SQLite persistence](https://github.com/ephemeral-ai-lab/layerfs/blob/main/core/crates/layerfs-persistence/src/backend/sqlite/query.rs): `core/crates/layerfs-persistence/src/backend/sqlite/query.rs`

### Other components

- **Agent or caller**

## Connections

- Agent or caller → Rust API: calls (evidence: `README.md`)
- Rust API → Branch operations: routes branch calls
- Rust API → Filesystem calls: routes file calls
- Rust API → Sandbox commands: manages sandboxes (evidence: `README.md`)
- Rust API → Daemon dispatch: dispatches
- Branch operations → History queries: reads history
- Branch operations → Store service: updates shared Store (evidence: `README.md`)
- Filesystem calls → Store service: uses shared Store (evidence: `README.md`)
- Store service → Workspace semantics: binds private Workspace (evidence: `core/crates/layerfs-store-service/src/store_service.rs`)
- Workspace semantics → Workspace overlay: uses overlay jobs
- Workspace semantics → Filesystem construction: constructs filesystem state
- Filesystem construction → File edits: applies file edits
- File edits → File mapping: uses mapping codec (evidence: `core/crates/layerfs-content/src/file/edit/engine.rs`)
- File mapping → Canonical objects: encodes objects
- Branch operations → Content merge: merges changes (evidence: `README.md`)
- Store service → SQLite persistence: persists state
- Sandbox commands → Daemon bridge: controls daemon
- Sandbox commands → FUSE operations: mounts Workspace (evidence: `README.md`)
- FUSE operations → Workspace semantics: serves filesystem requests
- Sandbox commands → Branch operations: commits Workspace (evidence: `README.md`)
