Skip to content
sonalysPublic

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

planrs

planrs is a collaborative, local-first workspace: a Rust server, a Yrs CRDT document model, and a Svelte web client that keeps working offline.

Install

On a computer with Docker, paste this into a terminal:

curl -fsSL https://raw.githubusercontent.com/sonalys/planrs/main/scripts/install.sh | sh

It creates ~/planrs with a compose.yml (planrs and PostgreSQL) and a private .env holding a generated database password, then asks whether to start planrs. Open the address it prints (http://localhost:3000) and create the administrator account. Run the same line again at any time: it never changes an existing install, only reports whether planrs is running and offers to start it.

planrs accepts connections from that computer only. To use it from other devices, serve it over HTTPS through a reverse proxy; the comments in the generated compose.yml show the other options.

Settings go before sh, for example curl -fsSL … | PLANRS_PORT=8080 sh. PLANRS_PORT, PLANRS_BIND (the IPv4 address the port listens on), and PLANRS_IMAGE shape a new install; afterwards they live in .env. PLANRS_DIR (the install folder) and PLANRS_START=yes|no (answer the question without asking) apply to every run. A new install will not take over containers or volumes Docker already has under the same Compose project name, for example from a source checkout named planrs; pick another folder with PLANRS_DIR then. Behavior: scripts/install.spec.md.

Run with PostgreSQL

From a checkout, Docker Compose starts the app and PostgreSQL 19 with a persistent database volume. Its default credentials are for local development only; use the installer above to run planrs for real.

make up-build   # build the server image and start the stack

make up starts the stack with the already-built planrs:local image, and make image IMAGE=<registry>/<owner>/planrs TAG=<tag> builds another reference. docker compose up --build still works where Docker BuildKit is available. Run make help for the full target list.

The container image serves the built web frontend, the GraphQL API, the REST login/user routes, and the WebSocket transport from one origin, so a deployment is reachable on a single host and port (http://localhost:3000 by default).

Configuration

The frontend is bundled from web/dist. PLANRS_WEB_DIR overrides that directory at runtime, and PLANRS_ADDR overrides the listen address (0.0.0.0:3000 by default). Session cookies are Secure by default; set PLANRS_COOKIE_SECURE=false only when intentionally serving plain HTTP to a trusted network. When no built frontend is present the process only serves the /api routes.

Uploaded files (for example images in pages, at most 50 MiB each) are stored in PLANRS_BLOB_DIR (data/blobs under the working directory by default, /app/data/blobs in the container image), one file per distinct content named by its SHA-256; their metadata lives in PostgreSQL. Keep the directory on persistent storage and back it up together with the database: the compose stack mounts the blob_data volume there. The server creates the directory at startup and refuses to start when it cannot write to it. An hourly job removes files no document uses any more.

When a member pastes a link, the server fetches the linked page once to make its preview (title, description, and a thumbnail stored as a blob); readers of the page never contact the linked site. The server only fetches https links on port 443 whose host resolves to public addresses. Set PLANRS_LINK_PREVIEWS=off to turn this off; links then stay plain.

PLANRS_DB_MAX_CONNECTIONS sets the size of the PostgreSQL connection pool (10 by default). Startup waits about half a minute for a database that is not reachable yet, and stops at once on rejected credentials or an invalid value.

The server keeps the documents being worked on decoded in memory and serves their reads and updates from there. PLANRS_DOCUMENT_CACHE_CAPACITY sets how many it keeps (256 by default); the least recently used go first, once their changes are written back. Every update is stored in the update log before it is acknowledged. The full snapshot and the modification time are written back every PLANRS_DOCUMENT_FLUSH_INTERVAL_SECS seconds (5 by default, at most 86400) and on shutdown. A document nobody has read or changed for PLANRS_DOCUMENT_IDLE_SECS seconds (300 by default) leaves memory. All three settings must be positive integers.

Pages can hold automations. The ones a change triggers run on the device that makes the change; the ones on a schedule run on the server, which looks for due automations every PLANRS_AUTOMATION_TICK_SECS seconds (15 by default, at most 86400, a positive integer).

The app runs database migrations at startup. The migration history is the ordered SQL set under migrations/; the initial file is a clean baseline for the pre-release data model, and later files extend it. Recreate the Postgres volume (docker compose down -v) instead of carrying forward an older development database. DATABASE_URL is required when running the binary directly.

On a fresh database, the first visitor is asked to create the workspace administrator account. The workspace starts empty; the administrator can fill it with demo pages from the empty-workspace screen, while other members are told the workspace is empty. No credentials are generated or written to the logs. Administrators add members by creating a single-use invitation link with a chosen role. Invitations expire after seven days and can be cancelled from the Members settings before use.

Roles are managed in the Members settings. A role's level is one relation on the workspace (DR-0039): admin roles manage the workspace and can edit every page, and member roles get only what is shared with them or with the role.

Single sign-on (OpenID Connect)

Setting PLANRS_OIDC_ISSUER adds a Sign in with … button next to the password form. Register a client at your provider with the redirect URL https://<your-host>/api/auth/oidc/callback. Pocket ID, Authentik, Keycloak, Authelia, and Dex work out of the box. The full behavior is in src/controller/oidc.spec.md and the reasoning in DR-0038.

Variable Default Meaning
PLANRS_OIDC_ISSUER unset (off) The provider's issuer URL, exactly as its discovery document states it.
PLANRS_OIDC_CLIENT_ID required The client id.
PLANRS_OIDC_CLIENT_SECRET unset The client secret; leave unset for a public client (PKCE is always used).
PLANRS_OIDC_REDIRECT_URL required https://<your-host>/api/auth/oidc/callback, as registered at the provider.
PLANRS_OIDC_SCOPES openid profile email Scopes to request; openid is always added. Add groups if your provider needs it for the groups claim.
PLANRS_OIDC_NAME SSO The provider's name on the sign-in button.
PLANRS_OIDC_AUTO_REDIRECT false Send the sign-in screen straight to the provider. Open /?login=password to reach the password form anyway.
PLANRS_OIDC_ALLOW_NEW_USERS false Create an account for anyone the provider signs in. Otherwise only linked accounts can sign in.
PLANRS_OIDC_LINK_EXISTING_USERS false On a first sign-in, take over the existing account whose username equals the username claim exactly. Only enable it if users cannot choose their username at the provider.
PLANRS_OIDC_USERNAME_CLAIM preferred_username The claim new usernames come from (then email, then sub); characters outside letters, digits, -, and _ become _.
PLANRS_OIDC_DEFAULT_ROLE member The role for new accounts, and for accounts whose groups give no role.
PLANRS_OIDC_GROUP_SYNC false Set each account's role from its groups at every sign-in.
PLANRS_OIDC_GROUPS_CLAIM groups The claim holding the groups; a dotted path such as realm_access.roles reaches nested claims.
PLANRS_OIDC_ROLE_MAP empty Group=role translations, separated by commas, semicolons, or newlines, for example Admins=admin,Staff=member,Everyone=. An empty role ignores the group. Unmapped groups whose names, ignoring case, are valid role names (letters, digits, -, _) become roles of the same name in lowercase, so Engineering syncs to engineering without a map entry, but never an administering one: only the map can make a group an administrator. Map entries match group names exactly.
PLANRS_OIDC_DISABLE_PASSWORD_LOGIN false Allow only single sign-on. The first person to sign in on a fresh workspace becomes the administrator.

With group sync on, the first mapped group wins, except that a role that administers the workspace always wins. Roles the provider names are created at level member and can be promoted in the Members settings. The provider also supplies each person's first name, last name, and picture (given_name, family_name, picture), which the app shows wherever it shows that person. An invalid value in any of these variables stops startup with a message naming the variable.

Example for Pocket ID:

PLANRS_OIDC_ISSUER=https://id.example.com
PLANRS_OIDC_CLIENT_ID=0f3c…
PLANRS_OIDC_CLIENT_SECRET=…
PLANRS_OIDC_REDIRECT_URL=https://planrs.example.com/api/auth/oidc/callback
PLANRS_OIDC_NAME="Pocket ID"
PLANRS_OIDC_SCOPES="openid profile email groups"
PLANRS_OIDC_ALLOW_NEW_USERS=true
PLANRS_OIDC_GROUP_SYNC=true
PLANRS_OIDC_ROLE_MAP="planrs_admins=admin"
PLANRS_OIDC_AUTO_REDIRECT=true

OTLP export uses gRPC and is enabled when an endpoint is configured through the standard OpenTelemetry variables:

OTEL_EXPORTER_OTLP_ENDPOINT=http://otel-collector:4317
OTEL_SERVICE_NAME=planrs
# Optional signal-specific endpoints:
# OTEL_EXPORTER_OTLP_TRACES_ENDPOINT=http://otel-collector:4317
# OTEL_EXPORTER_OTLP_LOGS_ENDPOINT=http://otel-collector:4317

Trace and log export are enabled independently by the general or signal-specific endpoint. Set OTEL_SDK_DISABLED=true to skip OpenTelemetry setup entirely. Without an endpoint the process still generates local trace and span ids for logging but does not try to reach a collector.

Architecture

  • Server — Axum serves the frontend, POST /api/graphql, the REST /api/setup, /api/login, /api/users, /api/roles, and /api/invitations routes (including invitation archive), and the /api/ws WebSocket. GraphQL covers workspace reads, document mutations, access relations, member activity, me, and the user directory.
  • Storage — PostgreSQL stores users, hashed login sessions, each document's latest Yrs state, a bounded recent update history, and document properties in JSONB. Every CRDT update is appended to the update log; full snapshots are materialized periodically so the hot path stays a small insert. A background job compacts old update rows while keeping a recent tail for history.
  • Authorization — the shared ReBAC engine in crates/planrs-auth resolves relationship grants for the server and the browser. The generic engine lives in crates/authz.
  • Unified WASM core — src/workspace_core.rs composes Yrs, the GlueSQL portable projection, the ReBAC model, and the local Juniper schema. The browser persists one binary snapshot (SQL projection + CRDT states + access state) in IndexedDB.
  • Web client — web/ is a Vite + Svelte 5 + TypeScript workspace. It opens one multiplexed WebSocket, caches documents in IndexedDB, and keeps editing offline through the WASM core. In production a service worker precaches the app shell; development deliberately unregisters it so hot reload stays fresh.
  • Observability — OpenTelemetry traces HTTP requests, GraphQL, repositories, CRDT work, ReBAC checks, and WebSocket operations. Domain mutations emit structured audit events on the audit target; auth sessions and WebSocket connections emit lifecycle events on the session target. Console logs are prefixed with the active trace_id and span_id, and SQLx spans include statement timing; override the default filter with RUST_LOG.

Development

make check runs the full local gate, including the dead-code and specification checks. make static runs only its static analysis (no tests): every finding is fixed, and dead code removed, before a change goes to review. The checks are:

  • WebSocket protocol: make wire writes the Rust and TypeScript codecs from src/controller/websocket.protocol, and make wire-check fails when they are out of date (DR-0052).
  • Docs: make spec-check validates requirement ID format and uniqueness, spec/design index coverage, and relative documentation links.
  • Rust: cargo clippy --workspace --all-targets -- -D warnings catches unreachable and unused code, and cargo machete (install with cargo install cargo-machete --locked) reports dependencies that are no longer used. make machete runs the dependency scan on its own.
  • Web: bun run lint (Biome) enforces the recommended rule set, and bun run lint:dead (Knip) reports unused files, exports, exported types, and dependencies. web/knip.json marks the service worker as an entry point and ignores generated wasm-bindgen output. The app tsconfig also enables noUnusedLocals and noUnusedParameters, so dead locals and imports fail the normal type-check.

make verify adds the production web build, browser interaction tests, and the Storybook build.

.gitea/workflows/ci.yml checks Rust formatting, runs clippy, scans for unused dependencies, and runs the test suite; it type-checks the web app, lints it with Biome, scans for dead files/exports/dependencies, validates the specification index, and builds both the web app and the container through the same make image recipe. Pushes to main and v* tags publish the image to the Gitea container registry as <server>/<owner>/planrs; set the repository variable REGISTRY to override the registry host.

For frontend development with hot reload, run Vite alongside the backend:

make up-build   # in one terminal
cd web && bun install && bun run dev   # in another

Open http://localhost:5173; Vite proxies /api (including /api/ws) to the backend. See web/README.md for the frontend layout and build commands.

Rebuild the WASM package after changing Rust code:

rustup target add wasm32-unknown-unknown
cargo build --target wasm32-unknown-unknown --lib --release
wasm-bindgen --target web target/wasm32-unknown-unknown/release/planrs.wasm --out-dir web/src/wasm

From web/, bun run build:wasm performs both steps through scripts/session-build.sh wasm, which reads the real Cargo target directory (it may be shared between worktrees) and holds a lock while it builds and generates the bindings. WasmCrdtDocument exposes defineShape, setSection, applyUpdate, loadSnapshot, getSection, and snapshot; schema and section values are JSON strings.

Specifications, design, and tests

Behavior is specified by requirement IDs in co-located *.spec.md files; tests are the acceptance evidence. Start at AGENTS.md for the agent workflow, docs/specs/README.md for the requirement registry and gap register, and docs/design/README.md for design decisions.

The test suites remain the executable record of current behavior:

  • Rust server tests — login, users, GraphQL, ReBAC enforcement, trash, document mutations, and the WebSocket protocol.
  • Repository tests — update snapshots, property projection and filters, trash/purge, and update-log compaction.
  • CRDT tests and unit tests — concurrent merge behavior, section types, references, and structural rules.
  • Authorization tests — roles, folder and parent inheritance, direct-grant precedence, ownership, and public links.
  • Generic authz tests — the subject / relation / resource contract, depth limits, and model round-trips.
  • Web tests — folders, sidebar behavior, page sections, tables, properties, rich text, sharing, routing, and offline sync. Browser-only interaction tests live beside them as *.browser.test.ts.

Specifications carry the functional requirements in requirement-ID form. Product-wide rules are in product requirements; feature specs are co-located: GraphQL relations, share dialog, sidebar, relation transport, and workspace index ordering. Run make spec-check to validate requirement IDs, index coverage, and links.

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages