On This Page

🔌 API Documentation

Complete API reference for SpendWise backend integrations and frontend services.

Groq AI API

SpendWise uses Groq's ultra-fast inference API for AI-powered financial insights and recommendations.

POST https://api.groq.com/openai/v1/chat/completions

Generate personalized financial insights, health scores, and spending recommendations.

Request Headers

Header Value Required
Authorization Bearer {GROQ_API_KEY} Required
Content-Type application/json Required

Request Body

{ "model": "llama-3.3-70b-versatile", "messages": [ { "role": "system", "content": "You are a helpful financial advisor. Always respond with valid JSON only." }, { "role": "user", "content": "Analyze this financial data: Income: $5000, Expenses: $3500..." } ], "temperature": 0.7, "max_tokens": 1000 }

Response Body

{ "healthScore": 75, "insights": [ { "title": "Great Savings!", "message": "You're saving 30% of your income. Keep it up!", "type": "success", "icon": "🎉" }, { "title": "Budget Warning", "message": "Food spending is at 85% of budget", "type": "warning", "icon": "âš ī¸" } ], "recommendations": [ "Continue building your emergency fund", "Consider automating your savings", "Review subscription services for unused ones" ], "summary": "Your financial health is strong this month with a 30% savings rate." }

Insight Types

Type Description Icon
success Positive achievement or milestone 🎉 ✅ 🏆
warning Budget approaching limit or concern âš ī¸ 📊
tip Helpful suggestion or advice 💡 📝
info Informational message â„šī¸ 📈

Firebase Authentication

Secure email/password authentication with verification and password reset functionality.

Sign Up

POST createUserWithEmailAndPassword(auth, email, password)

Create a new user account with email verification.

Parameters

Parameter Type Description
email string User's email address
password string Password (min 6 characters)

Usage Example

// lib/auth.ts import { createUserWithEmailAndPassword, sendEmailVerification } from 'firebase/auth'; import { auth } from './firebase'; export async function signUp(email: string, password: string) { const userCredential = await createUserWithEmailAndPassword(auth, email, password); await sendEmailVerification(userCredential.user); return userCredential.user; }

Sign In

POST signInWithEmailAndPassword(auth, email, password)

Authenticate an existing user.

Error Codes

Code Description
auth/user-not-found No user with this email exists
auth/wrong-password Incorrect password
auth/too-many-requests Too many failed attempts, try later
auth/user-disabled Account has been disabled

Password Reset

POST sendPasswordResetEmail(auth, email)

Send a password reset email to the user.

Firebase Realtime Database

Real-time NoSQL database for storing and syncing user financial data across devices.

Database Schema

/users/{userId}/ │ ├── transactions/{transactionId} │ ├── id: "uuid" │ ├── type: "income" | "expense" │ ├── amount: 1500.00 │ ├── category: "Food" │ ├── date: 1702234567890 // timestamp │ ├── note: "Groceries" │ └── paymentMethod: "Credit Card" │ ├── budgets/{budgetId} │ ├── id: "uuid" │ ├── category: "Food" │ ├── limit: 500.00 │ └── period: "monthly" │ ├── goals/{goalId} │ ├── id: "uuid" │ ├── name: "Emergency Fund" │ ├── targetAmount: 10000.00 │ ├── currentAmount: 3500.00 │ ├── deadline: 1735689600000 │ └── priority: "high" │ └── settings/ ├── currency: { code: "USD", symbol: "$", name: "US Dollar" } └── darkMode: true

CRUD Operations

Save Transaction

// lib/database.ts import { ref, set } from 'firebase/database'; import { db } from './firebase'; export async function saveTransaction(userId: string, transaction: Transaction) { const transactionRef = ref(db, `users/${userId}/transactions/${transaction.id}`); await set(transactionRef, transaction); }

Subscribe to Transactions

import { ref, onValue } from 'firebase/database'; export function subscribeToTransactions( userId: string, callback: (transactions: Transaction[]) => void ) { const transactionsRef = ref(db, `users/${userId}/transactions`); return onValue(transactionsRef, (snapshot) => { const data = snapshot.val(); const transactions = data ? Object.values(data) : []; callback(transactions as Transaction[]); }); }

Expo Notifications

Push notification system for budget alerts, reminders, and AI insights.

Notification Channels

Channel ID Name Priority Use Case
default General Default Daily reminders, tips
budget-alerts Budget Alerts High 80% and 100% budget warnings
insights AI Insights Default Weekly AI summaries

Send Notification

// lib/notifications.ts import * as Notifications from 'expo-notifications'; export async function sendNotification(title: string, body: string, data?: object) { await Notifications.scheduleNotificationAsync({ content: { title, body, data, sound: 'default', }, trigger: null, // Immediate }); } // Usage sendNotification( 'âš ī¸ Budget Alert', 'You have used 80% of your Food budget', { type: 'budget-alert', category: 'Food' } );

Schedule Recurring Notifications

// Daily reminder at 8 PM export async function scheduleDailyReminder(hour: number, minute: number) { await Notifications.scheduleNotificationAsync({ content: { title: '📝 Daily Reminder', body: 'Don\'t forget to log your expenses today!', }, trigger: { hour, minute, repeats: true, }, }); } // Weekly summary every Monday at 9 AM export async function scheduleWeeklySummary() { await Notifications.scheduleNotificationAsync({ content: { title: '📊 Weekly Summary', body: 'Your weekly spending report is ready!', }, trigger: { weekday: 2, // Monday hour: 9, minute: 0, repeats: true, }, }); }

Frontend Services

TypeScript service modules for interacting with backend APIs.

Service Structure

lib/ ├── firebase.ts // Firebase initialization ├── auth.ts // Authentication functions │ ├── signUp(email, password) │ ├── signIn(email, password) │ ├── logout() │ └── resetPassword(email) │ ├── database.ts // Realtime Database helpers │ ├── saveTransaction(userId, transaction) │ ├── saveBudget(userId, budget) │ ├── saveGoal(userId, goal) │ ├── saveSettings(userId, settings) │ ├── subscribeToTransactions(userId, callback) │ ├── subscribeToBudgets(userId, callback) │ ├── subscribeToGoals(userId, callback) │ └── subscribeToSettings(userId, callback) │ ├── ai.ts // Groq AI integration │ ├── getFinancialInsights(transactions, budgets, goals, currency) │ └── getQuickTip() │ └── notifications.ts // Expo Notifications ├── requestNotificationPermission() ├── sendNotification(title, body, data) ├── sendBudgetAlert(category, percentage) ├── sendInsightNotification(insight) ├── scheduleDailyReminder(hour, minute) ├── scheduleWeeklySummary() └── cancelAllNotifications()