Skip to content

Repository files navigation

Expense Management System

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.

Features

  • 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.

Screenshots

Add/Update tab — enter expenses for a date, grouped by amount, category, and notes:

Add/Update UI

Analytics tab — category breakdown as a bar chart with an underlying data table:

Analytics UI

Project Structure

  • frontend/: Streamlit application code.
    • app.py — entry point, wires up the Add/Update and Analytics tabs.
    • add_update_ui.py — Add/Update tab (calls GET/POST /expenses/{date}).
    • analytics_ui.py — Analytics tab (calls POST /analytics/).
  • backend/: FastAPI backend server code.
    • server.py — API routes.
    • db_helper.py — MySQL queries (connects to localhost:3306, db expense_manager).
    • logging_setup.py — file logger used by db_helper.py.
  • tests/: Test cases for the backend.
  • requirements.txt: Required Python packages.
  • README.md: This file.

API Endpoints (backend/server.py)

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.

Setup Instructions

  1. Clone the repository:
    git clone https://github.com/yourusername/Expense-Tracking-System.git
    cd Expense-Tracking-System
  2. Install dependencies:
    pip install -r requirements.txt
  3. Set up MySQL: create a database named expense_manager with an expenses table:
    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.py connects with host="localhost", user="root", password="root" — update these if your local MySQL setup differs.
  4. Run the FastAPI server (from the backend/ directory, since it imports db_helper directly):
    cd backend
    uvicorn server:app --reload
  5. Run the Streamlit app (from the project root):
    streamlit run frontend/app.py

Running Tests

pytest

Tests 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.

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages