A beautiful, modern expense tracker built with React that provides full CRUD (Create, Read, Update, Delete) functionality.
- ✅ Create: Add new expenses with description, amount, category, and date
- ✅ Read: View all your expenses in a clean, organized list
- ✅ Update: Edit any existing expense
- ✅ Delete: Remove expenses you no longer need
- 📊 Total Tracking: See your total expenses, entry count, and average expense
- 💾 Data Persistence: Expenses are saved to PostgreSQL database
- 📥 Data Export: Export all your expenses as a CSV file for backup or analysis (opens in Excel, Google Sheets, etc.)
- Node.js (>=18.0.0) and npm (>=9.0.0)
- PostgreSQL database (local or hosted, e.g., Railway, Supabase, or local PostgreSQL)
- Install dependencies:
npm install-
Set up environment variables:
- Create a
.envfile or set environment variables:
DATABASE_URL=postgresql://user:password@host:port/database JWT_SECRET=your-secret-key-here ADMIN_EMAILS=your-email@example.com PORT=3000- On Railway, add these as environment variables in your project settings
- Create a
-
For development, you have two options:
Option A: Run both frontend and backend (recommended for development)
# Terminal 1: Start the backend server npm run dev:server # Terminal 2: Start the frontend dev server npm run dev
Then open
http://localhost:5173(Vite dev server with hot reload)Option B: Run production build (simulates production)
npm run build npm start
Then open
http://localhost:3000
-
Add an Expense: Fill out the form with:
- Description (e.g., "Groceries", "Gas", "Dinner")
- Amount (in dollars)
- Category (Food, Transportation, Shopping, Bills, Entertainment, Healthcare, or Other)
- Date
-
Edit an Expense: Click the "Edit" button on any expense, make your changes, and click "Update Expense"
-
Delete an Expense: Click the "Delete" button on any expense and confirm the deletion
-
Export Data: Click the "Export All Expenses Data (CSV)" button to download a CSV file containing all your expenses. The file can be opened in Excel, Google Sheets, or any spreadsheet application.
- Push your code to GitHub
- Connect your GitHub repository to Railway
- Railway will automatically detect the Vite project and run:
- Build command:
npm run build - Start command:
npm run start
- Build command:
- Your app will be live at a Railway-provided URL
The railway.json configuration file is included for optimal deployment settings.
- React 18
- React Router (client-side routing)
- Vite (build tool)
- Express.js (backend API server)
- PostgreSQL (database)
- CSS3 (modern styling with gradients and animations)
pg(PostgreSQL client for Node.js)- localStorage (client-side caching)
expense-tracker/
├── src/
│ ├── components/
│ │ ├── ExpenseForm.jsx # Form for adding/editing expenses
│ │ ├── ExpenseList.jsx # List view of all expenses
│ │ ├── ExpenseSummary.jsx # Summary cards showing totals
│ │ └── *.css # Component-specific styles
│ ├── pages/
│ │ ├── AdminPortal.jsx # Admin portal to view all expenses
│ │ └── AdminPortal.css # Admin portal styles
│ ├── App.jsx # Main application component
│ ├── App.css # Main app styles
│ ├── main.jsx # Application entry point
│ └── index.css # Global styles
├── db.js # PostgreSQL database layer
├── server.js # Express backend server
├── index.html # HTML entry point
├── package.json # Dependencies and scripts
├── vite.config.js # Vite configuration
└── railway.json # Railway deployment config
Access the admin portal to view all expenses from all users:
- Navigate to
/adminor click the "🔐 Admin Portal" link in the header - View statistics: total expenses, amounts, averages
- Filter by category or user
- See breakdown by category and by user
- View all expenses in a sortable table
The admin portal provides comprehensive insights into all user activity across the platform.
Expense data is stored in PostgreSQL database:
- Database: All expenses and users are stored in PostgreSQL (persistent and reliable)
- Client-side: Each user's expenses are cached in localStorage for offline access
To access your data:
- CSV Export: Use the "Export All Expenses Data (CSV)" button in the app
- Admin Portal: View all user expenses at
/admin - API: Access expenses via REST API endpoints (see server.js)
- Add a PostgreSQL service to your Railway project
- Railway will automatically provide a
DATABASE_URLenvironment variable - The app will automatically create the necessary tables on startup
- Install PostgreSQL locally or use a cloud service (Supabase, Neon, etc.)
- Set the
DATABASE_URLenvironment variable:export DATABASE_URL=postgresql://user:password@localhost:5432/expense_tracker - Run
npm run dev:server- the database schema will be created automatically
Potential features you could add:
- Expense filtering and search
- Category-based statistics and charts
- Date range filtering
- Multiple currencies
- Expense recurrence/rules
- Backend integration for cloud storage