# apache/cordova-lib architecture

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

- Interactive diagram: https://gitdiagram.com/apache/cordova-lib
- Repository: https://github.com/apache/cordova-lib

## Overview

##### Project type and purpose
- This is an open-source Node.js library (cordova-lib) that implements the core logic behind the Cordova CLI (cordova) and the Cordova plugin manager (plugman).
- Its purpose is to provide reusable modules for project creation, platform management, build/compile/emulation, plugin install/uninstall, hook execution, templating, and other mobile-app lifecycle tasks.

##### File structure
- Top-level directories:
- src/cordova – all Cordova CLI commands (build, compile, emulate, prepare, run, serve, clean, etc.)
- src/plugman – plugin management commands (create, fetch, install, uninstall)
- src/platforms – platform discovery and configuration
- src/hooks – hook runner and context
- src/util – shared utilities (promise-util, default-engines, metadata, dependencies, etc.)
- templates – scaffolding templates for platforms and base projects
- Supporting assets:
- integration-tests/ and spec/ – end-to-end and unit tests (Jasmine)
- configuration files – package.json, .eslintrc.yml, templates/platformsConfig.json
- top-level cordova-lib.js – library entry point for Cordova CLI

##### README for additional insights
- Confirms that this library is consumed by both cordova CLI and plugman CLI.
- Mentions companion packages (cordova-common, cordova-create, cordova-serve).
- Lists npm scripts for linting, unit tests, integration tests.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% CLI Layer
    subgraph "CLI Layer"
        CLI["cordova-lib.js"]:::cli
    end

    %% Command Modules
    subgraph "Cordova Commands Module" 
        build["build.js"]:::cli
        compile["compile.js"]:::cli
        emulate["emulate.js"]:::cli
        prepare["prepare.js"]:::cli
        run["run.js"]:::cli
        serve["serve.js"]:::cli
        clean["clean.js"]:::cli
        cordova_cmd["cordova.js"]:::cli
    end

    subgraph "Plugman Commands Module"
        create_p["create.js"]:::cli
        fetch_p["fetch.js"]:::cli
        install_p["install.js"]:::cli
        uninstall_p["uninstall.js"]:::cli
        plugman_cmd["plugman.js"]:::cli
        init_defaults["init-defaults.js"]:::cli
        create_pkg["createpackagejson.js"]:::cli
        platform_pm["platform.js"]:::cli
        platform_op["platform_operation.js"]:::cli
        var_merge["variable-merge.js"]:::cli
    end

    %% Core Modules
    subgraph "Platform Management Module"
        index_plat["index.js"]:::business
        platforms["platforms.js"]:::business
        config_plat["platformsConfig.json"]:::business
    end

    subgraph "Hook Execution Module"
        ctx["Context.js"]:::business
        runner["HooksRunner.js"]:::business
        finder["scriptsFinder.js"]:::business
    end

    subgraph "Utility Modules"
        promise_util["promise-util.js"]:::util
        default_engines["default-engines.js"]:::util
        dependencies_u["dependencies.js"]:::util
        metadata_u["metadata.js"]:::util
        strip_license["strip-license.js"]:::util
    end

    subgraph "Templating Engine"
        base_tpl["base.js"]:::template
        subgraph "Platform Skeletons"
            android_tpl["android.xml / base.java"]:::template
            ios_tpl["ios.xml / base.m"]:::template
            windows_tpl["windows.xml / base.js"]:::template
        end
    end

    %% External Systems
    npm["npm Registry"]:::external
    git["Git Remote"]:::external
    fs["Local File System"]:::external

    %% Connections
    CLI -->|"dispatch to"| build
    CLI --> compile
    CLI --> emulate
    CLI --> prepare
    CLI --> run
    CLI --> serve
    CLI --> clean
    CLI --> cordova_cmd
    CLI --> create_p
    CLI --> fetch_p
    CLI --> install_p
    CLI --> uninstall_p
    CLI --> plugman_cmd

    %% Cordova flows
    build -->|"uses"| index_plat
    compile --> index_plat
    emulate --> index_plat
    prepare --> index_plat
    run --> index_plat
    serve --> index_plat
    clean --> index_plat
    cordova_cmd --> runner
    cordova_cmd --> promise_util
    cordova_cmd --> fs

    %% Plugman flows
    create_p --> default_engines
    fetch_p --> git
    install_p --> metadata_u
    install_p --> dependencies_u
    uninstall_p --> strip_license
    plugman_cmd --> runner
    plugman_cmd --> promise_util
    platform_pm --> index_plat
    platform_op --> index_plat
    var_merge --> metadata_u

    %% Hooks and Templates
    runner --> ctx
    runner --> finder
    create_p --> base_tpl
    prepare --> base_tpl
    create_p --> android_tpl
    create_p --> ios_tpl
    create_p --> windows_tpl

    %% External interactions
    build --> npm
    compile --> npm
    prepare --> fs
    install_p --> npm
    fetch_p --> npm
    runner --> fs

    %% Click Events
    click CLI "https://github.com/apache/cordova-lib/blob/master/cordova-lib.js"
    click build "https://github.com/apache/cordova-lib/blob/master/src/cordova/build.js"
    click compile "https://github.com/apache/cordova-lib/blob/master/src/cordova/compile.js"
    click emulate "https://github.com/apache/cordova-lib/blob/master/src/cordova/emulate.js"
    click prepare "https://github.com/apache/cordova-lib/blob/master/src/cordova/prepare.js"
    click run "https://github.com/apache/cordova-lib/blob/master/src/cordova/run.js"
    click serve "https://github.com/apache/cordova-lib/blob/master/src/cordova/serve.js"
    click clean "https://github.com/apache/cordova-lib/blob/master/src/cordova/clean.js"
    click cordova_cmd "https://github.com/apache/cordova-lib/blob/master/src/cordova/cordova.js"
    click create_p "https://github.com/apache/cordova-lib/blob/master/src/plugman/create.js"
    click fetch_p "https://github.com/apache/cordova-lib/blob/master/src/plugman/fetch.js"
    click install_p "https://github.com/apache/cordova-lib/blob/master/src/plugman/install.js"
    click uninstall_p "https://github.com/apache/cordova-lib/blob/master/src/plugman/uninstall.js"
    click plugman_cmd "https://github.com/apache/cordova-lib/blob/master/src/plugman/plugman.js"
    click init_defaults "https://github.com/apache/cordova-lib/blob/master/src/plugman/init-defaults.js"
    click create_pkg "https://github.com/apache/cordova-lib/blob/master/src/plugman/createpackagejson.js"
    click platform_pm "https://github.com/apache/cordova-lib/blob/master/src/plugman/platform.js"
    click platform_op "https://github.com/apache/cordova-lib/blob/master/src/plugman/platform_operation.js"
    click var_merge "https://github.com/apache/cordova-lib/blob/master/src/plugman/variable-merge.js"
    click index_plat "https://github.com/apache/cordova-lib/blob/master/src/platforms/index.js"
    click platforms "https://github.com/apache/cordova-lib/blob/master/src/platforms/platforms.js"
    click config_plat "https://github.com/apache/cordova-lib/blob/master/src/platforms/platformsConfig.json"
    click ctx "https://github.com/apache/cordova-lib/blob/master/src/hooks/Context.js"
    click runner "https://github.com/apache/cordova-lib/blob/master/src/hooks/HooksRunner.js"
    click finder "https://github.com/apache/cordova-lib/blob/master/src/hooks/scriptsFinder.js"
    click promise_util "https://github.com/apache/cordova-lib/blob/master/src/util/promise-util.js"
    click default_engines "https://github.com/apache/cordova-lib/blob/master/src/plugman/util/default-engines.js"
    click dependencies_u "https://github.com/apache/cordova-lib/blob/master/src/plugman/util/dependencies.js"
    click metadata_u "https://github.com/apache/cordova-lib/blob/master/src/plugman/util/metadata.js"
    click strip_license "https://github.com/apache/cordova-lib/blob/master/src/plugman/util/strip-license.js"
    click base_tpl "https://github.com/apache/cordova-lib/blob/master/templates/base.js"

    %% Styles
    classDef cli fill:#cce5ff,stroke:#66b0ff
    classDef business fill:#d4edda,stroke:#8fd19e
    classDef util fill:#fff3cd,stroke:#ffe38a
    classDef external fill:#e2e3e5,stroke:#c6c8ca,stroke-dasharray: 5 5
    classDef template fill:#f8d7da,stroke:#e9998f
```
