5 Weeks
Lead Engineer
OpenAI GPT-4 API
Next.js + Stripe
Building an AI-driven SaaS requires a highly robust edge-computing setup. CodeSense uses Next.js API routes to handle authentication and securely relay prompts to the OpenAI models.
To maintain conversation history and context, user sessions and prompt metadata are stored in Prisma/PostgreSQL, while Stripe handles the subscription tiering logic.
To provide meaningful code suggestions, the LLM needs context. I engineered a prompt-chaining system that automatically injects the user's selected framework, language, and surrounding code into the hidden system prompt.
This ensures the generated code matches the exact syntax and architecture of the user's existing project without requiring them to manually explain it every time.
Waiting for an AI model to generate 500 lines of code causes massive UX friction. To solve this, I implemented StreamingTextResponse from the Vercel AI SDK.
Chunks of data are streamed directly from the OpenAI server to the edge, and finally painted onto the user's React DOM in real-time, giving a typing effect that feels instant and responsive.
A SaaS is only a hobby until it can process payments. I integrated Stripe Webhooks to handle the complex logic of subscription states (Active, Past Due, Canceled).
When a user upgrades to the Pro Tier, a webhook hits the Next.js API, updates the user's Prisma record, and instantly unlocks unlimited GPT-4 queries on the frontend via React state re-validation.