ExpenseAI is an intelligent expense tracking application that helps you manage your personal or business expenses with AI-powered categorization. This application allows you to record, categorize, and analyze your expenses with a user-friendly interface and insightful visualizations.
For a demo of the app visit: expenseai.onrender.com
- Features
- Technologies Used
- Project Structure
- Installation
- Configuration
- Usage
- API Endpoints
- AI Categorization
- Database Schema
- Future Enhancements
- Contributing
- License
- Expense Management: Add, edit, delete, and view expenses
- AI-Powered Categorization: Automatically categorize expenses using Hugging Face models
- Monthly Reports: View expense summaries and breakdowns by month
- Data Visualization: Interactive charts to visualize spending patterns
- Category Management: Track spending by custom categories
- Responsive Design: Works on desktop and mobile devices
-
Frontend:
- HTML5, CSS3, JavaScript
- Bootstrap 5 for responsive design
- Chart.js for data visualization
-
Backend:
- Node.js and Express.js
- PostgreSQL database
- node-pg for database interactions
- Hugging Face API for AI-powered categorization
-
Development Tools:
- Nodemon for automatic server restarts
- dotenv for environment variable management
- cors for Cross-Origin Resource Sharing
ExpenseAI/
├── nodemon.json # Nodemon configuration
├── package.json # Node.js dependencies and scripts
├── server.js # Main application entry point
├── .env # Environment variables (not in repository. Use sample.env file for example.)
├── public/ # Static assets
│ ├── index.html # Main HTML file
│ ├── css/ # CSS stylesheets
│ │ └── style.css # Main stylesheet
│ └── js/ # Frontend JavaScript
│ ├── api.js # API client for backend communication
│ ├── app.js # Main application initialization
│ ├── expenses.js # Expenses page module
│ ├── monthly.js # Monthly view module
│ └── utils.js # Utility functions
└── src/ # Server-side code
├── config/ # Configuration files
│ ├── db.js # Database connection setup
│ └── db-init.js # Database initialization
├── controllers/ # Request handlers
│ └── expenseController.js # Expense-related logic
├── models/ # Data models
│ ├── category.js # Category model
│ └── expense.js # Expense model
└── routes/ # API routes
└── expenses.js # Expense-related routes
Follow these steps to set up ExpenseAI on your local machine:
-
Clone the repository:
git clone https://github.com/yourusername/ExpenseAI.git cd ExpenseAI -
Install dependencies:
npm install
-
Create a PostgreSQL database:
- Create a database for the application
- Create tables in database for the application
- Note the database connection details for configuration
-
Set up environment variables:
- Copy the sample environment file to create your own
.envfile:cp sample.env .env
- Edit the
.envfile and update the values with your actual configuration:# Server Configuration PORT=80 # Update with your PostgreSQL database credentials DB_HOST=localhost DB_PORT=5432 DB_NAME=expense_tracker DB_USER=your_user DB_PASSWORD=your_password # Get a Hugging Face API key from https://huggingface.co/settings/tokens HUGGINGFACE_API_KEY=your_huggingface_api_key
- Copy the sample environment file to create your own
-
Start the application:
- For development:
npm run dev
- For production:
npm start
- For development:
-
Access the application:
- Open your browser and go to
http://localhost:3000
- Open your browser and go to
The application uses PostgreSQL as its database. The connection is configured in src/config/db.js and uses the following environment variables:
DB_HOST: PostgreSQL server hostnameDB_PORT: PostgreSQL server portDB_NAME: Database nameDB_USER: Database usernameDB_PASSWORD: Database password
The AI-powered categorization uses Hugging Face models and is configured with these environment variables:
AI_API_URL: URL of the Hugging Face model APIHUGGINGFACE_API_KEY: Your Hugging Face API key
- View Expenses: The main page displays all your expenses in a table format
- Add Expense: Click the "Add Expense" button to record a new expense
- Edit Expense: Click the edit icon next to an expense to modify it
- Delete Expense: Click the delete icon to remove an expense
- Filter Expenses: Use the month filter to view expenses for a specific month
- Click on "Monthly View" in the navigation bar to access the monthly analysis
- View expense totals, category breakdowns, and visualizations
- Use the month selector to change the month being analyzed
- Select one or more expenses using the checkboxes
- Click the "Auto-Categorize" button to have the AI suggest categories
- The system will analyze the expense descriptions and assign appropriate categories
The application provides the following API endpoints:
GET /api/expenses- Get all expensesGET /api/expenses/:id- Get a specific expensePOST /api/expenses- Create a new expensePUT /api/expenses/:id- Update an expenseDELETE /api/expenses/:id- Delete an expense
GET /api/expenses/month/:year/:month- Get expenses for a specific monthGET /api/expenses/summary/:year/:month- Get a summary of expenses for a month
POST /api/expenses/categorize- Auto-categorize selected expenses
ExpenseAI uses Hugging Face's Natural Language Processing models to automatically categorize expenses based on their descriptions. The system uses:
- Zero-shot Classification: Determines the most appropriate category without prior training
- Fallback Mechanism: If AI categorization fails, the system uses keyword-based categorization
Models used:
facebook/bart-large-mnli- A robust zero-shot classification model- Alternative models can be configured by changing the
AI_API_URLenvironment variable
CREATE TABLE IF NOT EXISTS expenses (
id SERIAL PRIMARY KEY,
description VARCHAR(255) NOT NULL,
amount NUMERIC(10, 2) NOT NULL,
category VARCHAR(100),
expense_date DATE NOT NULL,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);CREATE TABLE IF NOT EXISTS categories (
id SERIAL PRIMARY KEY,
name VARCHAR(100) UNIQUE NOT NULL,
frequency INTEGER DEFAULT 1
);INSERT INTO categories (name)
VALUES
('Food'), ('Transportation'), ('Housing'), ('Entertainment'),
('Healthcare'), ('Utilities'), ('Shopping'), ('Education')
ON CONFLICT (name) DO NOTHING
);- Budget Management: Set and track budgets for different categories
- Export Functionality: Export expense data to CSV or PDF
- Multi-currency Support: Handle expenses in different currencies
- Receipt Scanning: OCR integration to automatically extract expense data from receipts
- User Authentication: Multi-user support with different access levels
- Advanced Analytics: More detailed insights and predictions based on spending patterns
Contributions are welcome! Please feel free to submit a Pull Request.
- Fork the project
- Create your feature branch (
git checkout -b feature/AmazingFeature) - Commit your changes (
git commit -m 'Add some AmazingFeature') - Push to the branch (
git push origin feature/AmazingFeature) - Open a Pull Request
This project is licensed under the Apache License - see the LICENSE file for details.
Created with ❤️ by S.Buchanan - GitHub Profile