# jeliasson/npm-husky-hooks architecture

> Architecture diagram of the GitHub repository jeliasson/npm-husky-hooks, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-13). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/jeliasson/npm-husky-hooks
- Repository: https://github.com/jeliasson/npm-husky-hooks

## Overview

@jeliasson/husky-hooks is a configurable Husky hook runner with a CLI for creating configuration and running hooks for Git events. The main flow parses the event command, loads and validates project configuration, dispatches configured hooks, and reports their results. The graph also includes the documented config-generation command and the README’s three principal hooks. Some hook implementations are only indexed, not excerpted; their dispatch links are supported by the indexed references, while unsampled implementation details are omitted.

Main entry points: [`src/config.ts`](https://github.com/jeliasson/npm-husky-hooks/blob/main/src/config.ts) (Project config), [`src/hooks.ts`](https://github.com/jeliasson/npm-husky-hooks/blob/main/src/hooks.ts) (Hook dispatcher), [`src/index.ts`](https://github.com/jeliasson/npm-husky-hooks/blob/main/src/index.ts) (Application entry), [`src/response.ts`](https://github.com/jeliasson/npm-husky-hooks/blob/main/src/response.ts) (Result and errors)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_entry["CLI entry"]
  node_cli["Argument parser<br/>[cli.ts]"]
  node_entrypoint["Application entry<br/>[index.ts]"]
  node_commands["CLI commands<br/>[commands.ts]"]
end

subgraph group_configuration["Configuration"]
  node_configfile["Project config<br/>[config.ts]"]
  node_schema["Config schema<br/>[types.ts]"]
end

subgraph group_runtime["Hook runtime"]
  node_hookdispatcher["Hook dispatcher<br/>[hooks.ts]"]
  node_branch["Branch protection<br/>[checkBranch.ts]"]
  node_lockfiles["Lock-file check<br/>[checkLockFiles.ts]"]
  node_commandhook["Command runner<br/>[runCmd.ts]"]
  node_testip["IP test hook<br/>[testCheckIp.ts]"]
  node_sleep["Delay test hook<br/>[testSleep.ts]"]
end

subgraph group_support["Hook support"]
  node_response["Result and errors<br/>[response.ts]"]
  node_git["Git executable"]
  node_filesystem["Project filesystem"]
  node_shell["Shell command"]
end

node_developer(("Developer or Husky"))

node_developer -->|"starts CLI"| node_cli
node_cli -->|"returns arguments"| node_entrypoint
node_entrypoint -->|"checks command"| node_commands
node_commands -->|"creates config"| node_configfile
node_commands -->|"reads options"| node_cli
node_entrypoint -->|"loads and validates"| node_configfile
node_configfile -->|"validates against"| node_schema
node_entrypoint -->|"dispatches hooks"| node_hookdispatcher
node_hookdispatcher -->|"dispatches"| node_branch
node_hookdispatcher -->|"dispatches"| node_lockfiles
node_hookdispatcher -->|"dispatches"| node_commandhook
node_hookdispatcher -->|"dispatches"| node_testip
node_hookdispatcher -->|"dispatches"| node_sleep
node_branch -->|"reads settings"| node_configfile
node_branch -->|"reads current branch"| node_git
node_lockfiles -->|"reads settings"| node_configfile
node_lockfiles -->|"checks file presence"| node_filesystem
node_commandhook -->|"runs command"| node_shell
node_commandhook -->|"reads config name"| node_configfile
node_sleep -->|"reads delay"| node_configfile
node_entrypoint -->|"reports errors"| node_response
node_branch -->|"creates result"| node_response
node_lockfiles -->|"creates result"| node_response
node_commandhook -->|"creates result"| node_response
node_sleep -->|"creates result"| node_response

click node_cli "https://github.com/jeliasson/npm-husky-hooks/blob/main/src/cli.ts"
click node_entrypoint "https://github.com/jeliasson/npm-husky-hooks/blob/main/src/index.ts"
click node_commands "https://github.com/jeliasson/npm-husky-hooks/blob/main/src/commands.ts"
click node_configfile "https://github.com/jeliasson/npm-husky-hooks/blob/main/src/config.ts"
click node_schema "https://github.com/jeliasson/npm-husky-hooks/blob/main/src/types.ts"
click node_hookdispatcher "https://github.com/jeliasson/npm-husky-hooks/blob/main/src/hooks.ts"
click node_branch "https://github.com/jeliasson/npm-husky-hooks/blob/main/src/hooks/checkBranch.ts"
click node_lockfiles "https://github.com/jeliasson/npm-husky-hooks/blob/main/src/hooks/checkLockFiles.ts"
click node_commandhook "https://github.com/jeliasson/npm-husky-hooks/blob/main/src/hooks/runCmd.ts"
click node_testip "https://github.com/jeliasson/npm-husky-hooks/blob/main/src/hooks/testCheckIp.ts"
click node_sleep "https://github.com/jeliasson/npm-husky-hooks/blob/main/src/hooks/testSleep.ts"
click node_response "https://github.com/jeliasson/npm-husky-hooks/blob/main/src/response.ts"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_cli,node_entrypoint,node_commands toneBlue
class node_configfile,node_schema toneAmber
class node_hookdispatcher,node_branch,node_lockfiles,node_commandhook,node_testip,node_sleep toneMint
class node_response,node_git,node_filesystem,node_shell toneRose
class node_developer toneIndigo
```

## Components

### CLI entry

- [Argument parser](https://github.com/jeliasson/npm-husky-hooks/blob/main/src/cli.ts): `src/cli.ts`
- [Application entry](https://github.com/jeliasson/npm-husky-hooks/blob/main/src/index.ts): `src/index.ts`
- [CLI commands](https://github.com/jeliasson/npm-husky-hooks/blob/main/src/commands.ts): `src/commands.ts`

### Configuration

- [Project config](https://github.com/jeliasson/npm-husky-hooks/blob/main/src/config.ts): `src/config.ts`
- [Config schema](https://github.com/jeliasson/npm-husky-hooks/blob/main/src/types.ts): `src/types.ts`

### Hook runtime

- [Hook dispatcher](https://github.com/jeliasson/npm-husky-hooks/blob/main/src/hooks.ts): `src/hooks.ts`
- [Branch protection](https://github.com/jeliasson/npm-husky-hooks/blob/main/src/hooks/checkBranch.ts): `src/hooks/checkBranch.ts`
- [Lock-file check](https://github.com/jeliasson/npm-husky-hooks/blob/main/src/hooks/checkLockFiles.ts): `src/hooks/checkLockFiles.ts`
- [Command runner](https://github.com/jeliasson/npm-husky-hooks/blob/main/src/hooks/runCmd.ts): `src/hooks/runCmd.ts`
- [IP test hook](https://github.com/jeliasson/npm-husky-hooks/blob/main/src/hooks/testCheckIp.ts): `src/hooks/testCheckIp.ts`
- [Delay test hook](https://github.com/jeliasson/npm-husky-hooks/blob/main/src/hooks/testSleep.ts): `src/hooks/testSleep.ts`

### Hook support

- [Result and errors](https://github.com/jeliasson/npm-husky-hooks/blob/main/src/response.ts): `src/response.ts`
- **Git executable**
- **Project filesystem**
- **Shell command**

### Other components

- **Developer or Husky**

## Connections

- Developer or Husky → Argument parser: starts CLI (evidence: `README.md`)
- Argument parser → Application entry: returns arguments (evidence: `src/index.ts`)
- Application entry → CLI commands: checks command (evidence: `src/index.ts`)
- CLI commands → Project config: creates config (evidence: `src/commands.ts`)
- CLI commands → Argument parser: reads options (evidence: `src/commands.ts`)
- Application entry → Project config: loads and validates (evidence: `src/index.ts`)
- Project config → Config schema: validates against (evidence: `src/config.ts`)
- Application entry → Hook dispatcher: dispatches hooks (evidence: `src/index.ts`)
- Hook dispatcher → Branch protection: dispatches (evidence: `src/hooks.ts`)
- Hook dispatcher → Lock-file check: dispatches (evidence: `src/hooks.ts`)
- Hook dispatcher → Command runner: dispatches (evidence: `src/hooks.ts`)
- Hook dispatcher → IP test hook: dispatches (evidence: `src/hooks.ts`)
- Hook dispatcher → Delay test hook: dispatches (evidence: `src/hooks.ts`)
- Branch protection → Project config: reads settings (evidence: `src/hooks/checkBranch.ts`)
- Branch protection → Git executable: reads current branch (evidence: `src/hooks/checkBranch.ts`)
- Lock-file check → Project config: reads settings (evidence: `src/hooks/checkLockFiles.ts`)
- Lock-file check → Project filesystem: checks file presence (evidence: `src/hooks/checkLockFiles.ts`)
- Command runner → Shell command: runs command (evidence: `src/hooks/runCmd.ts`)
- Command runner → Project config: reads config name (evidence: `src/hooks/runCmd.ts`)
- Delay test hook → Project config: reads delay (evidence: `src/hooks/testSleep.ts`)
- Application entry → Result and errors: reports errors (evidence: `src/index.ts`)
- Branch protection → Result and errors: creates result (evidence: `src/hooks/checkBranch.ts`)
- Lock-file check → Result and errors: creates result (evidence: `src/hooks/checkLockFiles.ts`)
- Command runner → Result and errors: creates result (evidence: `src/hooks/runCmd.ts`)
- Delay test hook → Result and errors: creates result (evidence: `src/hooks/testSleep.ts`)
