---
title: Self-hosting
description: Run your own Hindsight server with Docker, and every setting it reads.
sidebar:
  order: 3
---

The server ships as a container image. Every push to `main` that touches the server's code builds it and publishes it to `ghcr.io/mixidthesilly/hindsight-server`, tagged `latest` and with the commit hash.

You need Docker, a domain with an HTTPS reverse proxy in front of the server, and a Hack Club Auth app so people can sign in.

## The compose file

`deploy/docker-compose.yml` is a production stack with three services:

- `postgres`: `postgres:17-alpine`, with its data in a `pgdata` volume. Published on `127.0.0.1:5432` only.
- `server`: the image above. Published on `127.0.0.1:8080` only, so nothing reaches it without your proxy.
- `backup`: a `pg_dump` every 24 hours, gzipped into a `backups` volume. It keeps the last 14.

Put your settings in a `.env` file next to it:

```bash
POSTGRES_PASSWORD=pick-something-long
PUBLIC_URL=https://hindsight.example.com
# openssl rand -hex 32
SESSION_SECRET=
HCA_CLIENT_ID=
HCA_CLIENT_SECRET=
```

Those five are required: compose refuses to start without them. Then:

```bash
docker compose -f deploy/docker-compose.yml up -d
```

The compose file also reads these, all optional:

| Variable | Default | What it does |
|---|---|---|
| `HINDSIGHT_IMAGE` | `ghcr.io/mixidthesilly/hindsight-server:latest` | Use another image or tag. |
| `HINDSIGHT_PORT` | `8080` | The port published on `127.0.0.1`. |
| `HCA_BASE_URL` | `https://auth.hackclub.com` | Another Hack Club Auth server. |
| `RUST_LOG` | `hindsight_server=info,tower_http=info` | Log filter. |
| `ADMIN_HCA_IDS` | empty | See [settings](#every-server-setting). |
| `ADMIN_UPSTREAM` | empty | See [settings](#every-server-setting). |
| `CLAIM_SIGNING_KEY` | empty | See [settings](#every-server-setting). |
| `SLACK_BOT_TOKEN` | empty | See [the Slack bot](#the-slack-bot). |
| `SLACK_CHANNELS` | empty | See [the Slack bot](#the-slack-bot). |

### The reverse proxy

Three things your proxy has to get right:

- It must pass WebSocket upgrades through. The dashboard's live updates use `/ws`.
- It must allow request bodies of at least 32 MB. A daemon that was offline for a while uploads big batches, and the server accepts up to 32 MiB per upload.
- It has to reach the server. On the host that's `127.0.0.1:8080`. If your proxy runs in Docker, the compose file has a commented-out `networks` block that shows how to give the server an alias on your proxy's network.

The server checks itself at `GET /health`. It answers `{"status":"ok","version":"..."}` after a quick database ping, and 503 if Postgres is down. The image's own healthcheck calls it every 30 seconds.

## The image

The `Dockerfile` builds in two stages. The first compiles `hindsight-server` in `rust:1-bookworm` with `cargo build --release --locked -p hindsight-server`. The second is `debian:bookworm-slim` with `ca-certificates` and `curl`, running as a system user with uid 10001. It sets `BIND_ADDR=0.0.0.0:8080` and exposes port 8080.

To build it yourself:

```bash
docker build -t hindsight-server .
```

## Every server setting

The server reads these from the environment. It also loads a `.env` file if it finds one; real environment variables work the same and are what production uses. Blank values count as unset.

| Variable | Default | What it does |
|---|---|---|
| `DATABASE_URL` | none, required | Postgres connection string. |
| `BIND_ADDR` | `0.0.0.0:8080` | Address and port to listen on. |
| `PUBLIC_URL` | `http://localhost:8080` | The server's public address. Used to build the OAuth redirect (`PUBLIC_URL/auth/callback`) and the device-login links. A trailing slash is dropped. If it starts with `https://`, cookies are marked secure. |
| `SESSION_SECRET` | random per start | At least 32 characters. Encrypts session cookies. If it's unset the server makes a random one and warns you: everyone is signed out on every restart. A value shorter than 32 characters stops the server from starting. |
| `HCA_BASE_URL` | `https://auth.hackclub.com` | The Hack Club Auth server. |
| `HCA_CLIENT_ID` | empty | Your Hack Club Auth app's id. |
| `HCA_CLIENT_SECRET` | empty | Its secret. With either missing, `/auth/login` is off and answers 503. |
| `ATTENTION_WINDOW_SECONDS` | `35` | How long after a sign of attention the clock keeps running. Allowed range 30 to 900. |
| `CONTRIBUTION_WINDOW_SECONDS` | `300` | Time only counts within this many seconds of something you did (a prompt, an edit, a review, an answer to Byte, your own commit). Allowed range 0 to 1800. 0 turns the rule off. |
| `ADMIN_HCA_IDS` | empty | Comma-separated Hack Club ids that get an Admin link in the dashboard's sidebar. The admin panel keeps its own list. This only decides who sees the link. |
| `ADMIN_URL` | `/admin` | Where that link goes. |
| `ADMIN_UPSTREAM` | unset | A private admin panel to serve at `/admin` on this server's address, such as `http://secrets:8090`. Plain `http://`, a host and port only, no path. Anything else stops the server from starting, so a typo can't send admins' cookies somewhere odd. Unset, `/admin` is a 404. |
| `CLAIM_SIGNING_KEY` | derived from `SESSION_SECRET` | 64 hex characters, an ed25519 seed. Signs [claims](/docs/developers/api#claims). Set it and changing `SESSION_SECRET` no longer changes the signing key. |
| `SLACK_BOT_TOKEN` | unset | See [the Slack bot](#the-slack-bot). Starts with `xoxb-`. |
| `SLACK_CHANNELS` | unset | Comma-separated channel ids. Set both Slack variables or neither. |
| `OBJECT_STORE_BUCKET` | unset | Read but not used yet. |
| `OBJECT_STORE_ENDPOINT` | unset | Read but not used yet. |
| `RUST_LOG` | `hindsight_server=info,tower_http=info` | Log filter. |

The two windows are the crediting rules. The daemon has no such settings and takes whatever the server says each time it syncs. When you change either, or when a release changes the rules in code, the server starts redoing everyone's stored time in the background. Uploads keep working meanwhile.

The server doesn't check `PUBLIC_URL` against anything, so get it right. A wrong value breaks the sign-in redirect and the device-login links your daemons show.

## Hack Club sign-in

People sign in with Hack Club Auth, and each daemon is linked to an account through the device-code flow (`hindsight-daemon login`, which sends the person to your server's `/device` page).

1. **Make an app**

    Create one at [auth.hackclub.com](https://auth.hackclub.com) under Developer Apps.

2. **Set the redirect URI**

    Use `PUBLIC_URL/auth/callback`, for example `https://hindsight.example.com/auth/callback`.

3. **Allow every scope**

    The server asks for `openid profile email slack_id verification_status`. The app must be allowed all five. `email` is the one people forget. It lets Hack Club reviewers find an account by its address.

4. **Copy the id and secret**

    Put them in `HCA_CLIENT_ID` and `HCA_CLIENT_SECRET`.

## The Slack bot

This part is optional. With a bot token and a list of channels, the server adds everyone who has a Slack account to those channels: people already signed up when you turn it on, then each new person the first time they sign in. It asks Slack about each person once and records the answer, so someone who leaves a channel isn't pulled back in. It adds one person every 1.2 seconds, which is about what Slack's rate limit for inviting allows.

Create the app from this manifest (`deploy/slack-app-manifest.yml`) at api.slack.com/apps, under Create New App, then From a manifest:

```yaml
display_information:
  name: Hindsight
  description: Adds people who sign up for Hindsight to its Slack channels.
  background_color: "#1a1a1a"
features:
  bot_user:
    display_name: Hindsight
    always_online: false
oauth_config:
  scopes:
    bot:
      - channels:join            # join a public channel to add people to it
      - channels:write.invites   # add people to public channels
      - groups:write.invites     # add people to private channels the bot is in
settings:
  org_deploy_enabled: false
  socket_mode_enabled: false
  token_rotation_enabled: false
```

Install it to your workspace, then copy the bot token from OAuth & Permissions into `SLACK_BOT_TOKEN`. In `SLACK_CHANNELS`, use channel ids (like `C0123ABCDEF`), not names. A `#name` is refused and the server won't start. The id is at the bottom of the channel's details in Slack. For a private channel, add the bot to it by hand first.
