Distill – AI Paper-to-Insights
A full-stack AI web app that transforms academic papers into 7 interactive output formats: infographic, quiz, flashcards, mind-map, data table, slides, and report. Upload a PDF or paste an arXiv link; Gemini 2.5 Flash reads the paper natively (no text extraction) and generates structured, renderable output. Features Firebase Auth with Google sign-in, per-user token quota enforcement, rate limiting, Firestore persistence, and a Vercel serverless backend with cold-start pre-warming.
Proof points
- 7 Output Types
- PDF + arXiv Support
- Token Quota System
Technologies
Next.js 15, TypeScript, Gemini 2.5 Flash, Firebase, Tailwind CSS, Vercel, Firestore, Zod
Links
Problem
Academic papers are dense and time-consuming to digest. Existing summarization tools produce flat text, not the interactive formats (quizzes, flashcards, mind-maps) that aid actual learning and retention.
Approach
Built a Next.js 15 app with 7 distinct Gemini prompts — each targeting a different output schema validated with Zod. Eliminated all local PDF parsing by sending the file as Gemini inlineData (native PDF understanding, handles scanned docs). Added cold-start pre-warming, per-user token quotas, and rate limiting for a production-ready multi-tenant system.
Results
Deployed at distill.shiverion.com. Supports PDF upload up to 20 MB and arXiv URL input. Generates 7 interactive output types. Token quota and rate limiting enable safe public access. Cold-start mitigation (warmup GET on dashboard mount) reduces first-request timeout failures on Vercel Hobby.
Distill – AI Paper-to-Insights: Engineering Report
1. Executive Summary
Distill is a production-deployed Next.js 15 application that takes any academic paper (PDF upload or arXiv URL) and generates one of 7 structured output formats using Gemini 2.5 Flash's native PDF understanding. Each output type is a purpose-built interactive React renderer — not a flat text dump.
2. Output Formats
- Infographic — visual key-points card with stats and takeaways
- Quiz — interactive multiple-choice questions with answer reveal
- Flashcards — flip-card deck for concept review
- Mind Map — branch-grid concept hierarchy
- Data Table — multi-table structured data extracted from the paper
- Slides — paginated viewer with section-by-section breakdown
- Report — long-form written summary with structured sections
3. PDF Pipeline
Eliminated all local PDF parsing (pdfjs-dist worker resolution fails in Vercel serverless). Instead, the PDF is base64-encoded client-side and sent as Gemini inlineData (up to 20 MB). Gemini reads it natively — including scanned/image-only PDFs via OCR. arXiv URLs are fetched server-side and passed as extracted text.
4. Backend Architecture
/api/analyzePOST: multipart form (PDF) or JSON body (URL), auth check, rate limit, token quota pre-check, Gemini call, Firestore write, cache revalidation/api/analyzeGET: no-op pre-warm endpoint called on dashboard mount to keep the Vercel container alivemaxDuration = 60set on the route handler (effective on Pro plan; on Hobby the hard cap is 10s)- Token estimation for PDFs uses base64 size formula to avoid an extra Gemini API round-trip
5. Auth & Quota System
- Firebase Auth (Google Sign-In via popup with COOP header
same-origin-allow-popups) - httpOnly session cookie managed by
/api/auth/sessionPOST onIdTokenChangedlistener refreshes the session cookie when Firebase rotates the token (~hourly)- Per-user token quotas enforced in
lib/usage.ts— exception for the owner email (unlimited) - Rate limiting per UID via
lib/rate-limiter.ts
6. Security
- Content Security Policy headers with Firebase, Google Auth, and Vercel Live allowlists
- Firebase service account key and
.env.localblocked from git via.gitignore - No client-side API key exposure — all Gemini calls go through the serverless route
- Error responses never leak internal error messages to the client
7. Deployment
- Live at
https://distill.shiverion.com(Cloudflare DNS → Vercel) - Custom domain: A record
distill → 76.76.21.21(DNS only, no proxy) - Vercel project:
paprikaunderizzulhaq-iqbals-projects