[READ-ONLY] Mirror of https://github.com/karanshukla/navyfragen-feed. Feed for the app Navyfragen.app (forked from feed starter pack) navyfragen.app
README.md

navyfragen-feed #

A Bluesky custom feed generator for Navyfragen content. Surfaces posts that contain fragen.navy in their text, or images with navyfragen in the alt text.

Built on the AT Protocol using the official feed generator starter kit.

How it works #

  1. Jetstream subscription — connects to a Jetstream endpoint and consumes the Bluesky event stream as JSON, filtered server-side to app.bsky.feed.post. This uses far less bandwidth, CPU, and memory than the raw firehose, since no CAR/CBOR decoding is needed.
  2. Matching logic — each post is checked for fragen.navy in text, or navyfragen in image alt text. Matches are stored in a local SQLite database.
  3. Startup backfill — on each startup, recent posts are recovered via Bluesky's search API to fill any gap caused by downtime or redeployment.
  4. Feed serving — the app.bsky.feed.getFeedSkeleton XRPC endpoint returns a cursor-paginated list of matching post URIs, with a short in-process cache.

Requirements #

Node 24 (LTS). The @atproto/* packages are ESM-only as of @atproto/xrpc-server 0.11 and declare engines: node >= 22; the compiled output is CommonJS and loads them via require(), which needs Node 22.12+. Node 24 is the current LTS and satisfies both.

Environment variables #

Variable Required Default Description
FEEDGEN_PORT No 3000 HTTP port to listen on
FEEDGEN_LISTENHOST No localhost Host to bind (0.0.0.0 for Railway/Docker)
FEEDGEN_HOSTNAME Yes — Public hostname (e.g. navyfragen-feed.railway.app)
FEEDGEN_SERVICE_DID No auto-generated did:key DID for this service
FEEDGEN_PUBLISHER_DID Yes — DID of the Bluesky account that owns the feed
FEEDGEN_SQLITE_LOCATION No :memory: Path to SQLite database file. Use a persistent volume path in production (e.g. /data/feed.db)
FEEDGEN_SUBSCRIPTION_ENDPOINT No wss://jetstream1.us-east.bsky.network Jetstream endpoint to consume events from
FEEDGEN_SUBSCRIPTION_RECONNECT_DELAY No 3000 Milliseconds to wait before reconnecting to Jetstream
FEEDGEN_PDS_URL No https://bsky.social PDS for the backfill account
FEEDGEN_REQUIRE_AUTH No false Set to true to reject requests that do not carry valid service auth. Off by default: the skeleton is identical for every requester, so requiring auth only decides which clients can load the feed, and third-party clients whose service auth we reject see an empty feed
FEEDGEN_RETENTION_DAYS No 30 Days to retain posts before pruning
FEEDGEN_HANDLE No — Bluesky handle for backfill (e.g. you.bsky.social)
FEEDGEN_APP_PASSWORD No — App password for backfill. If unset, backfill is skipped

Important (Railway): Set FEEDGEN_SQLITE_LOCATION to a path on a mounted persistent volume (e.g. /data/feed.db). Without this, the database is wiped on every deployment.

Running locally #

yarn install
cp .env.example .env   # fill in at minimum FEEDGEN_HOSTNAME and FEEDGEN_PUBLISHER_DID
yarn start

The feed skeleton is available at:

http://localhost:3000/xrpc/app.bsky.feed.getFeedSkeleton?feed=at://<FEEDGEN_PUBLISHER_DID>/app.bsky.feed.generator/navyfragen

Publishing the feed to Bluesky #

Fill in the variables at the top of scripts/publishFeedGen.ts, then:

yarn publishFeed

Re-run the script any time you want to update the feed's display name, avatar, or description.

To remove the feed from Bluesky:

yarn unpublishFeed

Deploying on Railway #

  1. Connect this repository to a Railway service.
  2. Add a persistent volume mounted at /data.
  3. Set all required environment variables, plus FEEDGEN_SQLITE_LOCATION=/data/feed.db and FEEDGEN_LISTENHOST=0.0.0.0.
  4. Deploy.

Project structure #

src/
  index.ts            — entry point, loads config and starts the server
  server.ts           — Express app setup, FeedGenerator class, backfill logic
  jetstream.ts        — Jetstream subscription, matching logic, cursor persistence
  auth.ts             — JWT validation for incoming requests
  config.ts           — AppContext and Config types
  well-known.ts       — /.well-known/did.json endpoint
  algos/
    navyfragen.ts     — feed algorithm with in-process cache
  methods/
    feed-generation.ts   — getFeedSkeleton XRPC handler + per-user rate limiting
    describe-generator.ts — describeFeedGenerator XRPC handler
  db/
    index.ts          — SQLite connection with WAL mode
    migrations.ts     — database schema migrations
scripts/
  publishFeedGen.ts   — publish/update the feed record on Bluesky
  unpublishFeedGen.ts — delete the feed record from Bluesky