A simple expense tracking system with a Streamlit frontend and a FastAPI backend, backed by a MySQL database. It lets you log daily expenses by category, edit/replace a day's entries, and view a percentage breakdown of spending by category over a date range.
- Add/Update tab — enter up to 5 expenses (amount, category, notes) for a given date. Submitting replaces all existing entries for that date.
- Analytics tab — pick a start/end date range and get a bar chart plus table showing total spend and percentage share per category.
- Categories:
Rent,Food,Shopping,Entertainment,Other. - Backend logs every DB operation (fetch/insert/delete) to
backend/server.log.
Add/Update tab — enter expenses for a date, grouped by amount, category, and notes:
Analytics tab — category breakdown as a bar chart with an underlying data table:
- frontend/: Streamlit application code.
app.py— entry point, wires up the Add/Update and Analytics tabs.add_update_ui.py— Add/Update tab (callsGET/POST /expenses/{date}).analytics_ui.py— Analytics tab (callsPOST /analytics/).
- backend/: FastAPI backend server code.
server.py— API routes.db_helper.py— MySQL queries (connects tolocalhost:3306, dbexpense_manager).logging_setup.py— file logger used bydb_helper.py.
- tests/: Test cases for the backend.
- requirements.txt: Required Python packages.
- README.md: This file.
| Method | Path | Description |
|---|---|---|
| GET | /expenses/{date} |
Returns all expenses for the given date (YYYY-MM-DD). |
| POST | /expenses/{date} |
Replaces all expenses for the given date with the provided list. |
| POST | /analytics/ |
Body: {"start_date", "end_date"}. Returns per-category total and percentage of spend in that range. |
Interactive API docs are available at http://127.0.0.1:8000/docs once the backend is running.
- Clone the repository:
git clone https://github.com/yourusername/Expense-Tracking-System.git cd Expense-Tracking-System - Install dependencies:
pip install -r requirements.txt
- Set up MySQL: create a database named
expense_managerwith anexpensestable:CREATE TABLE expenses ( id INT AUTO_INCREMENT PRIMARY KEY, expense_date DATE NOT NULL, amount DECIMAL(10, 2) NOT NULL, category VARCHAR(255) NOT NULL, notes VARCHAR(255) );
db_helper.pyconnects withhost="localhost",user="root",password="root"— update these if your local MySQL setup differs. - Run the FastAPI server (from the
backend/directory, since it importsdb_helperdirectly):cd backend uvicorn server:app --reload - Run the Streamlit app (from the project root):
streamlit run frontend/app.py
pytestTests in tests/backend/test_db_helper.py expect specific rows to already exist in the database (e.g. an expense on 2026-07-11), so they're meant to run against a seeded/known dataset rather than an empty one.