Refactor API: Move middlewares out of main file