What TrailBase does
TrailBase is an open-source application backend, released under the OSL-3.0 licence and written in Rust. It fits in a single executable that bundles SQLite, an HTTP server, authentication, file storage, a WebAssembly runtime for your server code and an admin console.
The idea: you describe your data as strictly typed SQL tables, then declare a Record API on each. TrailBase derives REST endpoints from it — create, read, update, delete, filtered lists, realtime subscriptions — and JSON schemas that feed typed client libraries for JavaScript/TypeScript, Dart/Flutter, Rust, Go, Python, C#, Swift and Kotlin.
What TrailBase gives you
- APIs without code — one table, one declaration, and the REST API answers with cursor pagination and filters.
- Realtime — your clients subscribe to changes on a table or a record.
- User accounts — sign-up, sign-in, email verification, two-factor authentication, OAuth providers and bundled login pages.
- Precise access control — per-role access lists, refined by SQL rules such as "only the author edits their row".
- An admin console — tables, SQL editor, accounts, request logs and settings, in the browser.
Hosted backend or TrailBase on your VPS
Scroll the table
| Hosted backend (Firebase-style) | TrailBase on your VPS | |
|---|---|---|
| Data | With the provider | On your server |
| Billing | Usage-based: reads, writes, traffic | The fixed price of the VPS |
| Data model | NoSQL documents | SQL tables and versioned migrations |
| Moving parts | None, but no control | One container and one data folder |
| Maturity | Established service | Young project, alpha stage |
Prepare the server
An Ubuntu 24.04 VPS with 1 GB of RAM and 1 vCPU is enough: at rest, TrailBase uses between 80 and 150 MB of memory. Install Docker and the Compose plugin, and point a domain name at the VPS: your apps will call the API at that HTTPS address, and authentication email links will point back to it.
TrailBase is alpha by its own authors' account: it releases often, and not every version is equal. Pin a precise image version, as below, rather than latest.
Install TrailBase with Docker Compose
Prepare the folder and the .env file
The file holds the public domain and the password the administrator account will use.
mkdir -p /opt/trailbase && cd /opt/trailbase cat > .env <<EOF DOMAIN=trailbase.example.com ADMIN_PASSWORD=$(openssl rand -hex 12) EOF chmod 600 .envWrite the docker-compose.yml file
On the very first start, TrailBase creates the administrator
admin@localhostwith a random password written to its logs. The command starts the server once inside the container, replaces that password withADMIN_PASSWORD, then launches the server. The port is published on the loopback only: nginx will serve it over HTTPS.services: trailbase: image: trailbase/trailbase:0.36.3 container_name: trailbase restart: unless-stopped environment: ADMIN_PASSWORD: ${ADMIN_PASSWORD:?} PUBLIC_URL: https://${DOMAIN:?} entrypoint: ["tini", "--", "sh", "-c"] command: - | set -e D=/app/traildepot if [ ! -f "$$D/.admin-set" ]; then /app/trail --depot "$$D" run --address 127.0.0.1:4000 & pid=$$! until curl -fsS http://127.0.0.1:4000/api/healthcheck >/dev/null 2>&1; do sleep 1; done /app/trail --depot "$$D" user change-password admin@localhost "$$ADMIN_PASSWORD" kill "$$pid"; wait "$$pid" || true touch "$$D/.admin-set" fi exec /app/trail --depot "$$D" run --address 0.0.0.0:4000 volumes: - trailbase-depot:/app/traildepot ports: - "127.0.0.1:4000:4000" volumes: trailbase-depot: {}Start and check
The health check answers
Okonce the server is ready.docker compose up -d --wait curl -s http://127.0.0.1:4000/api/healthcheck
Change the administrator account's address
The account is called admin@localhost: it is not a mailbox that receives mail. Once signed in to the console (https://your-domain/_/admin/), give it a real address, or create your own account and promote it with docker exec trailbase /app/trail admin promote <address>. Keep the data folder safe too: it holds the database, the configuration and the keys that sign session tokens.
Publish TrailBase over HTTPS behind nginx
The reverse proxy terminates TLS and forwards everything to the local port. Two details matter: pass X-Forwarded-For, otherwise logs and rate limiting see the proxy's address, and turn off buffering so realtime subscriptions, served as Server-Sent Events, arrive without delay.
server {
listen 443 ssl;
server_name trailbase.example.com;
ssl_certificate /etc/letsencrypt/live/trailbase.example.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/trailbase.example.com/privkey.pem;
client_max_body_size 50m;
location / {
proxy_pass http://127.0.0.1:4000;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto https;
# realtime subscriptions (SSE)
proxy_set_header Connection '';
proxy_http_version 1.1;
proxy_buffering off;
proxy_cache off;
}
}Create a table and open its first API
A table is created from the console's explorer, which writes the migration for you, or with an SQL file in migrations/main/. It must be STRICT and have an integer or UUID primary key. The Record API is then declared in the console, or in config.textproto: here, anyone can read, only signed-in users can create.
docker exec trailbase sh -c 'cat > /app/traildepot/migrations/main/U1800000000__create_notes.sql <<EOF
CREATE TABLE notes (id INTEGER PRIMARY KEY, body TEXT NOT NULL) STRICT;
EOF'
docker exec trailbase sh -c 'cat >> /app/traildepot/config.textproto <<EOF
record_apis: [
{ name: "notes" table_name: "notes" acl_world: [READ] acl_authenticated: [CREATE, READ] }
]
EOF'
docker compose restartAn anonymous create is refused (403); a create with a sign-in token is accepted, and the list is readable by everyone.
TOKEN=$(curl -s -H 'content-type: application/json' \
-d '{"email":"admin@localhost","password":"<ADMIN_PASSWORD>"}' \
https://trailbase.example.com/api/auth/v1/login | jq -r .auth_token)
curl -s -H "Authorization: Bearer $TOKEN" -H 'content-type: application/json' \
-d '{"body":"Bonjour"}' https://trailbase.example.com/api/records/v1/notes
curl -s https://trailbase.example.com/api/records/v1/notesSign your users in
TrailBase provides the sign-up, sign-in and token refresh endpoints, plus ready-made login pages under /_/auth/. The client libraries manage the session for you: the trailbase npm package is initialised with your instance's address, signs the user in and attaches their token to every call.
For email verification and password reset, configure an SMTP server in the console settings: without it, no email goes out. OAuth providers (Google, GitHub, Microsoft…) are set up in the same place, using the public address declared in PUBLIC_URL.
Backup and updates
All of TrailBase's state lives in the trailbase-depot volume: SQLite databases, migrations, configuration, uploaded files and keys. A consistent backup is taken with the server stopped, in a few seconds:
cd /opt/trailbase
docker compose stop
docker run --rm -v trailbase_trailbase-depot:/d -v "$PWD":/b alpine tar czf /b/traildepot-$(date +%F).tar.gz -C /d .
docker compose startTo update, read the release notes first, back up, change the image number in docker-compose.yml, then run docker compose up -d. At the alpha stage, test the new version on a copy of the folder before applying it in production, and keep the previous image at hand to roll back.
TrailBase in one click on ServOrbit
From your client area, the Marketplace installs TrailBase on your VPS: pinned official image, administration password generated and shown in the client area, port published on the loopback and nginx reverse proxy over HTTPS. Pick a subdomain of one of your domains, or the VPS's free subdomain (trailbase.{dns_slug}.servorbit-dns.com): no need to buy a domain name. All that is left is to create your tables.
servorbit.com/ma-en/blog/self-host-trailbase-vps-firebase-alternative


