Self-hosting

TrailBase on a VPS: a self-hosted Firebase backend on SQLite

Firebase and its hosted cousins settle the backend question quickly, then raise another one: the bill, the quotas and where your data lives. TrailBase takes a different route: a single binary, written in Rust, that turns your SQLite tables into REST and realtime APIs, manages your users' accounts and ships an admin console. This guide installs it on a VPS with Docker Compose, publishes it over HTTPS behind nginx, and opens a first API end to end.

Deploy on a VPS Cloud →
6 min read3 steps
Contents· What TrailBase does1/11
  1. 01What TrailBase does
  2. 02What TrailBase gives you
  3. 03Hosted backend or TrailBase on your VPS
  4. 04Prepare the server
  5. 05Install TrailBase with Docker Compose
  6. 06Change the administrator account's address
  7. 07Publish TrailBase over HTTPS behind nginx
  8. 08Create a table and open its first API
  9. 09Sign your users in
  10. 10Backup and updates
  11. 11TrailBase in one click on ServOrbit

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
DataWith the providerOn your server
BillingUsage-based: reads, writes, trafficThe fixed price of the VPS
Data modelNoSQL documentsSQL tables and versioned migrations
Moving partsNone, but no controlOne container and one data folder
MaturityEstablished serviceYoung 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

  1. 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 .env
  2. Write the docker-compose.yml file

    On the very first start, TrailBase creates the administrator admin@localhost with a random password written to its logs. The command starts the server once inside the container, replaces that password with ADMIN_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: {}
  3. Start and check

    The health check answers Ok once 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 restart

An 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/notes

Sign 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 start

To 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.

Share this articleservorbit.com/ma-en/blog/self-host-trailbase-vps-firebase-alternative

Your application backend, on your VPS

Prices shown excluding VAT, with their renewal price.