# coreybutler/nvm-windows architecture

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

- Interactive diagram: https://gitdiagram.com/coreybutler/nvm-windows
- Repository: https://github.com/coreybutler/nvm-windows

## Overview

##### Project Type & Purpose
- This is a command‐line utility that lets Windows users manage multiple Node.js installations.
- Its purpose is to install, switch, upgrade, and manage different versions of Node.js without a dependency on an existing Node installation.
- The README emphasizes command line usage, administrator requirements for creating symlinks, and seamless switching between node versions using Go’s capabilities.

##### File Structure
- Top-Level Folders and Files:
– The “src” folder holds the core code subdivided by functionality into packages like “arch”, “author”, “encoding”, “file”, “node”, “semver”, “upgrade”, “utility”, and “web”.
– “assets” contains supporting scripts, binaries/build tools, installer scripts (e.g., “install.cmd”, “elevate.cmd”) and images used in the installer.
– “.github” contains workflows (CI/CD), issue templates, and contribution guidelines.
– There’s a “build.js” file, which probably ties into the build process.
- Architectural Implications:
– Code is organized into modular packages that likely reflect different functional responsibilities. For example, the “upgrade” package handles checking for and performing upgrades, while the “node” package deals with node installation management.
– The presence of “web” (likely a small web server or API) and “utility” (logging, renaming) indicates layered supporting services.
– Build and deployment assets, along with GitHub workflows, point to a robust CI/CD and installer process.

##### Main Components
A. Command-Line Interface (CLI) Layer:
- The entry point is the “nvm” command. This layer receives user commands and invokes underlying operations.
B. Core Management Modules (within src):
- Node Management Module (“src/node”): Responsible for operations such as installing specific versions, switching between versions, and managing the installation directories.
- Upgrade Module (“src/upgrade”): Contains sub-modules for checking, notifying, registering new upgrades, and performing the upgrade process.
- Architecture Module (“src/arch”): Deals with handling specifics of 32-bit versus 64-bit Node.js installations.
- Versioning Module (“src/semver”): Implements semantic versioning comparisons and validations.
- File Operations (“src/file”): Manages file system interactions like copying installation files and handling file-based configurations.
- Utility and Helper Modules (“src/utility”, “src/encoding”): Provide logging, instance renaming, and data encoding functions.
- Web Component (“src/web”): Although its exact role isn’t detailed, its inclusion suggests capabilities like serving status pages or providing an alternate interface for commands.
- Author/Bridge Module (“src/author”): Possibly used to bridge between native Windows operations (like symlink creation or integration with other Windows system APIs) and Go code.
C. Supporting Layers:
- Installer & Build Tools (within “assets/buildtools” and scripts in “assets”): This encapsulates the installer executable, elevation scripts (to run commands as Administrator), and tools required to prepare the build.
- External Services:
– Node.js Release Repository: The system communicates with external endpoints (like Node.js download sources) to retrieve version lists and installation packages.
– Optional: npm and yarn – though managed separately, the documentation advises reinstalling global modules when switching Node.js versions.
D. Configuration & Continuous Integration:
- GitHub Workflows and configuration files (under “.github”) indicate automated testing, release workflows, and a dependency management process.

##### Relationships and Interactions
- The CLI layer acts as the front door, parsing user commands and delegating tasks:
– It calls the Node Management Module for install/use operations.
– The Upgrade Module gets triggered to check or notify about newer versions.
- The Node Management Module interacts with the Architecture Module to determine or set the correct platform (32-bit/64-bit) version.
- The Semver Module is used when comparing version strings to decide install or upgrade eligibility.
- The File Operations and Utility Modules support any low-level filesystem changes (e.g., copying original node installations, updating symlinks).
- The Installer and Build Tools work alongside the core modules to generate the final executable and update configurations.
- External interactions include downloading version metadata and installer binaries from Node.js repositories or mirrors.

##### Architectural Patterns & Design Principles
- Modular Design: Each functionality (e.g., version handling, upgrade notifications) is compartmentalized into its own package.
- Layered Architecture: Separating the CLI from the underlying business logic and helper utilities.
- Clear Separation of Concerns: For instance, file manipulations, logging, web functionalities, and command processing are kept in their respective modules.
- Emphasis on System Integration: Special attention is paid to Windows-specific functionalities like symlink management and elevation to administrator privileges.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Top Layer: CLI Interface
    CLI["CLI Interface"]:::cli

    %% Subgraph: Core Modules
    subgraph "Core Modules"
        direction TB
        NodeMgmt["Node Management Module (src/node)"]:::core
        Upgrade["Upgrade Module (src/upgrade)"]:::core
        Arch["Architecture Module (src/arch)"]:::core
        Semver["Versioning Module (Semver) (src/semver)"]:::core
        FileOps["File Operations Module (src/file)"]:::core
        UtilGen["General Utilities (src/utility)"]:::core
        DataEnc["Data Encoding (src/encoding)"]:::core
        WebComp["Web Component (src/web)"]:::core
        AuthorBridge["Author/Bridge Module (src/author)"]:::core
    end

    %% Subgraph: Installer & Build Tools
    subgraph "Installer & Build Tools"
        direction TB
        Installer["Installer Scripts & Tools (assets)"]:::installer
    end

    %% Subgraph: Continuous Integration & Config
    subgraph "CI / Configuration"
        direction TB
        CI["Continuous Integration (.github)"]:::ci
    end

    %% External Components
    WinOS["Windows OS"]:::external
    NodeRepo["Node.js Release Repository"]:::external

    %% Connections from CLI
    CLI -->|"install/use"| NodeMgmt
    CLI -->|"upgrade"| Upgrade
    CLI -->|"web commands"| WebComp
    CLI -->|"admin commands"| AuthorBridge

    %% Core Module Interactions
    NodeMgmt -->|"platformCheck"| Arch
    NodeMgmt -->|"versionCompare"| Semver
    NodeMgmt -->|"fileOps"| FileOps
    FileOps -->|"utilOps"| UtilGen
    FileOps -->|"dataEncoding"| DataEnc
    Upgrade -->|"triggersInstall"| NodeMgmt

    %% External Interactions
    NodeMgmt -->|"downloads"| NodeRepo
    Upgrade -->|"versionCheck"| NodeRepo
    AuthorBridge -->|"symlink/elevate"| WinOS

    %% Build and CI Flow
    CI -->|"triggersBuild"| Installer
    Installer -->|"buildArtifact"| CLI

    %% Styles
    classDef cli fill:#FFD700,stroke:#333,stroke-width:2px;
    classDef core fill:#ADD8E6,stroke:#333,stroke-width:2px;
    classDef installer fill:#90EE90,stroke:#333,stroke-width:2px;
    classDef ci fill:#DDA0DD,stroke:#333,stroke-width:2px;
    classDef external fill:#FFA07A,stroke:#333,stroke-width:2px;

    %% Click Events
    click CLI "https://github.com/coreybutler/nvm-windows/blob/master/src/nvm.go"
    click NodeMgmt "https://github.com/coreybutler/nvm-windows/blob/master/src/node/node.go"
    click Upgrade "https://github.com/coreybutler/nvm-windows/tree/master/src/upgrade"
    click Arch "https://github.com/coreybutler/nvm-windows/blob/master/src/arch/arch.go"
    click Semver "https://github.com/coreybutler/nvm-windows/blob/master/src/semver/semver.go"
    click FileOps "https://github.com/coreybutler/nvm-windows/blob/master/src/file/file.go"
    click UtilGen "https://github.com/coreybutler/nvm-windows/blob/master/src/utility/logging.go"
    click DataEnc "https://github.com/coreybutler/nvm-windows/blob/master/src/encoding/encoding.go"
    click WebComp "https://github.com/coreybutler/nvm-windows/blob/master/src/web/web.go"
    click AuthorBridge "https://github.com/coreybutler/nvm-windows/blob/master/src/author/bridge.go"
    click Installer "https://github.com/coreybutler/nvm-windows/tree/master/assets"
    click CI "https://github.com/coreybutler/nvm-windows/blob/master/.github"
```
