# meta/jscodeshift architecture

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

- Interactive diagram: https://gitdiagram.com/meta/jscodeshift
- Repository: https://github.com/meta/jscodeshift

## Overview

jscodeshift is a JavaScript and TypeScript codemod toolkit: a user supplies source paths and a transform, the runner processes files, and transforms can use an AST-based Recast wrapper to inspect and modify code. The graph preserves the documented CLI and library workflows, parser choices, and major transformation APIs. Runner internals and several modules are unsampled, so uncertain control-flow links are omitted or marked unverified rather than inferred.

Main entry points: [`src/getParser.js`](https://github.com/meta/jscodeshift/blob/main/src/getParser.js) (Parser selection), [`src/Worker.js`](https://github.com/meta/jscodeshift/blob/main/src/Worker.js) (Transform worker), [`src/Collection.js`](https://github.com/meta/jscodeshift/blob/main/src/Collection.js) (AST collections), [`src/collections/JSXElement.js`](https://github.com/meta/jscodeshift/blob/main/src/collections/JSXElement.js) (JSX operations)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_execution["Execution"]
  node_cli["CLI entry<br/>[jscodeshift.js]"]
  node_options["Option parser<br/>[argsParser.js]"]
  node_runner["File runner<br/>[Runner.js]"]
  node_worker["Transform worker<br/>[Worker.js]"]
end

subgraph group_parsing["Parsing"]
  node_parserselect["Parser selection<br/>[getParser.js]"]
  node_babelparser["Babel parser<br/>[babel5Compat.js]"]
  node_babylonparser["Babylon parser<br/>[babylon.js]"]
  node_flowparser["Flow parser<br/>[flow.js]"]
  node_tsparser["TypeScript parser<br/>[ts.js]"]
  node_tsxparser["TSX parser<br/>[tsx.js]"]
end

subgraph group_ast["AST toolkit"]
  node_core["jscodeshift API<br/>[core.js]"]
  node_collection["AST collections<br/>[Collection.js]"]
  node_nodeops["Node operations<br/>[Node.js]"]
  node_jsxops["JSX operations<br/>[JSXElement.js]"]
  node_variableops["Variable operations"]
  node_importops["Import operations"]
  node_template["AST templates<br/>[template.js]"]
end

subgraph group_support["Utilities"]
  node_match["Node matching<br/>[matchNode.js]"]
  node_intersection["Type intersection<br/>[intersection.js]"]
  node_once["Once registration<br/>[once.js]"]
end

node_user(("Codemod user"))
node_transform["User transform"]
node_files[("Source files")]

node_user -->|"supplies options"| node_cli
node_cli -->|"parses arguments"| node_options
node_cli -->|"starts run"| node_runner
node_user -->|"provides transform"| node_transform
node_user -->|"selects paths"| node_files
node_runner -.->|"dispatches files"| node_worker
node_worker -->|"invokes transform"| node_transform
node_worker -->|"reads and writes"| node_files
node_worker -->|"selects parser"| node_parserselect
node_worker -->|"loads API"| node_core
node_transform -->|"uses API"| node_core
node_core -.->|"exposes collections"| node_collection
node_collection -->|"uses helper"| node_intersection
node_nodeops -->|"extends collections"| node_collection
node_nodeops -->|"matches nodes"| node_match
node_jsxops -->|"extends collections"| node_collection
node_jsxops -->|"uses node methods"| node_nodeops
node_jsxops -->|"uses module filter"| node_variableops
node_variableops -->|"extends collections"| node_collection
node_nodeops -->|"guards registration"| node_once
node_jsxops -->|"guards registration"| node_once
node_variableops -->|"guards registration"| node_once
node_parserselect -->|"selects parser"| node_babelparser
node_parserselect -->|"selects parser"| node_babylonparser
node_parserselect -->|"selects parser"| node_flowparser
node_parserselect -->|"selects parser"| node_tsparser
node_parserselect -->|"selects parser"| node_tsxparser

click node_cli "https://github.com/meta/jscodeshift/blob/main/bin/jscodeshift.js"
click node_options "https://github.com/meta/jscodeshift/blob/main/src/argsParser.js"
click node_runner "https://github.com/meta/jscodeshift/blob/main/src/Runner.js"
click node_worker "https://github.com/meta/jscodeshift/blob/main/src/Worker.js"
click node_core "https://github.com/meta/jscodeshift/blob/main/src/core.js"
click node_collection "https://github.com/meta/jscodeshift/blob/main/src/Collection.js"
click node_nodeops "https://github.com/meta/jscodeshift/blob/main/src/collections/Node.js"
click node_jsxops "https://github.com/meta/jscodeshift/blob/main/src/collections/JSXElement.js"
click node_variableops "https://github.com/meta/jscodeshift/blob/main/src/collections/VariableDeclarator.js"
click node_importops "https://github.com/meta/jscodeshift/blob/main/src/collections/ImportDeclaration.js"
click node_template "https://github.com/meta/jscodeshift/blob/main/src/template.js"
click node_parserselect "https://github.com/meta/jscodeshift/blob/main/src/getParser.js"
click node_babelparser "https://github.com/meta/jscodeshift/blob/main/parser/babel5Compat.js"
click node_babylonparser "https://github.com/meta/jscodeshift/blob/main/parser/babylon.js"
click node_flowparser "https://github.com/meta/jscodeshift/blob/main/parser/flow.js"
click node_tsparser "https://github.com/meta/jscodeshift/blob/main/parser/ts.js"
click node_tsxparser "https://github.com/meta/jscodeshift/blob/main/parser/tsx.js"
click node_match "https://github.com/meta/jscodeshift/blob/main/src/matchNode.js"
click node_intersection "https://github.com/meta/jscodeshift/blob/main/src/utils/intersection.js"
click node_once "https://github.com/meta/jscodeshift/blob/main/src/utils/once.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_cli,node_options,node_runner,node_worker,node_user,node_transform toneBlue
class node_parserselect,node_babelparser,node_babylonparser,node_flowparser,node_tsparser,node_tsxparser,node_files toneAmber
class node_core,node_collection,node_nodeops,node_jsxops,node_variableops,node_importops,node_template toneMint
class node_match,node_intersection,node_once toneRose
```

## Components

### Execution

- [CLI entry](https://github.com/meta/jscodeshift/blob/main/bin/jscodeshift.js): `bin/jscodeshift.js`
- [Option parser](https://github.com/meta/jscodeshift/blob/main/src/argsParser.js): `src/argsParser.js`
- [File runner](https://github.com/meta/jscodeshift/blob/main/src/Runner.js): `src/Runner.js`
- [Transform worker](https://github.com/meta/jscodeshift/blob/main/src/Worker.js): `src/Worker.js`

### Parsing

- [Parser selection](https://github.com/meta/jscodeshift/blob/main/src/getParser.js): `src/getParser.js`
- [Babel parser](https://github.com/meta/jscodeshift/blob/main/parser/babel5Compat.js): `parser/babel5Compat.js`
- [Babylon parser](https://github.com/meta/jscodeshift/blob/main/parser/babylon.js): `parser/babylon.js`
- [Flow parser](https://github.com/meta/jscodeshift/blob/main/parser/flow.js): `parser/flow.js`
- [TypeScript parser](https://github.com/meta/jscodeshift/blob/main/parser/ts.js): `parser/ts.js`
- [TSX parser](https://github.com/meta/jscodeshift/blob/main/parser/tsx.js): `parser/tsx.js`

### AST toolkit

- [jscodeshift API](https://github.com/meta/jscodeshift/blob/main/src/core.js): `src/core.js`
- [AST collections](https://github.com/meta/jscodeshift/blob/main/src/Collection.js): `src/Collection.js`
- [Node operations](https://github.com/meta/jscodeshift/blob/main/src/collections/Node.js): `src/collections/Node.js`
- [JSX operations](https://github.com/meta/jscodeshift/blob/main/src/collections/JSXElement.js): `src/collections/JSXElement.js`
- [Variable operations](https://github.com/meta/jscodeshift/blob/main/src/collections/VariableDeclarator.js): `src/collections/VariableDeclarator.js`
- [Import operations](https://github.com/meta/jscodeshift/blob/main/src/collections/ImportDeclaration.js): `src/collections/ImportDeclaration.js`
- [AST templates](https://github.com/meta/jscodeshift/blob/main/src/template.js): `src/template.js`

### Utilities

- [Node matching](https://github.com/meta/jscodeshift/blob/main/src/matchNode.js): `src/matchNode.js`
- [Type intersection](https://github.com/meta/jscodeshift/blob/main/src/utils/intersection.js): `src/utils/intersection.js`
- [Once registration](https://github.com/meta/jscodeshift/blob/main/src/utils/once.js): `src/utils/once.js`

### Other components

- **Codemod user**
- **User transform**
- **Source files**

## Connections

- Codemod user → CLI entry: supplies options
- CLI entry → Option parser: parses arguments (evidence: `bin/jscodeshift.js`)
- CLI entry → File runner: starts run (evidence: `bin/jscodeshift.js`)
- Codemod user → User transform: provides transform
- Codemod user → Source files: selects paths
- File runner → Transform worker: dispatches files
- Transform worker → User transform: invokes transform (evidence: `src/Worker.js`)
- Transform worker → Source files: reads and writes (evidence: `src/Worker.js`)
- Transform worker → Parser selection: selects parser (evidence: `src/Worker.js`)
- Transform worker → jscodeshift API: loads API (evidence: `src/Worker.js`)
- User transform → jscodeshift API: uses API
- jscodeshift API → AST collections: exposes collections
- AST collections → Type intersection: uses helper (evidence: `src/Collection.js`)
- Node operations → AST collections: extends collections (evidence: `src/collections/Node.js`)
- Node operations → Node matching: matches nodes (evidence: `src/collections/Node.js`)
- JSX operations → AST collections: extends collections (evidence: `src/collections/JSXElement.js`)
- JSX operations → Node operations: uses node methods (evidence: `src/collections/JSXElement.js`)
- JSX operations → Variable operations: uses module filter (evidence: `src/collections/JSXElement.js`)
- Variable operations → AST collections: extends collections (evidence: `src/collections/VariableDeclarator.js`)
- Node operations → Once registration: guards registration (evidence: `src/collections/Node.js`)
- JSX operations → Once registration: guards registration (evidence: `src/collections/JSXElement.js`)
- Variable operations → Once registration: guards registration (evidence: `src/collections/VariableDeclarator.js`)
- Parser selection → Babel parser: selects parser (evidence: `src/getParser.js`)
- Parser selection → Babylon parser: selects parser (evidence: `src/getParser.js`)
- Parser selection → Flow parser: selects parser (evidence: `src/getParser.js`)
- Parser selection → TypeScript parser: selects parser (evidence: `src/getParser.js`)
- Parser selection → TSX parser: selects parser (evidence: `src/getParser.js`)
