Project Structure
Project Structure
Section titled βProject StructureβWhat it means
Section titled βWhat it meansβAn Angular CLI-generated project follows a conventional layout: application code lives in src/app/, static assets in src/assets/, and each component/service/pipe typically gets its own folder or file group (.ts, .html, .css, .spec.ts). Modern Angular favors a feature-based structure β grouping files by what they do (e.g. orders/, users/) rather than by file type (all components in one folder, all services in another).
Examples
Section titled βExamplesβsrc/βββ app/β βββ app.component.tsβ βββ app.config.ts # providers, routes (standalone app setup)β βββ core/ # singleton services, guards, interceptorsβ β βββ auth.service.tsβ βββ shared/ # reusable components/pipes used across featuresβ β βββ loading-spinner.component.tsβ βββ features/β βββ users/β β βββ user-list.component.tsβ β βββ user-list.component.htmlβ β βββ user-list.component.cssβ β βββ user-list.component.spec.tsβ β βββ user.service.tsβ βββ orders/β βββ order-list.component.tsβββ assets/ # images, fonts, static filesβββ environments/ # environment.ts, environment.prod.tsβββ index.htmlβββ main.ts # bootstraps the appβββ styles.css # global stylesCommon mistake
Section titled βCommon mistakeβDumping every component into one flat components/ folder as the app grows β this works fine for small apps, but quickly becomes hard to navigate, since related files (a featureβs component, service, and tests) end up scattered rather than grouped together.
# Grows painfully as the app scalessrc/app/components/βββ user-list.component.tsβββ order-list.component.tsβββ product-list.component.tsβββ ... (50 more components, no grouping)
# Feature-based grouping keeps related files togethersrc/app/features/βββ users/ (user-list.component.ts, user.service.ts, ...)βββ orders/ (order-list.component.ts, order.service.ts, ...)Quick practice
Section titled βQuick practiceβ-
Where does the bulk of an Angular applicationβs code live in the default CLI structure?
Answer
src/app/. -
Whatβs the difference between organizing by βfeatureβ versus by βfile typeβ?
Answer
Feature-based grouping keeps everything related to one part of the app (component, service, tests) together in one folder; type-based grouping puts all components in one folder, all services in another, scattering related files as the app grows. -
Whatβs a common purpose for a
core/folder in a feature-based Angular project?Answer
Singleton, app-wide concerns like authentication services, HTTP interceptors, and route guards β things meant to be used once across the whole app, not per-feature.