# vadimdemedes/ink architecture

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

## Overview

Ink is a React renderer for terminal interfaces. A CLI supplies a React tree to the public render API; Ink reconciles components into a terminal-oriented tree, computes layout and output, then updates the terminal. The documented surface also includes input, focus, stream, accessibility, animation, and sizing hooks, plus static and transformed output. Edges are limited to README statements and source references or calls visible in the supplied excerpts; some unsampled runtime connections are therefore left out.

Main entry points: [`src/components/App.tsx`](https://github.com/vadimdemedes/ink/blob/master/src/components/App.tsx) (App Contexts), [`src/index.ts`](https://github.com/vadimdemedes/ink/blob/master/src/index.ts) (Ink API), [`src/dom.ts`](https://github.com/vadimdemedes/ink/blob/master/src/dom.ts) (Terminal Tree), [`src/ink.tsx`](https://github.com/vadimdemedes/ink/blob/master/src/ink.tsx) (Ink Instance)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_api["Public API"]
  node_public["Ink API<br/>[index.ts]"]
  node_render_api["Render API<br/>[render.ts]"]
  node_string_api["String Rendering"]
  node_components["UI Components"]
  node_hooks["React Hooks"]
  node_stdin_hook["Stdin Hook<br/>[use-stdin.ts]"]
end

subgraph group_runtime["App Runtime"]
  node_app["App Contexts<br/>[App.tsx]"]
  node_input["Input Parsing<br/>[input-parser.ts]"]
  node_keypress["Key Parsing<br/>[parse-keypress.ts]"]
  node_focus["Focus Management<br/>[FocusContext.ts]"]
end

subgraph group_tree["Tree and Layout"]
  node_reconciler["React Reconciler<br/>[reconciler.ts]"]
  node_dom["Terminal Tree<br/>[dom.ts]"]
  node_layout["Yoga Layout<br/>[dom.ts]"]
  node_output_render["Output Rendering"]
  node_output_model["Output Model<br/>[output.ts]"]
end

subgraph group_terminal["Terminal I/O"]
  node_ink["Ink Instance<br/>[ink.tsx]"]
  node_renderer["Renderer Adapter<br/>[renderer.ts]"]
  node_screen_update["Screen Updates<br/>[log-update.ts]"]
  node_stdout["Output Stream Context<br/>[StdoutContext.ts]"]
  node_stdin["Input Stream Context<br/>[StdinContext.ts]"]
  node_streams["Raw Mode Stream<br/>[stream.ts]"]
end

node_cli(("CLI Application"))

node_cli -->|"uses"| node_public
node_public -->|"exports"| node_render_api
node_public -->|"exports"| node_string_api
node_public -->|"exports"| node_components
node_public -->|"exports"| node_hooks
node_app -->|"parses input"| node_input
node_app -->|"parses keys"| node_keypress
node_input -->|"delegates to"| node_keypress
node_app -->|"provides context"| node_stdin
node_app -->|"provides context"| node_stdout
node_app -->|"provides context"| node_focus
node_stdin_hook -->|"reads context"| node_stdin
node_hooks -->|"manages focus"| node_focus
node_reconciler -->|"mutates tree"| node_dom
node_dom -->|"measures layout"| node_layout
node_dom -->|"renders nodes"| node_output_render
node_output_render -->|"builds output"| node_output_model
node_ink -->|"invokes"| node_renderer
node_ink -.->|"writes frames"| node_screen_update
node_screen_update -->|"writes to"| node_streams
node_app -->|"reads raw input"| node_streams

click node_public "https://github.com/vadimdemedes/ink/blob/master/src/index.ts"
click node_render_api "https://github.com/vadimdemedes/ink/blob/master/src/render.ts"
click node_string_api "https://github.com/vadimdemedes/ink/blob/master/src/render-to-string.ts"
click node_components "https://github.com/vadimdemedes/ink/tree/master/src/components"
click node_hooks "https://github.com/vadimdemedes/ink/tree/master/src/hooks"
click node_app "https://github.com/vadimdemedes/ink/blob/master/src/components/App.tsx"
click node_input "https://github.com/vadimdemedes/ink/blob/master/src/input-parser.ts"
click node_keypress "https://github.com/vadimdemedes/ink/blob/master/src/parse-keypress.ts"
click node_focus "https://github.com/vadimdemedes/ink/blob/master/src/components/FocusContext.ts"
click node_reconciler "https://github.com/vadimdemedes/ink/blob/master/src/reconciler.ts"
click node_dom "https://github.com/vadimdemedes/ink/blob/master/src/dom.ts"
click node_layout "https://github.com/vadimdemedes/ink/blob/master/src/dom.ts"
click node_output_render "https://github.com/vadimdemedes/ink/blob/master/src/render-node-to-output.ts"
click node_output_model "https://github.com/vadimdemedes/ink/blob/master/src/output.ts"
click node_ink "https://github.com/vadimdemedes/ink/blob/master/src/ink.tsx"
click node_renderer "https://github.com/vadimdemedes/ink/blob/master/src/renderer.ts"
click node_screen_update "https://github.com/vadimdemedes/ink/blob/master/src/log-update.ts"
click node_stdout "https://github.com/vadimdemedes/ink/blob/master/src/components/StdoutContext.ts"
click node_stdin "https://github.com/vadimdemedes/ink/blob/master/src/components/StdinContext.ts"
click node_stdin_hook "https://github.com/vadimdemedes/ink/blob/master/src/hooks/use-stdin.ts"
click node_streams "https://github.com/vadimdemedes/ink/blob/master/src/stream.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_public,node_render_api,node_string_api,node_components,node_hooks,node_stdin_hook toneBlue
class node_app,node_input,node_keypress,node_focus toneAmber
class node_reconciler,node_dom,node_layout,node_output_render,node_output_model toneMint
class node_ink,node_renderer,node_screen_update,node_stdout,node_stdin,node_streams toneRose
class node_cli toneIndigo
```

## Components

### Public API

- [Ink API](https://github.com/vadimdemedes/ink/blob/master/src/index.ts): `src/index.ts`
- [Render API](https://github.com/vadimdemedes/ink/blob/master/src/render.ts): `src/render.ts`
- [String Rendering](https://github.com/vadimdemedes/ink/blob/master/src/render-to-string.ts): `src/render-to-string.ts`
- [UI Components](https://github.com/vadimdemedes/ink/tree/master/src/components): `src/components`
- [React Hooks](https://github.com/vadimdemedes/ink/tree/master/src/hooks): `src/hooks`
- [Stdin Hook](https://github.com/vadimdemedes/ink/blob/master/src/hooks/use-stdin.ts): `src/hooks/use-stdin.ts`

### App Runtime

- [App Contexts](https://github.com/vadimdemedes/ink/blob/master/src/components/App.tsx): `src/components/App.tsx`
- [Input Parsing](https://github.com/vadimdemedes/ink/blob/master/src/input-parser.ts): `src/input-parser.ts`
- [Key Parsing](https://github.com/vadimdemedes/ink/blob/master/src/parse-keypress.ts): `src/parse-keypress.ts`
- [Focus Management](https://github.com/vadimdemedes/ink/blob/master/src/components/FocusContext.ts): `src/components/FocusContext.ts`

### Tree and Layout

- [React Reconciler](https://github.com/vadimdemedes/ink/blob/master/src/reconciler.ts): `src/reconciler.ts`
- [Terminal Tree](https://github.com/vadimdemedes/ink/blob/master/src/dom.ts): `src/dom.ts`
- [Yoga Layout](https://github.com/vadimdemedes/ink/blob/master/src/dom.ts): `src/dom.ts`
- [Output Rendering](https://github.com/vadimdemedes/ink/blob/master/src/render-node-to-output.ts): `src/render-node-to-output.ts`
- [Output Model](https://github.com/vadimdemedes/ink/blob/master/src/output.ts): `src/output.ts`

### Terminal I/O

- [Ink Instance](https://github.com/vadimdemedes/ink/blob/master/src/ink.tsx): `src/ink.tsx`
- [Renderer Adapter](https://github.com/vadimdemedes/ink/blob/master/src/renderer.ts): `src/renderer.ts`
- [Screen Updates](https://github.com/vadimdemedes/ink/blob/master/src/log-update.ts): `src/log-update.ts`
- [Output Stream Context](https://github.com/vadimdemedes/ink/blob/master/src/components/StdoutContext.ts): `src/components/StdoutContext.ts`
- [Input Stream Context](https://github.com/vadimdemedes/ink/blob/master/src/components/StdinContext.ts): `src/components/StdinContext.ts`
- [Raw Mode Stream](https://github.com/vadimdemedes/ink/blob/master/src/stream.ts): `src/stream.ts`

### Other components

- **CLI Application**

## Connections

- CLI Application → Ink API: uses
- Ink API → Render API: exports (evidence: `src/index.ts`)
- Ink API → String Rendering: exports (evidence: `src/index.ts`)
- Ink API → UI Components: exports (evidence: `src/index.ts`)
- Ink API → React Hooks: exports (evidence: `src/index.ts`)
- App Contexts → Input Parsing: parses input (evidence: `src/components/App.tsx`)
- App Contexts → Key Parsing: parses keys (evidence: `src/components/App.tsx`)
- Input Parsing → Key Parsing: delegates to (evidence: `src/input-parser.ts`)
- App Contexts → Input Stream Context: provides context (evidence: `src/components/App.tsx`)
- App Contexts → Output Stream Context: provides context (evidence: `src/components/App.tsx`)
- App Contexts → Focus Management: provides context (evidence: `src/components/App.tsx`)
- Stdin Hook → Input Stream Context: reads context (evidence: `src/hooks/use-stdin.ts`)
- React Hooks → Focus Management: manages focus (evidence: `src/hooks/use-focus-manager.ts`)
- React Reconciler → Terminal Tree: mutates tree (evidence: `src/reconciler.ts`)
- Terminal Tree → Yoga Layout: measures layout (evidence: `src/dom.ts`)
- Terminal Tree → Output Rendering: renders nodes (evidence: `src/dom.ts`)
- Output Rendering → Output Model: builds output (evidence: `src/render-node-to-output.ts`)
- Ink Instance → Renderer Adapter: invokes (evidence: `src/ink.tsx`)
- Ink Instance → Screen Updates: writes frames (evidence: `src/ink.tsx`)
- Screen Updates → Raw Mode Stream: writes to (evidence: `src/log-update.ts`)
- App Contexts → Raw Mode Stream: reads raw input (evidence: `src/components/App.tsx`)
