replica-backend
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
Chinesereplica-backend
replica-backend
Reads . Writes migrations and server code, and keeps
(checklist below) up to date.
replica/architecture.mdreplica/backend.md读取 。编写数据库迁移和服务端代码,并持续更新
(包含下方检查清单)。
replica/architecture.mdreplica/backend.mdThe rules
规则
- Official, public APIs only, with the user's own keys. Never call the original app's private endpoints, never reuse its OAuth client, never proxy through it.
- The user creates accounts and keys. Claude never signs up for services,
never types a password, card or live key. The user creates the Stripe,
Supabase, Resend or Google Cloud project and puts keys in . Claude writes
.env.localwith every variable name and no values..env.example - Test mode first. Stripe test keys and test cards until replica-deploy.
- 仅使用官方公开 API,并使用用户自己的密钥。 绝不调用原应用的私有端点, 绝不复用其 OAuth client,绝不通过原应用代理请求。
- 由用户创建账户和密钥。 Claude 绝不注册任何服务,绝不输入密码、
银行卡信息或生产环境密钥。用户自行创建 Stripe、Supabase、Resend 或
Google Cloud 项目,并将密钥放入 。Claude 编写
.env.local, 其中列出每个变量名,但不包含任何值。.env.example - 优先使用测试模式。 在 replica-deploy 之前使用 Stripe 测试密钥和测试卡。
Auth
身份验证
- Email sign up with verification, password reset, magic link if the original has it. OAuth (Google, Apple) with the user's own developer apps.
- Sessions: http-only secure cookies. Sign out everywhere.
- Roles and teams if the recon map has them: owner, admin, member, with one function that answers "can this user do this to this record".
- Account deletion that actually deletes. Apple requires it for apps with sign up.
- 支持通过电子邮件注册并进行验证、密码重置;如果原应用支持,则添加 magic link。使用用户自己的开发者应用进行 OAuth(Google、Apple)。
- 会话:使用 http-only secure cookies。支持退出所有设备上的登录。
- 如果侦察映射(recon map)中包含角色和团队,则支持 owner、admin、member, 并提供一个函数来回答“该用户能否对该记录执行此操作”。
- 提供真正执行删除的账户删除功能。对于支持注册的应用,Apple 要求提供此功能。
Database
数据库
- Migrations from , checked in, run by a script.
architecture.md - Access rules on every table: row level security policies on Supabase, or the authorisation function called in every query. Test it: a second user must get nothing back.
- Seed script with realistic fake data (no real people).
- Backups on (the host's daily backups count, check they are enabled).
- 根据 创建数据库迁移,提交到版本控制,并通过脚本运行。
architecture.md - 为每张表设置访问规则:在 Supabase 中使用 row level security policies, 或在每次查询中调用 authorisation function。进行测试:第二个用户必须获取不到 任何数据。
- 种子脚本应包含逼真的假数据(不得使用真实人员信息)。
- 启用备份(托管方的每日备份也算,但需确认其已启用)。
Payments
支付
- Stripe Checkout for sign up to a plan, the Customer Portal for changes and cancelling. Do not build card forms.
- Webhooks: verify the signature, store the event id, make every handler
idempotent (Stripe retries). Handle ,
checkout.session.completed,customer.subscription.updated,customer.subscription.deleted.invoice.payment_failed - Subscription status lives in your database, updated by webhooks, read by your app. Never trust the client.
- Cancelling is one click. Hard-to-cancel billing is a top complaint about most apps, and in many places it is illegal.
- 使用 Stripe Checkout 支持用户注册并订阅套餐,使用 Customer Portal 修改订阅和取消订阅。不要构建银行卡表单。
- Webhooks:验证签名、存储 event id,并确保每个 handler 都具有幂等性
(Stripe 会进行重试)。处理 、
checkout.session.completed、customer.subscription.updated、customer.subscription.deleted。invoice.payment_failed - 订阅状态存储在数据库中,由 webhooks 更新,并由应用读取。绝不信任客户端。
- 取消订阅只需一键操作。设置难以取消的订阅计费是大多数应用最常被投诉的 问题之一,而且在许多地区属于违法行为。
Email and jobs
邮件和后台作业
- Transactional email through Resend or Postmark from your own domain. Templates written fresh.
- Jobs for anything time-based (reminders, digests, sync, cleanup) with retries and a dead-letter log. Times in UTC, shown in the user's zone.
- 通过 Resend 或 Postmark 使用自己的域名发送事务性邮件。所有模板均重新编写。
- 凡是涉及时间的任务(提醒、摘要、同步、清理)均由 jobs 执行,支持重试并 记录 dead-letter 日志。时间以 UTC 保存,并按用户所在时区显示。
Integrations
集成
For each integration in the feature matrix: the official API, the OAuth
scopes needed (fewest possible), the provider's review process, rate limits.
Google scopes like Calendar need Google's OAuth verification before public
launch, which takes weeks. Start it early and write that in .
backend.md对于功能矩阵中的每个集成,记录:官方 API、所需的 OAuth scopes(尽可能少)、
服务商的审核流程和速率限制。Google Calendar 等集成所需的 Google scopes
在公开发布前需要通过 Google 的 OAuth verification,这可能需要数周。应尽早启动,
并将此要求记录在 中。
backend.mdSecurity checklist
安全检查清单
- secrets only in env vars, in
.env*, nothing in client bundles.gitignore - input validated on the server (zod or similar) on every route
- authorisation checked on every read and write, tested with a second user
- rate limits on auth, sign up, and anything that sends email or SMS
- webhooks verify signatures
- uploads: size and type limits, served from a separate domain or bucket
- no user data in URLs or logs
- dependencies audited ()
npm audit - privacy policy lists every processor (Stripe, Resend, host, analytics)
- 密钥仅存放在环境变量中,必须加入
.env*,客户端包中不得包含任何密钥.gitignore - 在服务端验证每个路由的输入(使用 zod 或类似工具)
- 每次读取和写入时都检查授权,并使用第二个用户进行测试
- 对身份验证、注册以及任何发送邮件或 SMS 的功能设置速率限制
- Webhooks 验证签名
- 上传文件:设置大小和类型限制,并通过独立域名或 bucket 提供访问
- URL 和日志中不得包含用户数据
- 审计依赖项()
npm audit - 隐私政策列出所有数据处理方(Stripe、Resend、托管方、分析服务)
Output
输出
Working auth, database, payments in test mode, email and the integrations,
, with the checklist ticked, feature
matrix rows updated. Next: .
.env.examplereplica/backend.md/replica-test可正常工作的身份验证、数据库、测试模式下的支付、邮件和集成功能,
,包含已勾选检查清单的 ,以及更新后的
功能矩阵行。下一步:。
.env.examplereplica/backend.md/replica-test