# sap/ui5-cli architecture

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

- Interactive diagram: https://gitdiagram.com/sap/ui5-cli
- Repository: https://github.com/sap/ui5-cli

## Overview

##### Project Type and Purpose
- This is an open-source, Node.js-based Command-Line Interface (CLI) tool (“ui5-cli”) that is part of the UI5 Tooling ecosystem.
- Its purpose is to provide a unified entry point (`ui5` command) to scaffold, configure, build, serve, and manage UI5 projects.

##### High-Level Architecture
a. Node.js Runtime & Entrypoint
- bin/ui5.cjs – the stub that invokes the CLI core
b. CLI Core & Dispatcher
- lib/cli/cli.js – argument parsing, help text, global options
- lib/cli/version.js – version reporting
c. Middleware Pipeline
- lib/cli/middlewares/logger.js – logging interceptor
- lib/cli/middlewares/base.js – common setup tasks
d. Command Modules
- lib/cli/commands/*.js – one module per command (add, build, config, init, remove, serve, tree, use, versions)
- Each command exports a handler function that implements business logic.
e. Framework Integration Layer
- lib/framework/*.js – adapters that translate CLI commands into UI5-specific operations (e.g., modify ui5.yaml, add/remove frameworks)
f. Project Initialization
- lib/init/init.js – scaffolding logic for new projects (layouts, sample files, config templates)
g. Utilities
- lib/utils/fsHelper.js – file system helper functions
h. External Systems
- Local File System – read/write project files, YAML configs
- YAML Parser (js-yaml) – parse/update `ui5.yaml`

##### Component Relationships & Data Flow
1. User invokes `ui5 <command> [options]` on the shell
2. bin/ui5.cjs loads CLI Core
3. CLI Core parses arguments → builds a command pipeline
4. Request flows through Middleware Pipeline (logging, validation)
5. Router dispatches to the specific Command Module
6. Command Module calls into Framework Integration Layer or Init module
7. Framework Layer and Init module use Utilities to manipulate the File System and YAML
8. Results (success/error, output) flow back up to the CLI Core → Console output

##### Architectural Patterns & Principles
- Modular Command Pattern (each command is its own module)
- Middleware Pipeline (cross-cutting concerns like logging)
- Layered Architecture (CLI Core → Commands → Framework → Utilities → FS)
- Separation of Concerns (init vs. build vs. serve code)
- Testable units (lib/ directories mirror test/lib for 1:1 test coverage)

##### Detail Level
- Every command module as a sub-component under “Commands”
- Middleware chain explicitly in sequence

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Entrypoint Layer
    Entrypoint["Entrypoint (bin/ui5.cjs)"]:::entrypoint
    click Entrypoint "https://github.com/sap/ui5-cli/blob/main/bin/ui5.cjs"

    %% CLI Core & Dispatcher
    CLICore["CLI Core & Dispatcher (lib/cli/cli.js)"]:::core
    click CLICore "https://github.com/sap/ui5-cli/blob/main/lib/cli/cli.js"
    Version["Version Reporter (lib/cli/version.js)"]:::core
    click Version "https://github.com/sap/ui5-cli/blob/main/lib/cli/version.js"
    Router["Command Router"]:::core

    Entrypoint -->|"invokes CLI Core"| CLICore
    CLICore -->|"parses args"| Version
    CLICore -->|"parses args"| Router

    %% Middleware Pipeline
    subgraph "Middleware Pipeline"
        direction TB
        Base["Base Middleware (lib/cli/middlewares/base.js)"]:::middleware
        click Base "https://github.com/sap/ui5-cli/blob/main/lib/cli/middlewares/base.js"
        Logger["Logger Middleware (lib/cli/middlewares/logger.js)"]:::middleware
        click Logger "https://github.com/sap/ui5-cli/blob/main/lib/cli/middlewares/logger.js"
    end

    Router -->|"through pipeline"| Base
    Base -->|"then"| Logger
    Logger -->|"after middleware"| Router

    %% Commands Layer
    subgraph "Commands" 
        direction TB
        Add["add.js"]:::command
        click Add "https://github.com/sap/ui5-cli/blob/main/lib/cli/commands/add.js"
        Build["build.js"]:::command
        click Build "https://github.com/sap/ui5-cli/blob/main/lib/cli/commands/build.js"
        Config["config.js"]:::command
        click Config "https://github.com/sap/ui5-cli/blob/main/lib/cli/commands/config.js"
        InitCmd["init.js"]:::command
        click InitCmd "https://github.com/sap/ui5-cli/blob/main/lib/cli/commands/init.js"
        Remove["remove.js"]:::command
        click Remove "https://github.com/sap/ui5-cli/blob/main/lib/cli/commands/remove.js"
        Serve["serve.js"]:::command
        click Serve "https://github.com/sap/ui5-cli/blob/main/lib/cli/commands/serve.js"
        Tree["tree.js"]:::command
        click Tree "https://github.com/sap/ui5-cli/blob/main/lib/cli/commands/tree.js"
        Use["use.js"]:::command
        click Use "https://github.com/sap/ui5-cli/blob/main/lib/cli/commands/use.js"
        Versions["versions.js"]:::command
        click Versions "https://github.com/sap/ui5-cli/blob/main/lib/cli/commands/versions.js"
    end

    Router -->|"dispatch to"| Add
    Router --> Build
    Router --> Config
    Router --> InitCmd
    Router --> Remove
    Router --> Serve
    Router --> Tree
    Router --> Use
    Router --> Versions

    %% Framework & Init Layer
    subgraph "Framework Integration"
        direction TB
        FW_Add["add.js"]:::framework
        click FW_Add "https://github.com/sap/ui5-cli/blob/main/lib/framework/add.js"
        FW_Remove["remove.js"]:::framework
        click FW_Remove "https://github.com/sap/ui5-cli/blob/main/lib/framework/remove.js"
        FW_Update["updateYaml.js"]:::framework
        click FW_Update "https://github.com/sap/ui5-cli/blob/main/lib/framework/updateYaml.js"
        FW_Use["use.js"]:::framework
        click FW_Use "https://github.com/sap/ui5-cli/blob/main/lib/framework/use.js"
        FW_Utils["utils.js"]:::framework
        click FW_Utils "https://github.com/sap/ui5-cli/blob/main/lib/framework/utils.js"
    end

    InitModule["Init Module (lib/init/init.js)"]:::framework
    click InitModule "https://github.com/sap/ui5-cli/blob/main/lib/init/init.js"

    Add -->|"calls"| FW_Add
    Remove -->|"calls"| FW_Remove
    Config -->|"calls"| FW_Update
    Use -->|"calls"| FW_Use
    InitCmd -->|"calls"| InitModule

    FW_Add --> FW_Utils
    FW_Remove --> FW_Utils
    FW_Update --> FW_Utils
    FW_Use --> FW_Utils
    InitModule --> FW_Utils

    %% Utilities & External Systems
    Utils["FS Helper (lib/utils/fsHelper.js)"]:::utils
    click Utils "https://github.com/sap/ui5-cli/blob/main/lib/utils/fsHelper.js"
    FS["Local File System"]:::external
    YAML["YAML Parser (js-yaml)"]:::external

    FW_Utils -->|"uses"| Utils
    InitModule --> Utils
    Utils -->|"reads/writes"| FS
    FW_Utils -->|"reads/writes"| YAML
    Utils -->|"parses"| YAML

    %% Styles
    classDef entrypoint fill:#d0e1f9,stroke:#0366d6,stroke-width:2px;
    classDef core fill:#cce5ff,stroke:#004085,stroke-width:2px;
    classDef middleware fill:#e2f0d9,stroke:#2e7d32,stroke-width:2px;
    classDef command fill:#d4edda,stroke:#155724,stroke-width:2px;
    classDef framework fill:#fff3cd,stroke:#856404,stroke-width:2px;
    classDef utils fill:#f8f9fa,stroke:#6c757d,stroke-width:2px;
    classDef external fill:#e2e3e5,stroke:#adb5bd,stroke-width:2px,stroke-dasharray: 5 5;
```
