đ 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 |
|---|---|---|
| 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()