[READ-ONLY] Mirror of https://github.com/flo-bit/contrail. atproto backend in a bottle flo-bit.dev/contrail
README.md
# Contrail — PostgreSQL Example A complete example of using Contrail to index AT Protocol calendar events and RSVPs with PostgreSQL. Includes persistent Jetstream ingestion (long-running listener) and user discovery/backfill. ## Setup ```bash # Copy this folder to a new project cp -r examples/postgres my-contrail-app cd my-contrail-app # Install dependencies pnpm install ``` > **Note:** The `contrail` dependency in `package.json` points at `github:flo-bit/contrail`. > If you're using a fork with PostgreSQL support that hasn't been merged yet, update the > dependency to point at your fork's branch: > > ```bash > pnpm add github:your-username/contrail#your-branch > ``` > > Or install from a local checkout: > > ```bash > pnpm add /path/to/your/contrail > ``` ### Start PostgreSQL **Option A: Docker (recommended)** ```bash docker compose up -d ``` This starts PostgreSQL on port 5433 (to avoid conflicts with a local instance) with a `contrail` database ready to use. Override the port with `PG_PORT=5432 docker compose up -d`. **Option B: Native PostgreSQL** ```bash createdb contrail ``` Set `DATABASE_URL` to point at your local instance: ```bash export DATABASE_URL="postgresql://user:password@localhost:5432/contrail" ``` ## Configure Edit `config.ts` to define your collections, queryable fields, relations, and references. See the [Contrail README](https://github.com/flo-bit/contrail) for all options. ## Run ### 1. Discover users and backfill records ```bash pnpm run sync ``` This finds users from ATProto relays and backfills their existing records from PDS. Safe to interrupt and restart — progress is saved per-DID in the database. ### 2. Start persistent ingestion ```bash pnpm run ingest ``` This opens a long-lived Jetstream connection and continuously indexes new records as they appear on the network. Events are batched and flushed every 5 seconds (or every 50 events, whichever comes first). Handles reconnection automatically. Press `Ctrl+C` for graceful shutdown — the current batch is flushed an…