Skip to content

victorboss/Python-Project---Expense-Monitoring-System

Repository files navigation

Expense Tracking System

Overview

This is an Expense Tracking System built with FastAPI for the backend and Streamlit for the frontend. The system allows users to add, update, and analyze their expenses. It interacts with a MySQL database to store and retrieve expense data.

Key Features

  • Expense Management: Add, update, and delete expenses by date.
  • Analytics: Generate summary and visualize expenses by category and bar chart with area chart.
  • User Interface: Simple and interactive UI built with Streamlit.

Technologies Used

  • Backend: FastAPI
  • Frontend: Streamlit
  • Database: MySQL
  • Data Visualization: Matplotlib for charts
  • Logging: Python logging for error and information tracking

Installation

Prerequisites

  • Python 3.7+
  • MySQL database running locally or on a server.
  • requirements.txt (see below for dependencies).

Steps

  1. Clone this repository to your local machine:

    git clone https://github.com/your-repo/expense-tracking.git
    cd expense-tracking
  2. Install the required Python dependencies:

    pip install -r requirements.txt
  3. Set up the MySQL database:

    • Make sure you have MySQL installed and running.
    • Create a database called expense_manager and set up the expenses table.
  4. Configure the database connection in db_connection.py:

    connection = mysql.connector.connect(
        host="localhost",
        user="root",
        password="root",  # Change the password if needed
        database="expense_manager"
    )
  5. Run the FastAPI server:

    uvicorn server:app --reload
  6. Run the Streamlit UI:

    streamlit run app.py

File Breakdown

  • db_connection.py: Handles MySQL database connections and CRUD operations for expenses.
  • logging_setup.py: Sets up logging for the application.
  • server.py: FastAPI app, which provides API endpoints to manage expenses and generate analytics.
  • add_update_ui.py: Streamlit UI for adding and updating expenses.
  • analytics_ui.py: Streamlit UI for visualizing expense data with graphs and pie charts.
  • app.py: Main entry point for the Streamlit application that integrates add_update_ui.py and analytics_ui.py.
  • test_db_connection.py: Unit tests for database connection and CRUD functionality.
  • conftest.py: Configures project root path for testing.

API Endpoints

  • GET /expenses/{expense_date}: Fetch all expenses for a specific date.
  • POST /expenses/{expense_date}: Add or update expenses for a specific date.
  • POST /analytics/: Fetch expense summary and analytics within a date range.

Running Tests

To test the database connection and CRUD operations, you can run the tests in test_db_connection.py using:

pytest test_db_connection.py

Usage

  • Add/Update Expenses: Use the "Add/Update" tab in the Streamlit UI to input new expenses or modify existing ones.
  • Expense Analytics: Use the "Analytics" tab in Streamlit to view detailed charts and category-wise summaries of your expenses.

Example Data

Sample response for GET /expenses/2024-08-15:

[
  {
    "amount": 10.0,
    "category": "Shopping",
    "notes": "Bought potatoes"
  }
]

Sample response for POST /analytics/:

[
  {
    "category": "Food",
    "total": 150.0
  },
  {
    "category": "Rent",
    "total": 500.0
  }
]

Contribution

Feel free to fork this project and create a pull request. Contributions to improve the functionality or UI are welcome!

License

This project is open-source and available under the MIT License.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published