Skip to content

git-adventures/ai-saas-clone

Repository files navigation

πŸ€– AI SaaS Platform - Multi-Tool AI Generation

ai-saas-clone

A fully-featured AI SaaS platform with 5 powerful AI tools for content generation. Built with cutting-edge technologies including Next.js 16 App Router, OpenRouter AI, Replicate AI, and a complete Stripe subscription system.

Credit: This project is based on the tutorial by Antonio Erdeljac (Code With Antonio)

✨ Features

🎨 Five AI Tools

  • πŸ’¬ Conversation - Advanced AI chat using one the most sophisticated conversation model
  • πŸ–ΌοΈ Image Generation - Turn your prompts into stunning images
  • 🎡 Music Generation - Generate 1-2 minute songs with AI vocals
  • 🎬 Video Generation - Create short video clips from text descriptions
  • πŸ’» Code Generation - Generate code using descriptive text

πŸš€ Core Features

  • 🎯 5 Free Generations - Try all tools with free tier limits
  • πŸ’³ Stripe Subscription - Upgrade to Pro for unlimited generations
  • πŸ” Clerk Authentication - Secure sign-in/sign-up with social logins
  • πŸ“Š Usage Tracking - Monitor your generation limits
  • πŸ“± Mobile Responsive - Works seamlessly across all devices
  • ⚑ Real-time Generation - Watch AI create content in real-time

πŸ’Ž Pro Features

  • ✨ Unlimited AI generations across all tools
  • 🎨 Priority generation queue
  • πŸ’Ύ Save and download all creations

πŸ› οΈ Tech Stack

Frontend

Backend & Database

AI Integration

Authentication & Payments

  • Clerk - Complete authentication solution
  • Stripe - Payment processing & subscriptions
  • Stripe Webhooks - Subscription management

State Management

  • Zustand - Global state management
  • React Context API

πŸ“‹ Prerequisites

Before you begin, ensure you have:

πŸš€ Getting Started

1. Clone the repository

git clone https://github.com/git-adventures/ai-saas-clone.git
cd ai-saas-clone

2. Install dependencies

npm install

3. Setup Environment Variables

Create a .env file in the root directory:

# Clerk Authentication
NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY=your_clerk_publishable_key
CLERK_SECRET_KEY=your_clerk_secret_key

# Clerk Redirect URLs
NEXT_PUBLIC_CLERK_SIGN_IN_URL=/sign-in
NEXT_PUBLIC_CLERK_SIGN_UP_URL=/sign-up
NEXT_PUBLIC_CLERK_AFTER_SIGN_IN_URL=/dashboard
NEXT_PUBLIC_CLERK_AFTER_SIGN_UP_URL=/dashboard

# Site Configuration
YOUR_SITE_URL=http://localhost:3000
YOUR_SITE_NAME=AI Platform Clone

# OpenRouter AI (Multiple Keys for Automatic Failover)
# Add up to 10 keys - system will automatically rotate when one runs out
OPENROUTER_API_KEY_1=your_openrouter_key_1
OPENROUTER_API_KEY_2=your_openrouter_key_2
OPENROUTER_API_KEY_3=your_openrouter_key_3
OPENROUTER_API_KEY_4=your_openrouter_key_4
# Optional: Add more keys (up to OPENROUTER_API_KEY_10)

# Replicate AI
REPLICATE_API_TOKEN=your_replicate_token

# Database (Neon PostgreSQL)
DATABASE_URL=your_neon_postgres_connection_string

# Stripe
STRIPE_API_KEY=your_stripe_secret_key
STRIPE_WEBHOOK_SECRET=your_stripe_webhook_secret
NEXT_PUBLIC_APP_URL=http://localhost:3000

4. Setup Prisma Database

# Generate Prisma Client
npx prisma generate

# Push database schema
npx prisma db push

# (Optional) Open Prisma Studio to manage database
npx prisma studio

5. Setup Stripe Webhooks (for local development)

# Install Stripe CLI
# Visit: https://stripe.com/docs/stripe-cli

# Login to Stripe CLI
stripe login

# Forward webhooks to your local server
stripe listen --forward-to localhost:3000/api/webhook

Copy the webhook signing secret to your .env file as STRIPE_WEBHOOK_SECRET.

6. Start the development server

npm run dev

Open http://localhost:3000 in your browser.

πŸ“¦ Available Scripts

Command Description
npm run dev Start development server
npm run build Build for production
npm start Start production server
npm run lint Run ESLint
npx prisma studio Open Prisma Studio
npx prisma generate Generate Prisma Client
npx prisma db push Push schema to database

πŸ”‘ Key Features Explained

πŸ”„ API Key Rotation System

The platform includes an intelligent API key rotation system for uninterrupted service:

  • Multiple Key Support: Configure up to 10 OpenRouter API keys (OPENROUTER_API_KEY_1 through OPENROUTER_API_KEY_10)
  • Automatic Failover: When one key runs out of credits or hits rate limits (402/429 errors), the system automatically switches to the next available key
  • Zero Downtime: Users experience seamless conversations and code generation without interruption
  • Smart Error Handling: Only switches keys for credit/rate-limit errors, returns immediately for other errors
  • Logging: Console logs show which key is being used

Example Console Output:

[CODE_API_KEY_1] Attempting request...
[CODE_API_KEY_1] Rate limited or out of credits, trying next key...
[CODE_API_KEY_2] Attempting request...
[CODE_API_KEY_2] Success!

Setup:

  1. Create multiple OpenRouter accounts
  2. Generate API keys for each account
  3. Add them to your .env file as OPENROUTER_API_KEY_1, OPENROUTER_API_KEY_2, etc.
  4. The system automatically uses them in order and rotates when needed

Free Tier System

  • Each user gets 5 free generations across all AI tools
  • Usage is tracked in the database per user
  • Counter resets with Pro subscription

AI Tools

  1. Conversation: Uses OpenRouter Meta Llama 3.3 70B for multi-turn conversations
  2. Image Generation: Powered by Pollinations.ai Flux model - free, fast, and high-quality
  3. Music Generation: AI-generated songs with vocals using Replicate
  4. Video Generation: Text-to-video using Replicate
  5. Code Generation: Intelligent code generation using OpenRouter Meta Llama 3.3 70B with syntax highlighting

πŸ“š Resources

πŸ™ Acknowledgments


⭐ If you found this project helpful, please give it a star!

Releases

No releases published

Packages

 
 
 

Contributors