Your Mastodon home timeline, ranked the way you choose. https://blog.thms.uk/2026/11/forage-for-mastodon/
  • TypeScript 93.6%
  • CSS 3.2%
  • JavaScript 1.8%
  • Go Template 1.1%
  • Dockerfile 0.2%
Find a file
Repository files (latest commit first)
Filename Latest commit message Latest commit date
Michael Thomas 3c88810281
All checks were successful
CI / check (pull_request) Successful in 2m35s
CI / e2e (pull_request) Successful in 1m40s
Build and publish / build (push) Successful in 47s
Build and publish / deploy (push) Successful in 27s
Web: the author's name on a post, and on a quoted post, opens their card too, as the avatar does; a quoted post's avatar opens it rather than going to their profile
2026-11-27 07:57:11 +00:00
.forgejo Run CI's checks and the Docker image on Node 26 2026-11-23 14:39:28 +00:00
apps Web: the author's name on a post, and on a quoted post, opens their card too, as the avatar does; a quoted post's avatar opens it rather than going to their profile 2026-11-27 07:57:11 +00:00
e2e Merge pull request 'Threads don't wait for fresh user data or trending tags; build timed in steps' (#119) from thread-build-stale-data into main 2026-11-26 21:58:07 +00:00
packages Core: Account.noteWithAccountInfo goes (the web app's account card lays out the bio and numbers itself), and with it the config import it alone used 2026-11-27 07:49:26 +00:00
screenshots README: screenshots 2026-11-17 11:46:04 +00:00
.dockerignore A Docker image: the server, its jobs and the built web app 2026-11-16 14:55:28 +00:00
.env.example Server: ENGINE_WORKER runs each feed engine in a worker thread 2026-11-18 13:49:03 +00:00
.gitignore Commit only .env.example; move web build defaults into webpack config 2026-11-15 11:41:23 +00:00
.nvmrc Update Node to v26 2026-11-23 14:19:32 +00:00
CHANGELOG.md README 2025-08-24 21:23:14 -04:00
compose.example.yml compose.example.yml: the data in ./data, not a named volume 2026-11-16 16:43:41 +00:00
Dockerfile Run CI's checks and the Docker image on Node 26 2026-11-23 14:39:28 +00:00
LICENSE readme 2026-01-01 11:47:36 -05:00
package-lock.json Update dev dependencies 2026-11-23 17:01:04 +00:00
package.json Update eslint to v10 2026-11-23 15:27:08 +00:00
PLAN.md Web: dotenv-flow goes; local overrides live in one git-ignored apps/web/.env, read with Node's process.loadEnvFile() 2026-11-23 07:39:03 +00:00
README.md Server: exit when the feed engine's worker dies, so Docker restarts it 2026-11-18 15:48:52 +00:00
renovate.json Renovate: core's vendored upstream CI workflow is left alone; Forgejo never runs it 2026-11-23 12:32:55 +00:00

Forage

Your Mastodon home timeline, ranked the way you choose.

Forage reads your Mastodon home timeline, along with what's trending on the servers you follow people on, and ranks it by what you say counts: who you follow and interact with, the hashtags you care about, what's popular, how recent a post is, what you've already seen. You set the weights and filters; the feed re-ranks as you change them. It runs on your own server as a small web app you can install on your phone, and keeps working while you're away: the feed is ready when you open it, and it opens offline with the last one.

It's for one Mastodon account per installation: yours.

Forage is built on fedialgo by michelcrypt4d4mus (originally by pkreissel), which does the ranking. This repository started as a fork of fedialgo's browser demo; the ranking now runs on a server instead of in the browser.

Forage's feed, beside the ranking controls: half in the light theme, half in the dark

Why a post is in your feed where it is: each thing that counted for it, with its points What's trending: the links people are sharing, with their previews and how widely they're shared
Why it's here: every post's score, explained. Trending: posts, links and hashtags across the servers you follow people on.

On a phone: the feed with tabs at the bottom, and the ranking controls in a sheet

Running it

You need a host with Docker and Docker Compose, a domain for Forage with HTTPS from a reverse proxy you already run (Caddy, nginx, Traefik…), and a Mastodon account.

  1. Copy compose.example.yml to compose.yml and .env.example to .env, in a directory of their own.
  2. Fill in .env: at least ALLOWED_ACCOUNT, APP_SECRET and PUBLIC_URL (see Settings). For APP_SECRET:
    openssl rand -base64 48
    
  3. Create the directory Forage keeps its data in, owned by the container's user (uid 1000):
    mkdir data && sudo chown 1000:1000 data
    
    If Docker creates it instead, it's owned by root and Forage can't write its database.
  4. Point your reverse proxy at port 3000 (see The reverse proxy).
  5. Start it:
    docker compose up -d
    
  6. Open PUBLIC_URL, log in with your Mastodon account, and approve Forage on your instance's page. The first feed takes a minute or two to build. To install it on a phone, use the browser's "Add to Home Screen" (iOS) or "Install app" (Android).

The image is code.thms.uk/michael/forage, built from this repository's main branch: latest, or a dated version such as 2026.11.16.42. Everything Forage keeps is in ./data, next to compose.yml (/data in the container).

Settings

Environment variables, in .env (which compose.yml reads).

Variable Required What it is
ALLOWED_ACCOUNT yes The one Mastodon account that can log in, as [email protected]. Anyone else is turned away.
APP_SECRET yes At least 32 characters. Encrypts the Mastodon access token and app credentials stored in the database. Changing it means logging in again.
PUBLIC_URL yes Where Forage is reached, e.g. https://feed.example. Your instance sends you back to PUBLIC_URL/auth/callback after you log in, and changing requests must come from this origin. Use https:// (session cookies are only marked secure then).
MASTODON_URL no Your instance's own address, when it isn't the domain in your handle: handles like @[email protected] on an instance running at https://mastodon.example.com.
LANGUAGE no Your language, as de or de-DE: trending hashtags in other languages are left out, and if the servers you follow people on don't make up 30 big enough ones, servers in your language fill in before the popular general ones. Forage knows de, es, eu, fr, it, ja, pt, ru and tr; the default is English.
TRENDING_SERVERS no Servers to ask what's trending when the ones you follow people on aren't enough, separated by commas, e.g. mastodon.social, hachyderm.io. Forage asks up to 30 servers: first the ones you follow the most people on (with at least 100 active users), then your language's (see LANGUAGE), then these, in this order. Without it, the top-up is a mix of popular general servers.
ENGINE_WORKER no true to build and rank your feed in a thread of its own, so the app stays quick to answer while a refresh is under way. Default false (one thread for everything). If that thread crashes, or stops answering for two minutes, the server exits so Docker starts it again (restart: unless-stopped in compose.yml).
LOG_LEVEL no debug, info (the default), warn or error.
PORT no The port inside the container (default 3000).
DATA_DIR no Where the database is kept in the container (default /data, which compose.yml maps to ./data).
STATIC_DIR no The built web app (the image sets it). Unset, the server serves only its API.

The reverse proxy

Forage serves plain HTTP on port 3000; your proxy terminates HTTPS and passes everything on. Three things matter:

  • Nothing under /api or /auth may be cached by the proxy or a CDN in front of it. Those answers are your feed and your login: a cached copy is served to whoever asks next. Forage marks them Cache-Control: private, no-store, which caches that follow the origin's headers obey, but a rule that caches everything can override it. With Cloudflare's proxy (the orange cloud), add a Cache Rule that bypasses the cache for /api/* and /auth/*.
  • Live updates come over a long-lived event stream at /api/events. The proxy mustn't buffer it, and must let it stay open: Forage sends a keep-alive every 25 seconds, so any read timeout over a minute is fine.
  • Media uploads (pictures and videos in replies) go through Forage to your instance, so allow request bodies as large as your instance does (around 100 MB for video on a default Mastodon).

Caddy doesn't cache, and does the other two by itself:

feed.example {
    reverse_proxy 127.0.0.1:3000
}

nginx needs them spelled out:

location / {
    proxy_pass http://127.0.0.1:3000;
    proxy_http_version 1.1;
    proxy_set_header Host $host;
    client_max_body_size 100m;
}

location /api/events {
    proxy_pass http://127.0.0.1:3000;
    proxy_http_version 1.1;
    proxy_set_header Host $host;
    proxy_buffering off;
    proxy_read_timeout 1h;
}

compose.example.yml publishes port 3000 on 127.0.0.1 only, for a proxy on the same host. If yours runs elsewhere, drop the 127.0.0.1: (and keep port 3000 away from the internet), or put both on a shared Docker network.

Updating

docker compose pull
docker compose up -d

Database changes are applied when the new version starts. There's no going back to an older version after one, so take a backup before updating. To stay on a version, use its dated tag instead of latest in compose.yml.

Changing a setting in .env takes effect when you restart (docker compose up -d). For LANGUAGE and TRENDING_SERVERS, Forage then fetches what's trending afresh.

Backups

All of Forage's state is one SQLite database, data/fedialgo.db: your login, weights and filters, and the ranked feed. Back it up while it runs with SQLite's own backup (copying the file alone can catch it mid-write), which writes data/backup.db:

docker compose exec forage node -e "require('better-sqlite3')('/data/fedialgo.db').backup('/data/backup.db')"

Then copy data/backup.db wherever your backups go. Or stop Forage (docker compose stop) and copy the whole data directory.

To restore, stop Forage, put the backup in data as fedialgo.db (removing any fedialgo.db-wal and fedialgo.db-shm beside it, and keeping it owned by uid 1000), and start it again.

The stored access token is encrypted with APP_SECRET, so keep that with your backups: restored without it, everything works except that you have to log in again. Losing the database altogether costs your weights and filters; the feed rebuilds itself after you log in.

Logs and monitoring

docker compose logs -f

Forage logs one JSON object per line on stdout. At startup, the ranking library also prints its configuration as plain text.

For health checks:

  • GET /healthz: the process is up. Always 200 {"status":"ok"}.
  • GET /readyz: Forage can serve requests (its database answers): 200 {"status":"ready",…}, or 503.

Neither needs a login. /readyz through your proxy (https://feed.example/readyz) is the one to monitor, with Uptime Kuma for example: it checks the proxy, the container and the database at once. The image's Docker health check uses it too, so docker compose ps shows whether the container is healthy.

Troubleshooting

  • Forage stops straight away with SqliteError: unable to open database file: it can't write to data. Give it to the container's user: sudo chown -R 1000:1000 data.
  • Logging in fails with "Your Mastodon server couldn't be reached", and the logs mention POST /api/v1/apps returned 404: your instance doesn't run at the domain in your handle. Set MASTODON_URL to its real address.
  • "That Mastodon account isn't the one this server is set up for": you approved Forage as a different account. Log out of the other account on your instance's site, or check ALLOWED_ACCOUNT.
  • Logging in loops back to the login page: the browser isn't at PUBLIC_URL exactly (scheme, host and port must all match). With an https:// PUBLIC_URL, opening Forage over plain HTTP (port 3000 directly, say) can't keep the session cookie.
  • Changes don't save ("Cross-origin request refused"): the same PUBLIC_URL mismatch, as the server sees it.
  • Another device or browser shows your feed without logging in: something between the internet and Forage is caching its answers (a CDN such as Cloudflare's proxy, or a caching proxy). Stop it caching /api and /auth (see The reverse proxy), purge its cache, and log in again on your devices after ending every session:
    docker compose exec forage node -e "require('better-sqlite3')('/data/fedialgo.db').prepare('DELETE FROM session').run()"
    
  • The feed never updates live, but reloading shows new posts: the proxy is buffering /api/events (see The reverse proxy).
  • Logged out after changing APP_SECRET: expected. Log in again.

Development

npm workspaces:

Workspace What it is
packages/core (fedialgo) The ranking library, vendored from upstream with git subtree
packages/shared The API's types (zod schemas), and the app's name and colours (brand.ts)
apps/server The server: Hono, SQLite (Drizzle), the feed engine
apps/web The web app: React, TanStack Query, a service worker
packages/fake-mastodon, packages/test-fixtures A Mastodon stand-in replaying recorded, scrubbed API responses, for tests
e2e Playwright specs: the built app and the real server against fake-mastodon

With Node 24 (see .nvmrc):

npm ci
npm test             # every workspace's tests
npm run lint
npm run typecheck
npm run e2e          # builds, then runs the end-to-end specs (needs: npx -w @fedialgo/e2e playwright install chromium)

To run it locally against a real account, start the server with your settings in its environment, then the web app's dev server, which passes /api and /auth on to it:

PORT=3001 PUBLIC_URL=http://localhost:3000 ALLOWED_ACCOUNT=[email protected] APP_SECRET=… DATA_DIR=./data \
    npm run dev -w @fedialgo/server
npm start            # the web app on http://localhost:3000

No test reaches the network: tests run against MSW or fake-mastodon, using recordings in packages/test-fixtures (see its README for recording new ones). PLAN.md has the architecture, the decisions behind it, and the testing policy. Pull requests into main run lint, typecheck, unit tests and the end-to-end specs; merging builds, smoke-tests and publishes the image.

Licence

GPL-3.0 (LICENSE), like fedialgo.