w3resource

Angular workspace and project file structure

A workspace can be defined as a collection of files for one or more projects. A collection of projects makes up a work space.

A project is the set of files that comprise a standalone application, a library or package, or a set of end-to-end tests.

In the creation of an Angular application, the Angular CLI command `ng new <project_name>` gets us started. When we run this command, the CLI installs the necessary Angular npm packages and other dependencies in a new workspace, with a root folder named project_name.

It also creates the following workspace and starter project files:

  • An initial skeleton app project (in the src/ subfolder).
  • An end-to-end test project (in the e2e/ subfolder).
  • Related configuration files.

The initial app project contains a simple welcome app, ready to run.

In this tutorial, we will explore the Angular file structure and the functions of some of these configuration files.

Workspace files

The top level of the workspace contains a series of workspace-wide configuration files.

Workspace Configuration Files Purpose of the configuration file
.editorconfig Configuration for code editors.
.gitignore Specifies intentionally untracked files that Git should ignore.
angular.json CLI configuration defaults for all projects in the workspace, including configuration options for build, serve, and test tools
that the CLI uses, such as TSLint, Karma, and Protractor.
node_modules Provides npm packages to the entire workspace.
package.json Configures and keeps track of npm package dependencies that are available to all projects in the workspace.
package-lock.json Provides version information for all packages installed into node_modules by the npm client. If you use the yarn client,
this file will be yarn.lock instead.
tsconfig.json Default TypeScript configuration for applications in the workspace, including TypeScript and Angular template compiler options.
tslint.json Default TSLint configuration for apps in the workspace.
README.md Introductory documentation for the application

Default app project files

The CLI command `ng new my-app` creates a workspace folder named "my-app" and generates a new app skeleton. This initial app is the default app for CLI commands (unless you change the default after creating additional apps).

A newly generated app contains the source files for a root module, with a root component and template. When the workspace file structure is in place, you can use the `ng generate command` on the command line to add functionality and data to the initial app.

Besides using the CLI on the command line, you can also use an interactive development environment like Angular Console, or manipulate files directly in the app's source folder and configuration files.

The src/ subfolder contains the source files (app logic, data, and assets), along with configuration files for the initial app. Workspace-wide node_modules dependencies are visible to this project.

Application Source and
Configuration Files
Purpose of the configuration files
.app/ Contains the component files in which your app logic and data are defined.
.assets/ Contains image files and other asset files to be copied as-is when you build your application.
environments/ Contains build configuration options for particular target environments. By default, there is an unnamed standard development environment and
a production ("prod") environment. You can define additional target environment configurations.
browserslist Configures sharing of target browsers and Node.js versions among various front-end tools.
favicon.ico An icon to use for this app in the bookmark bar.
index.html The main HTML page that is served when someone visits your site. The CLI automatically adds all JavaScript and CSS files when building your app,
so you typically don't need to add any <script> or<link> tags here manually.
main.ts The main entry point for your app. Compiles the application with the JIT compiler and bootstraps the application's root module (AppModule) to run in the browser.
You can also use the AOT compiler without changing any code by appending the -–aot flag to the CLI build and serve commands.
polyfills.ts Provides polyfill scripts for browser support.
styles.sass Lists CSS files that supply styles for a project. The extension reflects the style preprocessor you have configured for the project.
test.ts The main entry point for your unit tests, with some Angular-specific configuration. You don't typically need to edit this file.
tsconfig.app.json Inherits from the workspace-wide tsconfig.json file.
tsconfig.spec.json Inherits from the workspace-wide tsconfig.json file.
tslint.json Inherits from the workspace-wide tslint.json file.

Default app project e2e files

An e2e/ subfolder contains configuration and source files for a set of end-to-end tests that correspond to the initial app. Workspace-wide node_modules dependencies are visible to this project.

my-app/
  e2e/(end-to-end test app for my-app)
  	src/(app source files)
    	protractor.conf.js(test-tool config)
    	tsconfig.e2e.json(TypeScript config inherits from workspace tsconfig.json)

App source folder

Inside the src/ folder, the app/ folder contains your app's logic and data. Angular components, templates, and styles go here. An assets/ subfolder contains images and anything else your app needs. Files at the top level of src/ support testing and running your app.

App Source Files Functions of the source files
.app/app.component.ts Defines the logic for the app's root component, named AppComponent. The view associated with this root component
becomes the root of the view hierarchy as you add components and services to your app.
.app/app.component.html Defines the HTML template associated with the root AppComponent.
app/app.component.css Defines the base CSS stylesheet for the root AppComponent.
app/app.component.spec.ts Defines a unit test for the root AppComponent.
app/app.module.ts Defines the root module, named AppModule, that tells Angular how to assemble the application. Initially declares only the AppComponent.
As you add more components to the app, they must be declared here.
assets/* Contains image files and other asset files to be copied as-is when you build your application.

Previous: Getting started with Angular
Next: Architecture Overview