# The Role of @cloudflare/dofs in Cloudflare Computer: Core Data Layer and Virtual Filesystem

> Discover how @cloudflare/dofs serves as the core data layer for Cloudflare Computer, enabling a SQLite virtual filesystem for POSIX operations and state synchronization.

- Repository: [Cloudflare/computer](https://github.com/cloudflare/computer)
- Tags: deep-dive
- Published: 2026-09-04

---

**@cloudflare/dofs is the core data layer of Cloudflare Computer, providing a Durable Object-backed SQLite virtual filesystem that powers storage, POSIX operations, and state synchronization across the entire platform.**

Cloudflare Computer is a cloud development environment built on Cloudflare's edge infrastructure. At its foundation lies `@cloudflare/dofs`, a TypeScript package that abstracts Durable Object storage into a SQLite-backed virtual filesystem according to the cloudflare/computer source code. This package serves as the authoritative storage layer, enabling everything from basic file operations to real-time synchronization between edge and client.

## Database Wrapper and Schema Initialization

The foundation of `@cloudflare/dofs` is the `Database` class implemented in [`packages/dofs/src/storage.ts`](https://github.com/cloudflare/computer/blob/main/packages/dofs/src/storage.ts). This wrapper encapsulates a Durable Object's `storage` interface and exposes it as a SQLite database connection.

When initializing a Durable Object, you must create the virtual filesystem schema using the `initializeSchema` function exported from [`packages/dofs/src/index.ts`](https://github.com/cloudflare/computer/blob/main/packages/dofs/src/index.ts). This function creates the internal `vfs_*` tables required for filesystem operations and accepts a clock function—typically `Date.now`—for revision tracking.

```typescript
import { Database, initializeSchema } from "@cloudflare/dofs";

export class WorkspaceDO extends DurableObject {
  private readonly db: Database;

  constructor(ctx: DurableObjectState, env: Env) {
    super(ctx, env);
    this.db = new Database(ctx.storage);
    // Create the vfs_* tables; Date.now supplies a clock for rev tracking
    initializeSchema(this.db, Date.now);
  }
}

```

The `Database` instance becomes the single source of truth for all subsequent filesystem and synchronization operations within that Durable Object.

## POSIX-Style Filesystem Primitives

Beyond database management, `@cloudflare/dofs` implements complete POSIX-style filesystem operations in `packages/dofs/src/fs/`. These functions operate directly on the `Database` instance without requiring external storage mechanisms.

Available primitives include `mkdir`, `writeFile`, `readFile`, `rm`, `readdir`, `stat`, `chmod`, `symlink`, `readlink`, `find`, and `grep`. Each function accepts the database instance as its first parameter, followed by standard filesystem arguments.

```typescript
import { Database, readFile, writeFile, mkdir, stat } from "@cloudflare/dofs";

async function demo(db: Database) {
  await mkdir(db, "/example");
  await writeFile(db, "/example/hello.txt", "Hello, Cloudflare!", { mode: 0o644 });
  const contents = await readFile(db, "/example/hello.txt", "utf8");
  console.log(contents); // → "Hello, Cloudflare!"
  console.log(await stat(db, "/example/hello.txt"));
}

```

These primitives enable direct manipulation of the virtual filesystem within Durable Objects or testing environments.

## SQLiteWorkspaceProvider and FUSE Integration

To bridge the gap between the SQLite-backed filesystem and host-side applications, `@cloudflare/dofs` provides `SQLiteWorkspaceProvider` in [`packages/dofs/src/provider.ts`](https://github.com/cloudflare/computer/blob/main/packages/dofs/src/provider.ts). This class implements a `@platformatic/vfs`-compatible adapter that exposes the `WorkspaceFilesystem` through a Node-style `fs` API.

The `computerd` daemon consumes this provider to mount the virtual filesystem via FUSE (Filesystem in Userspace), allowing local development tools to interact with the cloud workspace as if it were a local directory.

```typescript
import { Database, initializeSchema, SQLiteWorkspaceProvider } from "@cloudflare/dofs";

async function startComputerd(storage: DurableObjectStorage) {
  const db = new Database(storage);
  await initializeSchema(db, Date.now);
  const provider = new SQLiteWorkspaceProvider({ db });
  // Provider implements @platformatic/vfs interface; computerd mounts via FUSE
  await mountFUSE(provider);
}

```

This architecture allows seamless integration between edge storage and local development environments.

## Sync Protocol Building Blocks

Real-time collaboration in Cloudflare Computer relies on the synchronization primitives defined in `packages/dofs/src/sync/`. These functions manage the bidirectional flow of data between the Durable Object state and connected clients.

Key functions include `applyChanges` for applying local modifications, `stageBlob` for preparing binary data, `fetchChanges` for retrieving remote updates, `pushObjects` for uploading state, `buildManifest` for generating state snapshots, and `currentRev` for tracking revision watermarks.

These building blocks are wired into `@cloudflare/computer-rpc` to enable efficient state synchronization. The sync layer operates entirely on the same `Database` instance used by the filesystem primitives, ensuring consistency between file contents and metadata during sync operations.

## Developer Utilities and Testing Support

`@cloudflare/dofs` includes comprehensive testing infrastructure in [`packages/dofs/src/testing.ts`](https://github.com/cloudflare/computer/blob/main/packages/dofs/src/testing.ts). The package exports `SQLiteTestStorage`, a Node-only utility for creating test database instances, and `RecordingStorage`, an in-process storage implementation for unit tests.

Type definitions for `Database`, `DurableObjectStorageLike`, and `SQLCursorLike` are also exported from [`packages/dofs/src/index.ts`](https://github.com/cloudflare/computer/blob/main/packages/dofs/src/index.ts), enabling type-safe development across the Cloudflare Computer ecosystem.

## Source Code Structure and Preview Status

The package is organized into distinct modules within `packages/dofs/`:

- **README.md** – Contains the preview-only warning noting that the API may evolve
- **src/index.ts** – Export hub re-exporting database, schema, provider, filesystem primitives, and sync helpers
- **src/storage.ts** – `Database` wrapper implementation around Durable Object storage
- **src/provider.ts** – `SQLiteWorkspaceProvider` implementing the `@platformatic/vfs` interface
- **src/fs/** – Individual filesystem primitive implementations
- **src/sync/** – Synchronization protocol functions
- **src/testing.ts** – Node-only testing utilities including `SQLiteTestStorage` and `RecordingStorage`

According to the package README, `@cloudflare/dofs` is intentionally marked as preview-only and subject to change, though the core architecture—Durable Object → SQLite → virtual FS → sync → client—remains stable.

## Summary

- **@cloudflare/dofs** provides the authoritative storage and filesystem layer for Cloudflare Computer, implementing a SQLite-backed virtual filesystem inside Durable Objects.
- The `Database` class in [`src/storage.ts`](https://github.com/cloudflare/computer/blob/main/src/storage.ts) wraps Durable Object storage, while `initializeSchema` creates the required `vfs_*` tables for revision tracking.
- POSIX-style operations (`mkdir`, `writeFile`, `readFile`, `stat`, etc.) operate directly on the database instance through functions exported from `src/fs/`.
- `SQLiteWorkspaceProvider` in [`src/provider.ts`](https://github.com/cloudflare/computer/blob/main/src/provider.ts) adapts the virtual filesystem to the `@platformatic/vfs` interface, enabling FUSE mounting by the `computerd` daemon.
- Synchronization primitives in `src/sync/` (`applyChanges`, `stageBlob`, `fetchChanges`, etc.) manage state consistency between edge and client.
- Testing utilities in [`src/testing.ts`](https://github.com/cloudflare/computer/blob/main/src/testing.ts) provide `SQLiteTestStorage` and `RecordingStorage` for unit testing outside the Workers environment.

## Frequently Asked Questions

### What is @cloudflare/dofs used for in Cloudflare Computer?

`@cloudflare/dofs` serves as the core data layer that provides a Durable Object-backed SQLite virtual filesystem. It handles all storage operations, file manipulation, and state synchronization required by the Cloudflare Computer development environment.

### How does @cloudflare/dofs store filesystem data?

The package stores filesystem metadata and content in SQLite tables within a Durable Object's storage using the `Database` class defined in [`src/storage.ts`](https://github.com/cloudflare/computer/blob/main/src/storage.ts). The `initializeSchema` function creates internal `vfs_*` tables that track files, directories, permissions, and revision history using a clock function like `Date.now`.

### Can I use @cloudflare/dofs outside of Cloudflare Computer?

While the package is published and functional, the README explicitly marks it as preview-only with APIs that may evolve. The architecture is designed specifically for Cloudflare Computer's needs, though the primitives could theoretically support any application requiring a SQLite-backed virtual filesystem in Durable Objects.

### What testing utilities does @cloudflare/dofs provide?

The package exports `SQLiteTestStorage` for Node.js-based integration testing and `RecordingStorage` for in-process unit testing from [`src/testing.ts`](https://github.com/cloudflare/computer/blob/main/src/testing.ts). These utilities allow developers to simulate Durable Object storage behavior without deploying to the Cloudflare Workers environment.