{ "id": "guide/file-structure", "title": "Workspace and project file structure", "contents": "\n\n\n
\n mode_edit\n
\n\n\n
\n

Workspace and project file structurelink

\n

You develop applications in the context of an Angular workspace. A workspace contains the files for one or more projects. A project is the set of files that comprise a standalone application or a shareable library.

\n

The Angular CLI ng new command creates a workspace.

\n\nng new <my-project>\n\n

When you run this command, the CLI installs the necessary Angular npm packages and other dependencies in a new workspace, with a root-level application named my-project.\nThe workspace root folder contains various support and configuration files, and a README file with generated descriptive text that you can customize.

\n

By default, ng new creates an initial skeleton application at the root level of the workspace, along with its end-to-end tests.\nThe skeleton is for a simple Welcome application that is ready to run and easy to modify.\nThe root-level application has the same name as the workspace, and the source files reside in the src/ subfolder of the workspace.

\n

This default behavior is suitable for a typical \"multi-repo\" development style where each application resides in its own workspace.\nBeginners and intermediate users are encouraged to use ng new to create a separate workspace for each application.

\n

Angular also supports workspaces with multiple projects.\nThis type of development environment is suitable for advanced users who are developing shareable libraries,\nand for enterprises that use a \"monorepo\" development style, with a single repository and global configuration for all Angular projects.

\n

To set up a monorepo workspace, you should skip the creating the root application.\nSee Setting up for a multi-project workspace below.

\n

Workspace configuration fileslink

\n

All projects within a workspace share a CLI configuration context.\nThe top level of the workspace contains workspace-wide configuration files, configuration files for the root-level application, and subfolders for the root-level application source and test files.

\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n
WORKSPACE CONFIG FILESPURPOSE
.editorconfigConfiguration for code editors. See EditorConfig.
.gitignoreSpecifies intentionally untracked files that Git should ignore.
README.mdIntroductory documentation for the root app.
angular.jsonCLI 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. For details, see Angular Workspace Configuration.
package.jsonConfigures npm package dependencies that are available to all projects in the workspace. See npm documentation for the specific format and contents of this file.
package-lock.jsonProvides version information for all packages installed into node_modules by the npm client. See npm documentation for details. If you use the yarn client, this file will be yarn.lock instead.
src/Source files for the root-level application project.
node_modules/Provides npm packages to the entire workspace. Workspace-wide node_modules dependencies are visible to all projects.
tsconfig.jsonThe base TypeScript configuration for projects in the workspace. All other configuration files inherit from this base file. For more information, see the Configuration inheritance with extends section of the TypeScript documentation.
tslint.jsonDefault TSLint configuration for projects in the workspace.
\n

Application project fileslink

\n

By default, the CLI command ng new my-app creates a workspace folder named \"my-app\" and generates a new application skeleton in a src/ folder at the top level of the workspace.\nA newly generated application contains source files for a root module, with a root component and template.

\n

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 application.\nThis initial root-level application is the default app for CLI commands (unless you change the default after creating additional apps).

\n
\n

Besides using the CLI on the command line, you can also manipulate files directly in the app's source folder and configuration files.

\n
\n

For a single-application workspace, the src/ subfolder of the workspace contains the source files (application logic, data, and assets) for the root application.\nFor a multi-project workspace, additional projects in the projects/ folder contain a project-name/src/ subfolder with the same structure.

\n

Application source fileslink

\n

Files at the top level of src/ support testing and running your application. Subfolders contain the application source and application-specific configuration.

\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n
APP SUPPORT FILESPURPOSE
app/Contains the component files in which your application logic and data are defined. See details below.
assets/Contains image 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.
favicon.icoAn icon to use for this application in the bookmark bar.
index.htmlThe 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.tsThe main entry point for your application. 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.tsProvides polyfill scripts for browser support.
styles.sassLists CSS files that supply styles for a project. The extension reflects the style preprocessor you have configured for the project.
test.tsThe main entry point for your unit tests, with some Angular-specific configuration. You don't typically need to edit this file.
\n
\n

If you create an application using Angular's strict mode, you will also have an additional package.json file in the src/app directory. For more information, see Strict mode.

\n
\n\n

Inside the src/ folder, the app/ folder contains your project's logic and data.\nAngular components, templates, and styles go here.

\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n
src/app/ FILESPURPOSE
app/app.component.tsDefines 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 application.
app/app.component.htmlDefines the HTML template associated with the root AppComponent.
app/app.component.cssDefines the base CSS stylesheet for the root AppComponent.
app/app.component.spec.tsDefines a unit test for the root AppComponent.
app/app.module.tsDefines 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.
\n

Application configuration fileslink

\n

The application-specific configuration files for the root application reside at the workspace root level.\nFor a multi-project workspace, project-specific configuration files are in the project root, under projects/project-name/.

\n

Project-specific TypeScript configuration files inherit from the workspace-wide tsconfig.json, and project-specific TSLint configuration files inherit from the workspace-wide tslint.json.

\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n
APPLICATION-SPECIFIC CONFIG FILESPURPOSE
.browserslistrcConfigures sharing of target browsers and Node.js versions among various front-end tools. See Browserslist on GitHub for more information.
karma.conf.jsApplication-specific Karma configuration.
tsconfig.app.jsonApplication-specific TypeScript configuration, including TypeScript and Angular template compiler options. See TypeScript Configuration and Angular Compiler Options.
tsconfig.spec.jsonTypeScript configuration for the application tests. See TypeScript Configuration.
tslint.jsonApplication-specific TSLint configuration.
\n

End-to-end test fileslink

\n

An e2e/ folder at the top level contains source files for a set of end-to-end tests that correspond to the root-level application, along with test-specific configuration files.

\n

For a multi-project workspace, application-specific end-to-end tests are in the project root, under projects/project-name/e2e/.

\n\n e2e/\n src/ (end-to-end tests for my-app)\n app.e2e-spec.ts\n app.po.ts\n protractor.conf.js (test-tool config)\n tsconfig.json (TypeScript config inherits from workspace)\n\n\n

Multiple projectslink

\n

A multi-project workspace is suitable for an enterprise that uses a single repository and global configuration for all Angular projects (the \"monorepo\" model). A multi-project workspace also supports library development.

\n

Setting up for a multi-project workspacelink

\n

If you intend to have multiple projects in a workspace, you can skip the initial application generation when you create the workspace, and give the workspace a unique name.\nThe following command creates a workspace with all of the workspace-wide configuration files, but no root-level application.

\n\nng new my-workspace --create-application false\n\n

You can then generate apps and libraries with names that are unique within the workspace.

\n\ncd my-workspace\nng generate application my-first-app\n\n

Multiple project file structurelink

\n

The first explicitly generated application goes into the projects/ folder along with all other projects in the workspace.\nNewly generated libraries are also added under projects/.\nWhen you create projects this way, the file structure of the workspace is entirely consistent with the structure of the workspace configuration file, angular.json.

\n\nmy-workspace/\n ... (workspace-wide config files)\n projects/ (generated applications and libraries)\n my-first-app/ --(an explicitly generated application)\n ... --(application-specific config)\n e2e/ ----(corresponding e2e tests)\n src/ ----(e2e tests source)\n ... ----(e2e-specific config)\n src/ --(source and support files for application)\n my-lib/ --(a generated library)\n ... --(library-specific config)\n src/ --source and support files for library)\n\n

Library project fileslink

\n

When you generate a library using the CLI (with a command such as ng generate library my-lib), the generated files go into the projects/ folder of the workspace. For more information about creating your own libraries, see Creating Libraries.

\n

Libraries (unlike applications and their associated e2e projects) have their own package.json configuration files.

\n

Under the projects/ folder, the my-lib folder contains your library code.

\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n
LIBRARY SOURCE FILESPURPOSE
src/libContains your library project's logic and data. Like an application project, a library project can contain components, services, modules, directives, and pipes.
src/test.tsThe main entry point for your unit tests, with some library-specific configuration. You don't typically need to edit this file.
src/public-api.tsSpecifies all files that are exported from your library.
karma.conf.jsLibrary-specific Karma configuration.
ng-package.jsonConfiguration file used by ng-packagr for building your library.
package.jsonConfigures npm package dependencies that are required for this library.
tsconfig.lib.jsonLibrary-specific TypeScript configuration, including TypeScript and Angular template compiler options. See TypeScript Configuration.
tsconfig.spec.jsonTypeScript configuration for the library tests. See TypeScript Configuration.
tslint.jsonLibrary-specific TSLint configuration.
\n\n \n
\n\n\n" }