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.
- 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)
- Python 3.8+
- MySQL Server (running on
localhost:3306) - pip (Python package manager)
- Start MySQL server.
- Create the database:
CREATE DATABASE budjet_planning_assistant;
- (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;
- Navigate to backend folder:
cd backend - Create
.envfile (if not present):DATABASE_URL=mysql://root:rootpassword@localhost:3306/budjet_planning_assistant - Install dependencies:
pip install -r requirements.txt
- Initialize the database tables:
Open a Python shell in the backend folder:
from app import db db.create_all()
- Run the backend server:
The API will be available at
python app.py
http://localhost:5000/api/
- Navigate to frontend folder:
cd ../frontend - Install Flask (if needed):
pip install Flask
- Run the frontend server:
The frontend will be available at
python app.py
http://localhost:5001/
- Use Postman or similar tool to test endpoints:
GET/POST/PUT/DELETE http://localhost:5000/api/budgetsGET/POST/PUT/DELETE http://localhost:5000/api/expenses
- Update
.envwith 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).
BTech1stYear-BudgetPlanningAssistant/
backend/
app.py
models.py
db.py
resources/
requirements.txt
mysql_connector.py
.env
frontend/
app.py
templates/
static/
README.md
This project intentionally contains 4 bugs for learning and debugging practice. Here are the bugs and how to solve them:
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 thepostandputmethods to reject negative amounts and return an error message.
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 thedatefield usingdatetime.strptimeand return an error if the format is invalid.
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 therequests.getcall in a try/except block and show a user-friendly error message if the backend is unreachable.
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.