Skip to content

finvediclabs/BTech1stYear-BudgetPlanningAssistant

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 

Repository files navigation

Budget Planning Assistant (Advanced Version)

A web-based financial assistant to manage monthly budgets, track categorized expenses, and visualize spending. Built with Flask (REST API + Jinja2), MySQL, SQLAlchemy, and Chart.js.


Features

  • Create, read, update, delete (CRUD) budgets and expenses
  • Categorize expenses (food, bills, travel, etc.)
  • RESTful API (Flask-RESTful)
  • Data stored in MySQL
  • Data visualization with Chart.js (frontend)

Prerequisites

  • Python 3.8+
  • MySQL Server (running on localhost:3306)
  • pip (Python package manager)

Database Setup

  1. Start MySQL server.
  2. Create the database:
    CREATE DATABASE budjet_planning_assistant;
  3. (Optional) Create user: If you want a user other than root, create and grant privileges:
    CREATE USER 'youruser'@'localhost' IDENTIFIED BY 'yourpassword';
    GRANT ALL PRIVILEGES ON budjet_planning_assistant.* TO 'youruser'@'localhost';
    FLUSH PRIVILEGES;

Backend Setup

  1. Navigate to backend folder:
    cd backend
  2. Create .env file (if not present):
    DATABASE_URL=mysql://root:rootpassword@localhost:3306/budjet_planning_assistant
    
  3. Install dependencies:
    pip install -r requirements.txt
  4. Initialize the database tables: Open a Python shell in the backend folder:
    from app import db
    db.create_all()
  5. Run the backend server:
    python app.py
    The API will be available at http://localhost:5000/api/

Frontend Setup

  1. Navigate to frontend folder:
    cd ../frontend
  2. Install Flask (if needed):
    pip install Flask
  3. Run the frontend server:
    python app.py
    The frontend will be available at http://localhost:5001/

API Testing

  • Use Postman or similar tool to test endpoints:
    • GET/POST/PUT/DELETE http://localhost:5000/api/budgets
    • GET/POST/PUT/DELETE http://localhost:5000/api/expenses

Notes

  • Update .env with your actual MySQL credentials if different.
  • For custom SQL, use backend/mysql_connector.py.
  • Data visualization (charts) is handled in the frontend (to be implemented).

Project Structure

BTech1stYear-BudgetPlanningAssistant/
  backend/
    app.py
    models.py
    db.py
    resources/
    requirements.txt
    mysql_connector.py
    .env
  frontend/
    app.py
    templates/
    static/
  README.md

Known Bugs and How to Fix Them

This project intentionally contains 4 bugs for learning and debugging practice. Here are the bugs and how to solve them:

1. Backend: Budget Creation Allows Negative Amounts

Bug: You can create a budget with a negative amount via the API or frontend. How to Fix:

  • In resources/budget.py, add a check in the post and put methods to reject negative amounts and return an error message.

2. Backend: Expense Date Not Validated

Bug: The API accepts any string for the expense date, even invalid dates (e.g., 'not-a-date'). How to Fix:

  • In resources/expense.py, validate the date field using datetime.strptime and return an error if the format is invalid.

3. Frontend: Budgets Page Crashes if Backend is Down

Bug: If the backend API is not running, the /budgets page throws an unhandled exception and shows an error page. How to Fix:

  • In frontend/app.py, wrap the requests.get call in a try/except block and show a user-friendly error message if the backend is unreachable.

4. Frontend: Expense Edit Form Does Not Pre-fill Values on Error

Bug: If you try to edit an expense and the backend returns an error (e.g., invalid data), the form reloads but does not pre-fill the previous values. How to Fix:

  • In frontend/app.py, when handling the edit POST, if the backend returns an error, re-render the form with the submitted values and the error message.

For more details, see the code comments in the relevant files.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors