Skip to content

A modern React + Vite expense management application powered by Firebase (Auth, Firestore, Hosting). Enables users to log, categorize, and analyze expenses in real time with a clean, mobile-first UI and cloud-native architecture.

Notifications You must be signed in to change notification settings

bnithin215/expense-tracker

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

3 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ’° Expense Tracker

A modern, real-time expense tracking application built with React, Firebase, and Vite.

✨ Features

  • πŸ” 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

πŸš€ Quick Start

Prerequisites

  • Node.js (v16 or higher)
  • npm or yarn
  • Firebase account

Installation

  1. Clone or create the project:
npm create vite@latest expense-tracker -- --template react
cd expense-tracker
  1. Install dependencies:
npm install firebase react-router-dom date-fns
  1. 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;
        }
      }
    }
  2. Configure environment variables:

    Create a .env file 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
  3. Run the application:

npm run dev

The app will open at http://localhost:3000

πŸ“ Project Structure

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

πŸ”§ Configuration

Firestore Data Model

/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
}

Available Categories

  • Groceries
  • Transport
  • Eating Out
  • Utilities
  • Rent
  • Other

You can customize categories in src/pages/Dashboard.jsx

🎯 Usage

  1. Sign In:

    • Click "Sign in with Google"
    • Authorize with your Google account
  2. Add Expense:

    • Click "Add" button
    • Fill in amount, category, date, and notes
    • Click "Save"
  3. Edit Expense:

    • Click "Edit" on any expense
    • Modify details
    • Click "Save"
  4. Delete Expense:

    • Click "Delete" on any expense
    • Expense is removed immediately
  5. Filter Expenses:

    • Use category dropdown to filter by category
    • Use search box to find by notes
  6. View Totals:

    • Check the sidebar for total amount
    • See breakdown by category

πŸ”’ Security

  • User authentication required for all operations
  • Data isolated per user in Firestore
  • Secure Firebase rules prevent unauthorized access
  • Environment variables protect sensitive config

πŸ› οΈ Troubleshooting

Common Issues

1. "Module not found" errors

  • Ensure all files are in correct directories
  • Check import paths match folder structure

2. Firebase initialization fails

  • Verify .env file 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 localhost to 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

πŸ“¦ Build for Production

npm run build

The built files will be in the dist/ directory.

πŸš€ Deployment

Deploy to Firebase Hosting

  1. Install Firebase CLI:
npm install -g firebase-tools
  1. Login to Firebase:
firebase login
  1. Initialize Firebase in your project:
firebase init
  1. Deploy:
npm run build
firebase deploy

Deploy to Vercel

  1. Install Vercel CLI:
npm install -g vercel
  1. Deploy:
vercel

🎨 Customization

Change Theme Colors

Edit src/styles.css:

:root {
  --bg: #f6f7fb;           /* Background */
  --card: #fff;            /* Card background */
  --muted: #6b7280;        /* Muted text */
  --accent: #2563eb;       /* Primary color */
  --danger: #ef4444;       /* Delete button */
}

Add New Categories

Edit src/pages/Dashboard.jsx:

const CATEGORIES = ['Groceries', 'Transport', 'Your Category', ...]

🀝 Contributing

Contributions are welcome! Feel free to submit issues or pull requests.

πŸ“§ Support

If you encounter any issues, please check the troubleshooting section or open an issue on GitHub.


Built with ❀️ using React, Firebase, and Vite

About

A modern React + Vite expense management application powered by Firebase (Auth, Firestore, Hosting). Enables users to log, categorize, and analyze expenses in real time with a clean, mobile-first UI and cloud-native architecture.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published