I have implemented a insights server using express and nodejs.
-
A data store of transactions using LokiJS (a fast in-memory document-oriented data store with persistence)
-
An Insights microservice with an endpoint (
/users/insights
) to retrieve insights for a customer -
Types of insights: -Spend by category -Income and outgoings -Bill tracking (increase or decrease in amount)
-
Some example insights: -"You've spent £142 at cafes in the last month" -"Your latest Vodafone bill is £14 higher than previous months" -"Your latest British Gas bill is £89 lower than your previous bill" -"For the last 3 months, on average you are spending 5% more than your income" -"Your income was £185 higher this month" -"Your outgoings have increased by 15% in the last 3 months"
-
Expected features: -Make it secure - e.g. only allow a customer to access their own insights -Allow the insights to be filtered
git@github.com:sakibshaik/nodejs-transaction-insights-server.git
cd nodejs-transaction-insights-server
npm install
- Running tests :
npm run test
- start server :
npm start
- server listens on port 3000 by default.
- The Insights can be generated by calling endpoint:
/users/insights
method:GET
with Basic Authorization header. Eg:curl --location --request GET 'http://localhost:3000/users/insights' \ --header 'Authorization: Basic c2FraWI6c2FraWIxMjM='
The application uses a fake data generator (located at helpers\fakeEventGenerators.js
) which generates random data defaulted to every 5 seconds (which can be set by setting an environment variable GENERATORFREQUENCY
in ms ) and stores an 'Transaction'
event in the db with following payload:
{ customer_id: String, amount: Float, date: Date, description: Text, type: String, category: String, merchant: String, }
The application currently doesn't retry the failures.
Tests:
- Unit tests located at
/tests/
Output is like:
{ "credit": { "Jan-2020": [ { "categories": "transfers", "amount": 3.13 } ], "Oct-2020": [ { "categories": "salary", "amount": 513.48 } ] }, "debit": { "Apr-2020": [ { "categories": "eating out", "amount": 706.04 } ] } }
- This service was built in 2 hours so the expected insights like in number 4 is not achieved but its possible to interpret it from the curremt output
- filtering the events can be implemented by passing the query params on endpoint
/users/insights
- default users supported can be found in
helpers\fakeEventGenerators.js
line no 9 onwards and more users can be added there