I'm working a lot more with JavaScript in node.js. My application has the following general 'classes' that are used.
Server side:
Client side (backbone.js):
The client side is pretty straight forward. I name all files related to what they are, such as UserModel.js, UserView.js, UserCollection.js, etc.
The server-side however, gets more messy. For example:
Models are related to MongoDB collections. Each Model is just a wrapper for various functionality. If I have a users collection, I have a collection called users
, my model is Users.js
.
Libraries I have for example Users.js
as well, that interacts with the model and contains the majority of logic.
However, this really shouldn't be called Users
, mainly because I'm getting confused now.
Routes are simply related to the URL. So if you have /account/
I would have an account.js
route - all lowercase.
Utilities - I just have one util.js that I don't use much so I'm less concerned and the naming seems fine for it's purpose and size.
How would you suggest naming things that are sort of generic like "Libraries", that differentiates them from Models/Routes.
The most important thing in your naming convention is consistency. You can figure out pretty much any naming convention as long as it is sane and consistent.
That being said, I would probably be more verbose in my names in this case. Paths might be good enough, but I would rather see UserRoutes.js
, UserModel.js
and maybe even UserLib.js
based on your examples.
In some of my node.js projects, I have even taken to not using a .js extension. My routes for instance would be user.routes
. It is easy enough to change the syntax highlighting in editors based on different extensions.
Helpers, extensions, generics, logic, repository, managers, mediator, communicator...any of those?
I usually name things based on the design pattern I use to implement them.
I actually do sort of what you're doing now. I have folders for models, routes, views, and controllers. I then have a file called user.js in each folder. When I need to fix a bug or implement something to do with users, it's pretty easy to figure out where I need to go.
I think it would be confusing if I tried to come up with clever names for all of these files when they are all implementing different aspects of a related thing.