Angular directory structure for large projects

I have spent a lot of time organizing the directory structure of my Angular 2 / 4 project to achieve the following:
  1. Developing new sections with ease by adding lazy loaded modules.
  2. Keeping modules organized in a single folder.
  3. Separating public and secure layouts and their related code
  4. Organizing global and re-usable assets
  5. Having lots of granularity with many files (not putting all the code in a single file, that's Webpack's job)
I run my Angular projects using a full MEAN stack on Heroku from a single project. I have omitted all the Express/Mongo (server-side code) to focus on Angular directory structure. I currently run 3 public modules and 9 secure modules in production and feel like this will scale nicely as my project grows:

config/
-----cluster.js   // Process Forking Support for NodeJs
-----express.js   // Express.js Setup
-----settings.js  // Server side settings from ENV vars and other defaults.
-----web.js    // Main entry point 
-----webpack.config.js // Webpack Setup
-----webpack.helpers.js // Support functions for Webpack
dist/ // Output build directory
node_modules/ // Auto generated
typings/ // Auto generated
src/
-----app/
----------public/    // Public modules that get lazy loaded
---------------styles/    // Styles for public layout
-------------------public.header.styles.css
---------------section1/   // Lazy loaded section 1
-------------------public.section1.component.html
-------------------public.section1.component.ts
-------------------public.section1.module.ts
-------------------public.section1.styles.css
---------------section2/   // Lazy loaded section 2
-------------------secure.section2.component.html
-------------------secure.section2.component.ts
-------------------secure.section2.module.ts
-------------------secure.section2.styles.css
---------------public.component.html // Layout for Public section
---------------public.component.ts  // Public Component
---------------public.guard.ts   // Auth Guard for the public section
---------------public.routing.ts  // Define Lazy Loaded chlidren routes
----------secure/    // Secure modules that get lazy loaded
---------------styles/    // Styles for secure layout
-------------------secure.header.styles.css
---------------section1/   // Lazy loaded section 1
-------------------secure.section1.component.html
-------------------secure.section1.component.ts
-------------------secure.section1.module.ts
-------------------secure.section1.styles.css
---------------section2/   // Lazy loaded section 2
-------------------secure.section2.component.html
-------------------secure.section2.component.ts
-------------------secure.section2.module.ts
-------------------secure.section2.styles.css
---------------secure.component.html // Layout for secure section
---------------secure.component.ts  // Public Component
---------------secure.guard.ts   // Auth Guard for the secure section
---------------secure.routing.ts  // Define Lazy Loaded chlidren routes
----------shared/    // Shared code / assets
---------------components/   // Shared custom made components
-------------------barchart/ 
-------------------dateranepicker/ 
---------------images/      // Shared images
-------------------logo.png 
-------------------favicon.png
-------------------spinner.png
---------------models/      // Shared classes
-------------------common.ts
-------------------grid.ts
---------------modules/      // Shared modules
-------------------shared.global.module.ts
---------------pipes/      // Shared custom pipes
-------------------filterBy.pipe.ts
-------------------orderBy.pipe.ts 
---------------services/     // Shared services
-------------------auth.service.ts
-------------------user.service.ts 
-------------------version.service.ts 
---------------styles/      // Global styles
-------------------app.alerts.styles.css
-------------------app.table.styles.css 
----------app.component.html // Main app html template: router-outlet and global toaster container.
----------app.component.ts  // Main app component: loads global styles, watches version updates, watches for toasts and renders them.
----------app.config.ts   // Global static config variables to be re-used in various services/modules.
----------app.module.ts   // Global module, doesnt do much
----------app.routing.ts  // Global routing module: sets up public, shared, default routes, auth guards, handles route changing events
-----main.html // Shell for the app, Webpack inserts assets in there.
-----main.ts // Angular Main App Module Bootstrap
-----vendors.ts // Includes all the main 3rd party libraries that dont change frequently so that Webpack puts them all in a single chunk.
.gitignore
package.json
tsconfig.json
typings.json

Comments

  1. Great blog about angular and this coding clearly explain the concept. Share more updates.
    Angular 4 Training in Chennai | Angularjs Training center in Chennai

    ReplyDelete
  2. thanks a lot for shraing guys..I got wonderful information from this blog. Thanks for sharing this post. it becomes easy to read and understand the information..this viderman page nice.
    AngularJS training in chennai | AngularJS training in anna nagar | AngularJS training in omr | AngularJS training in porur | AngularJS training in tambaram | AngularJS training in velachery

    ReplyDelete
  3. Process Lasso Pro Crack is a powerful process priority optimizer for Windows. It provides real-time CPU optimization and automation.process lasso Pro 11.1.0.34 Crack

    ReplyDelete
  4. APTRON Solutions is a leading training institute that offers top-notch AngularJS Course in Gurgaon . AngularJS from the best training institute in Gurgaon. Take the first step towards a successful career in web development by enrolling in our AngularJS course at APTRON Solutions. To know more about the course details, batch timings, and fees, visit our website or contact us today. Upgrade your skills with APTRON Solutions and unlock a world of exciting career opportunities in AngularJS development.

    ReplyDelete
  5. Unlock the full potential of JavaScript with APTRON Gurgaon's comprehensive NodeJs Course in Gurgaon. Designed for both beginners and experienced developers, this course provides hands-on training in building scalable, fast, and real-time web applications. Whether you are looking to enhance your skillset or start a career in backend development, APTRON Gurgaon ensures you are industry-ready with expert guidance and practical exposure.

    ReplyDelete

Post a Comment

Popular posts from this blog

Selenium on Heroku

Angular reload page when new version is deployed