# hkdobrev/run-if-changed architecture

> Architecture diagram of the GitHub repository hkdobrev/run-if-changed, 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/hkdobrev/run-if-changed
- Repository: https://github.com/hkdobrev/run-if-changed

## Overview

##### Main Components Identification

a. Git Hook Integration Layer
- Supported Git hooks (post-commit, post-checkout, post-merge, post-rewrite)
- This is the entry point of the system

b. Core Processing Components
- Configuration Manager (configLoad.js)
- File Change Detection System (gitChangedFilesSinceLastHead.js)
- Pattern Matching Engine (resolveMatchingPatterns.js)
- Command Execution System (runCommands.js)

##### Specific Design Elements

Use these visual elements:

- Blue rectangles for core components
- Green diamonds for decision points
- Yellow rectangles for external integrations (Git, npm/yarn commands)

##### Component Relationships

**Git Hooks → File Change Detection → Pattern Matching → Command Execution**
**↑                                                              ↓**
**Configuration Manager ←----------------------------------------'**

##### Important Details

a. Configuration Sources:
- Multiple possible config file locations
- Cosmiconfig integration

b. File Processing:
- Git diff operations
- Pattern matching logic
- Command resolution

c. External Integration Points:
- Git hooks system
- Package managers (npm, yarn, etc.)
- Build tools

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph "Git Hook Layer"
        GH["Git Hooks"]:::hooks
        PC["Post-Commit"]:::hook
        PCH["Post-Checkout"]:::hook
        PM["Post-Merge"]:::hook
        PR["Post-Rewrite"]:::hook
        GH --> PC
        GH --> PCH
        GH --> PM
        GH --> PR
    end

    subgraph "Configuration Layer"
        CS["Configuration Sources"]:::config
        PJ["package.json"]:::config
        RC[".run-if-changedrc"]:::config
        CF["run-if-changed.config.js"]:::config
        CS --> PJ
        CS --> RC
        CS --> CF
    end

    subgraph "Core Processing Layer"
        EP["Entry Point"]:::core
        CM["Configuration Manager"]:::core
        FD["File Change Detection"]:::core
        PM2["Pattern Matching Engine"]:::core
        CE["Command Execution"]:::core
        
        EP --> CM
        CM --> FD
        FD --> PM2
        PM2 --> CE
    end

    subgraph "External Integration"
        GI["Git Integration"]:::external
        NPM["NPM Commands"]:::external
        YARN["Yarn Commands"]:::external
    end

    PC & PCH & PM & PR --> EP
    CE --> NPM
    CE --> YARN
    FD --> GI
    
    %% Click Events
    click GH "https://github.com/hkdobrev/run-if-changed/tree/main//.husky/"
    click PC "https://github.com/hkdobrev/run-if-changed/tree/main//.husky/post-commit"
    click PCH "https://github.com/hkdobrev/run-if-changed/tree/main//.husky/post-checkout"
    click PM "https://github.com/hkdobrev/run-if-changed/tree/main//.husky/post-merge"
    click PR "https://github.com/hkdobrev/run-if-changed/tree/main//.husky/post-rewrite"
    click PJ "https://github.com/hkdobrev/run-if-changed/blob/main//package.json"
    click EP "https://github.com/hkdobrev/run-if-changed/blob/main//run-if-changed.js"
    click CM "https://github.com/hkdobrev/run-if-changed/blob/main//src/configLoad.js"
    click FD "https://github.com/hkdobrev/run-if-changed/blob/main//src/gitChangedFilesSinceLastHead.js"
    click PM2 "https://github.com/hkdobrev/run-if-changed/blob/main//src/resolveMatchingPatterns.js"
    click CE "https://github.com/hkdobrev/run-if-changed/blob/main//src/runCommands.js"

    %% Styles
    classDef hooks fill:#6c8ebf,stroke:#000
    classDef hook fill:#9cc1ff,stroke:#000
    classDef config fill:#d5e8d4,stroke:#000
    classDef core fill:#ffe6cc,stroke:#000
    classDef external fill:#f8cecc,stroke:#000

    %% Legend
    subgraph Legend
        L1["Git Hooks"]:::hooks
        L2["Hook Types"]:::hook
        L3["Configuration"]:::config
        L4["Core Components"]:::core
        L5["External Systems"]:::external
    end
```
