技术方案总览

数据库表结构 · API 路由 · 文件结构

数据库(Supabase)

复用已有表 + 新增 2 张表

-- 已有,不需要修改
public.user_profiles ← 搜索用户、展示资料用

-- 新增 1:好友申请表
public.friend_requests
id uuid PK
from_user_id uuid → auth.users
to_user_id uuid → auth.users
status text (pending/accepted/rejected)
message text (申请备注)
created_at timestamptz
updated_at timestamptz
UNIQUE(from_user_id, to_user_id)

-- 新增 2:好友关系表(双向)
public.friends
user_id uuid → auth.users
friend_id uuid → auth.users
created_at timestamptz
PRIMARY KEY(user_id, friend_id)

API 路由(Next.js App Router)

GET /api/friends/search?q=昵称 搜索用户
POST /api/friends/requests 发送好友申请
GET /api/friends/requests 收到的申请列表
POST /api/friends/requests/[id]/accept 同意申请
POST /api/friends/requests/[id]/reject 拒绝申请
GET /api/friends 我的好友列表

前端文件结构

app/friends/
search/page.tsx 搜索好友页
requests/page.tsx 好友申请页
list/page.tsx 我的好友列表页

lib/backend/
friends-repository.ts 所有好友相关 DB 操作

supabase/
friends-schema.sql 新表 + RLS 策略

消息页改动

在 page.tsx 的 MessagesView 组件顶部,插入三格快捷入口(搜索好友 / 好友申请 / 我的好友),用 Next.js router.push() 跳转到对应子页面。

✓

方案确认,写设计文档

开始输出完整设计 doc,然后进入实现计划阶段

✎

有问题想先讨论

告诉我哪里需要调整