# wd21th/selectorjs architecture

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

- Interactive diagram: https://gitdiagram.com/wd21th/selectorjs
- Repository: https://github.com/wd21th/selectorjs

## Overview

Selector Js is a VS Code extension that turns selected HTML into JavaScript DOM-query code, then copies the generated text to the clipboard. Users invoke commands from the command palette; selector commands parse the selection, generate declarations, and report completion. The README also documents selector variants (including nested details and events) and JavaScript createElement completion. The source index identifies relationships among the command and utility modules, but several command implementations were not excerpted, so their internal details are represented at subsystem level.

Main entry points: [`src/commands/index.js`](https://github.com/wd21th/selectorjs/blob/main/src/commands/index.js) (Command registry), [`src/utils/build-html-tree.js`](https://github.com/wd21th/selectorjs/blob/main/src/utils/build-html-tree.js) (HTML tree builder), [`src/commands/query-selector-all.command.js`](https://github.com/wd21th/selectorjs/blob/main/src/commands/query-selector-all.command.js) (All selectors), [`src/commands/query-selector-with-details.command.js`](https://github.com/wd21th/selectorjs/blob/main/src/commands/query-selector-with-details.command.js) (Nested details selector)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_extension["VS Code Extension"]
  node_extension["Extension activation<br/>[extension.js]"]
  node_command_registry["Command registry<br/>[index.js]"]
end

subgraph group_commands["Command Workflows"]
  node_selection["Editor selection<br/>[get-selection.js]"]
  node_single["Single selector"]
  node_all["All selectors"]
  node_by["Select by attribute"]
  node_all_by["Select all by attribute"]
  node_details["Nested details selector"]
  node_event["Selector with event"]
  node_create["Create element completion"]
end

subgraph group_utilities["HTML Utilities"]
  node_tree["HTML tree builder<br/>[build-html-tree.js]"]
  node_element_models["HTML element models<br/>[classes.js]"]
  node_attributes["Attribute parsing<br/>[get-attributes.js]"]
  node_selector_one["Single query builder<br/>[query-selector.js]"]
  node_selector_many["Multiple query builder"]
  node_var_names["Variable name helpers"]
  node_id_names["ID variable helper"]
  node_button_one["Button selector helper<br/>[button-correct.js]"]
  node_button_many["Button-all helper"]
  node_regex["HTML and text patterns<br/>[regex.js]"]
end

node_user(("VS Code user"))
node_clipboard["System clipboard"]

node_user -->|"invokes commands"| node_extension
node_extension -->|"loads registry"| node_command_registry
node_command_registry -->|"registers command"| node_single
node_command_registry -->|"registers command"| node_all
node_command_registry -->|"registers command"| node_by
node_command_registry -->|"registers command"| node_all_by
node_command_registry -->|"registers command"| node_details
node_command_registry -->|"registers command"| node_event
node_command_registry -->|"registers command"| node_create
node_single -->|"reads selection"| node_selection
node_single -->|"builds HTML tree"| node_tree
node_single -->|"generates declarations"| node_selector_one
node_all -->|"reads selection"| node_selection
node_all -->|"builds HTML tree"| node_tree
node_all -->|"generates declarations"| node_selector_many
node_all -->|"formats buttons"| node_button_one
node_by -->|"reads selection"| node_selection
node_by -->|"builds HTML tree"| node_tree
node_all_by -->|"reads selection"| node_selection
node_all_by -->|"builds HTML tree"| node_tree
node_details -->|"reads selection"| node_selection
node_details -->|"builds HTML tree"| node_tree
node_details -->|"names IDs"| node_id_names
node_details -->|"names classes"| node_var_names
node_tree -->|"creates elements"| node_element_models
node_tree -->|"reads attributes"| node_attributes
node_tree -->|"uses patterns"| node_regex
node_selector_one -->|"names IDs"| node_id_names
node_selector_one -->|"names classes"| node_var_names
node_selector_many -->|"names attributes"| node_id_names
node_selector_many -->|"names classes"| node_var_names
node_button_one -->|"names IDs"| node_id_names
node_button_many -->|"names IDs"| node_id_names
node_single -.->|"copies generated text"| node_clipboard
node_all -->|"copies generated text"| node_clipboard
node_by -->|"copies generated text"| node_clipboard
node_all_by -->|"copies generated text"| node_clipboard
node_details -->|"copies generated text"| node_clipboard
node_event -.->|"copies generated text"| node_clipboard
node_create -.->|"copies generated text"| node_clipboard

click node_extension "https://github.com/wd21th/selectorjs/blob/main/extension.js"
click node_command_registry "https://github.com/wd21th/selectorjs/blob/main/src/commands/index.js"
click node_selection "https://github.com/wd21th/selectorjs/blob/main/src/utils/get-selection.js"
click node_single "https://github.com/wd21th/selectorjs/blob/main/src/commands/query-selector.command.js"
click node_all "https://github.com/wd21th/selectorjs/blob/main/src/commands/query-selector-all.command.js"
click node_by "https://github.com/wd21th/selectorjs/blob/main/src/commands/query-selector-by.command.js"
click node_all_by "https://github.com/wd21th/selectorjs/blob/main/src/commands/query-selector-all-by.command.js"
click node_details "https://github.com/wd21th/selectorjs/blob/main/src/commands/query-selector-with-details.command.js"
click node_event "https://github.com/wd21th/selectorjs/blob/main/src/commands/query-selector-with-event.command.js"
click node_create "https://github.com/wd21th/selectorjs/blob/main/src/commands/create-element.command.js"
click node_tree "https://github.com/wd21th/selectorjs/blob/main/src/utils/build-html-tree.js"
click node_element_models "https://github.com/wd21th/selectorjs/blob/main/src/classes.js"
click node_attributes "https://github.com/wd21th/selectorjs/blob/main/src/utils/get-attributes.js"
click node_selector_one "https://github.com/wd21th/selectorjs/blob/main/src/utils/query-selector.js"
click node_selector_many "https://github.com/wd21th/selectorjs/blob/main/src/utils/query-selector-all.js"
click node_var_names "https://github.com/wd21th/selectorjs/blob/main/src/utils/check-class-var-name.js"
click node_id_names "https://github.com/wd21th/selectorjs/blob/main/src/utils/check-id-var-name.js"
click node_button_one "https://github.com/wd21th/selectorjs/blob/main/src/utils/button-correct.js"
click node_button_many "https://github.com/wd21th/selectorjs/blob/main/src/utils/button-all-correct.js"
click node_regex "https://github.com/wd21th/selectorjs/blob/main/src/regex.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_extension,node_command_registry,node_user toneBlue
class node_selection,node_single,node_all,node_by,node_all_by,node_details,node_event,node_create toneAmber
class node_tree,node_element_models,node_attributes,node_selector_one,node_selector_many,node_var_names,node_id_names,node_button_one,node_button_many,node_regex toneMint
class node_clipboard toneIndigo
```

## Components

### VS Code Extension

- [Extension activation](https://github.com/wd21th/selectorjs/blob/main/extension.js): `extension.js`
- [Command registry](https://github.com/wd21th/selectorjs/blob/main/src/commands/index.js): `src/commands/index.js`

### Command Workflows

- [Editor selection](https://github.com/wd21th/selectorjs/blob/main/src/utils/get-selection.js): `src/utils/get-selection.js`
- [Single selector](https://github.com/wd21th/selectorjs/blob/main/src/commands/query-selector.command.js): `src/commands/query-selector.command.js`
- [All selectors](https://github.com/wd21th/selectorjs/blob/main/src/commands/query-selector-all.command.js): `src/commands/query-selector-all.command.js`
- [Select by attribute](https://github.com/wd21th/selectorjs/blob/main/src/commands/query-selector-by.command.js): `src/commands/query-selector-by.command.js`
- [Select all by attribute](https://github.com/wd21th/selectorjs/blob/main/src/commands/query-selector-all-by.command.js): `src/commands/query-selector-all-by.command.js`
- [Nested details selector](https://github.com/wd21th/selectorjs/blob/main/src/commands/query-selector-with-details.command.js): `src/commands/query-selector-with-details.command.js`
- [Selector with event](https://github.com/wd21th/selectorjs/blob/main/src/commands/query-selector-with-event.command.js): `src/commands/query-selector-with-event.command.js`
- [Create element completion](https://github.com/wd21th/selectorjs/blob/main/src/commands/create-element.command.js): `src/commands/create-element.command.js`

### HTML Utilities

- [HTML tree builder](https://github.com/wd21th/selectorjs/blob/main/src/utils/build-html-tree.js): `src/utils/build-html-tree.js`
- [HTML element models](https://github.com/wd21th/selectorjs/blob/main/src/classes.js): `src/classes.js`
- [Attribute parsing](https://github.com/wd21th/selectorjs/blob/main/src/utils/get-attributes.js): `src/utils/get-attributes.js`
- [Single query builder](https://github.com/wd21th/selectorjs/blob/main/src/utils/query-selector.js): `src/utils/query-selector.js`
- [Multiple query builder](https://github.com/wd21th/selectorjs/blob/main/src/utils/query-selector-all.js): `src/utils/query-selector-all.js`
- [Variable name helpers](https://github.com/wd21th/selectorjs/blob/main/src/utils/check-class-var-name.js): `src/utils/check-class-var-name.js`
- [ID variable helper](https://github.com/wd21th/selectorjs/blob/main/src/utils/check-id-var-name.js): `src/utils/check-id-var-name.js`
- [Button selector helper](https://github.com/wd21th/selectorjs/blob/main/src/utils/button-correct.js): `src/utils/button-correct.js`
- [Button-all helper](https://github.com/wd21th/selectorjs/blob/main/src/utils/button-all-correct.js): `src/utils/button-all-correct.js`
- [HTML and text patterns](https://github.com/wd21th/selectorjs/blob/main/src/regex.js): `src/regex.js`

### Other components

- **VS Code user**
- **System clipboard**

## Connections

- VS Code user → Extension activation: invokes commands (evidence: `README.md`)
- Extension activation → Command registry: loads registry (evidence: `extension.js`)
- Command registry → Single selector: registers command (evidence: `src/commands/index.js`)
- Command registry → All selectors: registers command (evidence: `src/commands/index.js`)
- Command registry → Select by attribute: registers command (evidence: `src/commands/index.js`)
- Command registry → Select all by attribute: registers command (evidence: `src/commands/index.js`)
- Command registry → Nested details selector: registers command (evidence: `src/commands/index.js`)
- Command registry → Selector with event: registers command (evidence: `src/commands/index.js`)
- Command registry → Create element completion: registers command (evidence: `src/commands/index.js`)
- Single selector → Editor selection: reads selection (evidence: `src/commands/query-selector.command.js`)
- Single selector → HTML tree builder: builds HTML tree (evidence: `src/commands/query-selector.command.js`)
- Single selector → Single query builder: generates declarations (evidence: `src/commands/query-selector.command.js`)
- All selectors → Editor selection: reads selection (evidence: `src/commands/query-selector-all.command.js`)
- All selectors → HTML tree builder: builds HTML tree (evidence: `src/commands/query-selector-all.command.js`)
- All selectors → Multiple query builder: generates declarations (evidence: `src/commands/query-selector-all.command.js`)
- All selectors → Button selector helper: formats buttons (evidence: `src/commands/query-selector-all.command.js`)
- Select by attribute → Editor selection: reads selection (evidence: `src/commands/query-selector-by.command.js`)
- Select by attribute → HTML tree builder: builds HTML tree (evidence: `src/commands/query-selector-by.command.js`)
- Select all by attribute → Editor selection: reads selection (evidence: `src/commands/query-selector-all-by.command.js`)
- Select all by attribute → HTML tree builder: builds HTML tree (evidence: `src/commands/query-selector-all-by.command.js`)
- Nested details selector → Editor selection: reads selection (evidence: `src/commands/query-selector-with-details.command.js`)
- Nested details selector → HTML tree builder: builds HTML tree (evidence: `src/commands/query-selector-with-details.command.js`)
- Nested details selector → ID variable helper: names IDs (evidence: `src/commands/query-selector-with-details.command.js`)
- Nested details selector → Variable name helpers: names classes (evidence: `src/commands/query-selector-with-details.command.js`)
- HTML tree builder → HTML element models: creates elements (evidence: `src/utils/build-html-tree.js`)
- HTML tree builder → Attribute parsing: reads attributes (evidence: `src/utils/build-html-tree.js`)
- HTML tree builder → HTML and text patterns: uses patterns (evidence: `src/utils/build-html-tree.js`)
- Single query builder → ID variable helper: names IDs (evidence: `src/utils/query-selector.js`)
- Single query builder → Variable name helpers: names classes (evidence: `src/utils/query-selector.js`)
- Multiple query builder → ID variable helper: names attributes (evidence: `src/utils/query-selector-all.js`)
- Multiple query builder → Variable name helpers: names classes (evidence: `src/utils/query-selector-all.js`)
- Button selector helper → ID variable helper: names IDs (evidence: `src/utils/button-correct.js`)
- Button-all helper → ID variable helper: names IDs (evidence: `src/utils/button-all-correct.js`)
- Single selector → System clipboard: copies generated text
- All selectors → System clipboard: copies generated text (evidence: `src/commands/query-selector-all.command.js`)
- Select by attribute → System clipboard: copies generated text (evidence: `src/commands/query-selector-by.command.js`)
- Select all by attribute → System clipboard: copies generated text (evidence: `src/commands/query-selector-all-by.command.js`)
- Nested details selector → System clipboard: copies generated text (evidence: `src/commands/query-selector-with-details.command.js`)
- Selector with event → System clipboard: copies generated text
- Create element completion → System clipboard: copies generated text
