# nicbarker/clay architecture

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

- Interactive diagram: https://gitdiagram.com/nicbarker/clay
- Repository: https://github.com/nicbarker/clay

## Overview

Clay is a dependency-free C UI layout library: an application supplies dimensions, pointer and scroll state, declares a nested UI, then consumes sorted render commands through a renderer. The core also supports text measurement callbacks, scrolling, transitions, retained-mode rendering, visibility culling, and custom elements. Renderer adapters translate commands for graphics, terminal, and document/browser targets; language bindings expose the library to other ecosystems. Core workflow is documented in the README; sampled renderer excerpts show adapter responsibilities, but do not establish wiring among individual adapters.

Main entry points: [`clay.h`](https://github.com/nicbarker/clay/blob/main/clay.h) (Layout Engine), [`renderers/SDL2/clay_renderer_SDL2.c`](https://github.com/nicbarker/clay/blob/main/renderers/SDL2/clay_renderer_SDL2.c) (SDL Renderers), [`renderers/GLES3/clay_renderer_gles3.h`](https://github.com/nicbarker/clay/blob/main/renderers/GLES3/clay_renderer_gles3.h) (GLES3 Renderer), [`renderers/cairo/clay_renderer_cairo.c`](https://github.com/nicbarker/clay/blob/main/renderers/cairo/clay_renderer_cairo.c) (Cairo Renderer)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_core["Layout Core"]
  node_api["Declarative API<br/>[clay.h]"]
  node_state["Arena State<br/>[clay.h]"]
  node_text["Text Measurement<br/>[clay.h]"]
  node_layout["Layout Engine<br/>[clay.h]"]
  node_commands["Render Commands<br/>[clay.h]"]
end

subgraph group_interaction["Interaction Features"]
  node_pointer["Pointer And Hover<br/>[clay.h]"]
  node_scroll["Scroll Containers<br/>[clay.h]"]
  node_transitions["Layout Transitions<br/>[clay.h]"]
  node_retained["Retained Rendering<br/>[clay.h]"]
  node_culling["Visibility Culling<br/>[clay.h]"]
end

subgraph group_renderers["Renderer Adapters"]
  node_sdl["SDL Renderers"]
  node_gles["GLES3 Renderer"]
  node_cairo["Cairo Renderer"]
  node_terminal["Terminal Renderers"]
  node_other_renderers["Other Renderers"]
end

subgraph group_integrations["Language And Web"]
  node_bindings["Language Bindings"]
  node_web["Web And HTML Targets"]
end

node_application(("UI Application"))
node_environment(("Window And Input"))
node_output(("Display Or Document"))

node_environment -->|"provides input"| node_application
node_application -->|"declares UI"| node_api
node_application -->|"initializes arena"| node_state
node_application -->|"sets pointer"| node_pointer
node_application -->|"updates scroll"| node_scroll
node_application -->|"sets dimensions"| node_layout
node_api -->|"builds hierarchy"| node_layout
node_layout -->|"measures text"| node_text
node_layout -->|"uses arena"| node_state
node_layout -->|"produces commands"| node_commands
node_pointer -->|"updates interaction"| node_state
node_scroll -->|"updates offsets"| node_state
node_transitions -->|"animates layout"| node_layout
node_retained -->|"supports rendering"| node_commands
node_culling -->|"filters visibility"| node_commands
node_application -->|"renders commands"| node_sdl
node_application -->|"renders commands"| node_gles
node_application -->|"renders commands"| node_cairo
node_application -->|"renders commands"| node_terminal
node_application -.->|"selects adapter"| node_other_renderers
node_sdl -->|"draws UI"| node_output
node_gles -->|"draws UI"| node_output
node_cairo -->|"draws UI"| node_output
node_terminal -->|"draws UI"| node_output
node_other_renderers -.->|"renders output"| node_output
node_application -.->|"uses language API"| node_bindings
node_application -.->|"targets browser"| node_web
node_web -.->|"renders HTML or canvas"| node_output

click node_api "https://github.com/nicbarker/clay/blob/main/clay.h"
click node_state "https://github.com/nicbarker/clay/blob/main/clay.h"
click node_text "https://github.com/nicbarker/clay/blob/main/clay.h"
click node_layout "https://github.com/nicbarker/clay/blob/main/clay.h"
click node_commands "https://github.com/nicbarker/clay/blob/main/clay.h"
click node_pointer "https://github.com/nicbarker/clay/blob/main/clay.h"
click node_scroll "https://github.com/nicbarker/clay/blob/main/clay.h"
click node_transitions "https://github.com/nicbarker/clay/blob/main/clay.h"
click node_retained "https://github.com/nicbarker/clay/blob/main/clay.h"
click node_culling "https://github.com/nicbarker/clay/blob/main/clay.h"
click node_sdl "https://github.com/nicbarker/clay/blob/main/renderers/SDL2/clay_renderer_SDL2.c"
click node_gles "https://github.com/nicbarker/clay/blob/main/renderers/GLES3/clay_renderer_gles3.h"
click node_cairo "https://github.com/nicbarker/clay/blob/main/renderers/cairo/clay_renderer_cairo.c"
click node_terminal "https://github.com/nicbarker/clay/blob/main/renderers/terminal/clay_renderer_terminal_ansi.c"
click node_other_renderers "https://github.com/nicbarker/clay/tree/main/renderers"
click node_bindings "https://github.com/nicbarker/clay/tree/main/bindings"
click node_web "https://github.com/nicbarker/clay/tree/main/renderers/web"

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_api,node_state,node_text,node_layout,node_commands,node_application toneBlue
class node_pointer,node_scroll,node_transitions,node_retained,node_culling toneAmber
class node_sdl,node_gles,node_cairo,node_terminal,node_other_renderers toneMint
class node_bindings,node_web toneRose
class node_environment,node_output toneIndigo
```

## Components

### Layout Core

- [Declarative API](https://github.com/nicbarker/clay/blob/main/clay.h): `clay.h`
- [Arena State](https://github.com/nicbarker/clay/blob/main/clay.h): `clay.h`
- [Text Measurement](https://github.com/nicbarker/clay/blob/main/clay.h): `clay.h`
- [Layout Engine](https://github.com/nicbarker/clay/blob/main/clay.h): `clay.h`
- [Render Commands](https://github.com/nicbarker/clay/blob/main/clay.h): `clay.h`

### Interaction Features

- [Pointer And Hover](https://github.com/nicbarker/clay/blob/main/clay.h): `clay.h`
- [Scroll Containers](https://github.com/nicbarker/clay/blob/main/clay.h): `clay.h`
- [Layout Transitions](https://github.com/nicbarker/clay/blob/main/clay.h): `clay.h`
- [Retained Rendering](https://github.com/nicbarker/clay/blob/main/clay.h): `clay.h`
- [Visibility Culling](https://github.com/nicbarker/clay/blob/main/clay.h): `clay.h`

### Renderer Adapters

- [SDL Renderers](https://github.com/nicbarker/clay/blob/main/renderers/SDL2/clay_renderer_SDL2.c): `renderers/SDL2/clay_renderer_SDL2.c`
- [GLES3 Renderer](https://github.com/nicbarker/clay/blob/main/renderers/GLES3/clay_renderer_gles3.h): `renderers/GLES3/clay_renderer_gles3.h`
- [Cairo Renderer](https://github.com/nicbarker/clay/blob/main/renderers/cairo/clay_renderer_cairo.c): `renderers/cairo/clay_renderer_cairo.c`
- [Terminal Renderers](https://github.com/nicbarker/clay/blob/main/renderers/terminal/clay_renderer_terminal_ansi.c): `renderers/terminal/clay_renderer_terminal_ansi.c`
- [Other Renderers](https://github.com/nicbarker/clay/tree/main/renderers): `renderers`

### Language And Web

- [Language Bindings](https://github.com/nicbarker/clay/tree/main/bindings): `bindings`
- [Web And HTML Targets](https://github.com/nicbarker/clay/tree/main/renderers/web): `renderers/web`

### Other components

- **UI Application**
- **Window And Input**
- **Display Or Document**

## Connections

- Window And Input → UI Application: provides input
- UI Application → Declarative API: declares UI
- UI Application → Arena State: initializes arena
- UI Application → Pointer And Hover: sets pointer
- UI Application → Scroll Containers: updates scroll
- UI Application → Layout Engine: sets dimensions
- Declarative API → Layout Engine: builds hierarchy
- Layout Engine → Text Measurement: measures text
- Layout Engine → Arena State: uses arena
- Layout Engine → Render Commands: produces commands
- Pointer And Hover → Arena State: updates interaction
- Scroll Containers → Arena State: updates offsets
- Layout Transitions → Layout Engine: animates layout
- Retained Rendering → Render Commands: supports rendering
- Visibility Culling → Render Commands: filters visibility
- UI Application → SDL Renderers: renders commands
- UI Application → GLES3 Renderer: renders commands
- UI Application → Cairo Renderer: renders commands
- UI Application → Terminal Renderers: renders commands
- UI Application → Other Renderers: selects adapter
- SDL Renderers → Display Or Document: draws UI
- GLES3 Renderer → Display Or Document: draws UI
- Cairo Renderer → Display Or Document: draws UI
- Terminal Renderers → Display Or Document: draws UI
- Other Renderers → Display Or Document: renders output
- UI Application → Language Bindings: uses language API
- UI Application → Web And HTML Targets: targets browser
- Web And HTML Targets → Display Or Document: renders HTML or canvas
