# preactjs/preact architecture

> Architecture diagram of the GitHub repository preactjs/preact, 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/preactjs/preact
- Repository: https://github.com/preactjs/preact

## Overview

Preact is a compact Virtual DOM UI library. The principal workflow is that application code describes component trees (often via JSX), calls render or hydrate, and Preact reconciles those descriptions into DOM updates. Components and hooks manage state and context; optional packages provide React compatibility, server rendering, debugging, DevTools, and JSX runtime support. Several extension implementations were not sampled, so their documented capabilities are shown without speculative internal call paths.

Main entry points: [`src/diff/index.js`](https://github.com/preactjs/preact/blob/main/src/diff/index.js) (VNode diff), [`src/index.js`](https://github.com/preactjs/preact/blob/main/src/index.js) (Public API), [`compat/src/index.js`](https://github.com/preactjs/preact/blob/main/compat/src/index.js) (React compatibility), [`src/component.js`](https://github.com/preactjs/preact/blob/main/src/component.js) (Components and updates)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_core["Core rendering"]
  node_tree["VNode creation<br/>[create-element.js]"]
  node_api["Public API<br/>[index.js]"]
  node_renderer["Render and hydrate<br/>[render.js]"]
  node_diff["VNode diff<br/>[index.js]"]
  node_children["Child reconciliation<br/>[children.js]"]
  node_props["DOM properties<br/>[props.js]"]
end

subgraph group_components["Components and state"]
  node_component["Components and updates<br/>[component.js]"]
  node_context["Context providers<br/>[create-context.js]"]
  node_hooks["Hooks<br/>[index.js]"]
end

subgraph group_extensions["Compatibility and tooling"]
  node_compat["React compatibility<br/>[index.js]"]
  node_compatrender["Compat rendering<br/>[render.js]"]
  node_suspense["Suspense and lazy<br/>[suspense.js]"]
  node_debug["Runtime diagnostics<br/>[debug.js]"]
  node_devtools["DevTools integration<br/>[devtools.js]"]
end

subgraph group_runtime["JSX and server"]
  node_jsx["JSX runtime<br/>[index.js]"]
  node_server["Server rendering<br/>[server.js]"]
  node_scheduler["Async scheduler<br/>[scheduler.js]"]
end

node_app(("Application code"))
node_dom["Browser DOM"]

node_app -->|"describes UI"| node_tree
node_app -->|"calls render"| node_api
node_api -->|"exports creation"| node_tree
node_api -->|"exports rendering"| node_renderer
node_renderer -->|"reconciles tree"| node_diff
node_diff -->|"diffs children"| node_children
node_diff -->|"sets properties"| node_props
node_renderer -->|"updates DOM"| node_dom
node_diff -->|"patches DOM"| node_dom
node_component -->|"rerenders components"| node_diff
node_context -->|"queues updates"| node_component
node_hooks -.->|"provides hooks"| node_app
node_compat -->|"adapts components"| node_component
node_compat -->|"re-exports hooks"| node_hooks
node_compat -->|"exports rendering"| node_compatrender
node_compat -->|"exports Suspense"| node_suspense
node_debug -->|"hooks renderer"| node_api
node_devtools -.->|"integrates DevTools"| node_api
node_app -->|"uses JSX"| node_jsx
node_app -.->|"renders server-side"| node_server
node_component -.->|"schedules updates"| node_scheduler

click node_tree "https://github.com/preactjs/preact/blob/main/src/create-element.js"
click node_api "https://github.com/preactjs/preact/blob/main/src/index.js"
click node_renderer "https://github.com/preactjs/preact/blob/main/src/render.js"
click node_diff "https://github.com/preactjs/preact/blob/main/src/diff/index.js"
click node_children "https://github.com/preactjs/preact/blob/main/src/diff/children.js"
click node_props "https://github.com/preactjs/preact/blob/main/src/diff/props.js"
click node_component "https://github.com/preactjs/preact/blob/main/src/component.js"
click node_context "https://github.com/preactjs/preact/blob/main/src/create-context.js"
click node_hooks "https://github.com/preactjs/preact/blob/main/hooks/src/index.js"
click node_compat "https://github.com/preactjs/preact/blob/main/compat/src/index.js"
click node_compatrender "https://github.com/preactjs/preact/blob/main/compat/src/render.js"
click node_suspense "https://github.com/preactjs/preact/blob/main/compat/src/suspense.js"
click node_debug "https://github.com/preactjs/preact/blob/main/debug/src/debug.js"
click node_devtools "https://github.com/preactjs/preact/blob/main/devtools/src/devtools.js"
click node_jsx "https://github.com/preactjs/preact/blob/main/jsx-runtime/src/index.js"
click node_server "https://github.com/preactjs/preact/blob/main/compat/server.js"
click node_scheduler "https://github.com/preactjs/preact/blob/main/compat/scheduler.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_tree,node_api,node_renderer,node_diff,node_children,node_props,node_dom toneBlue
class node_component,node_context,node_hooks toneAmber
class node_compat,node_compatrender,node_suspense,node_debug,node_devtools toneMint
class node_jsx,node_server,node_scheduler toneRose
class node_app toneIndigo
```

## Components

### Core rendering

- [VNode creation](https://github.com/preactjs/preact/blob/main/src/create-element.js): `src/create-element.js`
- [Public API](https://github.com/preactjs/preact/blob/main/src/index.js): `src/index.js`
- [Render and hydrate](https://github.com/preactjs/preact/blob/main/src/render.js): `src/render.js`
- [VNode diff](https://github.com/preactjs/preact/blob/main/src/diff/index.js): `src/diff/index.js`
- [Child reconciliation](https://github.com/preactjs/preact/blob/main/src/diff/children.js): `src/diff/children.js`
- [DOM properties](https://github.com/preactjs/preact/blob/main/src/diff/props.js): `src/diff/props.js`

### Components and state

- [Components and updates](https://github.com/preactjs/preact/blob/main/src/component.js): `src/component.js`
- [Context providers](https://github.com/preactjs/preact/blob/main/src/create-context.js): `src/create-context.js`
- [Hooks](https://github.com/preactjs/preact/blob/main/hooks/src/index.js): `hooks/src/index.js`

### Compatibility and tooling

- [React compatibility](https://github.com/preactjs/preact/blob/main/compat/src/index.js): `compat/src/index.js`
- [Compat rendering](https://github.com/preactjs/preact/blob/main/compat/src/render.js): `compat/src/render.js`
- [Suspense and lazy](https://github.com/preactjs/preact/blob/main/compat/src/suspense.js): `compat/src/suspense.js`
- [Runtime diagnostics](https://github.com/preactjs/preact/blob/main/debug/src/debug.js): `debug/src/debug.js`
- [DevTools integration](https://github.com/preactjs/preact/blob/main/devtools/src/devtools.js): `devtools/src/devtools.js`

### JSX and server

- [JSX runtime](https://github.com/preactjs/preact/blob/main/jsx-runtime/src/index.js): `jsx-runtime/src/index.js`
- [Server rendering](https://github.com/preactjs/preact/blob/main/compat/server.js): `compat/server.js`
- [Async scheduler](https://github.com/preactjs/preact/blob/main/compat/scheduler.js): `compat/scheduler.js`

### Other components

- **Application code**
- **Browser DOM**

## Connections

- Application code → VNode creation: describes UI
- Application code → Public API: calls render
- Public API → VNode creation: exports creation (evidence: `src/index.js`)
- Public API → Render and hydrate: exports rendering (evidence: `src/index.js`)
- Render and hydrate → VNode diff: reconciles tree (evidence: `src/render.js`)
- VNode diff → Child reconciliation: diffs children (evidence: `src/diff/index.js`)
- VNode diff → DOM properties: sets properties (evidence: `src/diff/index.js`)
- Render and hydrate → Browser DOM: updates DOM
- VNode diff → Browser DOM: patches DOM (evidence: `src/diff/index.js`)
- Components and updates → VNode diff: rerenders components (evidence: `src/component.js`)
- Context providers → Components and updates: queues updates (evidence: `src/create-context.js`)
- Hooks → Application code: provides hooks
- React compatibility → Components and updates: adapts components (evidence: `compat/src/index.js`)
- React compatibility → Hooks: re-exports hooks (evidence: `compat/src/index.js`)
- React compatibility → Compat rendering: exports rendering (evidence: `compat/src/index.js`)
- React compatibility → Suspense and lazy: exports Suspense (evidence: `compat/src/index.js`)
- Runtime diagnostics → Public API: hooks renderer (evidence: `debug/src/debug.js`)
- DevTools integration → Public API: integrates DevTools
- Application code → JSX runtime: uses JSX
- Application code → Server rendering: renders server-side
- Components and updates → Async scheduler: schedules updates
