Skip to content

Instantly share code, notes, and snippets.

@e-oz
Last active December 20, 2015 22:38
Show Gist options
  • Save e-oz/6206082 to your computer and use it in GitHub Desktop.
Save e-oz/6206082 to your computer and use it in GitHub Desktop.
Structuring an Angular Project

Author of quoted text: Colin Johnsun
Original: http://www.johnpapa.net/structuring-an-angular-project/#comment-142821

I agree with Joel, I found that dividing by functional area made more sense to my workflow.
I tend to work on a particular function in my application and having all related code in the same folder made it easy and quicker to locate them. In my Angular apps, I don’t have separate controller and views folders. Instead, I would have a folder for login, sales, shipping, etc which would contain my related controllers and views. Although I do group by types for services and directives.
Ward mentions about cross cutting concerns. For me, Angular feels more like an MVVM framework than MVC and in my apps, the controllers are the view-models. In the “Shipping” and “Sales” module example, I would have a shipping controller and a sales controllers for each of the respective modules. If the notion of “customer” is roughly the same in both modules then this notion of customer can be abstracted out into an Angular customer service which can then be used by both modules via dependency injection. While I keep the view-models and views together by functionality, I tend to keep the models (ie services) all together in the services folder just because they can be are used in more than one module.
In my opinion, the folder organisation as laid out in the Angular project template ng-boilerplate (https://github.com/joshdmiller/ng-boilerplate) works out well for a stable structure for the long run.
But in any case, I guess it all comes down to personal preference.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment