# Self-hosting

Run the double-entry engine, web app, and CLI on your own server or computer for $0 forever. Each book lives in one SQLite file with no external database.

- **Core engine, web app, and Lean 4 proofs:** `AGPL-3.0-only` ([github.com/Gant-Street/rastrata](https://github.com/Gant-Street/rastrata))
- **CLI, MCP server, and plugin SDK:** `MIT`

## Run with Docker (recommended for servers)

One container runs the web app, API, SQLite storage, automated backups, and the `rastrata` CLI. Rastrata refuses to listen on a network address until you set a password.

1. Download [`docker-compose.yml`](https://github.com/Gant-Street/rastrata/blob/main/docker-compose.yml) from the repository.
2. Generate a password (at least 12 characters) and start the container:

```sh
export RASTRATA_PASSWORD="$(openssl rand -base64 18)"
docker compose up -d
```

3. Open `http://localhost:7278` and sign in with your password.

### Reverse proxy, custom domain, and secrets

- **Custom domain or PaaS (Railway, Render, Coolify, Caddy, Nginx):** Set `RASTRATA_PUBLIC_ORIGIN=https://books.example.com`. Rastrata adds that hostname to its allowed hosts, checks browser origins against HTTPS, and enables HSTS.
- **Dynamic port:** Rastrata reads `PORT` on Railway and Render when `RASTRATA_API_PORT` is unset. Otherwise it listens on `7278`.
- **Docker Secrets:** Pass `RASTRATA_PASSWORD_FILE=/run/secrets/rastrata_password` instead of `RASTRATA_PASSWORD`.
- **Health checks:** `GET /live` and `GET /ready` answer `200` on any host header. The container includes a built-in `HEALTHCHECK`.
- **Data volume:** Mount `/data` to persistent storage. The container drops root privileges on startup and runs `rastrata-service` as PID 1 so SQLite flushes on stop.

Run CLI diagnostics or mint an agent token inside the running container:

```sh
docker exec rastrata rastrata doctor
docker exec rastrata rastrata tokens create --label "Claude Code" --preset auto
```

## Install on Mac or Linux (no Docker)

- **Supported platforms:** macOS (Apple silicon or Intel) and Linux (`x64` or `arm64` with `systemd`).
- Use a non-root account. The installer keeps all files inside your home directory.

1. Download `rastrata-VERSION-OS-ARCH.tar.gz` and its `.sha256` file from [GitHub releases](https://github.com/Gant-Street/rastrata/releases).
2. Check the hash and run the installer:

```sh
shasum -a 256 -c rastrata-VERSION-darwin-arm64.tar.gz.sha256
tar -xzf rastrata-VERSION-darwin-arm64.tar.gz
cd rastrata-VERSION-darwin-arm64
./install.sh
```

> **Note:** Extract with `tar` in Terminal instead of Finder on macOS to avoid Gatekeeper quarantine flags. If macOS blocks the binary, run `xattr -dr com.apple.quarantine rastrata-VERSION-darwin-arm64` and run `./install.sh` again.
3. Open the web app and run checks:

```sh
rastrata open
rastrata doctor
```

Pass `--port 7300` or `--data-dir /path/to/books` to `./install.sh` to pick another port or data folder.

## Default file locations

| Component | Default path |
| --- | --- |
| Binaries (`rastrata`, `rastrata-service`) | `~/.local/bin/` |
| macOS launchd service | `~/Library/LaunchAgents/com.rastrata.service.plist` |
| Linux systemd user unit | `~/.config/systemd/user/rastrata.service` |
| Books, backups, owner key, and logs (macOS) | `~/Library/Application Support/Rastrata` |
| Books, backups, owner key, and logs (Linux) | `${XDG_DATA_HOME:-~/.local/share}/rastrata` |
| Local web address | `http://127.0.0.1:7278` (loopback only) |

> **Caution:** The local install listens on `127.0.0.1` and guards API requests with `owner.key` inside your data folder. Keep your data folder private (`chmod 700`).
## Connect your agent

Mint a scoped token and write your agent runbook:

```sh
rastrata connect --preset auto
rastrata agent status
```

To connect a desktop agent over stdio MCP in Docker (Claude Desktop, Cursor, or Docker Desktop MCP Toolkit):

```sh
docker run --rm -i \
  -e RASTRATA_API_URL="https://books.example.com" \
  -e RASTRATA_TOKEN="rst_..." \
  ghcr.io/gant-street/rastrata-mcp:latest
```

## Backups and recovery

Point backups at an external drive or synced folder, and test a restore anytime:

```sh
rastrata backup folder /Volumes/Backups/rastrata
rastrata backup create
rastrata backup verify
rastrata backup drill
```

Restore an offline backup to a fresh SQLite file:

```sh
rastrata restore BACKUP_ID --to /path/to/restored.sqlite
```

## Self-hosted vs. Rastrata Cloud

| Capability | Self-hosted ($0) | Rastrata Cloud ($19/mo) |
| --- | --- | --- |
| Double-entry engine, web app, and Lean 4 proofs | Included | Included |
| SQLite storage and CSV / JSONL export | Included | Included |
| CLI and MCP server with no AI markup | Included | Included |
| Statement imports (CSV, XLSX, OFX, QFX, QBO) and MIT plugins | Included | Included |
| Live US bank feeds (Stripe Financial Connections) | Manual / SimpleFIN / plugins | Included (daily sync) |
| One-click Stripe & Ramp OAuth sync | CLI / API key / plugins | Included |
| Remote MCP access (`https://app.rastrata.com/mcp`) | Self-managed HTTPS | Included |
| Team & accountant seats and managed daily backups | Self-managed | Included (unlimited users) |

Your books stay portable in both directions. Export from Cloud to self-host, or move your local books to Cloud anytime.
