Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Deploying 4got

Quick Start

git clone https://github.com/your-user/4got.git && cd 4got
cp data/config.default.kdl data/config.kdl   # edit owner-secret!
docker compose up -d

Open http://localhost:8888 — you have a working search engine. See First-run configuration to set your admin secret and API keys.

Docker Compose

The recommended way to run 4got. The docker-compose.yml builds both the Go server and the optional Python sidecar.

# Start the server only (no browser-backed engines)
docker compose up -d

# Start with the Python sidecar (Google/Qwant/Yandex in a real browser, math answers, reverse image search)
docker compose --profile sidecar up -d

# View logs
docker compose logs -f server

# Stop everything
docker compose down

Configuration lives in data/config.kdl (mounted as a volume). The SQLite database (data/4got.db) is created automatically on first run.

To customise ports, API keys, or peer settings, copy the override example and edit it:

cp docker-compose.override.yml.example docker-compose.override.yml
# edit docker-compose.override.yml, then:
docker compose up -d

First-run configuration

  1. Copy data/config.default.kdl to data/config.kdl if you haven’t already
  2. Set owner-secret to a strong random string — this is your admin password:
    python3 -c "import secrets; print(secrets.token_urlsafe(32))"
    
  3. Add API keys in the api-keys block (all optional):
    • wolframalpha — instant answers
    • deepl — translation widget
    • spotify-client-id / spotify-client-secret — music results
  4. Configure engine groups in data/groups.kdl (the defaults are sensible)
  5. Start the server and visit /admin/login to authenticate as owner
  6. Optionally set peer-secret and configure data/peers.kdl for federated search across multiple instances
  7. Run ./4got --bench for this machine’s capacity report (see Size it below)

Prerequisites

  • Go 1.23+ (the go.mod targets 1.25 but 1.23+ should work)
  • SQLite3 development headers (e.g. libsqlite3-dev on Debian, sqlite-dev on Alpine)
  • GCC or a C compiler (required by go-sqlite3’s CGO binding)
  • The programs under Programs it calls, for the features that use them
  • Playwright (optional) for the Python sidecar that handles JS-rendered engine scraping

Programs it calls

Each is optional: without one, only its feature goes. The container image has the first five.

  • cjxl, djxl (libjxl-tools): JPEG XL captchas, banners and cached pictures; banners as PNG for browsers without JPEG XL; uploaded still banners
  • avifenc (libavif-bin): AVIF banners and captchas for browsers without JPEG XL (else PNG and JPEG)
  • pdftotext (poppler-utils): the text of attached PDFs
  • tesseract (tesseract-ocr): the text in an image searched or attached
  • zbarimg (zbar-tools): QR codes and barcodes in an image searched
  • pandoc (pandoc): the text of attached DOCX and ODT files
  • ffmpeg (ffmpeg): uploaded animated GIF banners, as animated AVIF

On Debian: apt install --no-install-recommends libjxl-tools libavif-bin poppler-utils tesseract-ocr zbar-tools, and pandoc ffmpeg for the last two (about 580 MB more). The container image takes those two with --build-arg EXTRAS="pandoc ffmpeg".

Building from source

make build

This writes the binary outside the source tree (to ~/.cache/go-builds/4got/). Avoid a bare go build inside go-server/ — it leaves a ~50 MB binary in the checkout, which is gitignored (so git never warns) but still churns through Syncthing/Dropbox and any filesystem snapshots. A test in the suite fails if one appears.

Python sidecar (local dev only)

python-sidecar/start.sh creates its virtualenv outside the checkout by default — at ${XDG_CACHE_HOME:-~/.cache}/4got/python-sidecar-venv — for the same reason: a Playwright env is ~400 MB. Point it wherever you like:

SIDECAR_VENV=/opt/4got/venv ./python-sidecar/start.sh
SIDECAR_VENV=.venv          ./python-sidecar/start.sh   # in-tree, if you prefer

It uses uv when installed and falls back to python3 -m venv + pip otherwise, so no extra tooling is required. None of this applies to the Docker deployment above, which installs into the image.

CGO must be enabled (it is by default). If cross-compiling, set CGO_ENABLED=1 explicitly:

CGO_ENABLED=1 go build -o 4got .

The binary is fully self-contained. Copy it alongside the data/, static/, and templates/ directories.

The documentation

The server serves this documentation at /docs/ when a built book sits at docs/book/ beside data/. The Docker image builds it. From source, make book builds it into ~/.cache/4got/book (it needs mdbook); copy that to docs/book/ beside your data/. Recommended: your own copy matches your version, which matters if you run an older release or a fork.

Directory layout

4got/
  go-server/
    4got          # the binary
  data/
    config.kdl    # main configuration
    *.kdl         # subsystem configs (peers, groups, captcha, etc.)
    4got.db       # SQLite database (created automatically)
  static/         # CSS, JS, fonts
  templates/      # HTML templates

The binary reads the file FGOT_CONFIG names, or else the first config.kdl in $FGOT_DATA_DIR, data/ under the working directory, or ../data/ (when running from go-server/). With none it says so at startup and runs on FGOT_* environment variables alone.

Running directly

cd /path/to/4got
./go-server/4got

By default it listens on 0.0.0.0:8888. Override via config.kdl or environment variables:

FGOT_PORT=9999 FGOT_HOST=127.0.0.1 ./go-server/4got

Running with systemd

A production-ready unit file ships in the repo at 4got.service. Install it:

sudo cp 4got.service /etc/systemd/system/4got.service
sudo systemctl daemon-reload
sudo systemctl enable --now 4got
sudo journalctl -u 4got -f

The unit file targets network-online.target, runs as user/group 4got, applies security hardening (ProtectSystem=strict, ProtectHome=yes, NoNewPrivileges, PrivateTmp), and sets LimitNOFILE=65536 for high-concurrency deployments. Edit ReadWritePaths if your data directory is not /opt/4got/data.

Server storage at rest, and a one-time VACUUM

What people keep on the server (settings, profiles, research contexts, bookmarks and folders, scheduled searches, pasted Goggles) is sealed under the server history key, as server history is. The first start of a version that seals it seals what was kept in the clear, in the background, a person at a time, and then truncates the WAL; its log line says how many values and how long it took. Back up history.key apart from the database: without it none of this can be read, and once anything is sealed a start without it refuses.

Pages freed before the database zeroed what it deletes (secure_delete, on since 2026-10-06) can still hold old values in the clear inside the database file. The binary has no flag for clearing them. To clear them once, stop the server and VACUUM the database, with free disk equal to its size (it holds the database for minutes when it is large, so do it in a maintenance window):

sudo systemctl stop 4got
sqlite3 /opt/4got/data/4got.db 'VACUUM;'
sudo systemctl start 4got

Rolling back. Roll back only to v0.452.10 or later: an earlier release deletes sealed research contexts at start and runs sealed scheduled searches. While rolled back, leave settings alone: a release before sealing shows the sealed ranking, profiles and contexts as empty, and a change made then wins over the sealed one at the next upgrade.

Reverse proxy

nginx

server {
    listen 443 ssl http2;
    server_name search.example.com;

    # The Privacy page says a visitor's address is written nowhere that
    # outlives the request; nginx writes it in both of these logs.
    access_log off;
    error_log /dev/null;

    ssl_certificate     /etc/letsencrypt/live/search.example.com/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/search.example.com/privkey.pem;

    # A browser's settings travel in a few cookies of up to 4 KB each, so its
    # Cookie header can pass 8 KB (every API key set: 11 KB; every key and
    # every engine's weight: 18 KB), and the first answer after the upgrade
    # that packs a browser's old cookies carries up to 24 KB of Set-Cookie (a
    # browser at Firefox's 180 cookies). nginx's defaults (8 KB a request
    # header, 4 KB of response headers) answer 400 and 502.
    large_client_header_buffers 4 32k;

    location / {
        proxy_pass http://127.0.0.1:8888;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;
        proxy_buffer_size 32k;
        proxy_buffers 8 16k;

        # SSE support (AI research agent)
        proxy_buffering off;
        proxy_cache off;
        proxy_read_timeout 120s;
    }

    # Optional: serve static files directly
    location /static/ {
        alias /opt/4got/static/;
        expires 7d;
    }
}

Caddy

{
    # The Privacy page says a visitor's address is written nowhere that
    # outlives the request; Caddy's error lines hold it, with the URL.
    log {
        format filter {
            wrap json
            fields {
                request>remote_ip delete
                request>client_ip delete
                request>remote_port delete
                request>uri delete
                request>headers delete
                request>tls delete
            }
        }
    }
}

search.example.com {
    reverse_proxy 127.0.0.1:8888
}

Caddy handles TLS automatically via Let’s Encrypt.

Docker / Podman

From nothing to a working 4got you own, in three steps. There is no published image, so you build one from the Dockerfile in the repo root first (about four minutes, six the first time; the image is about 370 MB). Every command works the same with docker in place of podman.

git clone <repo-url> 4got && cd 4got
podman build -t 4got .

1. Start it.

podman run -d --name 4got -p 8888:8888 -v 4got-data:/data 4got

Everything the server keeps lives in the 4got-data volume, mounted at /data: config.kdl, the other .kdl files, the database and the caches. On the first start the container copies the shipped files into the empty volume and starts config.kdl from config.default.kdl. Search at http://localhost:8888.

2. Get your owner secret. The owner secret is your admin password. On the first start the server makes a strong one, writes it into /data/config.kdl (readable by its owner only), and logs one line saying where it is, never the secret itself. Read it with:

podman exec 4got grep owner-secret /data/config.kdl

It stays the same across restarts. To set your own instead, pass it when you start the container; it wins over the file:

podman run -d --name 4got -p 8888:8888 -v 4got-data:/data -e FGOT_OWNER_SECRET='your-own-long-secret' 4got

3. Log in and work down the Suggestions. Open http://localhost:8888/admin/login, paste the secret, and you land on /admin. Suggestions lists what is worth doing next (API keys left empty, AI research off, and so on), each with the file and key to change. Switches change one setting at once, and Edit a file opens groups.kdl and the other offered files with Validate and Save; both write into the volume and keep a backup.

4. Size it. podman exec 4got ./4got --bench prints a capacity report and exits, leaving the running server alone: memory and disk, how much cache fits, searches and people so far, your API keys’ daily limits, how many people a day each group could serve, and how fast history grows, with when to prune it. Set the cache sizes and group limits from it, and run it again once real searches have come in.

To change anything else by hand, edit the file in the volume and restart:

podman exec -it 4got sh    # files are in /data
podman restart 4got

To upgrade, rebuild the image, then podman rm -f 4got and run step 1 again with the same volume. Your config and secret are kept, files new in the release arrive, and files you deleted stay deleted (/data/.shipped-files remembers what was offered). Shipped updates to a file already in your volume, such as engines.kdl, do not replace your copy; only the *.default.kdl references are refreshed.

docker compose up -d (Docker Compose) does the same with the docker-compose.yml in the repo, and docker compose --profile sidecar up -d adds the Python sidecar; read the secret with docker compose exec server grep owner-secret /data/config.kdl.

Codebase size comparison

Measured 2026-10-27 at v0.408.1, with wc -l for lines and tok for tokens (Claude Opus 5.5’s tokenizer, an estimate), against 4get and SearXNG as of their 2026-08-01 commits. Vendored code (go-server/third_party, 8,106 lines) is left out.

LinesTokens
4got Go (minus tests)127,0631,926,507
4got browser JS and CSS24,929528,094
4got KDL config (engines, groups, translation)5,13465,090
4got HTML templates2,06375,558
4got Python (sidecar, tools)2,14129,430
4got, without tests161,3302,624,679
4got Go tests112,1812,092,128
SearXNG Python (minus tests)51,364625,301
SearXNG client (TypeScript, LESS)5,67751,409
SearXNG settings.yml3,45837,017
SearXNG Jinja templates2,29650,054
SearXNG, without tests62,795763,781
SearXNG tests3,76154,328
4get PHP38,092393,526
4get JS and CSS3,89629,340
4get (no tests)41,988422,866

Without its tests, 4got is 2.6 times SearXNG’s lines and 3.4 times its tokens, and 3.8 and 6.2 times 4get’s. It does more than either: oracles, the research agent and AI overview, Jev’s ranking, friends and federation, history with its lock, bookmarks and likes, pastes, Lens, and its own engines in Go. Its tests are nearly as large as its code: AI agents write them, and every claim in .meta/claims.jsonl names the test that catches its mutation.

Page weight

Measured 2026-10-29 on production (v0.435.1) with tools/page_weight.py, which loads a page in Firefox and reads the browser’s own Resource Timing (bytes over the wire, headers included; 0 for what came from the browser’s cache). The search was “sphagnum moss”, as a machine (no AI extras).

HTMLHTML as sentfirst visit, as sentagain, as sent
4got results page133.7 KB17.7 KB575 KB (87 requests)19.6 KB
DuckDuckGo, the JavaScript page19.2 KB19.5 KB1,641 KB (48 requests)20.1 KB

A second search costs about the same as its HTML, because 4got’s stylesheet and scripts are cached for a year (their addresses change with each release). The first visit’s 575 KB was 60 scripts (291 KB as sent, 743 KB once unpacked), 20 site icons (192 KB), the stylesheet (71 KB) and the page. The site icons are now kept at the size a row draws them: the same 20 came to 29 KB (favicon_shrink.go). Every results page still loads every script; loading each only where the page uses it is the next step.

An answer card is a small part of a page. Each card’s own HTML, on the same day: currency 1.3 KB, the time 1.5 KB, an area code 1.6 KB, a UUID 1.7 KB, weather 2.0 KB, a map 3.1 KB, radio by era 3.5 KB, the Wikipedia card with its other encyclopedias 4.0 KB, the dictionary with its tabs 6.9 KB. Of the 134 KB (unpacked) of the “sphagnum moss” page’s HTML, its 20 rows were 88 KB (4.4 KB each, with their menus), inline SVG icons 24 KB and inline scripts 5 KB.

4get.ca answered this server’s honest User-Agent with “Tshh, blocked!”, DuckDuckGo’s no-JavaScript page (html.duckduckgo.com) with a picture challenge, and searx.be with a browser check, so their results pages can’t be measured from here without pretending to be a browser. What they ship to every page can: 4get.ca’s stylesheet and script came to 65 KB as sent, and SearXNG’s results page needs its stylesheet (86 KB, 13.5 KB gzipped) and one script (4.6 KB, 1.9 KB gzipped), its map and other code loading only when used.

Rerun: python3 tools/page_weight.py pages URL … for whole pages, python3 tools/page_weight.py cards BASE QUERY … for the bytes of each answer card on a 4got.

PaaS providers

SQLite needs persistent storage on every PaaS. Ephemeral filesystems lose your cache, stats, and search history on every redeploy. Always mount a volume at /data.

Fly.io

A fly.toml is included in the repo root. Create a volume before deploying:

fly launch          # creates the app, detects the Dockerfile
fly volumes create 4got_data --region iad --size 1
fly deploy

The fly.toml mounts the volume at /data and exposes port 8888 internally. Fly handles TLS and routing automatically.

Railway

Railway auto-detects the Dockerfile. Set the PORT environment variable to 8888 in your service settings. Attach a persistent volume mounted at /data to keep SQLite state across deploys.

Render

Create a new Web Service with Docker deployment. Point it at the repo, then add a persistent disk mounted at /data (minimum 1 GB). Set the HTTP port to 8888 in the service configuration.

Coolify

Self-hosted PaaS. Point Coolify at the git repo, it will build from the Dockerfile. Add a persistent volume mapped to /data. No special configuration needed beyond that.

LXC / bare metal

Install Go 1.25+ and a C compiler (GCC), then build from source:

cd go-server
CGO_ENABLED=1 go build -o 4got .

Copy the binary alongside the required directories to the target machine:

rsync -a go-server/4got go-server/templates/ static/ data/ docs/ target:/opt/4got/

The binary runs from the project root and expects data/, static/, and go-server/templates/ as siblings (it searches multiple template paths automatically). See Running with systemd above for a production service file.

DNS privacy

To prevent search query leakage to your ISP via DNS resolution, run dnscrypt-proxy in front of your system resolver (Technitium, Unbound, or systemd-resolved). This encrypts outgoing DNS queries to upstream resolvers.

Recommended setup:

  1. Install dnscrypt-proxy and point it at trusted DoH/DoT servers (e.g. Quad9 9.9.9.9, Cloudflare 1.1.1.1).
  2. Configure your local resolver (Technitium/Unbound) to forward to 127.0.0.1:5353 (dnscrypt-proxy’s default listen port).
  3. Ensure 4got’s host uses this resolver chain so engine queries don’t leak plaintext DNS to your ISP.

Or just point Claude Code at this repo and ask it to help you deploy

claude "Deploy 4got to my server at /opt/4got. Set up systemd, nginx reverse proxy on search.example.com, and configure a Wolfram Alpha API key."

Address-bound instances (kids.4got.alexs.space, deployed 2026-09-03)

A worked example of bindings.kdl, from the live instance.

The point: a hostname cannot enforce a content filter, because the client writes the Host header. An address can — the connection is established before any HTTP is parsed. This is the same reason forcesafesearch.google.com resolves to different servers rather than setting a flag.

Setup, in this order. DNS is LAST; pointing a kids. name at an unfiltered instance serves unfiltered results under a name that reads as safe.

  1. Add the address to the interface, and persist it:

    sudo ip -6 addr add 2a07:e05:3:82::2/64 dev eth0
    # then add it to /etc/netplan/50-cloud-init.yaml and `netplan generate`
    
  2. Write data/bindings.kdl binding that address (see below).

  3. Restart, and confirm BOTH log lines appear:

    BIND: [2a07:e05:3:82::2]:8888 -> kids (3 settings, locked=true)
    BIND: also listening on [2a07:e05:3:82::2]:8888
    
  4. Verify it actually filters, sending a cookie that tries to turn filtering OFF.

  5. Only then create the DNS record — AAAA, unproxied. A proxied record sends traffic through Cloudflare, which terminates the connection and erases the destination address, so the binding would match nothing.

  6. Give it TLS. A bound listener speaks plain HTTP, so a public hostname pointed at it fails with SSL_ERROR_INTERNAL_ERROR_ALERT — Caddy is already on *:443 and has no certificate for the new name. Add a site block that proxies to the BOUND ADDRESS, never to localhost:

    kids.4got.alexs.space {
        encode zstd gzip
        reverse_proxy [2a07:e05:3:82::2]:8888
    }
    

    Proxying to 127.0.0.1 here would erase the destination and silently disable the binding — unfiltered results under a name that reads as safe. Forwarding to the bound address preserves it (verified: 0 adult-site links through the full HTTPS path with safesearch=0 sent).

    The ACME challenge (tls-alpn-01) reaches the host over IPv6, which works only because the AAAA is unproxied. A Cloudflare-proxied record breaks both the challenge and the binding.

    This step was MISSED on the first deployment: HTTP-only was reasoned about for a LAN, then carried unexamined onto a public hostname. Alex found it by clicking the link.

safesearch alone is not enough. Measured on the live instance: with safesearch forced to strict, porn still returned 8 links to adult sites (the sites themselves plus archive.ph, web.archive.org and webcache mirrors of them), because upstream engines filter imperfectly. Adding discard_domains took it to 0 across porn, xxx and nude, versus 32 on the normal listener.

The discard list mirrors the Kid-safe profile preset in profile_presets.go; keep them in step.

Verified adversarially: the test sent safesearch=0 AND an empty discard_domains= — an explicit attempt to clear the filter — and the locked binding overrode both.

IPv6 reach: this address is IPv6-only, so an IPv4-only client cannot reach it. It fails closed (unreachable, not unfiltered), but on a network without IPv6 it will not work at all. For general reach, bind an IPv4 address or a distinct port.