A simple, elegant expense tracking application built with Flask. Track your spending, categorize expenses, and stay on budget.
- β Add, view, and delete expenses
- π Filter expenses by category
- π΅ Real-time total calculation
- π± Responsive design
- π REST API endpoints
- β¨ Clean, modern UI
- π§ͺ Comprehensive test suite
expense-tracker/
βββ app.py # Main Flask application
βββ test_app.py # Pytest test suite
βββ requirements.txt # Python dependencies
βββ templates/
β βββ index.html # Main HTML template
βββ static/
β βββ css/
β βββ style.css # CSS styles
βββ README.md # This file
- Python 3.8 or higher
- pip (Python package manager)
-
Clone or download this repository
-
Navigate to the project directory
cd expense-tracker -
Install dependencies
pip install -r requirements.txt
-
Start the Flask development server
python app.py
-
Open your browser and visit
http://localhost:5000 -
Start tracking your expenses!
The application includes a comprehensive test suite using pytest.
pytest test_app.py -v# Test only the Expense class
pytest test_app.py::TestExpenseClass -v
# Test only the routes
pytest test_app.py::TestRoutes -v
# Test only the API
pytest test_app.py::TestAPI -vpip install pytest-cov
pytest test_app.py --cov=app --cov-report=htmltest_app.py::TestExpenseClass::test_expense_creation PASSED
test_app.py::TestExpenseClass::test_expense_with_date PASSED
test_app.py::TestRoutes::test_index_route PASSED
test_app.py::TestRoutes::test_add_expense_success PASSED
...
======================== XX passed in X.XXs ========================
- Fill in the amount, category, description, and date
- Click "Add Expense"
- Your expense will appear in the list below
- Use the dropdown menu to filter by category
- Select "All Categories" to view all expenses
- Click the "Delete" button next to any expense
- Confirm the deletion
- Click "Clear All Expenses" at the bottom
- Confirm to remove all data
The application provides REST API endpoints for programmatic access:
GET /api/expensesResponse:
[
{
"id": 1,
"amount": 50.00,
"category": "Food & Dining",
"description": "Lunch",
"date": "2024-02-09"
}
]GET /api/summaryResponse:
{
"by_category": {
"Food & Dining": 75.50,
"Transportation": 30.00
},
"total": 105.50,
"count": 3
}The application supports the following expense categories:
- π Food & Dining
- π Transportation
- ποΈ Shopping
- π¬ Entertainment
- π‘ Bills & Utilities
- π₯ Healthcare
- π¦ Other
Currently, the application uses in-memory storage. This means:
- β Fast and simple
- β Data is lost when the server restarts
- π‘ Future enhancement: Add SQLite or PostgreSQL for persistence
The test suite covers:
- Unit Tests - Testing the Expense class
- Route Tests - Testing Flask endpoints
- API Tests - Testing JSON API responses
- Integration Tests - Testing complete workflows
- Validation Tests - Testing input validation and error handling
- β Expense creation and validation
- β Adding expenses (valid and invalid inputs)
- β Deleting expenses
- β Filtering by category
- β Total calculation
- β API responses
- β Error handling
- β Complete user workflows
- Flask - Python web framework
- pytest - Testing framework
- HTML/CSS - Frontend (no JavaScript frameworks needed!)
This project was built using Claude (Anthropic's AI assistant) to demonstrate effective use of AI code generation tools for rapid application development.
- β Clean, readable code with comments
- β Comprehensive test coverage
- β Input validation and error handling
- β RESTful API design
- β Responsive UI design
- β Clear documentation
Potential improvements for the application:
- Persistent storage (SQLite/PostgreSQL)
- User authentication
- Budget setting and alerts
- Monthly/weekly summaries
- Data export (CSV, PDF)
- Charts and visualizations
- Receipt image uploads
- Recurring expense tracking
If port 5000 is already in use, modify app.py:
app.run(debug=True, host='0.0.0.0', port=5001) # Change portMake sure you've installed all dependencies:
pip install -r requirements.txtEnsure you're in the correct directory and have pytest installed:
pip install pytest
pytest test_app.py -vThis project is provided as-is for educational and demonstration purposes.
This is a demonstration project, but feel free to fork and modify for your own use!
For questions or feedback about this project, please reach out through the repository.
Happy expense tracking! π°