insights about a customer’s transactions

I have implemented a insights server using express and nodejs.

  1. A data store of transactions using LokiJS (a fast in-memory document-oriented data store with persistence)

  2. An Insights microservice with an endpoint (/users/insights) to retrieve insights for a customer

  3. Types of insights: -Spend by category -Income and outgoings -Bill tracking (increase or decrease in amount)

  4. 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"

  5. Expected features: -Make it secure - e.g. only allow a customer to access their own insights -Allow the insights to be filtered

Setting up the application:

  1. git@github.com:sakibshaik/nodejs-transaction-insights-server.git
  2. cd nodejs-transaction-insights-server
  3. npm install
  4. Running tests : npm run test
  5. start server : npm start

Server Details:

  1. server listens on port 3000 by default.
  2. 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/

Current State:

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 } ] } }

  1. 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
  2. filtering the events can be implemented by passing the query params on endpoint /users/insights
  3. default users supported can be found in helpers\fakeEventGenerators.js line no 9 onwards and more users can be added there