This project consists of a C++ backend for managing personal finance data (using Crow C++ web framework and SQLite3) and a simple HTML/Tailwind CSS/JavaScript frontend for interaction.
./: Contains the C++ backend source files (main.cpp,FinanceDB.h,FinanceDB.cpp,helper.h,helper.cpp), CMake build files, and therun.shscript../frontend/: Contains the static HTML frontend (index.html) with Tailwind CSS via CDN and JavaScript for API calls.backend_server.py: A Python Flask server that serves thefrontend/index.htmland acts as a simple static file server for the frontend.
To get the entire application (C++ backend and HTML frontend) up and running, follow these steps:
Before compiling and running, ensure you have the necessary tools and libraries installed on your system:
- CMake: For building the C++ backend.
On Arch Linux, install with:
sudo pacman -S cmake - g++ (C++ Compiler): A C++17 compatible compiler.
- SQLite3 Development Libraries:
On Debian/Ubuntu-based systems:
sudo apt-get update && sudo apt-get install libsqlite3-devOn Arch Linux:sudo pacman -S sqlite - Crow C++ Web Framework: Crow is primarily header-only. Ensure its dependencies are met. (The
CMakeLists.txthandles finding it). - Python 3 and Flask: For the frontend server.
Install Flask:
pip install Flask
-
Navigate to the project root directory in your terminal.
-
Make the
run.shscript executable (if you haven't already):chmod +x run.sh
-
Execute the
run.shscript:./run.sh
This script will:
- Build the C++ backend using CMake.
- Start the C++ backend server (on
http://localhost:5000) in the background. - Start the Python frontend server (on
http://localhost:8000) in the background. - Provide instructions on how to access the frontend.
-
Access the Frontend: Open your web browser and navigate to
http://localhost:8000.To stop both servers, simply press
Ctrl+Cin the terminal whererun.shis running.
The C++ backend (running on http://localhost:5000) exposes the following API endpoints:
- URL:
/ - Method:
GET - Description: Provides a welcome message and links to other main endpoints.
- Response: HTML content.
- URL:
/summary - Method:
GET - Description: Retrieves a list of all recorded monthly summaries, including salary, limit, saving percentage, and condition.
- Response: JSON array of monthly summary objects.
[ { "month_year": "11_2025", "salary": 5000.0, "limit": 4000.0, "saving_percentage": 20.0, "condition": "Good" } ]
- URL:
/expenses/<month_year>(e.g.,/expenses/11_2025) - Method:
GET - Description: Retrieves a list of detailed expense records for a specified month and year.
- Response: JSON array of expense record objects, now including
id(SQLiterowid).[ { "id": 1, "day_month_year": "01_11_2025_12345", "spent_on": "Groceries", "price": 150.75, "priority": 5 } ]
- URL:
/summary - Method:
POST - Description: Adds a new monthly summary or updates an existing one for the current month. Requires
salaryandlimit. - Request Body: JSON object.
{ "salary": 5000.0, "limit": 4000.0 } - Response: Success or error message (text).
- URL:
/expense - Method:
POST - Description: Adds a new expense record for the current day. Automatically updates the priority of the
spentOnitem and recalculates the monthly summary if a salary is set. - Request Body: JSON object.
{ "spentOn": "Dinner", "price": 75.50 } - Response: Success or error message (text).
- URL:
/highest - Method:
GET - Description: Retrieves a list of expenses grouped by
spent_on, showing the average price and the number of times purchased (priority), sorted by purchase frequency in descending order. - Response: JSON array of prioritized expense objects.
[ { "spent_on": "Coffee", "average_price": 4.50, "times_purchased": 10 } ]
- URL:
/sorted_by_price/<order>(e.g.,/sorted_by_price/truefor ascending,/sorted_by_price/falsefor descending) - URL:
/sorted_by_price/(defaults to ascending) - Method:
GET - Description: Retrieves all expense records for the current month, sorted by price in either ascending or descending order. Now includes
id(SQLiterowid). - Response: JSON array of expense record objects.
[ { "id": 2, "day_month_year": "01_11_2025_98765", "spent_on": "Bus Fare", "price": 2.50, "priority": 3 } ]
- URL:
/range/<start_date>/<end_date>(e.g.,/range/01-11-2025/15-11-2025) - Method:
GET - Description: Retrieves expense records within a specified date range (inclusive). Dates should be in
DD-MM-YYYYformat. Now includesid(SQLiterowid). - Response: JSON array of expense record objects.
[ { "id": 3, "day_month_year": "05_11_2025_54321", "spent_on": "Lunch", "price": 12.00, "priority": 2 } ]
- URL:
/total_spent - Method:
GET - Description: Retrieves the total amount spent for the current month.
- Response: JSON object with the total amount.
{ "total": 1500.50 }
- URL:
/delete_expense/<id>(e.g.,/delete_expense/123) - Method:
DELETE - Description: Deletes an expense record by its unique ID (SQLite
rowid). - Response: Success or error message (text).
Expense with ID 123 deleted successfully.
- URL:
/edit_expense/<id>(e.g.,/edit_expense/123) - Method:
PUT - Description: Updates an existing expense record by its unique ID (SQLite
rowid). Accepts optionalspentOn,price, andpriorityfields. - Request Body: JSON object (at least one field required).
{ "spentOn": "New Description", "price": 25.00, "priority": 4 } - Response: Success or error message (text).
Expense with ID 123 updated successfully.