⚙️ Services Documentation
Frontend services documentation with method signatures and usage examples.
Firebase Services
authService (lib/auth.ts)
Firebase Authentication integration for user management.
signUp(email: string, password: string): Promise<User>
Create a new user account and send email verification.
signIn(email: string, password: string): Promise<User>
Authenticate existing user with email and password.
logout(): Promise<void>
Sign out the current user and clear local state.
resetPassword(email: string): Promise<void>
Send password reset email to the specified address.
Usage Example
import { signUp, signIn, logout } from
'../lib/auth';
// Sign up new user
try {
const user = await signUp('user@example.com', 'password123');
console.log('User created:', user.uid);
} catch (error) {
console.error('Sign up failed:', error.message);
}
// Sign in existing user
const user = await signIn('user@example.com', 'password123');
// Logout
await logout();
databaseService (lib/database.ts)
Firebase Realtime Database operations for financial data.
saveTransaction(userId: string, transaction: Transaction):
Promise<void>
Save or update a transaction in the database.
subscribeToTransactions(userId: string, callback: (t: Transaction[]) =>
void): Unsubscribe
Subscribe to real-time transaction updates. Returns unsubscribe function.
saveBudget(userId: string, budget: Budget): Promise<void>
Save or update a budget entry.
saveGoal(userId: string, goal: Goal): Promise<void>
Save or update a savings goal.
saveSettings(userId: string, settings: Settings): Promise<void>
Save user preferences (currency, dark mode).
Usage Example
import { saveTransaction, subscribeToTransactions } from '../lib/database';
// Save a new transaction
await saveTransaction(userId, {
id: 'uuid-123',
type: 'expense',
amount: 50.00,
category: 'Food',
date: Date.now(),
note: 'Lunch',
paymentMethod: 'Credit Card'
});
// Subscribe to real-time updates
const unsubscribe = subscribeToTransactions(userId, (transactions) => {
console.log('Transactions updated:', transactions.length);
});
// Later: cleanup
unsubscribe();
AI Service
aiService (lib/ai.ts)
Groq API integration for AI-powered financial insights using LLaMA 3.3 70B.
getFinancialInsights(transactions, budgets, goals, currency):
Promise<AIInsightResponse>
Analyze financial data and generate personalized insights, health score,
and recommendations.
Returns: { healthScore, insights[], recommendations[], summary }
getQuickTip(): string
Get a random financial tip for display in the UI.
AI Response Structure
interface AIInsightResponse {
healthScore: 0-100; // Financial health
percentage
insights: [
{
title: "Great Savings!",
message: "You're saving 30% of income",
type: "success" | "warning" | "tip" | "info",
icon: "🎉"
}
];
recommendations: [
"Build an emergency fund",
"Review subscription costs"
];
summary: "Your finances look healthy...";
}
Configuration
| Setting | Value |
|---|---|
| Model | llama-3.3-70b-versatile |
| Temperature | 0.7 |
| Max Tokens | 1000 |
| API Key | EXPO_PUBLIC_GROQ_API_KEY (env) |
Notification Service
notificationService (lib/notifications.ts)
Expo Notifications for push alerts, reminders, and scheduled notifications.
requestNotificationPermission(): Promise<boolean>
Request push notification permission from the user.
sendNotification(title, body, data?): Promise<void>
Send an immediate local notification.
sendBudgetAlert(category, percentage): Promise<void>
Send a budget alert notification (at 80% or 100%).
scheduleDailyReminder(hour, minute): Promise<void>
Schedule a daily expense logging reminder.
scheduleWeeklySummary(): Promise<void>
Schedule weekly AI insight summary (Monday 9 AM).
cancelAllNotifications(): Promise<void>
Cancel all scheduled notifications.
Notification Channels (Android)
| Channel ID | Name | Priority | Sound |
|---|---|---|---|
| default | General | DEFAULT | Yes |
| budget-alerts | Budget Alerts | HIGH | Yes |
| insights | AI Insights | DEFAULT | Yes |
Usage Example
import {
requestNotificationPermission,
sendBudgetAlert,
scheduleDailyReminder
} from '../lib/notifications';
// Request permission on app start
const granted = await requestNotificationPermission();
if (granted) {
// Schedule daily reminder at 8 PM
await scheduleDailyReminder(20, 0);
// Send budget alert
await sendBudgetAlert('Food', 85);
}
Build & Deploy Services
EAS Build
Expo Application Services for cloud-based Android builds.
-
Development Build
Debug build with dev client for local testing -
Preview Build
APK for testing (not signed for Play Store) -
Production Build
AAB for Google Play Store release
Build Commands
# Development build
npx eas-cli build --platform android --profile development
# Preview APK (for testing)
npx eas-cli build --platform android --profile preview
# Production AAB (for Play Store)
npx eas-cli build --platform android --profile production
GitHub Actions CI/CD
Automated builds and deployments via GitHub Actions.
-
build-android.yml
Triggers on version tag push (v*), builds APK with EAS, creates GitHub Release -
pages.yml
Deploys docs/ folder to GitHub Pages on main branch push
Trigger a Release
# Create and push a version tag
git tag v2.1.0
git push origin v2.1.0
# GitHub Actions will:
# 1. Build APK using EAS
# 2. Create GitHub Release
# 3. Attach APK to release
Environment Configuration
Environment Variables
Required environment variables for the application.
| Variable | Description | Required |
|---|---|---|
| EXPO_PUBLIC_GROQ_API_KEY | Groq API key for AI insights | Required |
Local Development
# .env (gitignored)
EXPO_PUBLIC_GROQ_API_KEY=gsk_your_api_key_here
Production (EAS Secret)
# Set EAS secret for production builds
npx eas-cli secret:create --name EXPO_PUBLIC_GROQ_API_KEY --value gsk_your_api_key