title: How to modularize AngularJS applications / plugins
body: <p>I have a couple of (software-)architecture questions regarding a migration from Grails (REST-API, parts of AngularJS, MongoDB, Tomcat, Spock, several plugins) to Node.js + Angular.js.
  I probably have to explain the structure of the Grails project fist, so here we go:</p>
  
  <p>There is a main Grails application (beside a couple of other applications), which is built on several plugins. Each of these plugins is able to get executed by itself - that means it has its own UI, individual templates, services, controllers, routes, tests etc. It is also hosted on different repositories. 
  This is done by the Grails plugin mechanisms. The benefits are less testing-efforts, less compiling time, modularization, single responsibilities and so on.</p>
  
  <p>But still, the time to compile and test are too expensive. Also I don't like the fact that the API delivers parts of the templates/views. I would like to have the backend APIs "just to be backend APIs" and the frontend "just to be the frontend".
  So each AngularJS application/plugin will provide its own view, routes, service etc. But they might also depend on other plugins.</p>
  
  <p>So what I would like to achieve is as follow:</p>
  
  <ul>
  <li>One main AngularJS application, which includes several plugins (a plugin can be something like a report-generator, a guestbook or whatsoever, speaking of a single independent part of an application, either with a specific route, or just a small part of the page).</li>
  <li>Each plugin must be a stand-alone AngularJS application (probably executable during development via grunt or so). So that the UI developer does not need to start the whole backend application, further that we may run functional tests only with JavaScript</li>
  <li>Communication only via REST, The frontend must retrieve all it's data from the APIs</li>
  <li>Each plugin must be testable on its own</li>
  <li>A Plugin might require other plugins to work</li>
  <li>The main index.html (and app.js?) might be provided by a Nginx server, which is decoupled from the rest of the backend (API)</li>
  </ul>
  
  <p>Though I have a specific picture in my head, I am struggling in how to setup this architecture.</p>
  
  <p>In Grails the plugin mechanisms are somehow merging the plugin dependant settings (like URL mappings, dependencies, etc) to the main application in which they get included/injected - this is what I want to achieve with AngularJS as well. So:</p>
  
  <ul>
  <li>Are there some kind of same mechanisms for AngularJS?</li>
  <li>How may I provide/merge the routes of each plugin into the main application?</li>
  <li>How can I declare application- and plugin-dependencies?</li>
  <li>What tools might be usefull for the build process?</li>
  <li>How to establish lazy-retrievments of the plugin-resources (css/less files, views, services etc)?</li>
  <li>Prevent the application to provide all resources of the plugins on startup (I guess the routes are required on startup though)</li>
  </ul>
  
  <p>Since this is not just a how-to-do-this-or-that question I excuse myself if I am missing important parts or if some parts are not clear enough. Just ask me and I will answer each question in depths.</p>