[webui][api] refactoring to make the code more object oriented