# Examples

> Run Collaboration SDK examples by capability and open each example's guide, Server entry point, and Web entry point.

- Human documentation: [https://office.univer.ai/collaboration/examples](https://office.univer.ai/collaboration/examples)

- Agent Markdown: [https://office.univer.ai/collaboration/examples.md](https://office.univer.ai/collaboration/examples.md)

- Language: `en`

- Source file: `content/docs/collaboration/examples.mdx`

- Upstream source: [https://github.com/dream-num/office.univer.ai/blob/main/content/docs/collaboration/examples.mdx](https://github.com/dream-num/office.univer.ai/blob/main/content/docs/collaboration/examples.mdx)

---

All examples live in
[univer-collaboration-examples](https://github.com/dream-num/univer-collaboration-examples). They use
the same minimal `web/main.ts + server/main.ts` shape and run independently. Complete Quick Start
first, then choose another example based on your integration task.

| Example                               | Main concept               | Command                         |
| ------------------------------------- | -------------------------- | ------------------------------- |
| [Quick Start](#quick-start)           | Core collaboration path    | `pnpm example:quick-start`      |
| [Database Adapter](#database-adapter) | Persistence boundary       | `pnpm example:database-adapter` |
| [Permissions](#permissions)           | Identity and authorization | `pnpm example:permissions`      |
| [History](#history)                   | Derived version history    | `pnpm example:history`          |
| [Comments](#comments)                 | Independent comments       | `pnpm example:comments`         |
| [Worktree](#worktree)                 | Isolated editing and merge | `pnpm example:worktree`         |
| [Exchange](#exchange)                 | Office file exchange       | `pnpm example:exchange`         |

## Quick Start

Compose Collaboration Client, Transport, Endpoint, Service, and Memory Adapter. Use two browsers
to verify HTTP loading, WebSocket Sessions, Room, ACK, and broadcast for the same Sheet.

```bash
pnpm example:quick-start
```

Open `http://127.0.0.1:3010/?unit=quick-start-sheet&type=2`.

* [Example guide](https://github.com/dream-num/univer-collaboration-examples/blob/main/examples/quick-start/README.md)
* [Server entry](https://github.com/dream-num/univer-collaboration-examples/blob/main/examples/quick-start/server/main.ts)
* [Web entry](https://github.com/dream-num/univer-collaboration-examples/blob/main/examples/quick-start/web/main.ts)
* [Step-by-step guide on this site](https://office.univer.ai/collaboration/quick-start.md)

## Database Adapter

Compare custom Memory, PostgreSQL, and built-in SQLite Adapters. The implementations demonstrate
transactions, revision CAS, batch atomicity, and the `customData` transaction boundary.

```bash
pnpm example:database-adapter
```

Open `http://127.0.0.1:3010/?unit=database-adapter-sheet&type=2`.

* [Example guide](https://github.com/dream-num/univer-collaboration-examples/blob/main/examples/database-adapter/README.md)
* [Server entry](https://github.com/dream-num/univer-collaboration-examples/blob/main/examples/database-adapter/server/main.ts)
* [Web entry](https://github.com/dream-num/univer-collaboration-examples/blob/main/examples/database-adapter/web/main.ts)

## Permissions

Create trusted identity from a cookie and protect Unit HTTP reads, realtime JOIN, and changeset
submission separately. The page switches between a teaching `editor` and read-only `viewer`.

```bash
pnpm example:permissions
```

Open `http://127.0.0.1:3010`.

* [Example guide](https://github.com/dream-num/univer-collaboration-examples/blob/main/examples/permissions/README.md)
* [Server entry](https://github.com/dream-num/univer-collaboration-examples/blob/main/examples/permissions/server/main.ts)
* [Web entry](https://github.com/dream-num/univer-collaboration-examples/blob/main/examples/permissions/web/main.ts)
* [Identity and authorization guide](https://office.univer.ai/collaboration/identity-and-authorization.md)

## History

Add History Service, a separate Adapter, History Endpoint, and the browser history entry outside
Core. Unit creation and changeset commit Events build History as a reconstructable derived index.

```bash
pnpm example:history
```

Open `http://127.0.0.1:3010/?unit=history-sheet&type=2`, edit the Sheet, and select `History` at the
top of the page.

* [Example guide](https://github.com/dream-num/univer-collaboration-examples/blob/main/examples/history/README.md)
* [Server entry](https://github.com/dream-num/univer-collaboration-examples/blob/main/examples/history/server/main.ts)
* [Web entry](https://github.com/dream-num/univer-collaboration-examples/blob/main/examples/history/web/main.ts)

## Comments

Add Thread Comment Service, a separate Adapter, Comment Endpoint, and the frontend comment entry.
The Comment Endpoint reuses the main collaboration Endpoint's Sessions and Unit Rooms.

```bash
pnpm example:comments
```

Open `http://127.0.0.1:3010/?unit=comments-sheet&type=2`, select a cell, and use the comment entry.

* [Example guide](https://github.com/dream-num/univer-collaboration-examples/blob/main/examples/comments/README.md)
* [Server entry](https://github.com/dream-num/univer-collaboration-examples/blob/main/examples/comments/server/main.ts)
* [Web entry](https://github.com/dream-num/univer-collaboration-examples/blob/main/examples/comments/web/main.ts)

## Worktree

Demonstrate the complete isolated draft, Ready, Reopen, and per-Unit Merge lifecycle. Switch between
trunk and draft to see how Agent changes remain isolated before merge.

```bash
pnpm example:worktree
```

Open `http://127.0.0.1:3010/?unit=worktree-sheet&type=2&worktree=demo-worktree`.

* [Example guide](https://github.com/dream-num/univer-collaboration-examples/blob/main/examples/worktree/README.md)
* [Server entry](https://github.com/dream-num/univer-collaboration-examples/blob/main/examples/worktree/server/main.ts)
* [Web entry](https://github.com/dream-num/univer-collaboration-examples/blob/main/examples/worktree/web/main.ts)
* [CLI and human review workflow](https://office.univer.ai/cli/worktree.md)

## Exchange

Compose `@univerjs-pro/exchange-node` with Collaboration Service for server-side Sheet import and
export, task polling, snapshot import, and confirmed-revision export.

```bash
pnpm example:exchange
```

Open `http://127.0.0.1:3010/?unit=exchange-sheet&type=2`. Import through **File → Open (File)** and
export through **File → Save As**.

* [Example guide](https://github.com/dream-num/univer-collaboration-examples/blob/main/examples/exchange/README.md)
* [Server entry](https://github.com/dream-num/univer-collaboration-examples/blob/main/examples/exchange/server/main.ts)
* [Exchange workflow](https://github.com/dream-num/univer-collaboration-examples/blob/main/examples/exchange/server/exchange.ts)
* [Web entry](https://github.com/dream-num/univer-collaboration-examples/blob/main/examples/exchange/web/main.ts)

> **Examples are not production applications**
>
> Fixed users, teaching authorization, Memory Adapters, local secrets, and in-memory file and task
> stores exist only for instruction. The application still owns identity, authorization,
> persistence, secrets, files, deployment, and product interaction.
