# zvnoob/cppreact architecture

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

- Interactive diagram: https://gitdiagram.com/zvnoob/cppreact
- Repository: https://github.com/zvnoob/cppreact

## Overview

cppreact is an immediate-mode C++ UI library. Users build a widget tree, with stateful functions rebuilding their elements as state changes; the renderer runs layout, dispatches draw commands and routes input, while SDL2 and SFML provide optional concrete backends. The graph preserves layout, widgets, text/font handling, scrolling, input, and rendering as distinct capabilities. Source excerpts clarify several calls and transfers; other links are limited to explicit README workflow descriptions.

Main entry points: [`container`](https://github.com/zvnoob/cppreact/tree/main/container) (Widget Tree), [`renderer/renderer.hpp`](https://github.com/zvnoob/cppreact/blob/main/renderer/renderer.hpp) (Renderer Loop), [`container/func.hpp`](https://github.com/zvnoob/cppreact/blob/main/container/func.hpp) (Stateful Function), [`src/layout.cpp`](https://github.com/zvnoob/cppreact/blob/main/src/layout.cpp) (Layout Passes)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_api["UI Composition"]
  node_tree["Widget Tree"]
  node_func["Stateful Function<br/>[func.hpp]"]
  node_containers["Layout Containers"]
end

subgraph group_core["Runtime Core"]
  node_state[("Persistent State<br/>[state.hpp]")]
  node_arena["Arena Allocation<br/>[arena.hpp]"]
  node_identity["Widget Identity<br/>[identifiable.hpp]"]
  node_layout["Layout Passes<br/>[layout.cpp]"]
  node_element["Element Model<br/>[element.hpp]"]
  node_registry[("State Registry<br/>[registry.hpp]")]
  node_font["Font Fallback<br/>[font.hpp]"]
end

subgraph group_widgets["Widgets"]
  node_viewport["Viewport Scroll<br/>[viewport.hpp]"]
  node_scrolling["Scroll Input<br/>[scrolling.hpp]"]
  node_text["Text Shaping<br/>[text.hpp]"]
  node_input["Text Input<br/>[input.hpp]"]
  node_buttons["Buttons<br/>[button_full.hpp]"]
  node_visuals["Visual Widgets"]
end

subgraph group_render["Rendering"]
  node_commands["Render Commands<br/>[drawing.hpp]"]
  node_renderer["Renderer Loop<br/>[renderer.hpp]"]
end

subgraph group_platform["Platform Backends"]
  node_sdl["SDL Backend<br/>[sdl_renderer.hpp]"]
  node_sfml["SFML Backend<br/>[sfml_renderer.hpp]"]
end

node_user(("UI Author"))
node_gpu(("GPU Window"))
node_fonts["Font Files"]
node_events(("Pointer Keyboard"))

node_user -->|"constructs"| node_tree
node_tree -->|"includes"| node_func
node_func -->|"reads updates"| node_state
node_func -->|"allocates within"| node_arena
node_func -->|"looks up state"| node_registry
node_tree -->|"assigns IDs"| node_identity
node_tree -->|"enters layout"| node_layout
node_layout -->|"updates positions"| node_element
node_layout -->|"sizes children"| node_containers
node_tree -->|"may include"| node_text
node_tree -->|"may include"| node_input
node_tree -->|"may include"| node_buttons
node_tree -->|"may include"| node_visuals
node_tree -->|"may include"| node_viewport
node_viewport -->|"combines with"| node_scrolling
node_renderer -->|"runs frame"| node_tree
node_renderer -->|"performs layout"| node_layout
node_renderer -->|"collects dispatches"| node_commands
node_text -->|"shapes with"| node_font
node_renderer -->|"loads fonts"| node_font
node_font -->|"loads faces"| node_fonts
node_text -->|"emits drawing"| node_commands
node_visuals -->|"emits drawing"| node_commands
node_buttons -->|"routes events"| node_renderer
node_scrolling -->|"routes scroll"| node_renderer
node_input -->|"uses focus and IME"| node_renderer
node_renderer -.->|"implemented by"| node_sdl
node_renderer -.->|"implemented by"| node_sfml
node_sdl -->|"draws and presents"| node_gpu
node_sfml -.->|"draws and presents"| node_gpu
node_events -->|"polled by"| node_sdl
node_events -.->|"polled by"| node_sfml

click node_tree "https://github.com/zvnoob/cppreact/tree/main/container"
click node_func "https://github.com/zvnoob/cppreact/blob/main/container/func.hpp"
click node_state "https://github.com/zvnoob/cppreact/blob/main/internal/state.hpp"
click node_arena "https://github.com/zvnoob/cppreact/blob/main/internal/arena.hpp"
click node_identity "https://github.com/zvnoob/cppreact/blob/main/internal/identifiable.hpp"
click node_layout "https://github.com/zvnoob/cppreact/blob/main/src/layout.cpp"
click node_element "https://github.com/zvnoob/cppreact/blob/main/internal/element.hpp"
click node_registry "https://github.com/zvnoob/cppreact/blob/main/internal/registry.hpp"
click node_containers "https://github.com/zvnoob/cppreact/tree/main/container"
click node_viewport "https://github.com/zvnoob/cppreact/blob/main/container/viewport.hpp"
click node_scrolling "https://github.com/zvnoob/cppreact/blob/main/widgets/scrolling.hpp"
click node_text "https://github.com/zvnoob/cppreact/blob/main/widgets/text.hpp"
click node_font "https://github.com/zvnoob/cppreact/blob/main/internal/font.hpp"
click node_input "https://github.com/zvnoob/cppreact/blob/main/widgets/input.hpp"
click node_buttons "https://github.com/zvnoob/cppreact/blob/main/widgets/button_full.hpp"
click node_visuals "https://github.com/zvnoob/cppreact/tree/main/widgets"
click node_commands "https://github.com/zvnoob/cppreact/blob/main/internal/drawing.hpp"
click node_renderer "https://github.com/zvnoob/cppreact/blob/main/renderer/renderer.hpp"
click node_sdl "https://github.com/zvnoob/cppreact/blob/main/renderer/sdl_renderer.hpp"
click node_sfml "https://github.com/zvnoob/cppreact/blob/main/renderer/sfml_renderer.hpp"

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_func,node_containers,node_user toneBlue
class node_state,node_arena,node_identity,node_layout,node_element,node_registry,node_font toneAmber
class node_viewport,node_scrolling,node_text,node_input,node_buttons,node_visuals toneMint
class node_commands,node_renderer toneRose
class node_sdl,node_sfml,node_gpu,node_fonts,node_events toneIndigo
```

## Components

### UI Composition

- [Widget Tree](https://github.com/zvnoob/cppreact/tree/main/container): `container`
- [Stateful Function](https://github.com/zvnoob/cppreact/blob/main/container/func.hpp): `container/func.hpp`
- [Layout Containers](https://github.com/zvnoob/cppreact/tree/main/container): `container`

### Runtime Core

- [Persistent State](https://github.com/zvnoob/cppreact/blob/main/internal/state.hpp): `internal/state.hpp`
- [Arena Allocation](https://github.com/zvnoob/cppreact/blob/main/internal/arena.hpp): `internal/arena.hpp`
- [Widget Identity](https://github.com/zvnoob/cppreact/blob/main/internal/identifiable.hpp): `internal/identifiable.hpp`
- [Layout Passes](https://github.com/zvnoob/cppreact/blob/main/src/layout.cpp): `src/layout.cpp`
- [Element Model](https://github.com/zvnoob/cppreact/blob/main/internal/element.hpp): `internal/element.hpp`
- [State Registry](https://github.com/zvnoob/cppreact/blob/main/internal/registry.hpp): `internal/registry.hpp`
- [Font Fallback](https://github.com/zvnoob/cppreact/blob/main/internal/font.hpp): `internal/font.hpp`

### Widgets

- [Viewport Scroll](https://github.com/zvnoob/cppreact/blob/main/container/viewport.hpp): `container/viewport.hpp`
- [Scroll Input](https://github.com/zvnoob/cppreact/blob/main/widgets/scrolling.hpp): `widgets/scrolling.hpp`
- [Text Shaping](https://github.com/zvnoob/cppreact/blob/main/widgets/text.hpp): `widgets/text.hpp`
- [Text Input](https://github.com/zvnoob/cppreact/blob/main/widgets/input.hpp): `widgets/input.hpp`
- [Buttons](https://github.com/zvnoob/cppreact/blob/main/widgets/button_full.hpp): `widgets/button_full.hpp`
- [Visual Widgets](https://github.com/zvnoob/cppreact/tree/main/widgets): `widgets`

### Rendering

- [Render Commands](https://github.com/zvnoob/cppreact/blob/main/internal/drawing.hpp): `internal/drawing.hpp`
- [Renderer Loop](https://github.com/zvnoob/cppreact/blob/main/renderer/renderer.hpp): `renderer/renderer.hpp`

### Platform Backends

- [SDL Backend](https://github.com/zvnoob/cppreact/blob/main/renderer/sdl_renderer.hpp): `renderer/sdl_renderer.hpp`
- [SFML Backend](https://github.com/zvnoob/cppreact/blob/main/renderer/sfml_renderer.hpp): `renderer/sfml_renderer.hpp`

### Other components

- **UI Author**
- **GPU Window**
- **Font Files**
- **Pointer Keyboard**

## Connections

- UI Author → Widget Tree: constructs
- Widget Tree → Stateful Function: includes
- Stateful Function → Persistent State: reads updates
- Stateful Function → Arena Allocation: allocates within
- Stateful Function → State Registry: looks up state
- Widget Tree → Widget Identity: assigns IDs
- Widget Tree → Layout Passes: enters layout
- Layout Passes → Element Model: updates positions
- Layout Passes → Layout Containers: sizes children
- Widget Tree → Text Shaping: may include
- Widget Tree → Text Input: may include
- Widget Tree → Buttons: may include
- Widget Tree → Visual Widgets: may include
- Widget Tree → Viewport Scroll: may include
- Viewport Scroll → Scroll Input: combines with
- Renderer Loop → Widget Tree: runs frame
- Renderer Loop → Layout Passes: performs layout
- Renderer Loop → Render Commands: collects dispatches
- Text Shaping → Font Fallback: shapes with
- Renderer Loop → Font Fallback: loads fonts
- Font Fallback → Font Files: loads faces
- Text Shaping → Render Commands: emits drawing
- Visual Widgets → Render Commands: emits drawing
- Buttons → Renderer Loop: routes events
- Scroll Input → Renderer Loop: routes scroll
- Text Input → Renderer Loop: uses focus and IME
- Renderer Loop → SDL Backend: implemented by
- Renderer Loop → SFML Backend: implemented by
- SDL Backend → GPU Window: draws and presents
- SFML Backend → GPU Window: draws and presents
- Pointer Keyboard → SDL Backend: polled by
- Pointer Keyboard → SFML Backend: polled by
