A powerful web-based design editor built with Next.js and Fabric.js, inspired by Canva. Create, edit, and export graphics with an intuitive drag-and-drop interface, complete with AI features and subscription management.
- Interactive Canvas - Fabric.js-powered design workspace with zoom, pan, and precise controls
- Rich Text Editor - Advanced text tools with custom fonts, weights, styles, and formatting
- Shape Library - Comprehensive collection of shapes (circles, rectangles, triangles, diamonds, stars)
- Color Management - Fill colors, stroke colors, gradients, and opacity controls
- Layer Management - Full layer control with bring forward/send backward functionality
- Export Options - Save designs as PNG, JPEG, SVG, or JSON formats
- Responsive Design - Seamless experience across desktop, tablet, and mobile devices
- OAuth Integration - Secure login with GitHub and Google providers
- Session Management - Persistent user sessions with NextAuth.js
- User Profiles - Personalized user accounts and preferences
- Protected Routes - Secure access to editor and premium features
- Stripe Integration - Complete payment processing with Stripe Checkout
- Subscription Management - Monthly/yearly billing with automatic renewals
- Tiered Access - Free tier with limitations, premium tier with full access
- Webhook Handling - Real-time subscription status updates
- Usage Tracking - Monitor project limits and feature usage
- Background Removal - AI-powered background removal using Replicate API
- Image Generation - Create custom images with AI assistance
- Smart Cropping - Intelligent image cropping and optimization
- Content Enhancement - AI-driven design suggestions
- Project Persistence - Save and load projects with PostgreSQL database
- Auto-save - Automatic project saving to prevent data loss
- Project Templates - Pre-designed templates for quick starts
- Version History - Track changes and revert to previous versions
- Project Sharing - Share designs with team members
- Image Upload - Drag-and-drop image uploads with UploadThing
- Unsplash Integration - Access millions of stock photos
- File Optimization - Automatic image compression and optimization
- Multiple Formats - Support for PNG, JPEG, SVG, and more
- Framework: Next.js 14 (App Router)
- Canvas Library: Fabric.js
- Styling: Tailwind CSS
- UI Components: Radix UI / shadcn/ui
- State Management: Zustand + React Query (TanStack Query)
- TypeScript: Full type safety throughout
- API Framework: Hono.js for fast, lightweight APIs
- Database: PostgreSQL with Drizzle ORM
- Authentication: NextAuth.js with multiple providers
- File Storage: UploadThing for secure file uploads
- Payment Processing: Stripe for subscriptions and payments
- AI Services: Replicate for background removal and image generation
- Image Library: Unsplash API for stock photos
- Deployment: Vercel for seamless hosting
src/
βββ app/ # Next.js app router
β βββ api/ # API routes
β β βββ [[...route]]/ # Hono.js API handlers
β β βββ ai.ts # AI service endpoints
β β βββ images.ts # Image management
β β βββ projects.ts # Project CRUD
β β βββ subscriptions.ts # Stripe integration
β β βββ users.ts # User management
β βββ editor/[projectid]/ # Dynamic editor page
β βββ layout.tsx # Root layout with providers
β βββ globals.css # Global styles
βββ components/ # Reusable UI components
β βββ ui/ # shadcn/ui components
β βββ Modal/ # Modal components
β βββ Logo/ # Branding components
βββ db/ # Database configuration
β βββ schema.ts # Drizzle ORM schema
β βββ drizzle.ts # Database connection
β βββ drizzle-safe.ts # Safe database operations
βββ lib/ # Utility libraries
β βββ stripe.ts # Stripe configuration
β βββ hono.ts # API client setup
β βββ utils.ts # Common utilities
βββ providers/ # React context providers
β βββ Providers.tsx # Main provider wrapper
β βββ QueryProvider/ # React Query setup
βββ features/ # Feature-based modules
β βββ Editor/ # Canvas editor
β β βββ components/ # Editor-specific components
β β β βββ NavBar/ # Top navigation
β β β βββ SideBar/ # Tool sidebars
β β β βββ ToolBar/ # Bottom toolbar
β β β βββ Footer/ # Status footer
β β βββ hooks/ # Custom React hooks
β β βββ constants.ts # Editor constants
β β βββ types.ts # TypeScript definitions
β β βββ utils.ts # Editor utilities
β βββ Subscriptions/ # Payment system
β βββ components/ # Subscription UI
β β βββ SubscriptionModal.tsx
β βββ services/ # API mutations
β β βββ mutations/
β βββ store/ # Zustand stores
βββ auth.ts # Authentication configuration
- Node.js 18+ or Bun
- PostgreSQL database
- Stripe account
- GitHub/Google OAuth apps
- Replicate API key (for AI features)
- Unsplash API key
- UploadThing account
-
Clone the repository
git clone https://github.com/your-username/nextjs-canva-clone.git cd nextjs-canva-clone
-
Install dependencies
npm install # or bun install
-
Set up environment variables Create a
.env.local
file:# App Configuration NEXT_PUBLIC_APP_URL=http://localhost:3000 AUTH_URL=http://localhost:3000 AUTH_SECRET="your-secure-auth-secret" # Database DATABASE_URL="postgresql://username:password@host:port/database" # Authentication Providers AUTH_GITHUB_ID="your-github-oauth-client-id" AUTH_GITHUB_SECRET="your-github-oauth-client-secret" AUTH_GOOGLE_ID="your-google-oauth-client-id" AUTH_GOOGLE_SECRET="your-google-oauth-client-secret" # Payment Processing STRIPE_SECRET_KEY="sk_test_your-stripe-secret-key" STRIPE_PRICE_ID="price_your-stripe-price-id" STRIPE_WEBHOOK_SECRET="whsec_your-webhook-secret" # External APIs NEXT_PUBLIC_UNSPLASH_ACCESS_KEY="your-unsplash-access-key" UPLOADTHING_TOKEN="your-uploadthing-token" REPLICATE_TOKEN="your-replicate-api-token"
-
Set up the database
npm run db:push # or bun run db:push
-
Run the development server
npm run dev # or bun dev
-
Open your browser Navigate to http://localhost:3000
- NextAuth.js with JWT strategy
- Multiple OAuth providers (GitHub, Google)
- Session persistence and refresh
- Protected API routes with middleware
- Fabric.js integration with custom event handlers
- Real-time object manipulation and selection
- Responsive canvas sizing and zoom controls
- Custom hooks for canvas state management
- PostgreSQL with Drizzle ORM for type safety
- User, project, and subscription tables
- Optimistic updates with React Query
- Connection pooling for performance
- Stripe Checkout for subscription management
- Webhook handlers for real-time status updates
- Usage-based billing and feature gating
- Secure payment processing with SCA compliance
- Replicate API for background removal
- Async job processing with status polling
- Error handling and retry mechanisms
- Usage tracking for billing purposes
- Connect GitHub repository to Vercel
- Add environment variables in Vercel dashboard
- Configure PostgreSQL database (Neon, Supabase, etc.)
- Set up Stripe webhooks with production URL
- Deploy with automatic CI/CD
# Build the application
npm run build
# Start production server
npm start
- Configure production database
- Update OAuth redirect URLs
- Set up Stripe webhook endpoints
- Configure CDN for static assets
# Development
npm run dev # Start development server
npm run build # Build for production
npm run start # Start production server
npm run lint # Run ESLint
npm run type-check # TypeScript type checking
# Database
npm run db:push # Push schema changes
npm run db:studio # Open Drizzle Studio
npm run db:migrate # Run migrations
# Testing
npm run test # Run test suite
npm run test:watch # Watch mode testing
POST /api/auth/signin
- User authenticationPOST /api/auth/signout
- User logoutGET /api/auth/session
- Get current session
GET /api/projects
- List user projectsPOST /api/projects
- Create new projectPATCH /api/projects/:id
- Update projectDELETE /api/projects/:id
- Delete project
POST /api/subscriptions/checkout
- Create Stripe checkoutPOST /api/subscriptions/webhook
- Handle Stripe webhooksGET /api/subscriptions/status
- Get subscription status
POST /api/ai/remove-background
- Remove image backgroundPOST /api/ai/generate-image
- Generate AI imageGET /api/ai/status/:jobId
- Check processing status
POST /api/images/upload
- Upload image fileGET /api/images/unsplash
- Search Unsplash photosGET /api/images/:id
- Get image details
We welcome contributions! Please see our Contributing Guide for details.
- Fork the repository
- Create a feature branch
- Make your changes with tests
- Submit a pull request
- TypeScript for all new code
- ESLint + Prettier for formatting
- Conventional commits for messages
- Test coverage for new features
This project is licensed under the MIT License - see the LICENSE file for details.
Built with β€οΈ using Next.js, Fabric.js, and cutting-edge web technologies
Last updated: June 2025