Code Monkey home page Code Monkey logo

financial-calculator-backend's Introduction

Welcome to financial calculator backend πŸ‘‹

Documentation Maintenance Coverage License: MIT Twitter: JavierFeliuA

About

This project contains an API for a financial calculator. I coded this project in Python, using Flask and NumPy.

In conjunction with the Financial Calculator Frontend, this project provides a companion calculator for the personal finance book "Mejora Tu SituaciΓ³n."

Design Considerations

For this project, the book author presented me with a series of calculators built on MS Excel. The goal was to produce an online calculator that, given the same inputs, would return the same results as the Excel samples.

Most of Excel's financial formulas have the calculation method obfuscated. That is, you can't see how it arrives at the result.

The Python library NumPy contains 1:1 equivalents to all of Excel's financial formulas. For this reason, I decided to break up the problem into two:

  1. (This repository) An API in Python would receive the calculation parameters from the frontend and return the results calculated with NumPy.
  2. (The frontend repository) A frontend would provide a user interface for receiving calculation parameters and presenting the results.

Important links

  1. You can take a look at the frontend code here.
  2. Find the live calculator here.
  3. The live backend is here. The API is open, so you can test it using Postman (see the Postman section below for instructions).
  4. This project runs in a Kubernetes cluster at DigitalOcean. For information on how to create your cluster visit my do-managed-kubernetes repository.

Install

To use the project in your development machine, clone it, and go to the project's root:

git clone https://github.com/wanderindev/financial-calculator-backend.git
cd financial-calculator-backend

From the project's root, create and activate your virtual environment:

python3 -m venv venv
. venv/bin/activate

And install the project's dependencies:

pip install -r requirements.txt

Development

During develpment use:

docker-compose up --build

to create a container running the backend. Access the container at http://localhost:5001

Modify the code as needed and test using Postman (see instructions below), sending requests to the container running at localhost.

The calculators package contains all de classes for the different financial calculators.

The resources package contains all the endpoints

Postman

Import fc-backend.postman_collection.json into Postman for a collection of all endpoints.

Add a url variable to the environment with value http://localhost:5001 for development. Make sure you have a container running the backend as per instructions above before sending requests.

To test against the live backend, add a url variable to the Postman environment with value https://api.calcfina.com and send your requests.

Tests

To insure code quality, I added UnitTest to the project. All tests all located in the tests package.

To test the project, make sure your virtual environment is activated and run:

python -m unittest tests/test_credit_card_calculators.py tests/test_loan_calculators.py tests/test_retirement_calculators.py tests/test_saving_calculators.py

The included tests provide 98% coverage for the codebase. You can find the coverage report here.

Deployment

Before deployment, you have to replace the SECRET_KEY in line 32 of the Dockerfile for something, well, secret. Make sure you don't commit the modified Dockerfile to version control.

Next, you need to build the Docker image for the project and push it to your Docker Hub account:

docker build -t wanderindev/fc-backend .
docker push wanderindev/fc-backend

Replace wanderindev above (my Docker Hub account id) with your Docker Hub id.

Then, from the root of do-managed-kubernetes project run:

kubectl delete deployment api-calcfina
kubectl apply -f ./python/api-calcfina.yml

to create two pods running the backend and a service exposing them at port 80.

For more information on deploying to a Kubernetes cluster, visit my do-managed-kubernetes repository.

Author

πŸ‘€ Javier Feliu

Show your support

Give a ⭐️ if this project helped you!

πŸ“ License

This project is MIT licensed.


This README was generated with ❀️ by readme-md-generator

financial-calculator-backend's People

Contributors

wanderindev avatar

Stargazers

 avatar  avatar

Watchers

 avatar

Forkers

suraj0204

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.