CTRCraft is an AI-powered YouTube thumbnail generator built with Next.js, featuring user authentication, credit system, and Google Gemini AI integration for creating compelling YouTube thumbnails.
- π¨ AI-Powered Thumbnail Generation: Generate high-quality YouTube thumbnails using Google Gemini AI
- π User Authentication: Secure authentication with BetterAuth supporting email/password, Google, and GitHub
- π³ Credit System: Built-in credit system for managing thumbnail generation usage
- π± Modern UI: Beautiful, responsive interface built with Tailwind CSS and Radix UI
- π Cloudflare Deployment: Optimized for Cloudflare Pages deployment
- ποΈ Database: PostgreSQL database with Prisma ORM
- Frontend: Next.js 15, React 19, TypeScript
- Styling: Tailwind CSS, Radix UI components
- Authentication: BetterAuth
- Database: PostgreSQL with Prisma ORM
- AI: Google Gemini AI for image generation
- Deployment: Cloudflare Pages with OpenNext.js
- Icons: Tabler Icons, Lucide React
Before you begin, ensure you have the following installed:
- Node.js 18+
- npm or yarn
- PostgreSQL database
- Google Cloud Platform account (for Gemini AI)
- Google OAuth credentials (for Google sign-in)
- GitHub OAuth credentials (for GitHub sign-in)
Create a .env.local file in the root directory with the following variables:
# Database
DATABASE_URL="postgresql://username:password@localhost:5432/ctrcraft"
# Google OAuth (for authentication)
GOOGLE_CLIENT_ID="your_google_client_id"
GOOGLE_CLIENT_SECRET="your_google_client_secret"
# GitHub OAuth (for authentication)
GITHUB_CLIENT_ID="your_github_client_id"
GITHUB_CLIENT_SECRET="your_github_client_secret"
# Google AI API
GOOGLE_AI_API_KEY="your_google_ai_api_key"
# BetterAuth Secret (generate a random string)
BETTER_AUTH_SECRET="your_random_secret_string"
# App URL (for development)
BETTER_AUTH_URL="http://localhost:3000"- DATABASE_URL: PostgreSQL connection string for your database
- GOOGLE_CLIENT_ID/SECRET: OAuth credentials from Google Cloud Console
- GITHUB_CLIENT_ID/SECRET: OAuth credentials from GitHub Developer Settings
- GOOGLE_AI_API_KEY: API key for Google Gemini AI (get from Google AI Studio)
- BETTER_AUTH_SECRET: Random secret string for session encryption
- BETTER_AUTH_URL: Your app's URL (use
http://localhost:3000for development)
git clone <your-repo-url>
cd ctrcraftnpm install- Create a PostgreSQL database
- Update the
DATABASE_URLin your.env.localfile - Run database migrations:
npx prisma migrate dev- Generate Prisma client:
npx prisma generate- Go to Google Cloud Console
- Create a new project or select existing one
- Enable Google+ API
- Go to "Credentials" β "Create Credentials" β "OAuth 2.0 Client IDs"
- Set authorized redirect URIs:
http://localhost:3000/api/auth/callback/google(development)https://yourdomain.com/api/auth/callback/google(production)
- Copy Client ID and Client Secret to your
.env.local
- Go to GitHub β Settings β Developer settings β OAuth Apps
- Click "New OAuth App"
- Set Authorization callback URL:
http://localhost:3000/api/auth/callback/github(development)https://yourdomain.com/api/auth/callback/github(production)
- Copy Client ID and Client Secret to your
.env.local
- Go to Google AI Studio
- Create an API key
- Add the API key to your
.env.localasGOOGLE_AI_API_KEY
npm run devOpen http://localhost:3000 to view the application.
ctrcraft/
βββ src/
β βββ app/ # Next.js app router
β β βββ api/ # API routes
β β β βββ auth/ # Authentication endpoints
β β β βββ generate-image/ # AI image generation
β β βββ auth/ # Authentication pages
β β βββ create/ # Thumbnail creation page
β βββ components/ # React components
β β βββ ui/ # Reusable UI components
β βββ lib/ # Utility libraries
β β βββ auth.ts # BetterAuth configuration
β β βββ auth-client.ts # Client-side auth
β βββ generated/ # Generated Prisma client
βββ prisma/
β βββ schema.prisma # Database schema
β βββ migrations/ # Database migrations
βββ secrets/ # Service account files
βββ public/ # Static assets
npm run dev- Start development servernpm run build- Build for productionnpm run start- Start production servernpm run lint- Run ESLintnpm run preview- Preview Cloudflare build locallynpm run deploy- Deploy to Cloudflare Pages
The application uses the following main models:
- User: User accounts with credits system
- Session: User sessions for authentication
- Account: OAuth provider accounts
- Thumbnail: Generated thumbnails
- CreditTransaction: Credit usage tracking
- Build the project:
npm run build- Deploy to Cloudflare:
npm run deploy- Set environment variables in Cloudflare Pages dashboard:
GOOGLE_CLIENT_IDGOOGLE_CLIENT_SECRETGITHUB_CLIENT_IDGITHUB_CLIENT_SECRETGOOGLE_AI_API_KEYDATABASE_URLBETTER_AUTH_SECRETBETTER_AUTH_URL
- Fork the repository
- Create a feature branch:
git checkout -b feature-name - Commit your changes:
git commit -am 'Add some feature' - Push to the branch:
git push origin feature-name - Submit a pull request
This project is licensed under the MIT License.
If you encounter any issues or have questions, please open an issue on GitHub or contact the development team.
Note: Make sure to keep your environment variables secure and never commit them to version control. The .env.local file should be added to your .gitignore.