A modern e-commerce platform for selling books in multiple formats: audiobooks, ebooks, paperbacks, and hardcovers. Built with Next.js 14, PostgreSQL, Prisma, and integrated with Stripe for payments and Book Vault for print-on-demand fulfillment.
- π Multiple Book Formats: Audiobooks, eBooks, Paperbacks, and Hardcovers
- π Shopping Cart: Persistent cart using Zustand
- π³ Payment Processing: Stripe integration with webhook support
- π Digital Library: Download purchased digital content with tracking
- π¨ Bold Modern Design: Tailwind CSS with custom theme
- π Authentication: NextAuth.js with credentials provider
- π¨βπΌ Admin Dashboard: Manage books, orders, and customers
- π¦ Print Fulfillment: Book Vault API integration (ready to configure)
- Framework: Next.js 14 (App Router)
- Database: PostgreSQL with Prisma ORM
- Authentication: NextAuth.js
- Payments: Stripe
- Styling: Tailwind CSS
- State Management: Zustand
- Icons: Lucide React
- Notifications: React Hot Toast
- Node.js 18+
- PostgreSQL database
- Stripe account (for payments)
- Book Vault account (optional, for print fulfillment)
npm installUpdate the .env file with your credentials:
# Database
DATABASE_URL="postgresql://USER:PASSWORD@HOST:PORT/DATABASE"
# NextAuth
NEXTAUTH_SECRET="generate-a-random-secret-here"
NEXTAUTH_URL="http://localhost:3000"
# Stripe (get from https://dashboard.stripe.com)
STRIPE_SECRET_KEY="sk_test_..."
STRIPE_PUBLISHABLE_KEY="pk_test_..."
STRIPE_WEBHOOK_SECRET="whsec_..."
# PayPal (optional)
PAYPAL_CLIENT_ID="your_paypal_client_id"
PAYPAL_CLIENT_SECRET="your_paypal_client_secret"
PAYPAL_MODE="sandbox"
# Book Vault (optional)
BOOKVAULT_API_KEY="your_bookvault_api_key"
BOOKVAULT_API_URL="https://api.bookvault.app/v1"Generate NEXTAUTH_SECRET:
openssl rand -base64 32# Push schema to database
npx prisma db push
# Generate Prisma Client
npx prisma generate
# (Optional) Open Prisma Studio to view/edit data
npx prisma studioYou'll need to create an admin user. You can register normally at /register and then update the role in the database:
-- Run this in your PostgreSQL client or Prisma Studio
UPDATE users SET role = 'ADMIN' WHERE email = 'your-email@example.com';npm run devVisit http://localhost:3000
bookshop/
βββ app/
β βββ page.tsx # Homepage
β βββ books/ # Book catalog & detail pages
β βββ cart/ # Shopping cart
β βββ checkout/ # Checkout flow
β βββ library/ # User's digital library
β βββ login/ # Login page
β βββ register/ # Registration page
β βββ admin/ # Admin dashboard
β β βββ books/ # Book management
β β βββ orders/ # Order management
β βββ api/ # API routes
β βββ auth/ # NextAuth & registration
β βββ checkout/ # Order creation
β βββ download/ # Digital downloads
β βββ webhooks/ # Stripe webhooks
βββ components/
β βββ shop/ # Storefront components
β βββ admin/ # Admin components
β βββ ui/ # Reusable UI components
βββ lib/
β βββ db.ts # Prisma client
β βββ auth.ts # NextAuth config
β βββ store.ts # Zustand cart store
β βββ stripe.ts # Stripe client
β βββ paypal.ts # PayPal client
β βββ bookvault.ts # Book Vault API
βββ prisma/
βββ schema.prisma # Database schema
- Browse books by format (audiobook, ebook, paperback, hardcover)
- Search and filter books
- Preview samples (audio/ebook)
- Add to cart with persistent storage
- Secure checkout with Stripe
- Access digital library with download tracking
- User authentication and profiles
- Dashboard with key metrics
- Book management (CRUD operations)
- Order management and tracking
- Customer overview
- Format-specific pricing
- Sign up at stripe.com
- Get your test keys from the Dashboard
- Add them to
.env
For local development:
# Install Stripe CLI
stripe listen --forward-to localhost:3000/api/webhooks/stripeFor production:
- Go to Webhooks
- Add endpoint:
https://yourdomain.com/api/webhooks/stripe - Select event:
checkout.session.completed - Copy webhook signing secret to environment variables
Use Stripe test cards:
- Success:
4242 4242 4242 4242 - Decline:
4000 0000 0000 0002 - Any future expiry date and any 3-digit CVC
To enable print-on-demand fulfillment:
- Sign up at Book Vault
- Get API credentials from your account
- Add credentials to
.env - Add Book Vault SKUs to your paperback/hardcover book formats
- Orders with physical books will automatically forward to Book Vault for fulfillment
Currently, books need to be added directly to the database. Future enhancements will include:
- Admin UI for adding/editing books
- Image upload functionality
- Bulk import from CSV
- Integration with book APIs (Google Books, etc.)
For now, you can add books via Prisma Studio:
npx prisma studio- Push your code to GitHub
- Import project in Vercel
- Add environment variables
- Deploy
Consider using:
When making schema changes:
# Create migration
npx prisma migrate dev --name your_migration_name
# Deploy to production
npx prisma migrate deploy- Verify DATABASE_URL is correct
- Ensure PostgreSQL is running
- Check database exists
- Use Stripe CLI for local testing
- Check webhook secret matches
- Verify endpoint is publicly accessible (production)
- Ensure NEXTAUTH_SECRET is set
- Verify NEXTAUTH_URL matches your domain
- Book management UI in admin panel
- File upload for covers and digital files
- Email notifications for orders
- PayPal integration completion
- Review and rating system
- Wishlist functionality
- Advanced search and filtering
- Book recommendations
- Coupon/discount codes
- Inventory management
MIT
For issues and questions, please check the troubleshooting section or create an issue.