guide file structure - devonfw/devon4ng GitHub Wiki
The top-level file structure is defined by Angular CLI. You might put this "top-level file structure" into a sub-directory to facilitate your build, but this is not relevant for this guide. So the applications file structure relevant to this guide is the folder /src/app
inside the part managed by Angular CLI.
/src
βββ /app
βββ /account-management
βββ /billing
βββ /booking
βββ /core
βββ /shared
βββ /status
|
βββ app.module.ts
βββ app.component.spec.ts
βββ app.component.ts
βββ app.routing-module.ts
Besides the definition of app module the app
folder has feature modules on top-level.
The special modules shared and core are present as well.
A feature module contains the modules definition and two folders representing both layers.
/src
βββ /app
βββ /account-management
βββ /components
βββ /services
|
βββ account-management.module.ts
βββ account-management.component.spec.ts
βββ account-management.component.ts
βββ account-management.routing-module.ts
Additionally an entry component is possible. This would be the case in lazy loading scenarios.
So account-management.component.ts
would be only present if account-management
is lazy loaded.
Otherwise, the moduleβs routes would be defined Component-less
(see vsavkin blog post).
The component layer reflects the distinction between Smart Components and Dumb Components.
/src
βββ /app
βββ /account-management
βββ /components
βββ /account-overview
βββ /confirm-modal
βββ /create-account
βββ /forgot-password
βββ /shared
Every folder inside the /components
folder represents a smart component. The only exception is /shared
.
/shared
contains Dumb Components shared across Smart Components inside the components layer.
/src
βββ /app
βββ /account-management
βββ /components
βββ /account-overview
βββ /user-info-panel
| βββ /address-tab
| βββ /last-activities-tab
| |
| βββ user-info-panel.component.html
| βββ user-info-panel.component.scss
| βββ user-info-panel.component.spec.ts
| βββ user-info-panel.component.ts
|
βββ /user-header
βββ /user-toolbar
|
βββ account-overview.component.html
βββ account-overview.component.scss
βββ account-overview.component.spec.ts
βββ account-overview.component.ts
Inside the folder of a Smart Component the component is defined.
Besides that are folders containing the Dumb Components the Smart Component consists of.
This can be recursive - a Dumb Component can consist of other Dumb Components.
This is reflected by the file structure as well. This way the structure of a view becomes very readable.
As mentioned before, if a Dumb Component is used by multiple Smart Components inside the components layer
it is put inside the /shared
folder inside the components layer.
With this way of thinking the shared module makes a lot of sense. If a Dumb Component is used by multiple Smart Components from different feature modules, the Dumb Component is placed into the shared module.
/src
βββ /app
βββ /shared
βββ /user-panel
|
βββ user-panel.component.html
βββ user-panel.component.scss
βββ user-panel.component.spec.ts
βββ user-panel.component.ts
The layer folder /components
is not necessary inside the shared module.
The shared module only contains components!