Refactor architecture

refactor architecture similar to this module:
https://github.com/dpb587/kibana-metrics/blob/master/lib/proxy.js