guide file structure - devonfw/devon4ng GitHub Wiki

Table of Contents

File Structure

Top-level

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.

Listing 1. Top-level file structure shows feature modules
    /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.

Feature Modules

A feature module contains the modules definition and two folders representing both layers.

Listing 2. Feature module file structure has 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).

Components Layer

The component layer reflects the distinction between Smart Components and Dumb Components.

Listing 3. Components layer file structure shows Smart Components on top-level
    /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.

Listing 4. Smart components contain Dumb components
    /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.

Listing 5. The shared module contains Dumb Components shared across Smart Components from different feature modules
    /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!

⚠️ **GitHub.com Fallback** ⚠️