Monday, 17 December 2018

Node App Structure

Hi all.Looking for some node app structure input.I just started as a full stack dev for a startup, and have been tasked with tackling the “gaps” in their api. Their last full stack dev has been gone for a few months, so I’m the only dev who will be working on the backend for a few weeks while management works to fill another open full stack seat.Upon review, I found their node/express backend to be a little tough to understand given the app’s size, and the current structure. I find myself chasing code through many different files and directories.server.js entry point at the top level, with all app logic in a directory called scripts, broken up by role like route, controller, etc, with some other utilities in a tools directory.In the scripts directory, there are a couple dozen route files. A controller directory with a couple dozen matching controller/action files, and some other directories with some database connection utilities and configuration files.My plan, to make this more scalable, and familiarize myself with the codebase, is to slowly restructure the app into more of a component structure, with all features kept together, as opposed to organizing by file role. Something like:--components ----feature1 ------controllers ------middleware ------routes ------index.js ----feature2 ------controllers ------middleware ------routes ------index.js ----feature3 ------controllers ------middleware ------routes ------index.js --shared ----controllers ----middleware --test --util --app.jsMy thoughts with this are that it will be much easier to understand at first glance, and more scalable since new features will be added as their own app component.Has anyone used a structure similar to this? What are your thoughts?

Submitted December 18, 2018 at 02:25AM by LastNameBread

No comments:

Post a Comment