Let’s build a **full AI-powered SaaS app** step by step.

We’ll start with a basic but production-ready app that uses:

  • Next.js + TailwindCSS (modern, fast frontend)
  • Node.js backend / API routes
  • OpenAI API for the core AI logic
  • Stripe for payments (monetization)
  • Supabase or Firebase for auth + DB
  • Optional: Cron jobs / webhooks for automation

🧠 What We'll Build: “AI Content Generator SaaS”

Features:

  • ✅ Users can log in
  • ✅ Enter a topic → generate blog post / tweet / product description
  • ✅ Get credits (limited free, then upgrade via Stripe)
  • ✅ Admin panel (optional)
  • ✅ Fully hosted on Vercel + Supabase

⚙️ Stack Overview

PartTool
FrontendNext.js + Tailwind
Auth + DBSupabase
AI EngineOpenAI API
PaymentsStripe
DeploymentVercel (free plan)

🚀 Step 1: Set Up the Project

npx create-next-app@latest ai-saas --typescript
cd ai-saas
npm install openai @supabase/supabase-js stripe react-hook-form zod

🛠 Step 2: Core File Structure

ai-saas/
├── pages/
│   ├── index.tsx         ← Home / dashboard
│   ├── api/
│   │   └── generate.ts    ← AI content API route
│   └── login.tsx         ← Auth page
├── lib/
│   ├── openai.ts          ← OpenAI client
│   └── supabase.ts        ← Supabase client
├── components/
│   └── Editor.tsx         ← Prompt input + output UI
└── .env.local             ← API keys

🧠 Step 3: lib/openai.ts – OpenAI Agent Logic

import OpenAI from 'openai';

const openai = new OpenAI({
  apiKey: process.env.OPENAI_API_KEY!,
});

export async function generateContent(prompt: string) {
  const res = await openai.chat.completions.create({
    model: "gpt-4",
    messages: [
      { role: "system", content: "You are a content generator." },
      { role: "user", content: prompt }
    ]
  });
  return res.choices[0].message.content;
}

🔐 Step 4: .env.local (Add your API keys)

OPENAI_API_KEY=sk-...
NEXT_PUBLIC_SUPABASE_URL=https://...
NEXT_PUBLIC_SUPABASE_ANON_KEY=...
STRIPE_SECRET_KEY=sk_live_...

🔌 Step 5: pages/api/generate.ts

import type { NextApiRequest, NextApiResponse } from 'next';
import { generateContent } from '@/lib/openai';

export default async function handler(req: NextApiRequest, res: NextApiResponse) {
  const { prompt } = req.body;

  if (!prompt) return res.status(400).json({ error: "Missing prompt" });

  try {
    const content = await generateContent(prompt);
    res.status(200).json({ content });
  } catch (e) {
    res.status(500).json({ error: "Something went wrong" });
  }
}

💳 Step 6: Stripe Billing (Basic)

Use Stripe Checkout or Stripe Customer Portal for subscriptions.

Set up pricing tiers, and protect /generate route based on user plan.


🧠 Bonus: Add Usage Limits per Plan

Use Supabase to track usage:

// After successful generation
await supabase
  .from('usage')
  .insert({ user_id, prompt, created_at: new Date() });

🧪 Step 7: Deploy to Vercel

vercel

Connect your GitHub repo and deploy live.


✅ Next Feature Ideas

  • Email summaries → daily/weekly newsletter
  • Save generated content to user dashboard
  • CSV download of results
  • Team/workspace support
  • Webhooks or Zapier for integration

Posted May 15, 2025, 5:02 PM UTC

10
Loading comments…