Angular course · Module 3: Modules
Code Organization in Large Projects
In this lesson3
In large projects, organization is key - just like in the shogun's army, everyone must know their place.
Barrel Exports (index.ts)
// features/samurai/index.ts
export * from './samurai.component';
export * from './samurai.service';
export * from './samurai.model';
export * from './components/samurai-card.component';
// Usage - one import instead of many
import {
SamuraiComponent,
SamuraiService,
SamuraiCardComponent
} from './features/samurai';Naming Conventions
feature.component.ts # Component
feature.component.html # Template
feature.component.scss # Styles
feature.component.spec.ts # Tests
feature.service.ts # Service
feature.guard.ts # Guard
feature.directive.ts # Directive
feature.pipe.ts # Pipe
feature.module.ts # Module (legacy)
feature.routes.ts # Routes (standalone)Best Practices
- One component = one directory (with related files)
- Group by functionality, not by type
- Use barrel exports for clean imports
- Core for singletons, Shared for reusable elements
- Lazy loading for feature modules
- Maximum 400 lines per component file
Spotted a mistake in this lesson?
Check yourself
Answer the questions from this lesson. Pick an answer to see right away whether it is correct.
1. What is a 'barrel export' in the context of Angular code organization?
2. Which code organization principle is recommended in large Angular projects?
These are 2 of 3 questions for this lesson. Solve the rest in the game.
Hands-on tasks in the game
- Horizontal ordering
Arrange the tokens of a barrel export line re-exporting everything from a component file:
- Vertical ordering
Order the files of a typical component directory (component, template, styles, tests):
- Click in order
Click the elements in order to build the start of a barrel export: export * from