Skip to content

A website to track income and expenses, predict the stock market with AI, and chat with AI to learn more about how to manage your money.

Notifications You must be signed in to change notification settings

developersbm/FinanceBuddy-FinanceTracker

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

64 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

FinanceBuddy (MERN)

Documentation

Showcase (Main Website)

FinanceBuddy.mp4

Showcase (Stock Predictor)

stockpredictor.mov

Built With

  • React
  • MongoDB
  • Node.js
  • Express.js
  • Python
  • HTML
  • CSS

Backend (API, MongoDB & CRUD)

Connecting Database to MongoDB

  • Importing Mongoose library with an object (ODM), allowing to define schemas, models, and interact with Node.js.
  • Connect your database to the MongoDB URL stored in the hidden .env file.
  • Export the database so it can be used in other modules of the application.

Income & Expenses (Express Route Handlers)

Adding Data to Database (HTTP POST)

  • Parameters (request, response)
  • Destructure title, amount, category, description from req.body
  • Define IncomeSchema including all the requisites
  • Implement Try & Catch for errors:
    • If title, category, description, date are missing: throw error
    • Ensure amount is a number
    • Await income.save() and handle success or error

Getting Fetching from Database (HTTP GET)

  • Parameters (request, response)
  • Implement Try & Catch for errors
  • Fetch incomes using IncomeSchema.find().sort({createdAt: -1})
    • Pattern to fetch records in reverse chronological order, with the most recent ones first.

Delete (HTTP DELETE)

  • Parameters (request, response)
  • Extract id parameter
  • Use Mongoose's findByIdAndDelete() based on the id
    • Handle successful operation with .then()
    • Catch and handle errors with .catch()

Transactions

  • Import functions responsible for handling HTTP requests related to expenses/income.
  • Set up Express's Router.
    • const router = require('express').Router();
  • Export the configured router for use in other parts of the app.

(back to top)

Starting the server

Express Setup (Define the Port)

  • Use the middleware for parsing JSON body and add cors to allow request in the frontend URL.
  • Dynamic route mounting
  • Allow access to the backend
cd backend
npm start
  • Allow access to the frontend
cd frontend
npm start

(back to top)

Connecting Backend & Frontend

  • For this I use the globalContext.js Here I track different functions with the base URL of my backend route.
  • I use the library of axios to POST, GET, DELETE elements.

addIncome/Expenses

  • Sends an HTTP POST request to the specified URL ${BASE_URL}add-income, including the income data.
  • Sets up an error handling mechanism using .catch() to handle any errors that occur during the request, updating the error state with the error message from the response if an error occurs.
  • Calls the getIncomes() function after the request completes successfully, to fetch and update the list of incomes to reflect the newly added income.

getIncome/Expenses

  • Sends an HTTP GET request to the specified URL ${BASE_URL} get-incomes, including the income data.

deleteIncome/Expenses

  • Sends an HTTP DELETE request to the specified URL ${BASE_URL} delete-income and grabs the id that needs to be deleted.
  • Calls the getIncomes() function after the request completes successfully, to fetch and update the list of incomes to reflect the newly deleted income.

totalIncome/Expenses

  • It iterates over each income entry in the incomes/expenses array using the forEach() method.
  • For each income/expense entry, it adds the amount to the totalIncome variable.
  • After iterating through all income entries, it returns the calculated totalIncome/totalExpenses, representing the sum of all income amounts in the array.

totalBalance

  • For this function I only return the totalIncome() - totalExpenses()

transactionHistory

  • Generates a summary of the transaction history by combining income and expense records.
  • Sorting them based on their creation dates in descending order. This is executed by the comparator function that compares 2 transactions a & b by their creation dates.
  • Using splice to return the three most recent transactions.

(back to top)

About

A website to track income and expenses, predict the stock market with AI, and chat with AI to learn more about how to manage your money.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published