This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
npm run dev- Start Next.js development server on port 9002npm run build- Build the application for productionnpm start- Start production servernpm run lint- Run ESLint for code lintingnpm run typecheck- Run TypeScript type checking without emitting files
npm run genkit:dev- Start Genkit development server for AI flowsnpm run genkit:watch- Start Genkit server with file watching- Important: Genkit server must run in parallel to Next.js for AI features to work
- Frontend: Next.js 15 with App Router, React 18, TypeScript
- UI: Tailwind CSS, ShadCN UI components, Radix UI primitives
- Authentication: Firebase Auth (email/password)
- Database: Firestore for metadata storage
- File Storage: Firebase Storage for PDF/EPUB files and generated audio
- AI: Google Genkit with Gemini for summarization and quiz generation
- PDF Processing: pdfjs-dist for text extraction
- TTS: Browser SpeechSynthesis API
- AI code runs server-side only via Genkit (
src/ai/) - Client communicates with AI through API routes (
src/app/api/) - Never import server AI code directly in client components
- Comprehensive environment variable validation in
src/lib/firebase/clientApp.ts - Checks for placeholder values like "YOUR_API_KEY"
- Graceful degradation when Firebase config is invalid
- Files stored in user-scoped paths:
audiobooks/{userId}/... - Metadata stored in Firestore with user ID validation
- Security rules enforce user isolation for both storage and database
- Custom webpack config copies PDF.js worker to
/_next/static/chunks/ - Worker path explicitly set in
src/services/file-conversion.ts - This prevents "worker not found" errors in production
- Wraps Firebase Auth state management
- Provides loading states and error handling
- Redirects to
/authwhen user is not authenticated
file-conversion.ts: PDF text extraction using pdfjs-disttts.ts: Browser-based text-to-speechstorage.ts: Firebase Storage upload/download operationsfix-words.ts: Text cleanup using word-list library
summarize-audiobook-chapter.ts: Chapter summarizationgenerate-quiz-questions.ts: Quiz generation with multiple choiceexplain-sentence.ts: Sentence explanation for comprehension
- User can only access books where
userId == request.auth.uid - Prevents cross-user data access
- Rules must be deployed with
firebase deploy --only firestore:rules
- User-scoped file access:
audiobooks/{userId}/... - Only authenticated users can access their own files
- Firebase config:
NEXT_PUBLIC_FIREBASE_*(client-accessible) - AI API key:
GOOGLE_GENAI_API_KEY(server-only, no NEXT_PUBLIC prefix)
- Single page app with
ViewMode('library' | 'reader') - Selected book state drives content display
- Audio and text extraction states tracked separately
- Firestore snapshots for live book list updates
onSnapshotused for reactive UI updates
- Ensure
.env.localhas valid Firebase and Google AI credentials - Start Genkit server:
npm run genkit:dev - Start Next.js server:
npm run genkit:dev - Access at
http://localhost:9002
- Create new flows in
src/ai/flows/ - Export flow in
src/ai/dev.tsfor development - Add API route in
src/app/api/to expose to client - Use Zod schemas for input/output validation
- Test rules locally with Firebase emulators
- Deploy rules before testing:
firebase deploy --only firestore:rules,storage:rules - Use rules simulator in Firebase console for testing
- Worker path is critical - check
next.config.tswebpack config - Test with various PDF formats, handle password-protected files gracefully
- Text extraction happens client-side for immediate feedback
next.config.ts: Webpack PDF worker config, TypeScript/ESLint ignorestailwind.config.ts: ShadCN theme configurationcomponents.json: ShadCN component generation settingsfirebase.json: Firebase CLI deployment configuration
NEXT_PUBLIC_FIREBASE_API_KEY=
NEXT_PUBLIC_FIREBASE_AUTH_DOMAIN=
NEXT_PUBLIC_FIREBASE_PROJECT_ID=
NEXT_PUBLIC_FIREBASE_STORAGE_BUCKET=
NEXT_PUBLIC_FIREBASE_MESSAGING_SENDER_ID=
NEXT_PUBLIC_FIREBASE_APP_ID=
GOOGLE_GENAI_API_KEY=
- Check
.env.localfor placeholder values - Verify services enabled in Firebase console
- Ensure rules are deployed, not just saved locally
- Check webpack config in
next.config.ts - Verify worker file exists at
/_next/static/chunks/pdf.worker.min.mjs - Worker setup happens in
src/services/file-conversion.ts
- Genkit server must be running separately
- Check
GOOGLE_GENAI_API_KEYis valid (not placeholder) - Review Genkit terminal logs for specific API errors
- TypeScript errors ignored in build (
ignoreBuildErrors: true) - ESLint ignored during builds (
ignoreDuringBuilds: true) - This allows rapid iteration but run
npm run typecheckmanually