This project was generated using Angular CLI version 21.1.0.
This project follows a scalable and maintainable folder structure designed for medium-sized Angular applications. Below is an overview of the architecture and guidelines for the team.
src/
├── environments/
├── styles/
├── app/
│ ├── core/
│ │ ├── constants/
│ │ ├── enums/
│ │ ├── guards/
│ │ ├── interceptors/
│ │ ├── models/
│ │ └── services/
│ ├── shared/
│ │ ├── components/
│ │ ├── directives/
│ │ ├── models/
│ │ ├── pipes/
│ │ ├── utils/
│ │ └── validators/
│ ├── features/
│ └── layouts/
public/
├── docs/
├── fonts/
├── icons/
├── images/
└── favicon.ico
The core folder contains singleton services and application-wide functionality that should only be instantiated once throughout the application lifecycle.
- constants/ — Application-wide constants, API endpoints, and configuration values
- enums/ — TypeScript enums for user roles, order status, payment methods, and other enumerated types
- guards/ — Route guards for authentication, authorization, and role-based access control
- interceptors/ — HTTP interceptors for handling authentication tokens, error handling, logging, and request/response transformations
- models/ — TypeScript interfaces and types that represent data structures used across the entire application
- services/ — Singleton services such as authentication service, user service, API base service, and notification service
- Services in this folder should be provided at the root level
- Never import Core module into feature modules; it should only be imported once in the main app configuration
- All HTTP interceptors must be registered in the app configuration
- Keep models generic and reusable; feature-specific models should stay in their respective feature folders
The shared folder contains reusable components, directives, pipes, and utilities that can be used across multiple feature modules.
- components/ — Reusable UI components such as buttons, modals, cards, tables, loaders, form inputs, and pagination
- directives/ — Custom attribute and structural directives for DOM manipulation
- models/ — Shared interfaces and types for UI components like pagination, dropdown options, and table columns
- pipes/ — Custom pipes for data transformation in templates
- utils/ — Helper functions, utility classes, and common logic
- validators/ — Custom form validators for reactive and template-driven forms
- Every component here must be standalone and self-contained
- Components should be highly configurable through inputs and outputs
- Avoid business logic in shared components; keep them purely presentational
- Document all inputs, outputs, and usage examples for each shared component
- Before creating a new shared component, check if one already exists that can be extended
The features folder contains all the business feature modules of the application. Each feature represents a distinct section or functionality of the e-commerce platform.
For each feature, create a subfolder with its own internal structure:
- components/ — Feature-specific components
- services/ — Feature-specific services
- models/ — Feature-specific interfaces and types
- pages/ — Route-level page components
- products/ — Product listing, details, and search
- cart/ — Shopping cart management
- checkout/ — Checkout process and payment
- orders/ — Order history and tracking
- auth/ — Login, registration, and password recovery
- user-profile/ — User account settings and preferences
- wishlist/ — Saved items and favorites
- admin/ — Admin dashboard and management
- Each feature should be self-contained and lazy-loaded for performance
- Feature modules should only import from Core and Shared, never from other features
- If multiple features need the same functionality, move it to Shared
- Keep feature routing configurations within the feature folder
- Name feature folders using kebab-case
The layouts folder contains structural layout components that define the overall page structure and navigation.
- Main application layout with header, footer, and sidebar
- Admin dashboard layout
- Authentication layout for login and registration pages
- Error page layouts
- Print-friendly layouts
- Layouts should focus on structure and navigation only
- Use router outlets within layouts for content projection
- Keep layouts minimal and delegate content to feature components
- Create separate layouts for different user experiences
The environments folder contains environment-specific configuration files for different deployment targets.
- environment.ts — Default/development environment configuration
- environment.development.ts — Development-specific settings
- environment.staging.ts — Staging environment settings
- environment.production.ts — Production environment settings
- Never commit sensitive data like API keys or secrets to environment files
- Use environment variables for sensitive configuration in CI/CD pipelines
- Keep environment files consistent in structure across all environments
- Import environment using the configured file replacement in angular.json
The styles folder contains global SCSS partials and theme configurations used throughout the application.
- _variables.scss — Colors, fonts, spacing, breakpoints, and design tokens
- _mixins.scss — Reusable SCSS mixins for common patterns
- _typography.scss — Global font styles, headings, and text utilities
- _themes.scss — Light/dark theme variables and theme switching logic
- _reset.scss — CSS reset or normalize styles
- Prefix partial files with underscore to prevent direct compilation
- Import all partials into the main styles.scss file
- Use variables for all colors and spacing to maintain consistency
- Document complex mixins with usage examples in comments
The public folder contains static assets that are served directly without processing.
- images/ — Static images like banners, backgrounds, and product placeholders
- icons/ — SVG icons and icon sets
- fonts/ — Custom font files in woff, woff2, or ttf formats
- docs/ — Static documents like PDFs, terms of service, and privacy policies
- Optimize images before adding to reduce bundle size
- Use SVG format for icons when possible for scalability
- Organize assets into appropriate subfolders
- Use descriptive file names in kebab-case
- Navigate to the features folder
- Use Angular CLI to generate a new feature module with routing
- Create the internal structure with components, services, and pages subfolders
- Configure lazy loading in the main app routes
- Import only Core and Shared dependencies as needed
- Navigate to the shared/components folder
- Use Angular CLI to generate a standalone component
- Ensure the component is generic and reusable
- Add appropriate inputs and outputs for customization
- Export the component if using a shared module approach
- Determine if the service is application-wide or feature-specific
- For global services, add to core/services
- For feature services, add to the specific feature/services folder
- Use the providedIn root option for singleton services
- Navigate to core/guards
- Use Angular CLI to generate a functional guard
- Implement the required logic for route protection
- Register the guard in the appropriate route configuration
- Navigate to core/interceptors
- Use Angular CLI to generate an interceptor
- Implement the intercept method with required logic
- Register the interceptor in the app configuration using provideHttpClient with interceptors
- Navigate to the appropriate shared folder
- Use Angular CLI to generate the pipe or directive as standalone
- Ensure it is generic and well-documented
- Export for use across features
| Element | Convention | Example |
|---|---|---|
| Components | kebab-case | product-card, user-avatar |
| Services | camelCase with Service suffix | authService, cartService |
| Guards | camelCase with Guard suffix | authGuard, roleGuard |
| Interceptors | camelCase with Interceptor suffix | authInterceptor, errorInterceptor |
| Pipes | camelCase with Pipe suffix | currencyFormatPipe |
| Directives | camelCase with Directive suffix | highlightDirective |
| Models/Interfaces | PascalCase | Product, UserProfile, OrderItem |
| Constants | UPPER_SNAKE_CASE | API_BASE_URL, DEFAULT_PAGE_SIZE |
When importing in TypeScript files, follow this order:
- Angular core and common imports
- Third-party library imports
- Core module imports
- Shared module imports
- Feature-specific imports
- Relative imports
- Always use standalone components for new development
- Implement lazy loading for all feature modules
- Keep components small and focused on a single responsibility
- Use OnPush change detection strategy where applicable
- Write unit tests alongside new components and services
- Follow the DRY principle; if code is duplicated, refactor to shared
- Use environment files for configuration values
- Document public APIs and complex logic with comments
To start a local development server, run:
ng serveOnce the server is running, open your browser and navigate to http://localhost:4200/. The application will automatically reload whenever you modify any of the source files.
To build the project run:
ng buildThis will compile your project and store the build artifacts in the dist/ directory. By default, the production build optimizes your application for performance and speed.
To execute unit tests with the Vitest test runner, use the following command:
ng testFor end-to-end (e2e) testing, run:
ng e2eAngular CLI does not come with an end-to-end testing framework by default. You can choose one that suits your needs.
For more information on using the Angular CLI, including detailed command references, visit the Angular CLI Overview and Command Reference page.