···11# Spark Feed Generator
2233-This repository is a feed generator for the Spark atproto app. It is a simple
44-feed generator that fetches posts from a database and returns them in a format
55-that can be used by the Spark client.
33+A template for creating custom feed generators for [sprk.so](https://sprk.so).
6477-The whole structure is heavily based on the Bluesky
88-[feed-generator](https://github.com/bluesky-social/feed-generator) repository,
99-most of the things said there apply here as well.
55+## Architecture
1061111-## Setup
77+The feed generator has three main components:
1281313-### Option 1: Docker Compose (Recommended)
99+1. **Ingester** (`ingester/`) - Consumes the Spark firehose in real-time and
1010+ indexes records to MongoDB. By default, it indexes `so.sprk.feed.post`
1111+ records. Handlers for `follow`, `like`, and `repost` are included but
1212+ disabled - enable them by uncommenting in `ingester/index.ts`.
14131515-The easiest way to get started is using Docker Compose, which will automatically
1616-build the application and set up the MongoDB database.
1414+2. **Algorithms** (`algos/`) - Define how posts are selected and sorted for
1515+ your feed. Each algorithm exports:
1616+ - `handler` - Query function that returns posts from the database
1717+ - `needsAuth` - Whether the feed requires user authentication
1818+ - `publisherDid` - The DID of the feed publisher
1919+ - `rkey` - Unique identifier for this algorithm
17201818-1. Start the services (this will automatically build the image):
2121+3. **API Server** - Exposes XRPC endpoints that Spark clients call to fetch
2222+ feed content (`so.sprk.feed.getFeedSkeleton`, `so.sprk.feed.describeFeedGenerator`).
2323+ You won't need to modify these when creating a feed.
19242020-```sh
2121-docker-compose up -d
2222-```
2525+## Creating Custom Feeds
23262424-2. The application will be available at http://localhost:3000
2727+**For topic/community feeds:** Filter posts at the ingester level. Modify
2828+the handler in `ingester/handlers/post.ts` to only index posts matching your
2929+criteria (hashtags, keywords, specific authors, etc.).
25302626-3. To stop the services:
3131+**For personalized/sorted feeds:** Create a new algorithm in `algos/`. Copy
3232+`simple-desc.ts` as a starting point, then modify the query logic. Register
3333+your algorithm in `algos/index.ts`.
27342828-```sh
2929-docker-compose down
3535+Example algorithm structure:
3636+```ts
3737+// algos/my-feed.ts
3838+export const info = {
3939+ handler: async (ctx, params, did) => {
4040+ // Query posts from ctx.db.models.Post
4141+ // Return { cursor, feed: [{ post: "at://..." }] }
4242+ },
4343+ needsAuth: false, // Set true if feed needs user's DID
4444+ publisherDid: "did:plc:your-did",
4545+ rkey: "my-feed", // at://your-did/so.sprk.feed.generator/my-feed
4646+} as Algorithm;
3047```
31483232-### Option 2: Manual Setup
3333-3434-If you prefer to run the application manually or use an existing MongoDB
3535-instance:
4949+## Running
36503737-#### Prerequisites
5151+### Prerequisites
38523939-- [Deno](https://deno.com/) runtime
4040-- MongoDB instance (local or remote)
5353+Create a `.env` file in the project root:
41544242-#### Steps
4343-4444-1. Create a `.env` file in the root of the repository and add the following
4545- variables:
4646-4747-```
4848-SPRK_DB_NAME=feed-gen
5555+```sh
5656+# Required
5757+FEEDGEN_DOMAIN=feeds.example.com # Your feed generator's domain
5858+SPRK_DB_NAME=feed-gen # MongoDB database name
4959SPRK_DB_URI=mongodb://localhost:27017
5060SPRK_DB_USER=username
5151-SPRK_DB_PASSWORD=password
5252-SPRK_FEEDGEN_DOMAIN=feeds.example.com
6161+SPRK_DB_PASS=password
6262+6363+# Optional
6464+SPRK_HOST=0.0.0.0 # Server bind address
6565+SPRK_PORT=3000 # Server port
5366NODE_ENV=production
5467```
55685656-2. Install dependencies:
6969+### Docker Compose (Recommended)
7070+7171+Starts both the feed generator and a MongoDB instance:
57725873```sh
5959-deno install
7474+# Start services
7575+docker-compose up -d
7676+7777+# View logs
7878+docker-compose logs -f feed-gen
7979+8080+# Stop services
8181+docker-compose down
6082```
61836262-3. Make sure MongoDB is running.
8484+### Manual Setup
63856464-4. Start the development server:
8686+Requires [Deno](https://deno.com/) and a MongoDB instance.
65876688```sh
8989+# Install dependencies
9090+deno install
9191+9292+# Start server
6793deno task start
6894```
69957070-5. The application will be available at http://localhost:3000
9696+The server will be available at `http://localhost:3000`.
9797+9898+## Endpoints
9999+100100+| Endpoint | Description |
101101+|----------|-------------|
102102+| `GET /` | Service info |
103103+| `GET /health` | Health check |
104104+| `GET /.well-known/did.json` | DID document for `did:web` resolution |
105105+| `GET /xrpc/so.sprk.feed.describeFeedGenerator` | List available feeds |
106106+| `GET /xrpc/so.sprk.feed.getFeedSkeleton` | Fetch feed posts |