StudyLab turns private PDF uploads into summaries, topics, questions, quizzes, flashcards, and learning analytics. The existing Tailwind/Shadcn-style frontend is connected to Supabase Auth, Postgres, RLS, private Storage, and Gemini structured generation.
- Node.js 20+
- A Supabase project
- A Google AI Studio Gemini API key
-
Install dependencies with
npm install. -
Run
supabase/schema.sqlin the Supabase SQL editor. It creates the tables, indexes, auth-user trigger, privatestudy-pdfsbucket, and owner-only RLS policies. -
In Supabase Authentication settings, enable Email authentication, set the local Site URL to
http://localhost:3000, and add the production URL before deployment. StudyLab supports both immediate and confirmation-required signups. -
Copy
.env.exampleto.env.localand fill in:NEXT_PUBLIC_SUPABASE_URL=https://your-project.supabase.co NEXT_PUBLIC_SUPABASE_PUBLISHABLE_KEY=sb_publishable_your_key SUPABASE_SERVICE_ROLE_KEY=your_server_only_service_role_key GEMINI_API_KEY=your_google_ai_studio_key GEMINI_MODEL=gemini-2.5-flash-lite
GEMINI_API_KEYandSUPABASE_SERVICE_ROLE_KEYare server-only. The service role is used only after the request's cookie session is verified; ownership is always derived from that verified user. Never expose either value through aNEXT_PUBLIC_variable. -
Run
npm run dev, open http://localhost:3000, create an account, and upload a text-based PDF.
users: profile synchronized fromauth.usersstudy_sets: source file, summary, topics, and processing statequestions: MCQ, short-answer, and long-answer contentflashcards: active-recall cardsquiz_attempts: scores and weak-topic historyflashcard_reviews: review completion and known-card countsuser_settings: persisted account preferences
Every table has RLS. Child rows are accessible only when their study set belongs to the authenticated user. Private Storage paths begin with the user's UUID and use the same ownership rule.
POST /api/study-sets verifies the server-side user, validates the PDF and 25 MB limit, uploads to private Storage, extracts text with pdf-parse, asks Gemini for structured JSON, validates it with Zod, and stores the complete study set. MCQs are checked for exactly four options and an answer that matches one option. Extraction and AI failures are saved as safe failed states.
Authenticated handlers also save quiz attempts, flashcard reviews, settings, account email changes, and owner-only study-set deletion. User IDs are always derived from the verified session, never accepted from the browser.
- Add the deployment URL to Supabase Auth redirect URLs.
- Source PDFs use five-minute signed URLs.
- The generation handler allows up to 60 seconds; confirm the host supports that duration.
- Scanned/image-only PDFs return an OCR guidance error.
- Gemini free-tier quotas vary. Change
GEMINI_MODELwithout code changes when needed.
Run npm run build for the production compile and TypeScript validation.