NodeJS Project Structure
A simple nodejs application with MVC and API
.The first major distinction is between the dynamically generated directories which will be used for hosting and source directories.
.The source directories will have a config file or folder depending on the amount of configuration you may have . This includes the environment configuration and business logic configuration which you may choose to put inside config directory.
.Now the most vital directories where we distinguish between the server side/backend and the frontend modules . The 2 directories server and webapp represent the backend and frontend respectively which we can choose to put inside a source directory viz. src.
You can go with different names as per personal choice for server or webapp depending on what makes sense for you. Make sure you don't want to make it too long or to complex as it is in the end internal project structure.
.Inside the server directory you can have the controller ,the App.js/index.js which will be you main nodejs file and start point .The server dir. can also have the dto dir which holds all the data transfer objects which will be usd by API controllers.
The webapp directory can be divided into two major parts public and mvc , this is again influenced by what build strategy you want to use. We are using browserfiy the build the MVC part of webapp and minimize the contents from mvc directory simply put.
.Now the public directory can contain all the static resources,images,css(you can have saas files as well) and most importantly the HTML files .
The mvc directory will contain the front-end logic including the models,the view controllers and any other utils modules you may need as part of UI. Also the index.js or shell.js whichever may suite you is part of this directory as well.
So in conclusion the entire project structure will look like below.And a simple build task like gulp browserify will minify the mvc scripts and publish in public directory. We can then provide this public directory as static resource via express.use(satic('public' )) api.