# netcentric/fe-build architecture

> Architecture diagram of the GitHub repository netcentric/fe-build, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-05-31). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/netcentric/fe-build
- Repository: https://github.com/netcentric/fe-build

## Overview

##### Project Type and Purpose
- This is an open-source, CLI-driven “all-in-one” frontend build toolkit (npm package) specifically tailored to Adobe Experience Manager (AEM) projects.
- Its job is to read a project’s source files (JS and SCSS), apply linting, transpilation, bundling, and CSS compilation, then output AEM-compatible ClientLib folder structures.

##### File‐Structure Analysis
- Top‐level “cli/index.js”: the entry point exposing the `nc-fe-build` command.
- “config/”: modular webpack, babel, postcss, stylelint, performance and general build configurations.
- “tasks/”: discrete task modules (`run.js`, `webpack.js`, `styles.js`, `clientlibs.js`) each orchestrating a build step, plus unit tests.
- “utils/”: helper functions for merging configs, resolving entry points, loading plugins, file I/O, logging, and lint-error formatting.

##### README Insights
- Core features: ESLint → Babel → Webpack for JS, Stylelint → Sass → PostCSS/Autoprefixer for CSS, automatic ClientLib structure generation.
- Configuration is extensible via `.febuild` and the various `config/*.js` modules.
- Emphasis on automation, plugin-based config, and integration with AEM’s clientlibs.

a. Main Components
- CLI Interface (`cli/index.js`)
- Task Orchestrator (`tasks/run.js`)
- Task Modules:
- JS Build Task (`tasks/webpack.js`)
- CSS Build Task (`tasks/styles.js`)
- ClientLib Generation Task (`tasks/clientlibs.js`)
- Config Layer (`config/*.js`)
- Utility Layer (`utils/*.js`)
- External Tools/Engines: Node.js, ESLint, Babel, Webpack, Stylelint, Sass, PostCSS
- File System: Source Directory (`src/*.source.js|scss`), Output (AEM ClientLib folder)

b. Relationships & Data Flows
- User runs `nc-fe-build` → CLI Interface parses args → passes control to Task Orchestrator.
- Task Orchestrator loads and merges configurations via Config Layer & Utils.
- For JS Task: reads entry points → ESLint → Babel transforms → Webpack bundles → writes JS assets.
- For CSS Task: reads SCSS → Stylelint → Sass compiler → PostCSS (Autoprefixer) → writes CSS assets.
- ClientLib Task: scans generated assets → builds `css.txt` and `js.txt` → emits AEM ClientLib folder structure.
- Each task reports status through Utils/log and exits.

c. Architectural Patterns & Principles
- Modular Pipeline: each build step encapsulated in its own “task” module.
- Plugin/Config Factory: Config Layer exposes composable functions, merged via Utils.
- Single Responsibility & Separation of Concerns: CLI, Orchestrator, Tasks, Configs, and Utils are distinct layers.
- Test-driven Utility modules: each util function is unit-tested.

d. Key Technologies & Frameworks
- Node.js & npm (CLI runtime)
- ESLint, Stylelint (linting)
- Babel (JS transpilation)
- Webpack (+ Bundle Analyzer) (JS bundling)
- Sass, PostCSS (+ Autoprefixer) (CSS processing)
- AEM ClientLib spec (output consumer)

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "CLI Layer"
        CLI["CLI Interface"]:::internal
    end

    subgraph "Core Orchestrator"
        ORCH["Task Orchestrator"]:::internal
    end

    subgraph "Task Modules"
        JS_TASK["JS Build Task"]:::task
        CSS_TASK["CSS Build Task"]:::task
        CL_TASK["ClientLib Generation Task"]:::task
    end

    subgraph "Config Layer"
        CONFIG["Config Layer"]:::config
    end

    subgraph "Utility Layer"
        UTILS["Utility Layer"]:::utils
    end

    subgraph "External Tools"
        ESLINT["ESLint"]:::external
        BABEL["Babel"]:::external
        WEBPACK_E["Webpack"]:::external
        STYLEL["Stylelint"]:::external
        SASS["Sass"]:::external
        POSTCSS["PostCSS"]:::external
    end

    subgraph "File System"
        SRC["Source: src/*.js/.scss"]:::filesystem
        FEBUILD["Project Config (.febuild/.febuild.js)"]:::filesystem
        OUTPUT["AEM ClientLib Folder"]:::filesystem
        TESTSRC["Test Fixtures (test/src/)"]:::filesystem
    end

    CLI -->|"parse args"| ORCH
    ORCH -->|"merge configs"| CONFIG
    ORCH -->|"use helpers"| UTILS

    ORCH -->|"invoke"| JS_TASK
    ORCH -->|"invoke"| CSS_TASK
    ORCH -->|"invoke"| CL_TASK

    SRC -->|"read sources"| JS_TASK
    SRC -->|"read sources"| CSS_TASK

    FEBUILD -->|"override configs"| CONFIG

    JS_TASK -->|"lint"| ESLINT
    JS_TASK -->|"transpile"| BABEL
    JS_TASK -->|"bundle"| WEBPACK_E
    WEBPACK_E -->|"write JS assets"| OUTPUT

    CSS_TASK -->|"lint"| STYLEL
    CSS_TASK -->|"compile"| SASS
    CSS_TASK -->|"post-process"| POSTCSS
    POSTCSS -->|"write CSS assets"| OUTPUT

    CL_TASK -->|"scan assets & generate clientlibs"| OUTPUT

    TESTSRC -->|"load fixtures for tests"| UTILS

    click CLI "https://github.com/netcentric/fe-build/blob/main/cli/index.js"
    click ORCH "https://github.com/netcentric/fe-build/blob/main/tasks/run.js"
    click JS_TASK "https://github.com/netcentric/fe-build/blob/main/tasks/webpack.js"
    click CSS_TASK "https://github.com/netcentric/fe-build/blob/main/tasks/styles.js"
    click CL_TASK "https://github.com/netcentric/fe-build/blob/main/tasks/clientlibs.js"
    click CONFIG "https://github.com/netcentric/fe-build/blob/main/config/index.js"
    click UTILS "https://github.com/netcentric/fe-build/blob/main/utils/extendConfig.js"
    click TESTSRC "https://github.com/netcentric/fe-build/tree/main/test/src/"
    click FEBUILD "https://github.com/netcentric/fe-build/blob/main/test/.febuild"

    classDef internal fill:#ADD8E6,stroke:#333,stroke-width:1px
    classDef task fill:#90EE90,stroke:#333,stroke-width:1px
    classDef config fill:#FFFFE0,stroke:#333,stroke-width:1px
    classDef utils fill:#D3D3D3,stroke:#333,stroke-width:1px
    classDef external fill:#D8BFD8,stroke:#333,stroke-width:1px
    classDef filesystem fill:#F5DEB3,stroke:#333,stroke-width:1px
```
