An Expense Tracker application built with React.js for the frontend and Express.js for the backend, using MySQL 8 as the database. This app allows users to manage their expenses, track their income and expenses, and export reports to PDF.
- User Authentication: Users can register and log in using email and password.
- Expense Management:
- Add, edit, and delete expenses.
- Each expense includes an amount, category (Income/Expense), and an optional description.
- View a table of all expenses with total income and expenses summarized at the top.
- Export to PDF: Users can export their expense report as a PDF.
- React.js for building the user interface.
- Material UI UI components and styling.
- React Router for client-side routing.
- Axios for making HTTP requests to the backend.
- JWT for managing authentication tokens in the frontend.
- Express.js (Node.js) for creating the backend server.
- MySQL 8 for the database to store user and expense data.
- Sequelize ORM for interacting with MySQL and simplifying database queries.
- JWT for handling user authentication.
- bcrypt for hashing passwords securely.
- jsPDF for generating PDF reports of the expenses.
expense-tracker-demo/
│
├── assets/ # Snapshot of app
│
├── client/ # Frontend code (React.js)
│ ├── public/
│ ├── src/
│ │ ├── api/
│ │ ├── assets/
│ │ ├── components/
│ │ ├── context/
│ │ ├── hooks/
│ │ ├── layouts/
│ │ ├── pages/
│ │ ├── routes/
│ │ ├── services/
│ │ ├── styles/
│ │ ├── utils/
│ │ ├── App.js
│ │ └── index.js
│ ├── package.json
│ └── .env
│
├── server/ # Backend code (Express.js, MySQL, Sequelize)
│ ├── config/
│ ├── controllers/
│ ├── middleware/
│ ├── migrations/
│ ├── models/
│ ├── routes/
│ ├── seeders/
│ ├── utils/
│ ├── server.js
│ └── .env
├── README.md
- Node.js (version 14 or higher)
- MySQL 8 (or a cloud-based MySQL instance like Amazon RDS or ClearDB)
- npm (Node Package Manager)
-
Navigate to the
clientdirectory:cd client -
Install frontend dependencies:
npm install
-
Create a
.envfile in theclientdirectory and add the backend API URL:REACT_APP_API_URL=http://localhost:5000 -
Start the React development server:
npm start
The frontend will be available at
http://localhost:3000.
-
Navigate to the
serverdirectory:cd server -
Install backend dependencies:
npm install
-
Set up the MySQL database:
-
Ensure you have MySQL 8 running locally or use a cloud MySQL service like Amazon RDS or ClearDB.
-
Create a database and update the
.envfile with your MySQL credentials:DB_HOST=localhost DB_USER=root DB_PASSWORD=password DB_NAME=expense_tracker DB_PORT=3306 JWT_SECRET=your_jwt_secret_key
-
-
Run Sequelize migrations to create the necessary tables:
npx sequelize-cli db:migrate
-
Start the backend server:
node server.js
The backend will be available at
http://localhost:5000.
Make sure the following environment variables are configured in both the frontend and backend:
DB_HOST=localhost
DB_USER=root
DB_PASSWORD=password
DB_NAME=expense_tracker
DB_PORT=3306
JWT_SECRET=your_jwt_secret_key
REACT_APP_API_URL=http://localhost:5000
-
User Authentication:
- Users can register and log in to the app using their email and password.
- On successful login, users will receive a JWT token for session management.
-
Expense Management:
- Add Expense: Input the amount, select the category (Income or Expense), and optionally add a description.
- View Expenses: View a list of all expenses with a summary of total income and expenses at the top.
- Delete Expense: Remove an expense by clicking on the delete button next to it.
-
Export to PDF:
- Users can export their expense report as a PDF file for download.
- Here are some screenshots of the Expense Tracker application:
- Login
- Signup
- Dashboard
- Add Expense
The PDF export feature has been implemented to scale efficiently for larger datasets. The export is designed to handle large numbers of rows with optimized rendering, and pagination is used when necessary.
You can run tests using the following command (if you’ve set up tests):
npm testYou can deploy the backend and frontend on platforms like Heroku, DigitalOcean, Vercel, or Netlify.
-
Initialize a git repository:
git init git add . git commit -m "Initial commit"
-
Create a Heroku app:
heroku create expense-tracker-backend
-
Push to Heroku:
git push heroku master
-
Set environment variables on Heroku:
heroku config:set DB_HOST=your-database-host DB_USER=your-db-user DB_PASSWORD=your-db-password DB_NAME=your-db-name JWT_SECRET=your-jwt-secret-key
-
Open the deployed app:
heroku open
-
Deploy the frontend to Vercel:
- Sign up for Vercel and link your repository.
- Follow the deployment instructions on the Vercel dashboard.
- Modular Code: The app is organized with separate components, services, and routes to promote reusability and maintainability.
- Error Handling: The backend has proper error handling for edge cases such as invalid input, failed authentication, and database issues.
- Security: Passwords are securely hashed using bcrypt, and authentication is handled with JWT tokens.