moneyCalc
Retirement planning tool with individual financial calculators

Problem
FIRE (Financial Independence, Retire Early) is a personal finance movement pursued by a growing number of people worldwide. It is characterised by lifestyles which allow for the maximum amount of income to be directed towards savings, and utilisation of investments in order to build a portfolio which will allow for all lifestyle expenses to be funded by passive income and thus an early retirement.
At the present the main method of planning for FIRE is using spreadsheets, and several individuals sell pre-formatted spreadsheets for this purpose. I wanted to build a web based tool which would allow people to plan for their retirement without having to manually calculate factors like returns on investments, loan interest and tax expenditure.
Solution
moneyCalc provides users with a straight forward method of planning for their future. Setup is simple, they just need to create an account to get started. It provides a simple to use UI where their incomes, investments, loans, pensions and expenses can be added, and personal details such as target retirement age and tax options can be set.
All financial entries are run through custom built calculation functions to provide forecasts on their net worth for selectable time ranges, as well as breakdowns of the status of each entry. This allows for elements such as overpaying on loans, or salary sacrifice to be explored in order to help users judge the most valuable uses for their money and see how they might factor in to when they will be able to retire.
Multiple contributors can be added to allow for couples with shared finances to also get an accurate representation of their financial potential. Each contributors entries and long term forecasts can be viewed in individual breakdowns as well as being displayed as a whole for a complete household overview.
The applications surplus income functionality allows for unused post-tax and post-expenditure income to be directed to overpaying loans or making extra contributions to their investment portfolio. Once percentage allocations are set for each, the choice of priority of overpayments by loan and portion of contributions by investment are easily made in a simple UI.
Architecture
- Frontend: Nextjs (state management, UI)
- Backend: Nestjs REST API
- Auth: JWT-based authentication using Next Auth
- Database: PostgreSQL using Neon Serverless
Standout Features
Live rates for:
- Inflation (Using CPIH)
- RPI Rate
Enabled by using custom parsing functions to extract data from the Office for National Statistics website.
15+ Purpose built calculation functions spanning 4500+ lines covering aspects such as:
- Tax calculated for income, savings interest and dividends with dynamically updated personal allowance, and savings and dividends allowances
- Optional inclusion of National Insurance for users that are, for example, self employed
- Expense entries can factor in inflation for accurate predictions of future household expenditure
- Investment forecasts with features such as maximum yearly deposits, one time withdrawals and variable interest rates
- UK Student loans that are automatically zeroed once the relevant time period has passed
- Pension balances that track yearly contributions to ensure that government limits are not exceeded
- Strategic post retirement withdrawals from pensions and investments to reduce tax implications
Security implementations:
- Databases use a pseudonymised architecture where users PII (Personally Identifiable Information) is stored in a dedicated identity database, while their entries are housed in a seperate database and referenced using opaque internal IDs
- Custom built rate limitting to protect against brute force attacks and email relay abuse
- Mandatory email verification using generated single use code
Key Challenges
- Development of architecture for controlled data distribution within the application, and ensuring each component had access to the neccessary data required by the calculations actioned within. This required extensive planning and cohesive structuring of data within objects
- The volume and variety of data required for operation of the application lead to the use of 6 different PostgreSQL databases which led to several unique challenges:
- The separation of the different data types allowed the tailoring of how each type of data request was handled with relevant safeguards for each. ie interest rates can safely be retrieved in browser where as PII must remain on the server side
- All database requests involving user data take place on the Nest backend, before being transferred to the frontend. This meant that the use of security elements such as CORS was mandatory in addition to the use of JWT token based guards to ensure that only authenticated requests originating at the applications frontend are accepted
- The handling of the different data types required requests to be sent in a well timed manner to ensure that processes like authentication were completed in time for session tokens to be used in calls to the backend
- The sheer number of calculations taking place to build the data set used by the dashboards graphs caused issues with content load times. The initial build required ~30 seconds of load time to produce the graph when the lifetime view is selected (spanning from today until the user reaches 100 years old in a monthly scale). Through refactoring, conversion of specific functions to operate asynchronously, and the use of worker functions this time has been reduced to ~7 seconds in the worst case. While this is longer than I would normally find acceptable, allowances have to be made when such a detailed dataset is being constructed
What I Learned
This project has provided opportunity to become more comfortable in the handling of large bodies of data in databases and in the client browser. I have learnt how to better build data structures and enable the passing of key information through the architecture of a complicated application.
I have gained vast experience in building mathematical calculation functions to turn variables into important data to present to the user in a format that is easily understandable.
This was my first time building a full-stack application utilising a Node.js driven backend using Nest framework. I have gained a solid insight into the development of route controllers and how powerful they can be when well configured.
Next Steps
This is a project which I am still actively maintaining and expanding upon.
Planned future features include:
- Addition of a PWA with offline functionality is currently in progress. This will allow users to better plan their future on the go, whether or not internet access is available
- The ability for users to assign shared financial responsibility to specific expenditure to allow for more accurate household forecasts. This will be valuable to couples who pool their finances and want to plan for retirement with unified incomings and outgoings
- A machine learning driven interface that can suggest future expenses and identify trends within the users data to better predict when retirement will be possible