{"id":13427592,"url":"https://github.com/bluesky-social/feed-generator","last_synced_at":"2025-10-03T13:42:22.194Z","repository":{"id":164081623,"uuid":"638516110","full_name":"bluesky-social/feed-generator","owner":"bluesky-social","description":"ATProto Feed Generator Starter Kit","archived":false,"fork":false,"pushed_at":"2025-02-01T00:11:54.000Z","size":305,"stargazers_count":1850,"open_issues_count":52,"forks_count":654,"subscribers_count":38,"default_branch":"main","last_synced_at":"2025-05-11T11:14:19.685Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/bluesky-social.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-05-09T14:17:39.000Z","updated_at":"2025-05-10T20:19:41.000Z","dependencies_parsed_at":null,"dependency_job_id":"fafaf9cc-6495-474f-a795-c2e277c3ddb2","html_url":"https://github.com/bluesky-social/feed-generator","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bluesky-social%2Ffeed-generator","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bluesky-social%2Ffeed-generator/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bluesky-social%2Ffeed-generator/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bluesky-social%2Ffeed-generator/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bluesky-social","download_url":"https://codeload.github.com/bluesky-social/feed-generator/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254069441,"owners_count":22009551,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-07-31T01:00:33.028Z","updated_at":"2025-10-03T13:42:17.156Z","avatar_url":"https://github.com/bluesky-social.png","language":"TypeScript","funding_links":[],"categories":["\u003ca name='clients-and-libraries'\u003e\u003c/a\u003e Clients and Libraries","TypeScript"],"sub_categories":["\u003ca name='typescript'\u003e\u003c/a\u003e TypeScript"],"readme":"# ATProto Feed Generator\n\nThis is a starter kit for creating ATProto Feed Generators. It's not feature complete, but should give you a good starting ground off of which to build and deploy a feed.\n\n## Overview\n\nFeed Generators are services that provide custom algorithms to users through the AT Protocol.\n\nThey work very simply: the server receives a request from a user's server and returns a list of [post URIs](https://atproto.com/specs/at-uri-scheme) with some optional metadata attached. Those posts are then hydrated into full views by the requesting server and sent back to the client. This route is described in the [`app.bsky.feed.getFeedSkeleton` lexicon](https://docs.bsky.app/docs/api/app-bsky-feed-get-feed-skeleton).\n\nA Feed Generator service can host one or more algorithms. The service itself is identified by DID, while each algorithm that it hosts is declared by a record in the repo of the account that created it. For instance, feeds offered by Bluesky will likely be declared in `@bsky.app`'s repo. Therefore, a given algorithm is identified by the at-uri of the declaration record. This declaration record includes a pointer to the service's DID along with some profile information for the feed.\n\nThe general flow of providing a custom algorithm to a user is as follows:\n- A user requests a feed from their server (PDS) using the at-uri of the declared feed\n- The PDS resolves the at-uri and finds the DID doc of the Feed Generator\n- The PDS sends a `getFeedSkeleton` request to the service endpoint declared in the Feed Generator's DID doc\n  - This request is authenticated by a JWT signed by the user's repo signing key\n- The Feed Generator returns a skeleton of the feed to the user's PDS\n- The PDS hydrates the feed (user info, post contents, aggregates, etc.)\n  - In the future, the PDS will hydrate the feed with the help of an App View, but for now, the PDS handles hydration itself\n- The PDS returns the hydrated feed to the user\n\nFor users, this should feel like visiting a page in the app. Once they subscribe to a custom algorithm, it will appear in their home interface as one of their available feeds.\n\n## Getting Started\n\nWe've set up this simple server with SQLite to store and query data. Feel free to switch this out for whichever database you prefer.\n\nNext, you will need to do two things:\n\n1. Implement indexing logic in `src/subscription.ts`. \n   \n   This will subscribe to the repo subscription stream on startup, parse events and index them according to your provided logic.\n\n2. Implement feed generation logic in `src/algos`\n\n   For inspiration, we've provided a very simple feed algorithm (`whats-alf`) that returns all posts related to the titular character of the TV show ALF. \n\n   You can either edit it or add another algorithm alongside it. The types are in place, and you will just need to return something that satisfies the `SkeletonFeedPost[]` type.\n\nWe've taken care of setting this server up with a did:web. However, you're free to switch this out for did:plc if you like - you may want to if you expect this Feed Generator to be long-standing and possibly migrating domains.\n\n### Deploying your feed\nYour feed will need to be accessible at the value supplied to the `FEEDGEN_HOSTNAME` environment variable.\n\nThe service must be set up to respond to HTTPS queries over port 443.\n\n### Publishing your feed\n\nTo publish your feed, go to the script at `scripts/publishFeedGen.ts` and fill in the variables at the top. Examples are included, and some are optional. To publish your feed generator, simply run `yarn publishFeed`.\n\nTo update your feed's display data (name, avatar, description, etc.), just update the relevant variables and re-run the script.\n\nAfter successfully running the script, you should be able to see your feed from within the app, as well as share it by embedding a link in a post (similar to a quote post).\n\n## Running the Server\n\nInstall dependencies with `yarn` and then run the server with `yarn start`. This will start the server on port 3000, or what's defined in `.env`. You can then watch the firehose output in the console and access the output of the default custom ALF feed at [http://localhost:3000/xrpc/app.bsky.feed.getFeedSkeleton?feed=at://did:example:alice/app.bsky.feed.generator/whats-alf](http://localhost:3000/xrpc/app.bsky.feed.getFeedSkeleton?feed=at://did:example:alice/app.bsky.feed.generator/whats-alf).\n\n## Some Details\n\n### Skeleton Metadata\n\nThe skeleton that a Feed Generator puts together is, in its simplest form, a list of post URIs.\n\n```ts\n[\n  {post: 'at://did:example:1234/app.bsky.feed.post/1'},\n  {post: 'at://did:example:1234/app.bsky.feed.post/2'},\n  {post: 'at://did:example:1234/app.bsky.feed.post/3'}\n]\n```\n\nHowever, we include an additional location to attach some context. Here is the full schema:\n\n```ts\ntype SkeletonItem = {\n  post: string // post URI\n\n  // optional reason for inclusion in the feed\n  // (generally to be displayed in client)\n  reason?: Reason\n}\n\n// for now, the only defined reason is a repost, but this is open to extension\ntype Reason = ReasonRepost\n\ntype ReasonRepost = {\n  $type: 'app.bsky.feed.defs#skeletonReasonRepost'\n  repost: string // repost URI\n}\n```\n\nThis metadata serves two purposes:\n\n1. To aid the PDS in hydrating all relevant post information\n2. To give a cue to the client in terms of context to display when rendering a post\n\n### Authentication\n\nIf you are creating a generic feed that does not differ for different users, you do not need to check auth. But if a user's state (such as follows or likes) is taken into account, we _strongly_ encourage you to validate their auth token.\n\nUsers are authenticated with a simple JWT signed by the user's repo signing key.\n\nThis JWT header/payload takes the format:\n```ts\nconst header = {\n  type: \"JWT\",\n  alg: \"ES256K\" // (key algorithm) - in this case secp256k1\n}\nconst payload = {\n  iss: \"did:example:alice\", // (issuer) the requesting user's DID\n  aud: \"did:example:feedGenerator\", // (audience) the DID of the Feed Generator\n  exp: 1683643619 // (expiration) unix timestamp in seconds\n}\n```\n\nWe provide utilities for verifying user JWTs in the `@atproto/xrpc-server` package, and you can see them in action in `src/auth.ts`.\n\n### Pagination\nYou'll notice that the `getFeedSkeleton` method returns a `cursor` in its response and takes a `cursor` param as input.\n\nThis cursor is treated as an opaque value and fully at the Feed Generator's discretion. It is simply passed through the PDS directly to and from the client.\n\nWe strongly encourage that the cursor be _unique per feed item_ to prevent unexpected behavior in pagination.\n\nWe recommend, for instance, a compound cursor with a timestamp + a CID:\n`1683654690921::bafyreia3tbsfxe3cc75xrxyyn6qc42oupi73fxiox76prlyi5bpx7hr72u`\n\n## Suggestions for Implementation\n\nHow a feed generator fulfills the `getFeedSkeleton` request is completely at their discretion. At the simplest end, a Feed Generator could supply a \"feed\" that only contains some hardcoded posts.\n\nFor most use cases, we recommend subscribing to the firehose at `com.atproto.sync.subscribeRepos`. This websocket will send you every record that is published on the network. Since Feed Generators do not need to provide hydrated posts, you can index as much or as little of the firehose as necessary.\n\nDepending on your algorithm, you likely do not need to keep posts around for long. Unless your algorithm is intended to provide \"posts you missed\" or something similar, you can likely garbage collect any data that is older than 48 hours.\n\nSome examples:\n\n### Reimplementing What's Hot\nTo reimplement \"What's Hot\", you may subscribe to the firehose and filter for all posts and likes (ignoring profiles/reposts/follows/etc.). You would keep a running tally of likes per post and when a PDS requests a feed, you would send the most recent posts that pass some threshold of likes.\n\n### A Community Feed\nYou might create a feed for a given community by compiling a list of DIDs within that community and filtering the firehose for all posts from users within that list.\n\n### A Topical Feed\nTo implement a topical feed, you might filter the algorithm for posts and pass the post text through some filtering mechanism (an LLM, a keyword matcher, etc.) that filters for the topic of your choice.\n\n## Community Feed Generator Templates\n\n- [Python](https://github.com/MarshalX/bluesky-feed-generator) - [@MarshalX](https://github.com/MarshalX)\n- [Ruby](https://github.com/mackuba/bluesky-feeds-rb) - [@mackuba](https://github.com/mackuba)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbluesky-social%2Ffeed-generator","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbluesky-social%2Ffeed-generator","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbluesky-social%2Ffeed-generator/lists"}