Cfans 技術交付參考

系統架構 · 資料庫結構 · API 清單(供 C fans 團隊參考)

由 AI-CTO 整理 · 對應 STG 環境 · 更新 2026-06-15 · 此頁僅供內部技術參考

① 系統架構

跨平台三端共用一套後端,前後端皆 TypeScript。

前端 AppExpo(React Native + Expo Router + NativeWind)
一份程式碼出 iOS / Android / Web 三平台;用戶與創作者同 App,依角色 gating。
後台 AdminReact + Vite + TypeScript
Scope-based 權限;部署於 Vercel。
後端 BaaSSupabase:Auth + PostgreSQL(全表 RLS)+ Storage + Realtime + Edge Functions。
部署Web/Admin → Vercel;iOS/Android → 原生 build(TestFlight / Play 內測)。
金流鑽石經濟(儲值 / 解鎖 / 訂閱 / 提領),交易全程 append-only log;第三方金流(MyPay/IAP)介面集中可換。
儲存桶影片、付費內容(preview/original)、KYC 證件、訊息附件、頭像 —— 各自 RLS。

② 資料庫結構(26 張表,全表 RLS)

完整 schema 視覺化見 product/cfans-db-schema-v1.html;以下為分域總覽。

帳號 / 身份

  • profiles(用戶/創作者,role gating)
  • follows(追蹤關係)
  • creator_applications(創作者申請+KYC)
  • admins / admin_scopes / admin_scope_grants

內容

  • videos(貼文主體:可見性/付費/成人)
  • video_media_items(一篇多媒體,圖+影片)
  • video_comments / video_likes / video_saves
  • paid_contents(單篇付費內容)

金流 / 鑽石

  • diamond_wallets / diamond_transactions(append-only)
  • orders / order_status_logs / pricing_tiers
  • video_unlocks / paid_content_unlocks / message_unlocks(永久購買紀錄)
  • subscriptions / creator_earnings / usd_settlement_runs

訊息

  • conversations(對話)
  • messages(含付費私訊)

稽核

  • audit_logs(後台操作日誌,不可改不可刪)
🔒 安全:所有表啟用 Row Level Security(RLS);鑽石交易 / 後台操作日誌 / 收益 為 append-only(DB 層擋 update/delete),確保金流與稽核不可竄改。

③ API 清單(Supabase RPC + Edge Function)

App 與後台透過下列 RPC 與後端互動(另有約 25 支內部 trigger/guard 函式維持資料完整性,此處省略)。

內容 / Feed / 搜尋

  • get_recommended_videos 為你推薦
  • get_following_videos 追蹤動態
  • get_hot_videos / get_hot_creators / get_hot_paid_contents 熱搜
  • search_videos_by_hashtag / search_videos_by_topic / search_accounts

金流 / 鑽石

  • topup_diamond 儲值 · spend_diamond 消費
  • unlock_video / unlock_paid_content / unlock_paid_message 解鎖
  • subscribe_to_creator 訂閱 · is_active_subscriber
  • withdraw_earnings 提領 · get_unlocked_content_url

訊息

  • find_or_create_conversation 開對話
  • send_paid_message 付費私訊

帳號

  • delete_my_account 刪除帳號(軟刪+匿名化)
  • handle_new_auth_user 註冊自動建檔(trigger)
  • Edge Function phone-signup-bypass 手機/Email 帳號建立

後台 Admin

  • admin_dashboard_stats / admin_search_users
  • admin_mark_withdrawal_paid 標記撥款 · admin_set_creator_fees 費率
  • settle_usd_subscriptions USD 月結 · has_scope/my_scopes 權限