# cheeriojs/cheerio architecture

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

- Interactive diagram: https://gitdiagram.com/cheeriojs/cheerio
- Repository: https://github.com/cheeriojs/cheerio

## Overview

Cheerio is a server- and browser-usable HTML/XML parsing and manipulation library. The principal workflow loads markup, parses it into a DOM-backed collection, supports jQuery-style selection, traversal, extraction, attributes, CSS, forms and structural edits, then renders HTML/XML or text. Loading also includes buffer decoding, streams and URL fetching in the batteries-included entry point. The graph follows documented behavior and source-index references; unsampled implementations are represented only where the tree or README supports their role.

Main entry points: [`src/cheerio.ts`](https://github.com/cheeriojs/cheerio/blob/main/src/cheerio.ts) (Cheerio collection), [`src/load-parse.ts`](https://github.com/cheeriojs/cheerio/blob/main/src/load-parse.ts) (Load factory), [`src/load.ts`](https://github.com/cheeriojs/cheerio/blob/main/src/load.ts) (Selection and loading), [`src/index.ts`](https://github.com/cheeriojs/cheerio/blob/main/src/index.ts) (Public entry points)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_entry["Entry and loading"]
  node_entrypoint["Public entry points<br/>[index.ts]"]
  node_slim["Slim entry<br/>[slim.ts]"]
  node_loaders["Load and decode<br/>[index.ts]"]
  node_options["Parser options<br/>[options.ts]"]
end

subgraph group_dom["DOM core"]
  node_loadparse["Load factory<br/>[load-parse.ts]"]
  node_parsing["Parser selection<br/>[parse.ts]"]
  node_parse5["Parse5 adapter<br/>[parse5-adapter.ts]"]
  node_collection["Cheerio collection<br/>[cheerio.ts]"]
  node_selectors["Selection and loading<br/>[load.ts]"]
end

subgraph group_api["Collection API"]
  node_traversal["Traversal<br/>[traversing.ts]"]
  node_attributes["Attributes and properties<br/>[attributes.ts]"]
  node_css["CSS methods<br/>[css.ts]"]
  node_forms["Form methods<br/>[forms.ts]"]
  node_manipulation["DOM manipulation<br/>[manipulation.ts]"]
  node_extract["Data extraction<br/>[extract.ts]"]
end

subgraph group_output["Rendering and output"]
  node_static["Static utilities<br/>[static.ts]"]
  node_rendering["HTML and XML rendering<br/>[load-parse.ts]"]
  node_text["Text output<br/>[static.ts]"]
end

node_user(("Library caller"))

node_user -->|"calls"| node_entrypoint
node_entrypoint -->|"exports"| node_loaders
node_entrypoint -->|"loads via"| node_loadparse
node_entrypoint -->|"flattens"| node_options
node_user -.->|"chooses"| node_slim
node_slim -->|"loads through"| node_selectors
node_loaders -->|"passes markup"| node_loadparse
node_loadparse -->|"parses through"| node_parsing
node_loadparse -->|"uses adapter"| node_parse5
node_loadparse -->|"creates factory"| node_selectors
node_selectors -->|"flattens"| node_options
node_selectors -->|"instantiates"| node_collection
node_collection -->|"mixes in"| node_traversal
node_collection -->|"mixes in"| node_attributes
node_collection -->|"mixes in"| node_css
node_collection -->|"mixes in"| node_forms
node_collection -->|"mixes in"| node_manipulation
node_collection -->|"mixes in"| node_extract
node_manipulation -->|"parses inserted markup"| node_parsing
node_selectors -->|"provides API"| node_static
node_static -->|"delegates extraction"| node_extract
node_static -->|"renders markup"| node_rendering
node_static -->|"returns text"| node_text
node_rendering -->|"serializes with"| node_parse5
node_rendering -->|"selects renderer"| node_parsing

click node_entrypoint "https://github.com/cheeriojs/cheerio/blob/main/src/index.ts"
click node_slim "https://github.com/cheeriojs/cheerio/blob/main/src/slim.ts"
click node_loaders "https://github.com/cheeriojs/cheerio/blob/main/src/index.ts"
click node_options "https://github.com/cheeriojs/cheerio/blob/main/src/options.ts"
click node_loadparse "https://github.com/cheeriojs/cheerio/blob/main/src/load-parse.ts"
click node_parsing "https://github.com/cheeriojs/cheerio/blob/main/src/parse.ts"
click node_parse5 "https://github.com/cheeriojs/cheerio/blob/main/src/parsers/parse5-adapter.ts"
click node_collection "https://github.com/cheeriojs/cheerio/blob/main/src/cheerio.ts"
click node_selectors "https://github.com/cheeriojs/cheerio/blob/main/src/load.ts"
click node_traversal "https://github.com/cheeriojs/cheerio/blob/main/src/api/traversing.ts"
click node_attributes "https://github.com/cheeriojs/cheerio/blob/main/src/api/attributes.ts"
click node_css "https://github.com/cheeriojs/cheerio/blob/main/src/api/css.ts"
click node_forms "https://github.com/cheeriojs/cheerio/blob/main/src/api/forms.ts"
click node_manipulation "https://github.com/cheeriojs/cheerio/blob/main/src/api/manipulation.ts"
click node_extract "https://github.com/cheeriojs/cheerio/blob/main/src/api/extract.ts"
click node_static "https://github.com/cheeriojs/cheerio/blob/main/src/static.ts"
click node_rendering "https://github.com/cheeriojs/cheerio/blob/main/src/load-parse.ts"
click node_text "https://github.com/cheeriojs/cheerio/blob/main/src/static.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_entrypoint,node_slim,node_loaders,node_options toneBlue
class node_loadparse,node_parsing,node_parse5,node_collection,node_selectors toneAmber
class node_traversal,node_attributes,node_css,node_forms,node_manipulation,node_extract toneMint
class node_static,node_rendering,node_text toneRose
class node_user toneIndigo
```

## Components

### Entry and loading

- [Public entry points](https://github.com/cheeriojs/cheerio/blob/main/src/index.ts): `src/index.ts`
- [Slim entry](https://github.com/cheeriojs/cheerio/blob/main/src/slim.ts): `src/slim.ts`
- [Load and decode](https://github.com/cheeriojs/cheerio/blob/main/src/index.ts): `src/index.ts`
- [Parser options](https://github.com/cheeriojs/cheerio/blob/main/src/options.ts): `src/options.ts`

### DOM core

- [Load factory](https://github.com/cheeriojs/cheerio/blob/main/src/load-parse.ts): `src/load-parse.ts`
- [Parser selection](https://github.com/cheeriojs/cheerio/blob/main/src/parse.ts): `src/parse.ts`
- [Parse5 adapter](https://github.com/cheeriojs/cheerio/blob/main/src/parsers/parse5-adapter.ts): `src/parsers/parse5-adapter.ts`
- [Cheerio collection](https://github.com/cheeriojs/cheerio/blob/main/src/cheerio.ts): `src/cheerio.ts`
- [Selection and loading](https://github.com/cheeriojs/cheerio/blob/main/src/load.ts): `src/load.ts`

### Collection API

- [Traversal](https://github.com/cheeriojs/cheerio/blob/main/src/api/traversing.ts): `src/api/traversing.ts`
- [Attributes and properties](https://github.com/cheeriojs/cheerio/blob/main/src/api/attributes.ts): `src/api/attributes.ts`
- [CSS methods](https://github.com/cheeriojs/cheerio/blob/main/src/api/css.ts): `src/api/css.ts`
- [Form methods](https://github.com/cheeriojs/cheerio/blob/main/src/api/forms.ts): `src/api/forms.ts`
- [DOM manipulation](https://github.com/cheeriojs/cheerio/blob/main/src/api/manipulation.ts): `src/api/manipulation.ts`
- [Data extraction](https://github.com/cheeriojs/cheerio/blob/main/src/api/extract.ts): `src/api/extract.ts`

### Rendering and output

- [Static utilities](https://github.com/cheeriojs/cheerio/blob/main/src/static.ts): `src/static.ts`
- [HTML and XML rendering](https://github.com/cheeriojs/cheerio/blob/main/src/load-parse.ts): `src/load-parse.ts`
- [Text output](https://github.com/cheeriojs/cheerio/blob/main/src/static.ts): `src/static.ts`

### Other components

- **Library caller**

## Connections

- Library caller → Public entry points: calls (evidence: `Readme.md`)
- Public entry points → Load and decode: exports (evidence: `src/index.ts`)
- Public entry points → Load factory: loads via (evidence: `src/index.ts`)
- Public entry points → Parser options: flattens (evidence: `src/index.ts`)
- Library caller → Slim entry: chooses
- Slim entry → Selection and loading: loads through (evidence: `src/slim.ts`)
- Load and decode → Load factory: passes markup (evidence: `src/index.ts`)
- Load factory → Parser selection: parses through (evidence: `src/load-parse.ts`)
- Load factory → Parse5 adapter: uses adapter (evidence: `src/load-parse.ts`)
- Load factory → Selection and loading: creates factory (evidence: `src/load-parse.ts`)
- Selection and loading → Parser options: flattens (evidence: `src/load.ts`)
- Selection and loading → Cheerio collection: instantiates (evidence: `src/load.ts`)
- Cheerio collection → Traversal: mixes in (evidence: `src/cheerio.ts`)
- Cheerio collection → Attributes and properties: mixes in (evidence: `src/cheerio.ts`)
- Cheerio collection → CSS methods: mixes in (evidence: `src/cheerio.ts`)
- Cheerio collection → Form methods: mixes in (evidence: `src/cheerio.ts`)
- Cheerio collection → DOM manipulation: mixes in (evidence: `src/cheerio.ts`)
- Cheerio collection → Data extraction: mixes in (evidence: `src/cheerio.ts`)
- DOM manipulation → Parser selection: parses inserted markup (evidence: `src/api/manipulation.ts`)
- Selection and loading → Static utilities: provides API (evidence: `src/load.ts`)
- Static utilities → Data extraction: delegates extraction (evidence: `src/static.ts`)
- Static utilities → HTML and XML rendering: renders markup (evidence: `src/static.ts`)
- Static utilities → Text output: returns text (evidence: `src/static.ts`)
- HTML and XML rendering → Parse5 adapter: serializes with (evidence: `src/load-parse.ts`)
- HTML and XML rendering → Parser selection: selects renderer (evidence: `src/load-parse.ts`)
