Angular Workspace and Project File Structure
Angular Workspace and Project File Structure
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.
ng new <my-project>
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. The
workspace root folder contains various support and configuration files, and a README file with
generated descriptive text that you can customize.
By default, ng new creates an initial skeleton application at the root level of the workspace, along
with its end-to-end tests. The skeleton is for a simple Welcome application that is ready to run
and easy to modify. The root-level application has the same name as the workspace, and the
source files reside in the src/ subfolder of the workspace.
This default behavior is suitable for a typical "multi-repo" development style where each
application resides in its own workspace. Beginners and intermediate users are encouraged to
use ng new to create a separate workspace for each application.
Angular also supports workspaces with multiple projects. This type of development environment
is suitable for advanced users who are developing shareable libraries, and for enterprises that use
a "monorepo" development style, with a single repository and global configuration for all
Angular projects.
To set up a monorepo workspace, you should skip the creating the root application. See Setting
up for a multi-project workspace below.
WORKSPACE
PURPOSE
CONFIG FILES
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. For details, see Angular
Workspace Configuration.
tsconfig.json The 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.
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. This initial root-level application is
the default app for CLI commands (unless you change the default after creating additional apps).
Besides using the CLI on the command line, you can also manipulate files directly in the
app's source folder and configuration files.
For a single-application workspace, the src/ subfolder of the workspace contains the source files
(application logic, data, and assets) for the root application. For a multi-project workspace,
additional projects in the projects/ folder contain a project-name/src/ subfolder with the same
structure.
Application source files
Files at the top level of src/ support testing and running your application. Subfolders contain the
application source and application-specific configuration.
APP
SUPPORT PURPOSE
FILES
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.
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 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
APP
SUPPORT PURPOSE
FILES
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.
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.
Inside the src/ folder, the app/ folder contains your project's logic and data. Angular components,
templates, and styles go here.
app/app.component.css Defines the base CSS stylesheet for the root AppComponent.
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.
APPLICATION-
SPECIFIC CONFIG PURPOSE
FILES
For a multi-project workspace, application-specific end-to-end tests are in the project root,
under projects/project-name/e2e/.
content_copye2e/
app.po.ts
Multiple projects
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.
Setting up for a multi-project workspace
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. The
following command creates a workspace with all of the workspace-wide configuration files, but
no root-level application.
You can then generate apps and libraries with names that are unique within the workspace.
content_copycd my-workspace
content_copymy-workspace/
Libraries (unlike applications and their associated e2e projects) have their
own package.json configuration files.
Under the projects/ folder, the my-lib folder contains your library code.
LIBRARY
PURPOSE
SOURCE FILES
src/lib Contains your library project's logic and data. Like an application
project, a library project can contain components, services, modules,
directives, and pipes.
src/test.ts The main entry point for your unit tests, with some library-specific
configuration. You don't typically need to edit this file.
src/public-api.ts Specifies all files that are exported from your library.
package.json Configures npm package dependencies that are required for this
library.