Skip to main content

Workspace structure

When you create a new Angular workspace with ng new, the CLI generates the following structure:

Root configuration files

The workspace root contains essential configuration files for your project.

angular.json

The workspace configuration file defines build, serve, and test configurations:
angular.json
Key sections:
  • projects: Contains configuration for each application or library
  • architect: Defines builders for different tasks (build, serve, test)
  • options: Specifies paths, assets, styles, and build settings

package.json

The npm configuration file lists dependencies and scripts:
package.json
Key sections:
  • scripts: Convenient commands to run CLI commands
  • dependencies: Runtime packages required by your application
  • devDependencies: Development tools and build packages
Use npm start as a shortcut for ng serve to start the development server.

TypeScript configuration files

Angular uses multiple TypeScript configuration files for different contexts.

tsconfig.json

The base TypeScript configuration:
tsconfig.json
Important options:
  • experimentalDecorators: Enables decorators like @Component
  • module: Specifies module system (ES2022)
  • target: JavaScript version for output (ES2022)
  • strictTemplates: Enables strict type checking in templates

tsconfig.app.json

Extends base configuration for application builds:
tsconfig.app.json

tsconfig.spec.json

Configuration for test files:
tsconfig.spec.json

Other root files

.editorconfig

Defines consistent coding styles across different editors:
.editorconfig

.gitignore

Specifies files and directories Git should ignore:
.gitignore

Source directory (src/)

The src/ directory contains your application code and assets.

src/index.html

The main HTML page that hosts your Angular application:
src/index.html
The <app-root> element is where Angular inserts your application.

src/main.ts

The application entry point that bootstraps the Angular application:
src/main.ts
This file:
  • Imports the platform browser module
  • Imports the root application module
  • Bootstraps the application to run in the browser

src/styles.css

Global styles applied across your entire application:
src/styles.css

src/assets/

Directory for static assets like images, fonts, and files:
Files in this directory are copied as-is during the build process.

App directory (src/app/)

The application source code lives in the src/app/ directory.

Component files

Each component typically consists of four files:

app.component.ts

The component class containing logic:
src/app/app.component.ts

app.component.html

The component template:
src/app/app.component.html

app.component.css

Component-specific styles:
src/app/app.component.css

app.component.spec.ts

Unit tests for the component:
src/app/app.component.spec.ts

app.module.ts

The root module that defines the application structure:
src/app/app.module.ts

Build and output directories

dist/

Generated by ng build, contains compiled application ready for deployment:

.angular/

Cache directory created by the Angular CLI to speed up builds:
Both dist/ and .angular/ directories should be added to .gitignore and not committed to version control.

Multi-project workspaces

Workspaces can contain multiple projects (applications and libraries):
Create additional applications:
Create libraries:

Next steps

Now that you understand the project structure, explore Angular’s core concepts.

Components

Build reusable UI components

Templates

Create dynamic HTML templates

Services

Share data and logic across components

Routing

Navigate between different views