我用 Next.js 16、Supabase 和 FSRS 建構 StudyCove AI 學習應用的心得
What I learned building an AI study app with Next.js 16, Supabase and FSRS
Kashif 分享以 Next.js 16、Supabase 和 FSRS 建構 StudyCove AI 學習應用時的實作教訓,涵蓋間隔重複排程、AI 題目驗證、長任務處理、Server Actions 和心智圖儲存。以 90 頁 PDF 生成 40 題模擬考曾導致請求逾時,改用 Postgres 工作表及 claim/dispatch pattern 後,介面可輪詢進度。
I'm Kashif, and for the last few months I've been building StudyCove, an app that turns lecture PDFs into flashcards, practice quizzes, timed mock exams, mind maps and a daily study plan.
This isn't a launch post. It's the handful of things that bit me while building it, in case they save you a weekend.
The stack
- Next.js 16 + React 19 (App Router, Server Actions)
- Supabase for Postgres, auth (Google OAuth) and row-level security
- unpdf to pull text out of uploaded PDFs
- ts-fsrs for spaced-repetition scheduling
- Mind Elixir for the editable mind maps
- Cloud Run for the app, Cloudflare in front
1. Don't write your own spaced-repetition scheduler
My first version used a hand-rolled SM-2 variant. It "worked", but intervals drifted in weird ways once people skipped a few days. Switching to FSRS via ts-fsrs fixed it, and the library handles the awkward cases (lapses, relearning, overdue cards) better than I would have. Store the full card state, not just the next due date, so you can re-schedule if you ever change parameters.
2. Validate every AI-generated question strictly
LLMs will happily return a multiple-choice question with two correct answers, an answer that isn't in the options, or a duplicate of question 3. I now validate each question against a strict schema and drop or regenerate anything that fails, instead of trusting the response. Users notice one broken question far more than they notice ten good ones.
3. Long jobs don't belong in a request
Generating a 40-question mock exam from a 90-page PDF can take a while. Doing it inside a request meant timeouts and stuck spinners. Moving generation to a job table with a claim/dispatch pattern in Postgres (and an index on the dispatch query) made it reliable, and lets the UI poll for progress.
4. Server Actions can hang, so give them a deadline
I hit cases where a Server Action promise never settled after a network blip, leaving buttons disabled forever. Wrapping UI-side calls in a small "settle within N seconds or show a retry" helper made the app feel far more solid on bad connections, which is exactly where students are (library Wi-Fi, buses).
5. Mind maps: use a library, then fight the save loop
Rendering mind maps on a canvas myself was a time sink. Mind Elixir gave me editing, drag and keyboard shortcuts for free. The catch: its change events plus my autosave created a save loop. An inFlight guard and a revision number on every save fixed it, and revision numbers also stopped two tabs from overwriting each other.
What's next
I'm working on making mock exams feel closer to real papers (sections, marks, time per question). If you've built something similar, or you're a student with opinions, I'd love to hear what you'd do differently.
You can try it at studycove.pro.
來源:DEV Community · dev.to