A modern e-commerce platform for selling and distributing e-books with subscription-based access, built with Next.js 14, Clerk authentication, Stripe payments, and Supabase.
- Book Catalog: Browse, search, and filter books by category, author, price, and rating
- Shopping Cart: Add, remove, and manage cart items with format selection
- Secure Payments: Stripe integration for one-time purchases and subscriptions
- File Management: Cloudflare R2 integration for secure file storage and delivery
- Flexible Plans: Basic ($9/month), Standard ($15/month), Annual ($59/year)
- Access Control: Book access based on subscription status and usage limits
- Premium Features: Download capabilities with premium add-on
- Usage Tracking: Monitor books consumed vs. subscription limits
- Authentication: Clerk-powered user management with social login
- Responsive Design: Mobile-first approach with beautiful UI
- Search & Discovery: Advanced search with auto-suggestions
- Reviews & Ratings: User-generated reviews with helpful voting
- Wishlist: Save books for later purchase
- TypeScript: Full type safety throughout the application
- shadcn/ui: Modern, accessible UI components
- Performance: Optimized with Next.js App Router and Image optimization
- SEO: Meta tags, structured data, and sitemap generation
- Error Handling: Comprehensive error boundaries and user feedback
- Framework: Next.js 14 with App Router
- Language: TypeScript
- Styling: Tailwind CSS + shadcn/ui
- Authentication: Clerk
- Database: Supabase (PostgreSQL)
- Payments: Stripe
- File Storage: Cloudflare R2
- State Management: React Query + React Hook Form
- Validation: Zod
- Deployment: Vercel
-
Clone the repository
git clone <repository-url> cd leaflyx
-
Install dependencies
npm install
-
Set up environment variables Create a
.env.localfile in the root directory:# Database DATABASE_URL=your_supabase_database_url NEXT_PUBLIC_SUPABASE_URL=your_supabase_url NEXT_PUBLIC_SUPABASE_ANON_KEY=your_supabase_anon_key SUPABASE_SERVICE_ROLE_KEY=your_supabase_service_role_key # Authentication CLERK_SECRET_KEY=your_clerk_secret_key NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY=your_clerk_publishable_key CLERK_WEBHOOK_SECRET=your_clerk_webhook_secret # Payments STRIPE_SECRET_KEY=your_stripe_secret_key NEXT_PUBLIC_STRIPE_PUBLISHABLE_KEY=your_stripe_publishable_key STRIPE_WEBHOOK_SECRET=your_stripe_webhook_secret # File Storage CLOUDFLARE_ACCOUNT_ID=your_cloudflare_account_id CLOUDFLARE_R2_ACCESS_KEY=your_r2_access_key CLOUDFLARE_R2_SECRET_KEY=your_r2_secret_key CLOUDFLARE_R2_BUCKET_NAME=your_r2_bucket_name CLOUDFLARE_R2_ENDPOINT=your_r2_endpoint # External APIs GOOGLE_BOOKS_API_KEY=your_google_books_api_key # Application NEXT_PUBLIC_APP_URL=http://localhost:3000 NEXT_PUBLIC_APP_NAME="LeafLyx"
-
Set up the database
- Create a Supabase project
- Run the SQL schema from
schema.sqlin your Supabase SQL editor - Configure Row Level Security (RLS) policies
-
Configure Clerk
- Create a Clerk application
- Set up authentication routes and webhooks
- Configure social login providers (optional)
-
Set up Stripe
- Create a Stripe account
- Configure webhook endpoints
- Set up subscription products and prices
-
Configure Cloudflare R2
- Create an R2 bucket
- Set up API tokens with appropriate permissions
- Configure CORS settings
-
Run the development server
npm run dev- Open your browser Navigate to http://localhost:3000
src/
βββ app/ # Next.js App Router
β βββ (auth)/ # Auth group routes
β βββ (main)/ # Main app routes
β βββ api/ # API routes
β βββ globals.css
β βββ layout.tsx
β βββ page.tsx # Homepage
βββ components/ # Reusable components
β βββ ui/ # shadcn/ui components
β βββ auth/
β βββ books/
β βββ cart/
β βββ layout/
β βββ subscription/
βββ lib/ # Utilities & configurations
βββ hooks/ # Custom React hooks
βββ types/ # TypeScript definitions
βββ middleware.ts
npm run dev- Start development servernpm run build- Build for productionnpm run start- Start production servernpm run lint- Run ESLintnpm run type-check- Run TypeScript type checking
- TypeScript: Strict typing throughout
- ESLint: Code linting with Next.js configuration
- Prettier: Code formatting (configured via ESLint)
- Components: Reusable, composable components
- Error Handling: Comprehensive error boundaries
The application uses a comprehensive PostgreSQL schema with the following main tables:
users- User profiles and preferencesbooks- Book metadata and pricingbook_files- File storage informationsubscriptions- User subscription datauser_book_access- Book access permissionscarts&cart_items- Shopping cart functionalityorders&order_items- Purchase historybook_reviews&book_ratings- User reviews and ratingswishlists- User wishlist management
- Connect your repository to Vercel
- Configure environment variables in Vercel dashboard
- Deploy - Vercel will automatically build and deploy your application
Make sure to set all required environment variables in your Vercel project settings:
- Database credentials
- Authentication keys
- Payment processing keys
- File storage credentials
- External API keys
For production deployment:
- Run database migrations using the schema from
schema.sql - Seed initial data (categories, subscription plans, etc.)
- Configure RLS policies for security
- Set up monitoring and logging
- Clerk Integration: Secure user authentication with multi-factor support
- Role-Based Access: User, admin roles with specific permissions
- API Protection: JWT verification on all protected endpoints
- Session Management: Secure session handling
- Encryption: Data encrypted in transit and at rest
- PCI Compliance: Stripe handles all payment data
- File Security: Signed URLs for secure file access
- Rate Limiting: API rate limits to prevent abuse
- Access Verification: Verify user permissions before file access
- Signed URLs: Time-limited URLs for secure downloads
- Download Tracking: Log all download attempts
- Content Protection: DMCA compliance procedures
- Core Web Vitals: Track loading performance
- API Response Times: Monitor backend performance
- Error Tracking: Comprehensive error logging
- User Analytics: Track user behavior and engagement
- Subscription Conversion: Track subscription sign-ups
- Revenue Analytics: Monitor sales and revenue
- User Retention: Track user engagement over time
- Book Performance: Monitor popular titles and categories
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
- TypeScript: Use strict typing for all new code
- Testing: Write tests for new features
- Documentation: Update documentation for API changes
- Code Review: All changes require code review
- Performance: Consider performance impact of changes
This project is licensed under the MIT License - see the LICENSE file for details.
For support and questions:
- Documentation: Check the project documentation
- Issues: Create an issue in the GitHub repository
- Discussions: Use GitHub Discussions for questions
- Email: Contact the development team
- β Core e-commerce functionality
- β User authentication
- β Subscription system
- β File management
- π In-browser reading experience
- π Enhanced recommendations
- π Social features (reviews, ratings)
- π Advanced search filters
- π Physical book marketplace
- π Author/publisher portal
- π Mobile app development
- π API for third-party integrations
Built with β€οΈ by the LeafLyx team