# hacking-by-heart/js-mutator architecture

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

- Interactive diagram: https://gitdiagram.com/hacking-by-heart/js-mutator
- Repository: https://github.com/hacking-by-heart/js-mutator

## Overview

js-mutator is a JavaScript-aware libFuzzer custom mutator: libFuzzer supplies seed bytes, the adapter calls the mutation or crossover API, and the library returns bounded JavaScript that is valid by default or deliberately malformed according to configuration. Internally, mutation uses seed-aware editing and grammar-based generation. The repository also provides V8 fuzzing targets for ordinary parsing, lazy compilation, and streaming compilation. The excerpts establish adapter/API and harness/helper links; the mutator-to-generator dispatch is shown as unverified because its call site was not excerpted.

Main entry points: [`harness/common.h`](https://github.com/hacking-by-heart/js-mutator/blob/main/harness/common.h) (Harness helpers), [`harness/parser.cc`](https://github.com/hacking-by-heart/js-mutator/blob/main/harness/parser.cc) (Parse target), [`harness/parse.h`](https://github.com/hacking-by-heart/js-mutator/blob/main/harness/parse.h) (Parse support), [`harness/compile.cc`](https://github.com/hacking-by-heart/js-mutator/blob/main/harness/compile.cc) (Lazy compile)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_engine["Mutation engine"]
  node_public_api["Mutator API<br/>[mutator.h]"]
  node_mutation["Seed mutation<br/>[mutator.cc]"]
  node_generation["Grammar generation<br/>[generator.cc]"]
  node_generator_model["Generation model<br/>[generator.h]"]
end

subgraph group_adapter["Fuzzer interface"]
  node_adapter_code["Callback adapter<br/>[libfuzzer.cc]"]
end

subgraph group_v8["V8 fuzz targets"]
  node_harness_helpers["Harness helpers<br/>[common.h]"]
  node_parse_helpers["Parse support<br/>[parse.h]"]
  node_parse_target["Parse target<br/>[parser.cc]"]
  node_lazy_target["Lazy compile<br/>[compile.cc]"]
  node_stream_target["Streaming compile<br/>[streaming.cc]"]
  node_diff_target["Parse diff<br/>[diff.cc]"]
end

node_libfuzzer(("libFuzzer"))
node_v8_engine["V8 parser/compiler"]

node_libfuzzer -->|"invokes callbacks"| node_adapter_code
node_adapter_code -->|"calls mutate/crossover"| node_public_api
node_public_api -->|"implemented by"| node_mutation
node_mutation -.->|"dispatches generation"| node_generation
node_generation -->|"uses definitions"| node_generator_model
node_parse_target -->|"calls parse pass"| node_parse_helpers
node_parse_target -->|"uses helpers"| node_harness_helpers
node_parse_helpers -->|"uses helpers"| node_harness_helpers
node_lazy_target -->|"uses helpers"| node_harness_helpers
node_stream_target -->|"uses helpers"| node_harness_helpers
node_parse_target -->|"parses input"| node_v8_engine
node_lazy_target -->|"compiles functions"| node_v8_engine
node_stream_target -->|"streams compilation"| node_v8_engine
node_diff_target -->|"uses parse pass"| node_parse_helpers
node_diff_target -->|"uses helpers"| node_harness_helpers

click node_adapter_code "https://github.com/hacking-by-heart/js-mutator/blob/main/adapters/libfuzzer.cc"
click node_public_api "https://github.com/hacking-by-heart/js-mutator/blob/main/include/js_mutator/mutator.h"
click node_mutation "https://github.com/hacking-by-heart/js-mutator/blob/main/src/mutator.cc"
click node_generation "https://github.com/hacking-by-heart/js-mutator/blob/main/src/generator.cc"
click node_generator_model "https://github.com/hacking-by-heart/js-mutator/blob/main/src/generator.h"
click node_harness_helpers "https://github.com/hacking-by-heart/js-mutator/blob/main/harness/common.h"
click node_parse_helpers "https://github.com/hacking-by-heart/js-mutator/blob/main/harness/parse.h"
click node_parse_target "https://github.com/hacking-by-heart/js-mutator/blob/main/harness/parser.cc"
click node_lazy_target "https://github.com/hacking-by-heart/js-mutator/blob/main/harness/compile.cc"
click node_stream_target "https://github.com/hacking-by-heart/js-mutator/blob/main/harness/streaming.cc"
click node_diff_target "https://github.com/hacking-by-heart/js-mutator/blob/main/harness/diff.cc"

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_public_api,node_mutation,node_generation,node_generator_model toneBlue
class node_adapter_code toneAmber
class node_harness_helpers,node_parse_helpers,node_parse_target,node_lazy_target,node_stream_target,node_diff_target toneMint
class node_libfuzzer,node_v8_engine toneIndigo
```

## Components

### Mutation engine

- [Mutator API](https://github.com/hacking-by-heart/js-mutator/blob/main/include/js_mutator/mutator.h): `include/js_mutator/mutator.h`
- [Seed mutation](https://github.com/hacking-by-heart/js-mutator/blob/main/src/mutator.cc): `src/mutator.cc`
- [Grammar generation](https://github.com/hacking-by-heart/js-mutator/blob/main/src/generator.cc): `src/generator.cc`
- [Generation model](https://github.com/hacking-by-heart/js-mutator/blob/main/src/generator.h): `src/generator.h`

### Fuzzer interface

- [Callback adapter](https://github.com/hacking-by-heart/js-mutator/blob/main/adapters/libfuzzer.cc): `adapters/libfuzzer.cc`

### V8 fuzz targets

- [Harness helpers](https://github.com/hacking-by-heart/js-mutator/blob/main/harness/common.h): `harness/common.h`
- [Parse support](https://github.com/hacking-by-heart/js-mutator/blob/main/harness/parse.h): `harness/parse.h`
- [Parse target](https://github.com/hacking-by-heart/js-mutator/blob/main/harness/parser.cc): `harness/parser.cc`
- [Lazy compile](https://github.com/hacking-by-heart/js-mutator/blob/main/harness/compile.cc): `harness/compile.cc`
- [Streaming compile](https://github.com/hacking-by-heart/js-mutator/blob/main/harness/streaming.cc): `harness/streaming.cc`
- [Parse diff](https://github.com/hacking-by-heart/js-mutator/blob/main/harness/diff.cc): `harness/diff.cc`

### Other components

- **libFuzzer**
- **V8 parser/compiler**

## Connections

- libFuzzer → Callback adapter: invokes callbacks (evidence: `README.md`)
- Callback adapter → Mutator API: calls mutate/crossover (evidence: `adapters/libfuzzer.cc`)
- Mutator API → Seed mutation: implemented by (evidence: `src/mutator.cc`)
- Seed mutation → Grammar generation: dispatches generation
- Grammar generation → Generation model: uses definitions (evidence: `src/generator.cc`)
- Parse target → Parse support: calls parse pass (evidence: `harness/parser.cc`)
- Parse target → Harness helpers: uses helpers (evidence: `harness/parser.cc`)
- Parse support → Harness helpers: uses helpers (evidence: `harness/parse.h`)
- Lazy compile → Harness helpers: uses helpers (evidence: `harness/compile.cc`)
- Streaming compile → Harness helpers: uses helpers (evidence: `harness/streaming.cc`)
- Parse target → V8 parser/compiler: parses input (evidence: `harness/parser.cc`)
- Lazy compile → V8 parser/compiler: compiles functions (evidence: `harness/compile.cc`)
- Streaming compile → V8 parser/compiler: streams compilation (evidence: `harness/streaming.cc`)
- Parse diff → Parse support: uses parse pass (evidence: `harness/diff.cc`)
- Parse diff → Harness helpers: uses helpers (evidence: `harness/diff.cc`)
