How moneymentor-09/moneymentor-frontend works
Project Type and Purpose
• MoneyMentor is a full-stack, server-rendered web application built with Next.js (App Router) that provides AI-powered personal finance management.
• The frontend is React/TypeScript/Tailwind-based; the backend logic lives in Next.js API routes and Supabase (Auth, Database, RLS); external AI calls go to OpenAI GPT.
File Structure
• Top-level “app” directory: Next.js 14 App Router pages and serverless API routes under app/api (auth, chat, transactions, proxyLogin, etc.).
• “components” directory: UI building blocks (ShadCN/UI + Tailwind) and domain-specific components (dialogs, charts, nav, transactions list, etc.).
• “hooks” directory: custom React hooks (use-authListener, use-inactivity-timer, use-toast, use-mobile).
• “lib” directory: business logic utilities (constants, CSV parser, fraud detection, Supabase client/server wrappers, transactions CSV helpers, utils).
• “scripts” directory: SQL scripts to initialize and secure the Supabase database.
• Config files: next.config.mjs, tsconfig.json, postcss.config.mjs, middleware.ts.
Key Insights from README
• Frontend: Next.js + React 18, TS, Tailwind CSS, ShadCN/UI, Recharts for visualization.
• Backend/Auth/DB: Supabase for authentication, DB, RLS.
• AI Engine: OpenAI GPT API.
• Deployment: Vercel (serverless functions) or any Next.js-capable host.
Main Components
a. Client (Browser/Mobile)
• React/Next.js pages served to the client.
• UI components (charts, dialogs, forms).
b. Next.js Application (Vercel Serverless)
• App Router handlers (server-side rendering, static props).
• API Routes:
– /api/auth/* (Email/Password, Google OAuth, OTP, forgot/reset password)
– /api/chat (proxy for OpenAI)
– /api/transactions/* (CRUD, batch, manifest)
– /api/proxyLogin
• Middleware (e.g., session timeout, RLS enforcement).
• lib modules for business logic: fraud detection, CSV parsing, utils.
c. Supabase
• Auth (JWT, sessions, RLS).
• Database (profiles, transactions, budgets, alerts, functions/triggers).
d. OpenAI GPT API
• Chat-based insights, spending analysis, recommendations.
e. Deployment & CI/CD
• Vercel / GitHub integration (push → automatic deploy).
f. External Services
• Email provider (for OTP or password reset emails).
• Potential SMS/OTP provider (if phone OTP is external).
Relationships & Interactions
• User → Browser UI → Next.js pages (SSR/CSR)
• Browser UI → Next.js API routes (fetch / mutate data)
• API routes → Supabase client/server (read/write, RLS)
• API routes → OpenAI GPT API (chat endpoint)
• lib modules invoked within API routes and server components
• Next.js middleware enforces inactivity logout and RLS checks
• SQL scripts used offline for initial DB setup (profiles, transactions, budgets, alerts, RLS, functions)
Architectural Patterns & Design Principles
• Separation of concerns:
• Presentation layer (components, pages)
• Business logic layer (lib/)
• Data access layer (supabase client/server wrappers)
• Serverless micro-endpoints: each feature (auth, transactions, chat) in its own API route.
• RLS at the database layer for multi-tenant security.
• API layer as a façade to external services (OpenAI, Supabase).
• Custom hooks for cross-cutting concerns (auth listening, inactivity timer, toasts).
Elements
• Clear labels (e.g., “Next.js App (Serverless)”, “Supabase Database & Auth”).
• UI Components (rectangles, light blue)
• API / Business Logic (rounded rectangles, green)
• Layering: group UI pages/components together, group API routes and lib modules together, group DB and scripts together.
4. Inside “Next.js Serverless,” subdivide into:
• App Router / Page Rendering
• API Routes (auth, transactions, chat, proxyLogin)
• Middleware
• lib modules (fraudDetection, csvParser, supabase client)