# radix-ui/primitives architecture

> Architecture diagram of the GitHub repository radix-ui/primitives, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-01-06). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/radix-ui/primitives
- Repository: https://github.com/radix-ui/primitives

## Overview

##### Main Components Structure

A. Core Layer
- Primitive, number, and rect packages

B. React Components Layer
- Above the core layer
- Components into logical groups:
- Navigation (Menubar, NavigationMenu, Tabs)
- Overlay (Dialog, Popover, Toast, Tooltip)
- Form Controls (Checkbox, Radio, Select, Switch)
- Layout (AspectRatio, ScrollArea, Separator)
- Utility (Portal, Presence, VisuallyHidden)

C. Hooks Layer
- As a side section
- Custom hooks (useCallbackRef, useControllableState, etc.)
- To components that utilize them

##### Component Relationships

- Dependencies between components
- Composition patterns
- Shared utilities

→ Direct dependencies
⇢ Composition relationships
⇄ Two-way interactions

##### Infrastructure Elements

Supporting systems:
- Storybook integration
- Testing infrastructure (Cypress)
- SSR testing setup
- Build system

##### Key Technical Aspects to Highlight

A. Accessibility Features
- To relevant components

B. State Management
- State flow between controlled and uncontrolled components
- Context providers

C. Portal System
- Demonstrate portal architecture
- Relationship with overlay components

##### Implementation Details

Use specific visual elements:
**┌─────────────────┐**
- Component Group │
- ┘

**⚡ Core Primitives**
**🔄 State Management**
**🎯 Event Handlers**
**🔒 Accessibility Features**

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Styles
    classDef core fill:#2b4c7e,color:white
    classDef navigation fill:#6b9080,color:white
    classDef overlay fill:#e76f51,color:white
    classDef form fill:#2a9d8f,color:white
    classDef layout fill:#457b9d,color:white
    classDef utility fill:#8338ec,color:white
    classDef infra fill:#495057,color:white
    classDef testing fill:#6c757d,color:white
    classDef build fill:#343a40,color:white

    %% Core Layer
    subgraph CoreLayer["Core Layer"]
        Primitive["Primitive Package"]:::core
        Number["Number Package"]:::core
        Rect["Rect Package"]:::core
    end

    %% React Components Layer
    subgraph ComponentsLayer["React Components Layer"]
        %% Navigation Components
        subgraph NavComponents["Navigation Components"]
            Menubar["Menubar"]:::navigation
            NavMenu["Navigation Menu"]:::navigation
            Tabs["Tabs"]:::navigation
        end

        %% Overlay Components
        subgraph OverlayComponents["Overlay Components"]
            Dialog["Dialog"]:::overlay
            Popover["Popover"]:::overlay
            Toast["Toast"]:::overlay
            Tooltip["Tooltip"]:::overlay
        end

        %% Form Components
        subgraph FormComponents["Form Controls"]
            Checkbox["Checkbox"]:::form
            Radio["Radio Group"]:::form
            Select["Select"]:::form
            Switch["Switch"]:::form
        end

        %% Layout Components
        subgraph LayoutComponents["Layout Components"]
            AspectRatio["Aspect Ratio"]:::layout
            ScrollArea["Scroll Area"]:::layout
            Separator["Separator"]:::layout
        end

        %% Utility Components
        subgraph UtilityComponents["Utility Components"]
            Portal["Portal"]:::utility
            Presence["Presence"]:::utility
            VisuallyHidden["Visually Hidden"]:::utility
        end
    end

    %% Infrastructure
    subgraph Infrastructure["Infrastructure"]
        Storybook["Storybook"]:::infra
        CypressTest["Cypress Testing"]:::testing
        SSRTest["SSR Testing"]:::testing
        BuildSystem["Build System"]:::build
    end

    %% Relationships
    CoreLayer --> ComponentsLayer
    Portal --> OverlayComponents
    UtilityComponents --> FormComponents
    UtilityComponents --> OverlayComponents
    Infrastructure --> ComponentsLayer

    %% Click Events
    click Primitive "https://github.com/radix-ui/primitives/tree/main/packages/core/primitive"
    click Number "https://github.com/radix-ui/primitives/tree/main/packages/core/number"
    click Rect "https://github.com/radix-ui/primitives/tree/main/packages/core/rect"
    click Menubar "https://github.com/radix-ui/primitives/tree/main/packages/react/menubar"
    click NavMenu "https://github.com/radix-ui/primitives/tree/main/packages/react/navigation-menu"
    click Tabs "https://github.com/radix-ui/primitives/tree/main/packages/react/tabs"
    click Dialog "https://github.com/radix-ui/primitives/tree/main/packages/react/dialog"
    click Popover "https://github.com/radix-ui/primitives/tree/main/packages/react/popover"
    click Toast "https://github.com/radix-ui/primitives/tree/main/packages/react/toast"
    click Tooltip "https://github.com/radix-ui/primitives/tree/main/packages/react/tooltip"
    click Checkbox "https://github.com/radix-ui/primitives/tree/main/packages/react/checkbox"
    click Radio "https://github.com/radix-ui/primitives/tree/main/packages/react/radio-group"
    click Select "https://github.com/radix-ui/primitives/tree/main/packages/react/select"
    click Switch "https://github.com/radix-ui/primitives/tree/main/packages/react/switch"
    click AspectRatio "https://github.com/radix-ui/primitives/tree/main/packages/react/aspect-ratio"
    click ScrollArea "https://github.com/radix-ui/primitives/tree/main/packages/react/scroll-area"
    click Separator "https://github.com/radix-ui/primitives/tree/main/packages/react/separator"
    click Portal "https://github.com/radix-ui/primitives/tree/main/packages/react/portal"
    click Presence "https://github.com/radix-ui/primitives/tree/main/packages/react/presence"
    click VisuallyHidden "https://github.com/radix-ui/primitives/tree/main/packages/react/visually-hidden"
    click Storybook "https://github.com/radix-ui/primitives/tree/main/.storybook/"
    click CypressTest "https://github.com/radix-ui/primitives/tree/main/cypress/"
    click SSRTest "https://github.com/radix-ui/primitives/tree/main/ssr-testing/"
    click BuildSystem "https://github.com/radix-ui/primitives/blob/main/build.mjs"

    %% Legend
    subgraph Legend["Legend"]
        L1["Core Components"]:::core
        L2["Navigation"]:::navigation
        L3["Overlay"]:::overlay
        L4["Form Controls"]:::form
        L5["Layout"]:::layout
        L6["Utility"]:::utility
        L7["Infrastructure"]:::infra
        L8["Testing"]:::testing
    end
```
