relay filter/appview bootstrap
1# Prism
2
3Prism是一个用于gmstn的[ATProto](https://atproto.com/) AppView服务。它从[TAP](https://docs.bsky.app/blog/introducing-tap)消费事件,并将其存储/缓存以供将来检索,这样查询就不会对其他PDS造成太大负担。
4
5<a href="https://docs.bsky.app/docs/advanced-guides/federation-architecture#app-views">
6 <img src="./assets/prism-appview-concept.png" width="400" alt="appview-prism-pinkfloyd"/>
7</a>
8
9Prism实现了用于访问缓存feed的XRPC端点。Lexicon定义可以在`lexicons/`目录中找到。
10
11## 架构
12
13```
14ATProto Relay → TAP (backfill + firehose) → Prism (Rust/Axum) → PostgreSQL
15 ↓
16 XRPC API + WebSocket
17```
18
19## 本地运行
20
21### 前置条件
22
23Rust, docker/podman
24
25### 快速开始
26
271. 启动数据库:
28
29```bash
30docker compose up postgres tap
31# or
32podman-compose up postgres tap
33```
34
352. 运行数据库迁移:
36
37```bash
38export DATABASE_URL=postgres://postgres:postgres@localhost:5432/prism
39cargo sqlx migrate run --source migrations
40```
41
423. 运行开发服务器:
43
44```bash
45cargo run
46```
47
48服务将在 http://localhost:3000 上可用
49
50### 完整堆栈 (包含TAP)
51
52```bash
53docker compose up
54```
55
56这将启动:
57- PostgreSQL 端口 5432
58- TAP 端口 8080 (HTTP) 和 2480 (WebSocket)
59- Prism 端口 3000
60
61## API端点
62
63| 端点 | 描述 |
64|----------|-------------|
65| `GET /xrpc/systems.gmstn.development.channel.listChannels?author=<did>` | 按作者列出频道 |
66| `GET /xrpc/systems.gmstn.development.channel.listInvites?recipient=<did>` | 按接收者列出邀请 |
67| `GET /xrpc/systems.gmstn.development.channel.listMemberships?recipient=<did>` | 按接收者列出成员资格 |
68| `GET /xrpc/systems.gmstn.development.lattice.listLattices?author=<did>` | 按作者列出晶格 |
69| `GET /xrpc/systems.gmstn.development.shard.listShards?author=<did>` | 按作者列出碎片 |
70| `WS /ws` | 用于实时记录更新的WebSocket |
71
72所有列表端点都支持`limit`(1-100,默认50)和`cursor`(ISO8601时间戳)参数。
73
74## 配置
75
76环境变量:
77
78| 变量 | 默认值 | 描述 |
79|----------|---------|-------------|
80| `DATABASE_URL` | `postgres://postgres:postgres@localhost:5432/prism` | PostgreSQL连接字符串 |
81| `TAP_WS_URL` | `ws://localhost:2480/channel` | TAP WebSocket URL |
82| `HOST` | `0.0.0.0` | 服务器绑定地址 |
83| `PORT` | `3000` | 服务器端口 |
84| `RUST_LOG` | `prism=info` | 日志级别 |
85
86## 开发
87
88```bash
89# 检查代码
90cargo check
91
92# 运行测试
93cargo test
94
95# 准备sqlx离线缓存(需要运行中的数据库)
96cargo sqlx prepare
97```