Skip to content
Public template

About

Rust and Tokio starter template for RentnerProxy apps, with a TypeScript UI.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

RentnerProxy app template (Rust)

Use this template or fork it to start a RentnerProxy app with a Rust backend. Greeting is a small Tokio backend built on rentnerproxy-app-runtime with a packaged React UI. It saves one greeting per installation, follows the host theme and language, and asks the host to confirm a change. It also hooks into the platform's Proxy Hosts table: a Greeting column and a row action whose dialog the platform draws with its own components.

It behaves like the TypeScript template app-template-ts and passes the same runtime test. Choose Rust for CPU-heavy or memory-sensitive apps on small appliances:

Backend Peak memory Threads bin/app
Rust 18 MB 2 12 MB
Bun (TS) 56 MB 16 109 MB

Measured on Linux AMD64 with 400 Greeting operations. The manifest therefore declares memoryMiB: 32 and processLimit: 16.

Run locally

Use AMD64 or ARM64 Linux (or WSL), Bun 1.4.4, rustup (it installs the toolchain pinned in core/rust-toolchain.toml), GNU tar and zstd.

bun install --frozen-lockfile --ignore-scripts
bun run dev
bun run check        # TypeScript, Oxlint, formatting, rustfmt and Clippy
bun run core:test    # Rust backend tests
bun run core:build   # debug backend for bun run test
bun run test         # TypeScript tests and the runtime test against the backend
bun run build

Open the loopback URL printed by bun run dev. It builds the debug backend, and the local Platform stub starts it with synthetic installation data and hosts the UI in an isolated iframe. Use the controls to switch theme, language or route, simulate readiness changes, or replace the iframe. The greeting survives a restart in .app-dev/data.

The stub also serves the core.sock platform API from the published contract: context, authorization checks, notifications, audit events, owned proxy host changes as durable operations, and the event stream. Operations it does not simulate answer 501 notImplemented. To give the app a database, set APP_DEV_DATABASE_URL to the superuser URL of a disposable PostgreSQL 18. The stub then provisions the database and runs the migrations like the platform. With APP_TEST_DATABASE_URL pointing to such a server, bun run test checks the provisioning and bun run test:database checks the backend's own connection.

To see the UI drawn the way the platform draws installed apps, start a platform checkout's dev server with APP_UI_DEV_DIR set to this repository's absolute dist/dev-ui path and APP_UI_DEV_API set to the stub URL followed by dev/v1/platform-call, then open /dev/app-ui there as the owner. Choose UI bridge 1.3.0 and the keys greeting-read,greeting-write; the page surface shows the Greeting page, the host row dialog surface the row action for the proxy host UUID you enter. The preview forwards app operations to the stub with those keys, and the stub checks them against api/openapi.json like the platform does.

bun run build writes a .tar.zst development archive under dist/ with a synthetic source identity. GitHub CI builds the same package on both Linux architectures, runs the packaged backend in the platform appliance image and attaches development archives with the tested repository ID and commit.

Layout

Path Content
core/ The Rust backend: src/lib.rs starts the app, src/greeting.rs and src/host_greetings.rs implement the operations, src/database.rs connects to the app database
web/src/ The React UI in features/Greeting/, the host row dialog in features/HostGreeting/, shared validation in lib/, and the TypeScript tests
scripts/ Build, dev host and Platform stub, run from the root package.json
api/openapi.json, app.config.json, migrations/ The app's operations, its manifest and its data migrations

Adapt the app

  • Change the namespaced app ID, version, display metadata and requested permissions in app.config.json. The build validates it against @rentnerproxy/app-contracts, and the backend reads the same file when it checks its bootstrap.
  • Define app operations and their permissions in api/openapi.json. The example separates greeting-read and greeting-write. This document describes only the app's own operations; the platform protocol comes from the contract. Its x-rentnerproxy-native-ui block lets the platform render the overview form and details table natively.
  • Implement operations in core/src/ with the App trait of rentnerproxy-app-runtime, and the static React UI in web/src/features/Greeting/. The UI requests operations through the typed MessageChannel bridge. The backend stays the authority for every operation; the UI's checks only help the user.
  • Extend platform surfaces in x-rentnerproxy-extensions of api/openapi.json. The example declares an app.page for the Greeting page, a proxyHosts.table.column answered by get-host-greetings in core/src/host_greetings.rs with one cell per visible host, and a proxyHosts.table.rowAction that opens web/src/features/HostGreeting/. That dialog is drawn with @rentnerproxy/app-ui: the app renders UI kit elements in its hidden frame and the platform draws them as its own dialog, including the form draft, Save, Discard, Close and the unsaved-change lock. The host operations declare proxy.hosts.read.v1 access, so the platform checks each host and drops the cells of hosts a user may not see; the manifest requests that grant.
  • A repository created from this template does not inherit its labels. In a new RentnerProxy repository, copy the labels that .github/labeler.yml and Dependabot use before the first pull request: gh label clone RentnerProxy/app-template-rs --repo RentnerProxy/<repository>. Outside the RentnerProxy organization, the labeling, autofix and PR maintenance jobs are skipped.

Platform passes the bootstrap descriptor on stdin and authorizes access to the private app.sock and core.sock sockets. Bootstrap::read checks it, and the backend verifies its own installation context with PlatformClient::verify_context before it announces readiness. AppServer authenticates every request on app.sock and validates payloads and results against the contract. Greeting stores its greeting in its private working directory.

The requires ranges in app.config.json decide the protocol versions the app runs with. The platform negotiates the lower bound of each range, at most the version it implements, and tells the app exactly those versions in the bootstrap. Bootstrap::read accepts them, and readiness reports the negotiated appProtocol, capped at the protocol of the runtime's contract crate (PROTOCOL_VERSION). Keep >=1.0.0 <2.0.0 to run on every platform of major 1. Raise a lower bound only when the app uses a feature of that protocol, and for appProtocol or platformApi only with a rentnerproxy-app-runtime release that speaks it; platforms below it then refuse to install the app. The example requires uiBridge >=1.3.0 <2.0.0, because the platform draws the row action from UI kit elements from UI bridge 1.3.0 on; an app without UI kit elements can keep >=1.0.0.

Every app operation carries an idempotency key (request.idempotency_key()), and the platform may deliver the same request again, for example after a lost response. save-greeting sets an absolute value, so a repeat is harmless. An operation whose repeat would change state again, such as one that appends, counts or sends something, must store each key with its result in the same transaction as the change and answer a repeat with the stored result.

PlatformClient calls core.sock through the contract's typed request and response descriptors. Give every change an idempotency key from new_idempotency_key() and reuse it for retries, also after a restart; the client repeats such calls itself when the platform is briefly unavailable. wait_for_operation() polls durable operations, and follow_events() resumes the event stream from the last processed cursor and calls your on_resync when the cursor expired (410). An error with stale_generation() (412, or a rejected credential or generation) means a newer generation replaced this process: stop background work instead of retrying.

The sandbox counts threads against processLimit and admits only Unix sockets, so the backend runs on a current-thread Tokio runtime with a small blocking pool.

Data and migrations

The platform provisions a PostgreSQL database for apps that declare data. It runs the declared migrations/**.sql steps in one transaction as a separate schema owner and records the reached version. Steps must be plain SQL without transaction control or psql commands. Version 0 means a new installation; each step leads from fromVersion to the target. The example targets version 2 from both 0 and 1, because Greeting 1.0 kept version 1 in files only. Bump targetVersion, readVersions and writeVersions together and add a step for every version that installations may have.

At runtime, AppDatabase::from_env() reads RENTNERPROXY_APP_DATABASE_URL_FILE, and app::connect() in core/src/database.rs connects with tokio-postgres as the runtime role through the platform's socket directory. That role may only read and change rows in the app schema, such as the example table app.greeting_history. Keep the URL and password out of logs.

Package and submit

The build produces bin/app, a generated app.json with target and source identity, api/openapi.json, ui/ assets, migrations/, and LICENSE. The backend is a native binary linked against the glibc of the build host. Build on a host whose glibc is not newer than the appliance's (Debian 13); the CI runners and the appliance runtime test check this.

The Marketplace candidate build uses the same bun run build entrypoint. It supplies APP_PACKAGE_DIR, APP_TARGET, APP_SOURCE_REPOSITORY_ID and APP_SOURCE_COMMIT.

  • Crates: it fetches the crates of core/Cargo.lock. They must come from crates.io, or from a RentnerProxy Git repository pinned to a full commit.
  • Toolchain: it compiles the backend offline with its own pinned stable Rust toolchain on Debian 13, without core/rust-toolchain.toml and without .cargo/ configuration. Keep rust-version in core/Cargo.toml accurate.
  • Checks: it checks the package against the appliance's libraries and starts it in the appliance.

Push the intended revision to a public GitHub repository. Submit its owner/repo and the full commit SHA from git rev-parse HEAD, along with the app ID, version, and targets. Marketplace builds the submitted source in isolation. Its approval and signed catalog workflow uses the exact approved package digests.

About

Rust and Tokio starter template for RentnerProxy apps, with a TypeScript UI.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Used by

Contributors

Languages