The solution is to develop small software: divide the whole application into self-contained components that each constitutes very few files (e.g. controller, service, data access, test, etc.)
There are top 3 benefits that the solution brings
- Keep the software complexity low
- Improves maintainability. Each file is relatively small and so is easier to understand and change
- Improves modularity. The separate modules are easier to test, implement or design.
The project structure is shown as per below.
src
+-- components
| +-- payslip # Payslip calculation and format
| +-- tax # Tax data access and tax calculation
+-- libs # Libraries
+-- app.js # App entry point
In each component, use the principle of SoC to layer the application.
Separate component code into layers: controller, services,and data access layer
The tax rate list only has 5 tax rate level, so we can compare annual salary with each tax rate in the tax rate list to calculate tax at each rate level. If salary is greater than the maximum income of the rate level, the tax at the rate level is (maximum income - start income) * rate. If salary is less than the start income of the rate level, the tax at the rate level is 0. If salary is between the start income and maximum income of the rate level, the tax at the rate level is (maximum income - start income) * rate. Then we add the tax amount at each rate level up to get annual income tax.
- Install Node.js
- Unzip payslip.zip file into a folder
- Or download the project from Github
git clone https://github.com/Mattlu88/payslip.git
- Open a terminal or windows command and navigate to the directory where the project is unzipped or downloaded
- Install application
npm install
npm install -g .
- Run application
GenerateMonthlyPayslip "Mary Song" 60000
- Install testing framework Jest
npm install
- Run test
npm run test
- Assumptions
- The application can be run from command line from anywhere by GenerateMonthlyPayslip command on user's system
- The employee name must be entered
- The annual salary must be entered and must not be negative
- The gross monthly income and monthly income tax are rounding to 2 decimal places if necessary
- Trade-offs
- The project is using functional programming approach, so a few core concepts are applied such as using pure function and avoiding mutable data or states.