Skip to content

Instantly share code, notes, and snippets.

@demisx
Last active July 14, 2023 14:07
Show Gist options
  • Save demisx/cbbf605db31e7c9f5cf6 to your computer and use it in GitHub Desktop.
Save demisx/cbbf605db31e7c9f5cf6 to your computer and use it in GitHub Desktop.
AngularAtom--Component-based organization for AngularJS 1.x apps. Read more on AngularAtom organization at http://demisx.github.io/angularjs/atom/component-feature-based-organization/2014/12/02/angular-1-component-organization-1.html

Angular application directory structure

Leverages Angular UI Router instead of core ngRoute module. UI Router allows us to organize our application interface into a state machine. Unlike the $route service in the Angular ngRoute module, which is organized around URL routes, UI-Router is organized around states, which may optionally have routes, as well as other behavior, attached.

LIFT* Organization principle:

  • L - Locating code easy
  • I - Identify code at a glance
  • F - Flat structure as long as we can
  • T - Try to stay DRY

*The term was originially coined by John Papa.

[app-name]/ # app root directory
|--_build/ # output build directory for gulp-processed files
|__app/ # container for all user-generated app code
| |__components/ # stateless components (e.g. features, shared UI widgets, shared services etc.)
| | |__[component-1] # component 1, e.g `auth`, `profile`, `dashboard` etc.
| | | |__index.js # module definition and dependencies
| | | |__config.js # component specific configuration
| | | |__[animation-name]-animation.js # component specific animation
| | | |__[animation-name]-animation.spec.js # animation unit test
| | | |__[filter-name]-filter.js # component specific filter
| | | |__[filter-name]-filter.spec.js # filter unit test
| | | |__[directive-name].html # directive template
| | | |__[directive-name]-directive.js # component specific directive (can be a UI widget)
| | | |__[directive-name]-directive.spec.js # directive unit test
| | | |__[model-name]-model.js # component specific model
| | | |__[model-name]-model.spec.js # model unit test
| | | |__[service-name]-service.js # component specific service
| | | |__[service-name]-service.spec.js # service unit test
| | | |__[component-1].{scss|less} # component specific CSS
| | | |__[image-name].{png|gif|jpg} # component specific images
| | | |__data/ # component specific JSON data files and related assets
| | | |__i18n/ # resource files with locale specific localization rules for this component
| | | | |__en-US/
| | | | | |__[resource-name-1].json
| | | | | |__[resource-name-2].json
| | | | | |__...
| | | | |__fr-FR/
| | | | |__...
| | | |
| | | |__vendor/ # 3rd party libraries used by this component
| | | |__[sub-component-1.1]/ # sub-component of component 1, e.g. `signin` or `signout`
| | | |__index.js # subcomponent module definition and dependencies
| | | |__config.js # subcomponent specific config
| | | |__[animation-name]-animation.js # subcomponent specific animation
| | | |__... # same structure as `component-1`, except `app.js` module definition
| | |__[component-2] # component 2, e.g. `video-player`, `analytics`, etc.
| | | |__...
| | |__helpers/ # a collection of various utilities not specific to any component, usually implemented as JS pure functions
| | |__index.js
| | |__checkmark-filter.js
| | |__checkmark-filter.spec.js
| | |__string-parser-service.js
| | |__string-parser-service.spec.js
| | |__...
| |
| |__layouts/ # layout specific partials
| | |__default.html # default application layout
| | |__home.html # home page layout, if different from default
| | |__public.html # public section layout, if different from default
| | |__secure.html # secure section layout, if different from default
| | |__...
| |
| |__states/ # application UI states (can be 'routes/' if a concept of states is not used)
| | |__[ui-state-1]/ # ui state 1
| | | |__index.js # state module definition and dependencies
| | | |__config.js # state specific config
| | | |__config.spec.js # state config unit test
| | | |__[view-name]-controller.js # state controller
| | | |__[view-name]-controller.spec.js # state controller unit test
| | | |__[view-name].html # state view partial
| | | |__[ui-state-1].scss # state specific CSS
| | | |__[image-name].{png|gif|jpg} # state specific image(s)
| | | |__i18n/ # resource files with locale specific localization rules for this state
| | | |__[ui-state-1.1]/ # child ui state 1.1
| | | |__index.js # child state module definition and dependencies
| | | |__config.js # child state specific config
| | | |__config.spec.js # child state config unit test
| | | |__[ui-state-1.1]-controller.js # child state controller
| | | |__[ui-state-1.1]-controller.spec.js # child state controller unit test
| | | |__[view-name].html # child state view partial
| | | |__[ui-state-1.1].scss # child state specific CSS
| | | |__[image-name].{png|gif|jpg} # child state specific image(s)
| | | |__i18n/ # resource files with locale specific localization rules for this state
| | |__[ui-state-2]/ # ui state 2
| | |__...
| |
| |__app.js # global app module definition and dependencies
| |__config.js # global app configuration
| |__index.html # application bootstrap entry page
|
|__bower_components/ # 3rd party vendor client libraries global to the entire app
| |__angular/
| |__angular-animate/
| |__font-awesome/
| |__lo-dash/
| |__...
|
|__config/ # global project-wide config files not relevant to any existing folder, if any
|
|__node_modules/ # 3rd party vendor node.js modules global to the entire app
| |__chai/
| |__gulp/
| |__gulp-grep/
| |__...
|
|__scripts/ # shell executable and config scripts
| |__...
|
|__specs/
| |__e2e/ # end-to-end specs
| | |__helpers/ # e2e specific helpers
| | |__page-objects/ # collection of page objects
| | | |__[page-object-name].js # page object
| | | |__...
| | |__[spec-name-describing-feature].js # e2e test
| | |__protractor.config.js # protractor config file
| | |__...
| |
| |__unit/
| |__helpers/ # unit test specific helpers
| | |__matchers.js # customer matchers
| | |__state-test-helpers.js # helper functions for testing UI router states
| |__karma.config.js # karma config file
| |__karma.setup.js # karma global vars and requires
| |__...
|
|__bower.json
|__gulpfile.json
|__package.json
|__README.md
|__...
[app-name]/ # app root directory
|--_build/ # output build directory for gulp-processed files
|__app/ # container for all user-generated app code
|__bower_components/ # 3rd party vendor client libraries global to the entire app
|__config/ # global project-wide config files not relevant to any existing folder, if any
|__node_modules/ # 3rd party vendor node.js modules global to the entire app
|__scripts/ # shell executable and config scripts
|__specs/
| |__e2e/ # end-to-end specs
| | |__helpers/ # e2e specific helpers
| | |__page-objects/ # collection of page objects
| | | |__[page-object-name].js # page object
| | | |__...
| | |__[spec-name-describing-feature].js # e2e test
| | |__protractor.config.js # protractor config file
| | |__...
| |
| |__unit/
| |__helpers/ # unit test specific helpers
| | |__matchers.js # customer matchers
| | |__state-test-helpers.js # helper functions for testing UI router states
| |__karma.config.js # karma config file
| |__karma.setup.js # karma global vars and requires
| |__...
|
|__bower.json
|__gulpfile.json
|__package.json
|__README.md
|__...
[app-name]/
...
|__app/ # container for all user-generated application code
| |__components/ # stateless components (e.g. features, shared UI widgets, shared services etc.)
| |__layouts/ # layout specific partials
| |__states/ # application states (can be 'routes/' if a concept of states is not used)
| |__app.js # global app module definition and dependencies
| |__config.js # global app configuration
| |__index.html # application bootstrap entry page
...
[app-name]/
...
|__app/
| |__components/ # stateless components (e.g. features, shared UI widgets, shared services etc.)
| | |__[component-1] # component 1, e.g `auth`, `profile`, `dashboard` etc.
| | | |__index.js # module definition and dependencies
| | | |__config.js # component specific configuration
| | | |__[animation-name]-animation.js # component specific animation
| | | |__[animation-name]-animation.spec.js # animation unit test
| | | |__[filter-name]-filter.js # component specific filter
| | | |__[filter-name]-filter.spec.js # filter unit test
| | | |__[directive-name].html # directive template
| | | |__[directive-name]-directive.js # component specific directive (can be a UI widget)
| | | |__[directive-name]-directive.spec.js # directive unit test
| | | |__[model-name]-model.js # component specific model
| | | |__[model-name]-model.spec.js # model unit test
| | | |__[service-name]-service.js # component specific service
| | | |__[service-name]-service.spec.js # service unit test
| | | |__[component-1].{scss|less} # component specific CSS
| | | |__[image-name].{png|gif|jpg} # component specific images
| | | |__data/ # component specific JSON data files and related assets
| | | |__i18n/ # resource files with locale specific localization rules for this component
| | | | |__en-US/
| | | | | |__[resource-name-1].json
| | | | | |__[resource-name-2].json
| | | | | |__...
| | | | |__fr-FR/
| | | | |__...
| | | |
| | | |__vendor/ # 3rd party librariess used by this component
| | | |__[sub-component-1.1]/ # sub-component of component 1, e.g. `signin` or `signout`
| | | |__index.js # subcomponent module definition and dependencies
| | | |__config.js # subcomponent specific config
| | | |__[animation-name]-animation.js # subcomponent specific animation
| | | |__... # same structure as `component-1`, except `app.js` module definition
| | |__[component-2] # component 2, e.g. `video-player`, `analytics`, etc.
| | | |__...
| | |__helpers/ # a collection of various utilities not specific to any component, usually implemented as JS pure functions
| | |__index.js
| | |__checkmark-filter.js
| | |__checkmark-filter.spec.js
| | |__string-parser-service.js
| | |__string-parser-service.spec.js
| | |__...
...
[app-name]/
...
|__app/
| |__components/
| |__layouts/ # layout specific partials
| | |__default.html # default application layout
| | |__home.html # home page layout, if different from default
| | |__public.html # public section layout, if different from default
| | |__secure.html # secure section layout, if different from default
| | |__...
...
[app-name]/
...
|__app/
| |__components/
| |__layouts/
| |__states/ # application UI states
| | |__[ui-state-1]/ # ui state 1
| | | |__index.js # state module definition and dependencies
| | | |__config.js # state specific config
| | | |__config.spec.js # state config unit tes
| | | |__[view-name]-controller.js # state controller
| | | |__[view-name]-controller.spec.js # state controller unit test
| | | |__[view-name].html # state view template
| | | |__[ui-state-1].scss # state specific CSS
| | | |__[image-name].{png|gif|jpg} # state specific image(s)
| | | |__i18n/ # resource files with locale specific localization rules for this state
| | | |__[ui-state-1.1]/ # child ui state 1.1
| | | |__index.js # child state module definition and dependencies
| | | |__config.js # child state specific config
| | | |__config.spec.js # child state unit test
| | | |__[ui-state-1.1]-controller.js # child state controller
| | | |__[ui-state-1.1]-controller.spec.js # child state controller unit test
| | | |__[view-name].html # child state view template
| | | |__[ui-state-1.1].scss # child state specific CSS
| | | |__[image-name].{png|gif|jpg} # child state specific image(s)
| | | |__i18n/ # resource files with locale specific localization rules for this state
| | |__[ui-state-2]/ # ui state 2
| | |__...
...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment