Building an AI SaaS in 2026 is more accessible than ever, but the boilerplate is still painful. Auth, billing, rate limiting, streaming AI responses, admin dashboards - there is a lot to wire up before you write a single line of product code.
This guide walks through the architecture of a production-ready AI SaaS and shows you how to ship one in days instead of months.
A well-organized AI SaaS has these key directories:
src/
app/
(auth)/ # Login, register, forgot password
(dashboard)/ # Main app, chat, settings
(admin)/ # Admin panel, user management
api/
auth/ # NextAuth routes
chat/ # AI streaming endpoint
webhooks/ # Stripe webhook handler
lib/
auth.ts # Auth config
stripe.ts # Stripe helpers
ai.ts # AI provider config
db/ # Drizzle schema + migrations
Auth.js v5 makes multi-provider auth straightforward. The key is setting up proper session callbacks to include the user role and subscription tier:
// src/lib/auth.ts
export const authConfig = {
providers: [Google, GitHub, Email],
callbacks: {
session({ session, user }) {
session.user.role = user.role
session.user.tier = user.subscriptionTier
return session
}
}
}
The billing flow needs three pieces: checkout session creation, webhook handling, and tier-based access control.
Key webhook events to handle:
checkout.session.completed - Activate subscriptioncustomer.subscription.updated - Plan changescustomer.subscription.deleted - Cancellationsinvoice.payment_failed - Payment issuesThe Vercel AI SDK handles streaming elegantly. Your API route streams tokens as they arrive:
// src/app/api/chat/route.ts
export async function POST(req) {
const { messages } = await req.json()
const session = await auth()
// Check daily usage limits based on tier
const usage = await getDailyUsage(session.user.id)
if (usage >= TIER_LIMITS[session.user.tier]) {
return new Response("Daily limit reached", { status: 429 })
}
const result = streamText({
model: openai("gpt-4o"),
messages,
})
return result.toDataStreamResponse()
}
Every AI SaaS needs usage limits per tier. Track daily message counts in your database and enforce limits in middleware or the API route. Typical tiers:
An admin panel lets you monitor users, revenue, and usage. Key metrics to track: DAU, messages sent, conversion rate from free to paid, MRR.
The AI SaaS Starter template includes all of this pre-built: auth, Stripe, AI chat, admin panel, rate limiting, and more. $49 one-time purchase - ship your AI product this week.
npx vercel --prodBuilding an AI SaaS is mostly plumbing. The AI part is the easy bit - it is the auth, billing, rate limiting, and admin tooling that eats your time. Use a proven template to skip the boring parts and focus on what makes your product unique.