Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Folder structure for both server side and thick client web app

Currently I am using Node.js for the backend and either extjs or backbone for the client and I am now completely confused on the folder structure.

Using express my folder structure is as follow

appname
  |--controllers
  |--models
  |  |--appmodel.js
  |--public
  |  |--css
  |  |--js // any client-side javascripts
  |--routes
  |  |--router.js
  |--views
  |  |--appview.ejs
  |--app.js

where app.js is the point of entry and it uses router.js to handle routing and rendering of the views. This works fine if it is only server-side development. Now if I want to use ExtJS or Backbone for the client, how should I organize my code? Should I add it to public folder or views?

appname
  |--controllers
  |  |--extbasedcontroller.js // correct location?
  |--models
  |  |--appmodel.js
  |  |--extbasedmodels.js // correct location?
  |--public
  |  |--css
  |  |--js
  |  |  |--extjs // extjs files
  |--routes
  |  |--router.js
  |--views
  |  |--appview.ejs
  |  |--extbasedview.ejs // correct location?
  |--app.js

If this is the case, where should I put the model for my extjs files? If I put it in models folder it feels like I'm mixing up client and server code in one folder and it's going to be confusing...

like image 639
GantengX Avatar asked May 25 '13 05:05

GantengX


2 Answers

Just put the whole /webapp under /public so you'll end creating, for instance, frontend's models under /public/webapp/models

appname
  |--models
  |  |--appmodel.js
  |--public
  |  |  |--webapp // extjs/backbone files
  |  |  |  |--models
  |  |  |  |--controllers
  |  |  |  |--css
  |  |  |  |--js
  |  |  |  |--img
  |  |  |  |--views
  |  |  |  |  |--appview.ejs
  |  |  |  |  |--extbasedview.ejs
  |--routes
  |  |--router.js
  |--app.js
like image 133
amurdaca Avatar answered Oct 28 '22 19:10

amurdaca


In your place, I would do that way:

appname
  |--ServerCode
  |  |--controllers
  |  |--models
  |  |  |--appmodel.js
  |  |--routes
  |  |  |--router.js
  |  |--views
  |  |  |--appview.ejs
  |  |--app.js
  |--public
  |  |--css
  |  |--js // any client-side javascripts
  |  |--models
  |  |--controllers
  |  |--...

The main idea is to place public folder outside of the scope of your server javascript files.

See an example here: https://github.com/madhums/node-express-mongoose-demo/

like image 33
Julien Avatar answered Oct 28 '22 19:10

Julien