# Deploy the server

The server is one Docker container. It serves the parent web app, the API for the kid Macs and the Mac app downloads. It keeps all data in one folder.

## 1. Create the files

On the Linux host, make a folder for Guardian:

```sh
mkdir -p ~/guardian && cd ~/guardian
```

Create `compose.yaml`:

```yaml
services:
  guardian:
    image: ghcr.io/tubededentifrice/guardian:latest
    restart: unless-stopped
    env_file: .env
    ports:
      - "127.0.0.1:8787:8787"
    volumes:
      - ./data:/data
```

If the reverse proxy is on a different host, change the port line to `"8787:8787"`.

Create `.env`:

```sh
PUBLIC_URL=https://guardian.example.org
TZ=Europe/Paris
LLM_BASE_URL=https://api.openai.com/v1
LLM_API_KEY=
LLM_MODEL=gpt-6-luna
```

| Variable | Value |
|---|---|
| `PUBLIC_URL` | The HTTPS address of the server. No trailing slash. |
| `TZ` | Your time zone. Schedules and daily limits use it. You can change it later in Settings. |
| `LLM_BASE_URL` | Optional. An OpenAI-compatible endpoint. |
| `LLM_API_KEY` | Optional. The key for that endpoint. |
| `LLM_MODEL` | Optional. The model name. |
| `LLM_REASONING_EFFORT` | Optional. `low` makes decisions faster with reasoning models. |
| `LOG_LEVEL` | Optional. `info` (default) or `debug`. |
| `MAC_APPCAST_URL` | Optional. The Mac app update feed. Default: the signed app of the Guardian project. |

> [!WARNING]
> Passkeys and push notifications are bound to the host name of `PUBLIC_URL`. If you change it later, each parent must add a new passkey and turn on notifications again.

## 2. Start the server

```sh
docker compose up -d
curl -s localhost:8787/healthz
```

The answer is `{"ok":true}`. At the first start, the server creates the database and the push keys in `data/`.

## 3. Set up the reverse proxy

The proxy must:

- Pass `Host`, `X-Forwarded-For` and `X-Forwarded-Proto`.
- Not buffer the event streams (`/api/live` and `/api/device/v1/stream`).
- Keep these streams open for at least 90 seconds without data.
- Not ask for a login (for example Cloudflare Access). The Mac app cannot pass it. Guardian has its own passkey login.

Caddy:

```
guardian.example.org {
	reverse_proxy 127.0.0.1:8787
}
```

nginx, in the `server { … }` block of the host, with TLS:

```nginx
location / {
    proxy_pass http://127.0.0.1:8787;
    proxy_http_version 1.1;
    proxy_set_header Connection "";
    proxy_set_header Host $host;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header X-Forwarded-Proto $scheme;
    proxy_buffering off;
    proxy_read_timeout 120s;
}
```

Check from another computer:

```sh
curl -s https://guardian.example.org/healthz
```

## The AI decides rule

The server asks the LLM only for groups with the **AI decides** rule, for example YouTube. The LLM gets the page details, the age of the kid, your instructions and the history of the day. It does not get the name or the birthdate of the kid.

Without the `LLM_*` variables, these pages get a challenge, and Settings shows "AI not set up".

Write your rules for the AI in **Settings** > **Instructions for the AI**, and in each kid profile. Example: "Science, engineering and learning videos are fine. Block attention-grabbing entertainment such as pranks and challenge videos."

## Build the image yourself

To build from the source in place of the published image:

```sh
git clone https://github.com/tubededentifrice/guardian.git
cd guardian
cp deploy/.env.example deploy/.env   # then edit it
docker compose -f deploy/docker-compose.yml up -d --build
```

The data is then in `deploy/data/`.

Next: [add the parents](https://guardian.opendle.com/docs/parents.md).

