How to generate a module in Angular

Creating modules is essential for organizing Angular applications into logical feature groups, enabling lazy loading, and maintaining clean architecture in large-scale applications. As the creator of CoreUI, a widely used open-source UI library, I’ve organized countless Angular applications into feature modules for better maintainability, team collaboration, and performance optimization in enterprise projects. From my expertise, the most effective approach is to use Angular CLI’s ng generate module command with proper routing and feature organization. This method creates well-structured modules with proper imports, exports, and routing configuration for scalable application architecture.

Use ng generate module command to create feature modules with proper organization and routing setup.

ng generate module features/user --routing
ng generate module shared
ng generate module core

The ng generate module command creates a new NgModule with proper TypeScript class structure and Angular decorators. Use the --routing flag to automatically generate a routing module for feature modules that need their own routes. Organize modules by feature (user, product, dashboard) or by purpose (shared for common components, core for singletons). The generated module includes imports, declarations, exports arrays and can be configured for lazy loading. Angular CLI automatically updates the app module imports when needed.

Best Practice Note:

This is the same approach we use in CoreUI Angular projects for organizing complex enterprise applications. Create feature modules for distinct application areas, shared modules for reusable components, and core modules for singleton services. Use --routing for feature modules and configure lazy loading in the main routing module for better performance.


Speed up your responsive apps and websites with fully-featured, ready-to-use open-source admin panel templates—free to use and built for efficiency.


About the Author