A calm, composed AI study platform built with Next.js 14 (App Router), TypeScript, Tailwind CSS, Prisma ORM, and PostgreSQL with
pgvector. Upload lecture notes and PDFs for instant AI Q&A with clickable source citations, auto-generated practice quizzes, and PWA mobile offline support.
Study Companion turns dense lecture notes, research PDFs, and class slides into an interactive, cited intelligence workspace. Unlike generic chatbots that hallucinate or provide uncited summaries, Study Companion performs per-user vector retrieval-augmented generation (RAG) directly over your uploaded document chunksβciting the exact document and chunk index for every answer.
Designed with a Calm & Composed UI/UX identity, the application features a warm, unhurried visual palette (warm beige #FAF6EF, soft sage green #93AE8B, peach #E8B894, and warm charcoal text #33312B) paired with comfortable humanist typography (DM Sans body + Plus Jakarta Sans headings) to eliminate eye strain during long study sessions.
-
Server-Side Text Extraction: Parses raw PDF document streams on upload using
pdf-parse. - Semantic Text Chunking: Splits extracted text into ~500 token (~1800 character) blocks with ~50 token overlap to preserve paragraph context across boundaries.
-
Vector Embeddings: Computes 1536-dimensional vector embeddings for each chunk and persists them in PostgreSQL using
pgvector. -
Status Lifecycle: Documents transition automatically from
pending$\rightarrow$ processing$\rightarrow$ ready(orfailedwith error capture).
- Strict User Scoping: Vector similarity searches (cosine distance
<=>) execute strictly over the logged-in user's chunksβnever leaking cross-user data. - Interactive Source Citations: Answers include clickable reference chips (e.g.
[Lecture_12.pdf, Chunk #3]) displaying source document names and chunk indices. - Strict Context Prompting: Instructs the LLM to answer using only the provided context and clearly state when information is unavailable.
- Document Comprehension Testing: Automatically generates multiple-choice practice quizzes derived from indexed document chunks.
- Instant Feedback & Scoring: Real-time option evaluation, explanations, and direct citations back to the source text.
-
Installable Web App: Web App Manifest (
public/manifest.json) supporting standalone display mode on iOS and Android. -
Service Worker Caching: Service worker (
public/sw.js) caches static assets and document libraries for offline access. -
Mobile Ergonomics: All touch targets
$\ge 44\text{px}$ with responsive layouts optimized for mobile keyboards.
- Session Authentication: Secured via NextAuth.js Credentials Provider and
bcryptjspassword hashing. - Input Validation: All server endpoints and client forms are validated using Zod schemas.
- Server-Only Isolation: LLM and embedding integration routines (
lib/llm.ts) are strictly server-only and never exposed to the client.
| Layer | Choice |
|---|---|
| Framework | Next.js 14+ (App Router), TypeScript |
| Styling | Tailwind CSS (Calm Warm Palette: #FAF6EF / #93AE8B / #33312B) |
| Typography | DM Sans (body) + Plus Jakarta Sans (headings) via next/font/google |
| Database | PostgreSQL (Neon / Supabase with pgvector extension) |
| ORM | Prisma ORM |
| Auth | NextAuth.js (Credentials Provider with bcryptjs) |
| File Parsing | pdf-parse (Server-Side) |
| Validation | Zod |
| PWA | Web App Manifest + Service Worker (sw.js) |
| CI | GitHub Actions (tsc --noEmit & ESLint) |
model User {
id String @id @default(cuid())
email String @unique
hashedPassword String?
name String?
createdAt DateTime @default(now())
documents Document[]
}
model Document {
id String @id @default(cuid())
userId String
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
filename String
storageUrl String
status String @default("pending") // pending | processing | ready | failed
createdAt DateTime @default(now())
chunks Chunk[]
}
model Chunk {
id String @id @default(cuid())
documentId String
document Document @relation(fields: [documentId], references: [id], onDelete: Cascade)
content String
embedding Unsupported("vector(1536)")? // pgvector 1536-dim vector column
chunkIndex Int
}- Node.js: v18.x or v20.x
- npm or pnpm
- PostgreSQL: A Postgres database instance with
pgvectorenabled (e.g. Neon, Supabase, or Docker Postgres).
git clone https://github.com/matorverse/Retrivo.git
cd Retrivo
npm installCopy .env.example to .env.local:
cp .env.example .env.localConfigure the environment variables in .env.local:
# PostgreSQL connection string (must support pgvector)
DATABASE_URL="postgresql://user:password@localhost:5432/study_companion?schema=public"
# NextAuth secret & URL
NEXTAUTH_SECRET="your-development-secret-key-at-least-32-chars"
NEXTAUTH_URL="http://localhost:3000"
# Server-Side API Keys
OPENAI_API_KEY="sk-..."
ANTHROPIC_API_KEY="sk-ant-..."
# Blob storage token
BLOB_READ_WRITE_TOKEN="vercel_blob_rw_..."Generate the Prisma client and push the schema (including raw SQL pgvector extension):
# Generate Prisma Client
npx prisma generate
# Apply DB schema and pgvector extension
npx prisma db pushnpm run devOpen http://localhost:3000 in your browser.
# Run TypeScript type check
npx tsc --noEmit
# Run ESLint check
npm run lint
# Build production bundle
npm run buildβββ app/
β βββ (auth)/
β β βββ login/page.tsx # Login page
β β βββ signup/page.tsx # Signup page
β βββ (dashboard)/
β β βββ dashboard/page.tsx # Main workspace (Library, Chat, Quiz tabs)
β βββ api/
β β βββ auth/ # NextAuth & registration handlers
β β βββ chat/route.ts # Cited RAG chat endpoint
β β βββ documents/ # Document upload & deletion endpoints
β βββ globals.css # Calm theme CSS custom properties
β βββ layout.tsx # Root layout with fonts & PWA headers
β βββ page.tsx # Public landing page
βββ components/
β βββ AuthProvider.tsx # Client SessionProvider wrapper
β βββ ChatInterface.tsx # Cited RAG Q&A chat component
β βββ Navbar.tsx # Navigation header
β βββ QuizInterface.tsx # Interactive practice quiz component
βββ lib/
β βββ auth.ts # NextAuth options & session helpers
β βββ db.ts # Prisma client singleton
β βββ llm.ts # Server-side PDF parsing, chunking & embeddings
β βββ rag.ts # PostgreSQL pgvector similarity search
β βββ storage.ts # File storage abstraction
β βββ validations.ts # Zod validation schemas
βββ prisma/
β βββ migrations/ # Raw SQL migration for pgvector extension
β βββ schema.prisma # Data model definitions
βββ public/
β βββ manifest.json # Web App Manifest
β βββ sw.js # Offline service worker
βββ README.md # Project documentation
Built as a CSE semester portfolio project. Designed for calm, focused, and cited learning.