A production-ready RAG-based web application that allows users to upload books and have context-aware, citation-backed conversations with an AI assistant powered by Gemini.
- Multi-format Support: Upload PDF, EPUB, and TXT files
- Smart Ingestion: Automatic text extraction with OCR fallback for scanned pages
- RAG-Powered Chat: Context-aware conversations with accurate citations
- User Memory: Save quotes, preferences, and reading goals
- Persona Modes: Switch between Scholar, Friend, and Quizzer personalities
- Vector Search: Fast semantic search using PostgreSQL with pgvector
- Next.js 16 with TypeScript and App Router
- Tailwind CSS 4 for styling
- Radix UI for accessible components
- Zustand for state management
- React Query for data fetching
- Node.js/TypeScript with Express
- Neon DB (Serverless PostgreSQL with pgvector)
- Gemini 2.0 Flash for LLM (with Gemini 1.5 Pro fallback)
- Gemini text-embedding-001 for embeddings
- Bull for job queue (Redis)
- Tesseract.js for OCR
- Local filesystem (development)
- MinIO (S3-compatible, production)
- Node.js 20+ and npm
- Neon DB account (free tier available)
- Gemini API key (Pro subscription recommended)
- Docker and Docker Compose (for Redis and MinIO)
# Install frontend dependencies
npm install
# Install backend dependencies
cd backend
npm install
cd ..Copy the example environment file and fill in your credentials:
cp env.example .envEdit .env with your actual values:
DATABASE_URL: Your Neon DB connection stringGEMINI_API_KEY: Your Gemini API keyJWT_SECRET: A secure random string
- Create a free account at neon.tech
- Create a new project and database
- Copy the connection string to your
.envfile - Run the schema migration:
# Connect to your Neon DB and run the schema
psql $DATABASE_URL -f backend/src/db/schema.sqlStart Redis and MinIO (optional):
docker-compose up -d# Terminal 1: Start backend
cd backend
npm run dev
# Terminal 2: Start frontend
npm run devThe application will be available at:
- Frontend: http://localhost:3000
- Backend API: http://localhost:3001
- MinIO Console: http://localhost:9001 (minioadmin/minioadmin)
bookbuddy/
├── app/ # Next.js app directory
│ ├── chat/ # Chat interface
│ ├── upload/ # File upload page
│ └── library/ # Book library
├── components/ # React components
│ ├── chat/ # Chat-related components
│ ├── upload/ # Upload components
│ └── quotes/ # Quotes panel
├── lib/ # Utility functions
├── backend/ # Express backend
│ └── src/
│ ├── server.ts # Main server file
│ ├── db/ # Database connection and schema
│ ├── routes/ # API routes
│ ├── services/ # Business logic
│ └── middleware/ # Express middleware
├── docker-compose.yml # Docker services
└── env.example # Environment variables template
npm run dev- Start development servernpm run build- Build for productionnpm start- Start production servernpm run lint- Run ESLint
npm run dev- Start development server with hot reloadnpm run build- Compile TypeScriptnpm start- Start production servernpm test- Run tests
GET /health- Health checkPOST /api/upload- Upload a bookGET /api/ingest/status/:jobId- Check ingestion statusPOST /api/query- Query with RAGPOST /api/chat/:convId/message- Send chat messageGET /api/book/:id/quotes- Get saved quotesPOST /api/user/memory- Save user preferences
# Run backend tests
cd backend
npm test
# Run frontend tests (to be added)
npm testSee docs/DEPLOYMENT.md for detailed deployment instructions.
- Railway: Free tier available
- Render: Free tier with auto-sleep
- Fly.io: Free tier with resource limits
- VPS: Oracle Cloud Always Free, Google Cloud $300 credit
See env.example for all available environment variables.
Contributions are welcome! Please read our contributing guidelines first.
MIT License - see LICENSE file for details.
Note: This project requires a Gemini API key. Get yours at Google AI Studio.