Efficient and minimal collaborative code editor, self-hosted, no database required
Find a file
2023-01-02 00:37:50 -06:00
.github/workflows Only log in to DockerHub on push event 2022-02-19 10:49:52 -05:00
public Update dependencies and switch build to Vite (#30) 2021-11-12 02:38:14 -05:00
rustpad-server Improve persistence logic (#55) 2022-10-02 04:10:35 +00:00
rustpad-wasm Update frontend dependencies and clippy lints (#33) 2021-12-27 20:21:00 +00:00
src Add additional support for Monaco basic languages (#35) 2022-01-02 23:38:41 +00:00
.dockerignore Update dependencies and switch build to Vite (#30) 2021-11-12 02:38:14 -05:00
.editorconfig Initial commit 2021-05-31 11:53:19 -05:00
.env Allow configuring the number of days to expire documents (#18) 2021-07-15 19:19:43 -04:00
.gitignore Update dependencies and switch build to Vite (#30) 2021-11-12 02:38:14 -05:00
.prettierignore Update dependencies and switch build to Vite (#30) 2021-11-12 02:38:14 -05:00
.prettierrc Initial commit 2021-05-31 11:53:19 -05:00
Cargo.lock Improve persistence logic (#55) 2022-10-02 04:10:35 +00:00
Cargo.toml Rename rustpad-core to rustpad-wasm, add Serde 2021-06-01 17:44:33 -05:00
Dockerfile Add multi-platform build support for linux/arm64 (#32) 2021-12-27 17:16:57 -05:00
index.html Add og:title and og:description meta tags (#59) 2022-12-10 17:50:34 -05:00
LICENSE Add MIT license 2021-06-03 14:54:53 -05:00
package-lock.json Update frontend dependencies and clippy lints (#33) 2021-12-27 20:21:00 +00:00
package.json Update frontend dependencies and clippy lints (#33) 2021-12-27 20:21:00 +00:00
README.md Update README to reflect new Fly.io hosting 2023-01-02 00:37:50 -06:00
tsconfig.json Set up WebAssembly compilation and loading 2021-06-01 12:42:23 -05:00
vite.config.js Update dependencies and switch build to Vite (#30) 2021-11-12 02:38:14 -05:00

Rustpad

Docker Pulls Docker Image Size GitHub Workflow Status

Rustpad is an efficient and minimal open-source collaborative text editor based on the operational transformation algorithm. It lets users collaborate in real time while writing code in their browser. Rustpad is completely self-hosted and fits in a tiny Docker image, no database required.


rustpad.io

The server is written in Rust using the warp web server framework and the operational-transform library. We use wasm-bindgen to compile text operation logic to WebAssembly code, which runs in the browser. The frontend is written in TypeScript using React and interfaces with Monaco, the text editor that powers VS Code.

Architecturally, client-side code communicates via WebSocket with a central server that stores in-memory data structures. This makes the editor very fast, allows us to avoid provisioning a database, and makes testing much easier. The tradeoff is that documents are transient and lost between server restarts, or after 24 hours of inactivity.

Development setup

To run this application, you need to install Rust, wasm-pack, and Node.js. Then, build the WebAssembly portion of the app:

wasm-pack build --target web rustpad-wasm

When that is complete, you can install dependencies for the frontend React application:

npm install

Next, compile and run the backend web server:

cargo run

While the backend is running, open another shell and run the following command to start the frontend portion.

npm run dev

This command will open a browser window to http://localhost:3000, with hot reloading on changes.

Testing

To run integration tests for the server, use the standard cargo test command. For the WebAssembly component, you can run tests in a headless browser with

wasm-pack test --chrome --headless rustpad-wasm

Configuration

Although the default behavior of Rustpad is to store documents solely in memory and collect garbage after 24 hours of inactivity, this can be configured by setting the appropriate variables. The application server looks for the following environment variables on startup:

  • EXPIRY_DAYS: An integer corresponding to the number of days that inactive documents are kept in memory before being garbage collected by the server (default 1 day).
  • SQLITE_URI: A SQLite connection string used for persistence. If provided, Rustpad will snapshot document contents to a local file, which enables them to be retained between server restarts and after their in-memory data structures expire. (When deploying a Docker container, this should point to the path of a mounted volume.)
  • PORT: Which local port to listen for HTTP connections on (defaults to 3030).
  • RUST_LOG: Directives that control application logging, see the env_logger docs for more information.

Deployment

Rustpad is distributed as a single 6 MB Docker image, which is built automatically from the Dockerfile in this repository. You can pull the latest version of this image from Docker Hub. It has multi-platform support for linux/amd64 and linux/arm64.

docker pull ekzhang/rustpad

(You can also manually build this image with docker build -t rustpad . in the project root directory.) To run locally, execute the following command, then open http://localhost:3030 in your browser.

docker run --rm -dp 3030:3030 ekzhang/rustpad

We deploy a public instance of this image using Fly.io.

In the media


All code is licensed under the MIT license.