Building SpendWise: AI-Powered Personal Finance with Next.js and Gemini
How I built an AI-powered personal finance platform that handles structured AI response validation, budget snapshots, and real-time dashboards — and what I learned about shipping production-ready financial software.
The Idea
Tracking personal finances is one of those problems everyone has and nobody enjoys solving. Spreadsheets work until they don't. Existing apps either lack intelligence or charge premium prices for basic features. I wanted to build something that combined the convenience of automated tracking with the insight of AI-powered analysis — without the subscription fatigue.
Tech Stack
- Frontend: Next.js 14, TypeScript, Tailwind CSS
- Backend: Next.js API routes, Prisma ORM
- Database: MongoDB
- Authentication: NextAuth.js (Google OAuth + credentials)
- AI: Google Gemini
- Caching: Redis
The Two-Stage AI Pipeline
The biggest technical challenge was making Google Gemini produce structured, reliable financial insights. Gemini excels at natural language but financial categorization requires strict, deterministic output. Here is how I solved it:
Stage 1 — Categorization: Send the transaction data to Gemini with a prompt asking it to categorize spending into predefined buckets (Food, Transport, Utilities, Entertainment, etc.). The response is free-form markdown.
Stage 2 — Validation: Take Gemini's output and feed it through a validation layer that parses the categories, checks against the allowed list, and rejects anything ambiguous. If validation fails, the system retries with a more constrained prompt.
This two-stage approach eliminated hallucinated categories entirely while keeping the AI responses natural and readable for the user.
Budget Snapshots
One design decision I am proud of: budget history preservation through snapshots. When a user edits a budget, the system stores a snapshot of the previous version rather than updating in place. This means users can view their budget at any point in time — last month, three months ago — and see exactly what their targets were.
Key Takeaways
- AI is powerful but needs guardrails. Never trust unstructured output from an LLM in a financial context.
- Redis caching made the dashboard feel instant. Without it, every page load would hit MongoDB — fine for 10 users, painful for 100.
- NextAuth.js handled OAuth beautifully, but credentials auth required extra session management work.
Was this post helpful?
Comments
Be the first to commentBe the first to share your thoughts.