- Node.js 18+ installed
- PostgreSQL database (local or cloud like Neon, Supabase, RDS)
- OpenAI API key -(Optional) Google Gemini API key -(Optional) Pinecone Vector DB account
Copy env.example to .env.local and fill in your values:
cp env.example .env.localRequired environment variables:
DATABASE_URL: PostgreSQL connection string (usesslmode=requireon most cloud providers)OPENAI_API_KEY: Your OpenAI API keyNEXTAUTH_SECRET: Random secret for NextAuth (generate withopenssl rand -base64 32)NEXTAUTH_URL: Your app URL (http://localhost:3000 for development)
Optional (if using voice/Gemini and vector search):
GOOGLE_GEMINI_API_KEY: Your Google Gemini API keyPINECONE_API_KEY: Pinecone API keyPINECONE_ENVIRONMENT: Pinecone environment (e.g.us-east-1-aws)PINECONE_INDEX_NAME: Index name (default:ai-pdf-tutor)
File handling (already defaulted in env.example):
UPLOAD_DIR: Local upload directory (default./uploads)MAX_FILE_SIZE: Max upload size in bytes (default10485760≈ 10MB)APP_URL: App base URL (defaulthttp://localhost:3000)
# Install dependencies
npm install
# Ensure DATABASE_URL is set to a Postgres instance
export DATABASE_URL=postgres://user:password@host:5432/dbname?sslmode=require
# Create and run migrations locally (ensure Postgres is reachable)
npx prisma migrate dev --name init
# (Optional) Seed the database with a test user
npm run db:seedIf you plan to enable vector-based search and chunk storage references, create/verify a Pinecone index:
# Requires PINECONE_API_KEY (and optionally PINECONE_INDEX_NAME) in .env.local
npm run setup:pineconenpm run devVisit http://localhost:3000 to see the application.
✅ Authentication System
- Email/password signup and login
- Secure password hashing with bcrypt
- Session management with NextAuth
✅ PDF Upload & Management
- Drag-and-drop PDF upload
- File validation and storage
- PDF metadata tracking
✅ Split-Screen Interface
- PDF viewer with page navigation
- Real-time chat interface
- Responsive design
✅ AI Integration
- OpenAI GPT-4 integration (via Vercel AI SDK)
- Optional Google Gemini key support for voice services
- PDF text extraction and analysis
- Context-aware responses
✅ Chat System
- Persistent chat history
- Message threading
- Real-time UI updates
✅ Voice Controls
- Web Speech API-based voice input and output
- Microphone and speaker controls
- Auto-speak toggle and compatibility checks
✅ Vector-Ready Processing
- PDF chunking with bounding boxes and metadata
- Message-to-relevant-chunk linkage
- Optional Pinecone vector database integration
- Push code to GitHub
- Connect repository to Vercel
- In Vercel Project Settings → Environment Variables, set:
DATABASE_URL(Postgres URL; includesslmode=requireif needed)OPENAI_API_KEY,NEXTAUTH_SECRET,NEXTAUTH_URL- (Optional)
GOOGLE_GEMINI_API_KEY - (Optional)
PINECONE_API_KEY,PINECONE_ENVIRONMENT,PINECONE_INDEX_NAME
- Deploy. The build will run
prisma migrate deployautomatically.
If you see database connection errors during build or runtime:
- Verify
DATABASE_URLis correct and accessible from Vercel - Ensure the DB allows external connections and SSL settings match
- Check that migrations exist and the target database is empty/compatible
DATABASE_URL: Production PostgreSQL URLOPENAI_API_KEY: Production OpenAI keyNEXTAUTH_SECRET: Production secretNEXTAUTH_URL: Production domain- (Optional)
GOOGLE_GEMINI_API_KEY - (Optional)
PINECONE_API_KEY,PINECONE_ENVIRONMENT,PINECONE_INDEX_NAME
POST /api/auth/register- User registrationPOST /api/upload- PDF file uploadGET /api/pdfs/[id]- Get PDF metadataGET /api/pdfs/[id]/file- Serve PDF filePOST /api/chat- Chat with AI tutorPOST /api/search- Semantic search within PDF chunksGET /api/user/pdfs- List user PDFsGET /api/user/chats- List user chats
The application uses the following main models:
User- User accounts and authenticationPDF- Uploaded PDF documentsChat- Chat sessionsMessage- Individual chat messagesPDFChunk- Extracted and indexed chunks of PDFsMessageRelevantChunk- Join table linking messages to relevant chunks
- PDF Annotation System - Visual highlighting and annotations on the PDF canvas
- Advanced Voice Features - Voice activity detection, multi-language, commands
- Vector Search UX - Surfaces with filters, confidence scores, and navigation
- File Processing - Add text extraction caching and background jobs
- User Management - Profile management and settings
- Analytics - Usage metrics and learning progress