DEV Community

LeadHunting AI
LeadHunting AI

Posted on Originally published at leadhunting.app

Building a Production SaaS with Next.js 16: Complete Architecture Guide

Building a Production SaaS with Next.js 16

Here is the complete architecture of LeadHunting AI — a production SaaS built on Next.js 16.

Tech Stack

  • Frontend: Next.js 16 (App Router), React 19, TypeScript, Tailwind CSS, shadcn/ui
  • Backend: Prisma ORM v6, Supabase PostgreSQL
  • AI: Google AI Studio (Gemini Flash, Imagen 3, Veo 2, TTS) — all free tier
  • Payments: Stripe (dynamic pricing via price_data)
  • Email: Amazon SES + Gmail SMTP + Brevo + Resend (cascade failover)
  • Deployment: Vercel Hobby (free)

Key Architecture Decisions

1. SPA + Server-Side Rendering Hybrid

Marketing pages are server-rendered for SEO. Dashboard is client-rendered for interactivity.

2. Built-in Cron Scheduler (No Vercel Cron)

A heartbeat endpoint triggered by real traffic runs all background tasks. No paid cron service needed.

3. Credit Billing System (500%+ Margin)

Users pre-pay credits. Credits deducted before AI generation. Auto-refund on failure. Admin uses $0 free tier.

4. Multi-Provider Email Cascade

SES → Gmail SMTP → Brevo → Resend → Log-only. 33,000+ free emails/month.

5. Autonomous Content Pipeline

Every 6 hours: Gemini generates blog post → Imagen creates image → TTS creates audio → Veo creates video → auto-publishes to DEV.to + Hashnode.

6. Security Headers

CSP (no unsafe-eval), COEP, COOP, CORP, HSTS, X-Content-Type-Options.

7. Compliance Engine

CAN-SPAM (unsubscribe + physical address), TCPA (consent tracking), GDPR (data export + erasure).

Cost Breakdown

All services on free tier = $0/month admin cost. Users pay credits at 500%+ margin.

Links


Originally published on leadhunting.app

Top comments (1)

Collapse
 
veristria profile image
StackShortlist •

Solid writeup. What would you cut first if you were shipping a v1 alone in a weekend?