# benoror/better-npm-run architecture

> Architecture diagram of the GitHub repository benoror/better-npm-run, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2024-12-28). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/benoror/better-npm-run
- Repository: https://github.com/benoror/better-npm-run

## Overview

##### Main Components

a) Core Components:
- Command Parser
- Environment Handler
- Script Executor
- .env File Loader
- CLI Interface

b) External Interfaces:
- NPM Scripts Integration
- Shell Environment
- File System (.env file)

**[CLI Input] -> [better-npm-run Core] -> [Script Execution]**

**[CLI Interface (bnr/better-npm-run)]**
- ↓
**[Command Parser] ←→ [package.json betterScripts]**
- ↓
**[Environment Handler] ←→ [.env File Loader]**
- ↓
**[Script Executor] → [Shell/Process Execution]**

##### Specific Elements

- CLI Commands (bnr/better-npm-run)
- package.json betterScripts configuration
- .env file
- Environment variables

b) Process Flows:
- Command parsing flow
- Environment variable resolution
- Script execution pipeline

##### Important Details to Highlight

- Environment Variable Priority:
1. betterScripts env configuration
2. .env file values
3. Existing environment variables

- Command Processing:
- How the tool processes both string commands and object configurations
- Parameter parsing mechanism

##### Technical Specifications

- Rectangles: Core components
- Green: Input sources
- Blue: Processing components
- Yellow: Output/Execution

##### Implementation Details

- lib/exec.js: Main execution logic
- index.js: Entry point and CLI handling
- Environment handling (test/env.js, test/env-extend.js)
- Parameter processing (test/params.js)

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Input
        CLI[CLI Interface]:::cli
        PKG[package.json betterScripts]:::config
        ENV[.env File]:::config
        SHELL[Shell Environment]:::external
    end

    subgraph Core["Core Processing"]
        CP[Command Parser]:::core
        EH[Environment Handler]:::core
        ENV_LOAD[.env File Loader]:::core
        SE[Script Executor]:::core
    end

    subgraph Execution
        PROC[Process Execution]:::execution
    end

    %% Connections
    CLI --> CP
    PKG --> CP
    CP --> EH
    ENV --> ENV_LOAD
    ENV_LOAD --> EH
    SHELL --> EH
    EH --> SE
    SE --> PROC

    %% Click Events
    click CLI "https://github.com/benoror/better-npm-run/blob/master/index.js"
    click SE "https://github.com/benoror/better-npm-run/blob/master/lib/exec.js"
    click EH "https://github.com/benoror/better-npm-run/blob/master/test/env.js"
    click CP "https://github.com/benoror/better-npm-run/blob/master/test/command.js"
    click ENV "https://github.com/benoror/better-npm-run/blob/master/.env"
    click PKG "https://github.com/benoror/better-npm-run/blob/master/package.json"

    %% Styles
    classDef cli fill:#90EE90,stroke:#333,stroke-width:2px
    classDef config fill:#FFE4B5,stroke:#333,stroke-width:2px
    classDef core fill:#87CEEB,stroke:#333,stroke-width:2px
    classDef execution fill:#FFA07A,stroke:#333,stroke-width:2px
    classDef external fill:#D3D3D3,stroke:#333,stroke-width:2px

    %% Legend
    subgraph Legend
        L1[CLI Component]:::cli
        L2[Configuration Files]:::config
        L3[Core Components]:::core
        L4[Execution Layer]:::execution
        L5[External Systems]:::external
    end

    %% Notes
    note["Note: This package is deprecated.<br/>Recommended alternative: cross-env"]
    style note fill:#FFE4E1,stroke:#FF6347,stroke-width:2px
```
