A modern, real-time expense tracking application built with React, Firebase, and Vite.
- π Google Authentication - Secure sign-in with Firebase Auth
- π΅ Real-time Expense Tracking - Add, edit, and delete expenses instantly
- π Category Management - Organize expenses by categories
- π Search & Filter - Find expenses by notes and category
- π Automatic Totals - Real-time calculation of totals per category
- π¨ Modern UI - Clean, responsive design
- β‘ Fast - Built with Vite for optimal performance
- Node.js (v16 or higher)
- npm or yarn
- Firebase account
- Clone or create the project:
npm create vite@latest expense-tracker -- --template react
cd expense-tracker- Install dependencies:
npm install firebase react-router-dom date-fns-
Set up Firebase:
a. Go to Firebase Console
b. Create a new project
c. Enable Google Authentication:
- Navigate to Authentication > Sign-in method
- Enable Google provider
d. Create Firestore Database:
- Navigate to Firestore Database
- Click Create database
- Choose production mode
- Select a location
e. Set up Firestore Security Rules:
rules_version = '2'; service cloud.firestore { match /databases/{database}/documents { match /users/{userId}/{document=**} { allow read, write: if request.auth != null && request.auth.uid == userId; } } }
-
Configure environment variables:
Create a
.envfile in the root directory:VITE_FIREBASE_API_KEY=your_api_key VITE_FIREBASE_AUTH_DOMAIN=your_auth_domain VITE_FIREBASE_PROJECT_ID=your_project_id VITE_FIREBASE_STORAGE_BUCKET=your_storage_bucket VITE_FIREBASE_MESSAGING_SENDER_ID=your_sender_id VITE_FIREBASE_APP_ID=your_app_id
Get these values from:
- Firebase Console > Project Settings > General > Your apps > Web app
-
Run the application:
npm run devThe app will open at http://localhost:3000
expense-tracker/
βββ src/
β βββ components/
β β βββ ExpenseForm.jsx # Modal form for add/edit
β β βββ ExpenseList.jsx # List of expenses
β β βββ TotalsCard.jsx # Summary card
β βββ hooks/
β β βββ useAuth.js # Authentication logic
β β βββ useExpenses.js # Firestore CRUD operations
β βββ pages/
β β βββ Dashboard.jsx # Main dashboard
β β βββ Login.jsx # Login page
β βββ App.jsx # Router configuration
β βββ main.jsx # Entry point
β βββ firebase.js # Firebase initialization
β βββ styles.css # Global styles
βββ .env # Environment variables
βββ index.html
βββ package.json
βββ vite.config.js
/users/{userId}/expenses/{expenseId}
{
amount: number, // Expense amount
category: string, // Category name
date: timestamp, // Expense date
notes: string, // Optional notes
createdAt: timestamp, // Auto-generated
updatedAt: timestamp // Auto-updated
}- Groceries
- Transport
- Eating Out
- Utilities
- Rent
- Other
You can customize categories in src/pages/Dashboard.jsx
-
Sign In:
- Click "Sign in with Google"
- Authorize with your Google account
-
Add Expense:
- Click "Add" button
- Fill in amount, category, date, and notes
- Click "Save"
-
Edit Expense:
- Click "Edit" on any expense
- Modify details
- Click "Save"
-
Delete Expense:
- Click "Delete" on any expense
- Expense is removed immediately
-
Filter Expenses:
- Use category dropdown to filter by category
- Use search box to find by notes
-
View Totals:
- Check the sidebar for total amount
- See breakdown by category
- User authentication required for all operations
- Data isolated per user in Firestore
- Secure Firebase rules prevent unauthorized access
- Environment variables protect sensitive config
1. "Module not found" errors
- Ensure all files are in correct directories
- Check import paths match folder structure
2. Firebase initialization fails
- Verify
.envfile exists and has all variables - Check variable names start with
VITE_ - Restart dev server after changing .env
3. Google sign-in doesn't work
- Enable Google provider in Firebase Console
- Add
localhostto authorized domains - Check Firebase API key is correct
4. "Permission denied" on Firestore
- Update Firestore security rules
- Ensure user is authenticated
- Check user UID matches document path
5. Expenses don't appear
- Check browser console for errors
- Verify Firestore rules are correct
- Ensure user is authenticated
npm run buildThe built files will be in the dist/ directory.
- Install Firebase CLI:
npm install -g firebase-tools- Login to Firebase:
firebase login- Initialize Firebase in your project:
firebase init- Deploy:
npm run build
firebase deploy- Install Vercel CLI:
npm install -g vercel- Deploy:
vercelEdit src/styles.css:
:root {
--bg: #f6f7fb; /* Background */
--card: #fff; /* Card background */
--muted: #6b7280; /* Muted text */
--accent: #2563eb; /* Primary color */
--danger: #ef4444; /* Delete button */
}Edit src/pages/Dashboard.jsx:
const CATEGORIES = ['Groceries', 'Transport', 'Your Category', ...]Contributions are welcome! Feel free to submit issues or pull requests.
If you encounter any issues, please check the troubleshooting section or open an issue on GitHub.
Built with β€οΈ using React, Firebase, and Vite