DEV Community

AchillesAlpha
AchillesAlpha

Posted on

How I Built an AI-Powered SEO Content Engine with Next.js and OpenAI

I run a niche review site and was spending 3-4 hours per article writing SEO content. I decided to automate the entire pipeline — from keyword research to WordPress publishing — and turned it into a SaaS product.

Here's the technical breakdown of how I built it.

The Problem

Writing SEO content manually is painfully slow:

  • Research keywords
  • Write 1500+ word articles with proper heading structure
  • Add internal links to existing content
  • Format for WordPress
  • Publish and set meta tags

I wanted to reduce this to "enter a keyword, click publish."

Architecture

User Dashboard (Next.js 16)
    |
    ├── Keyword Research (OpenAI API)
    ├── Article Generation (GPT-4o-mini)
    ├── Smart Internal Linking Engine
    └── WordPress REST API Publisher
         |
         └── User's WordPress Site
Enter fullscreen mode Exit fullscreen mode

Stack:

  • Frontend: Next.js 16 with App Router + Tailwind CSS
  • Database: PostgreSQL with Prisma 6 ORM
  • AI: OpenAI GPT-4o-mini for content generation
  • Auth: JWT with httpOnly cookies
  • Billing: Stripe Checkout + Webhooks
  • Hosting: Render (auto-deploy from GitHub)

Key Implementation Details

AI Article Generation

The prompt engineering was the hardest part. Raw GPT output reads like AI wrote it. I spent weeks refining prompts to produce content that:

  • Uses natural paragraph transitions
  • Includes relevant statistics and examples
  • Follows proper SEO heading hierarchy (H1 > H2 > H3)
  • Generates meta descriptions optimized for click-through

Smart Internal Linking

This is the feature I'm most proud of. When generating a new article, the system:

  1. Fetches all existing articles for that site
  2. Identifies semantically relevant content
  3. Automatically inserts contextual internal links
  4. Limits to 3-5 links per article to avoid over-optimization

Internal linking is one of the highest-impact SEO tactics that most people skip because it's tedious to do manually.

WordPress Integration

Publishing uses the WordPress REST API with application passwords:

const response = await fetch(`${site.wpUrl}/wp-json/wp/v2/posts`, {
  method: 'POST',
  headers: {
    'Authorization': `Basic ${Buffer.from(`${user}:${appPassword}`).toString('base64')}`,
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({
    title: article.title,
    content: article.htmlContent,
    status: 'publish',
    meta: { description: article.metaDescription },
  }),
});
Enter fullscreen mode Exit fullscreen mode

Stripe Integration

Used Stripe Checkout for subscriptions — it handles the entire payment UI:

const session = await stripe.checkout.sessions.create({
  mode: 'subscription',
  line_items: [{ price: priceId, quantity: 1 }],
  success_url: `${APP_URL}/dashboard?success=true`,
  cancel_url: `${APP_URL}/dashboard`,
});
Enter fullscreen mode Exit fullscreen mode

Webhook handles subscription lifecycle (created, canceled, renewed).

Results

I've been using this on my own site (topstacktools.com) for the past week:

  • 20 articles published
  • Google has already indexed the site
  • Average article generation time: ~45 seconds
  • Zero manual formatting needed

Try It

I launched it as a SaaS product with a free tier (3 articles/month, no credit card needed):

usetopseo.com

The code is private but I'm happy to answer technical questions in the comments.


Built with Next.js 16, Prisma 6, OpenAI, Stripe, and PostgreSQL. Deployed on Render.

Top comments (0)