# scarf-sh/scarf-js architecture

> Architecture diagram of the GitHub repository scarf-sh/scarf-js, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-11-19). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/scarf-sh/scarf-js
- Repository: https://github.com/scarf-sh/scarf-js

## Overview

Scarf.js is a dependency’s npm postinstall analytics reporter. Installation triggers dependency-tree discovery, policy and consent checks, payload preparation, and a best-effort install-event request; it can also persist consent and throttle user messages. The runtime is concentrated in report.js, so these nodes describe distinct responsibilities rather than separate modules. README documents configuration and opt-out behavior; the available source excerpts do not show every internal call, so uncertain connections are omitted.

Main entry points: [`report.js`](https://github.com/scarf-sh/scarf-js/blob/master/report.js) (Install reporter)

## Diagram (Mermaid)

```mermaid
flowchart TD

node_installer(("npm installer"))
node_reporter["Install reporter<br/>[report.js]"]
node_discovery["Dependency discovery<br/>[report.js]"]
node_policy["Settings and consent<br/>[report.js]"]
node_payload["Payload preparation<br/>[report.js]"]
node_throttle[("Prompt throttling<br/>[report.js]")]
node_preferences[("Saved preferences<br/>[report.js]")]
node_service["Scarf event service"]

node_installer -->|"runs postinstall"| node_reporter
node_reporter -->|"gets dependency info"| node_discovery
node_reporter -->|"checks reporting eligibility"| node_policy
node_policy -->|"checks prompt rate"| node_throttle
node_policy -->|"saves consent"| node_preferences
node_reporter -->|"redacts dependency info"| node_payload
node_reporter -->|"posts install event"| node_service

click node_reporter "https://github.com/scarf-sh/scarf-js/blob/master/report.js"
click node_discovery "https://github.com/scarf-sh/scarf-js/blob/master/report.js"
click node_policy "https://github.com/scarf-sh/scarf-js/blob/master/report.js"
click node_payload "https://github.com/scarf-sh/scarf-js/blob/master/report.js"
click node_throttle "https://github.com/scarf-sh/scarf-js/blob/master/report.js"
click node_preferences "https://github.com/scarf-sh/scarf-js/blob/master/report.js"

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_installer,node_service toneIndigo
class node_reporter,node_discovery,node_policy,node_payload toneTeal
class node_throttle,node_preferences toneAmber
```

## Components

### Other components

- **npm installer**
- [Install reporter](https://github.com/scarf-sh/scarf-js/blob/master/report.js): `report.js`
- [Dependency discovery](https://github.com/scarf-sh/scarf-js/blob/master/report.js): `report.js`
- [Settings and consent](https://github.com/scarf-sh/scarf-js/blob/master/report.js): `report.js`
- [Payload preparation](https://github.com/scarf-sh/scarf-js/blob/master/report.js): `report.js`
- [Prompt throttling](https://github.com/scarf-sh/scarf-js/blob/master/report.js): `report.js`
- [Saved preferences](https://github.com/scarf-sh/scarf-js/blob/master/report.js): `report.js`
- **Scarf event service**

## Connections

- npm installer → Install reporter: runs postinstall
- Install reporter → Dependency discovery: gets dependency info (evidence: `report.js`)
- Install reporter → Settings and consent: checks reporting eligibility (evidence: `report.js`)
- Settings and consent → Prompt throttling: checks prompt rate (evidence: `report.js`)
- Settings and consent → Saved preferences: saves consent (evidence: `report.js`)
- Install reporter → Payload preparation: redacts dependency info (evidence: `report.js`)
- Install reporter → Scarf event service: posts install event (evidence: `report.js`)
