# pmndrs/drei architecture

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

- Interactive diagram: https://gitdiagram.com/pmndrs/drei
- Repository: https://github.com/pmndrs/drei

## Overview

##### Main System Components

The system should be organized into these primary sections:

a) Core Components Layer
- Connection to Three.js core functionality

b) Feature Categories Layer
- Components into major categories as shown in the file structure:
- Cameras
- Controls
- Gizmos
- Abstractions
- Shaders
- Loaders
- Performance
- Portals
- Staging

c) Integration Layer
- Integration with React ecosystem
- Connection points with @react-three/fiber
- Web and native platform support

##### Component Relationships

- Dependencies between components
- Data flow patterns
- Hook relationships
- Event handling paths

- Blue: Core components
- Green: Helper utilities
- Orange: Performance-related components
- Purple: Visual effects and materials
- Gray: Development tools

- Rectangles: Main components
- Hexagons: Hooks
- Circles: Utilities
- Diamonds: Entry points

##### Detailed Component Structure

Create nested groupings for:

a) Core Functionality
- Cameras
- PerspectiveCamera
- OrthographicCamera
- CubeCamera
- Controls
- OrbitControls
- TransformControls
- Other control variants

b) Advanced Features
- Materials
- Custom Shaders
- Material Modifiers
- Effects
- Post-processing
- Environmental
- Optimization
- Performance Monitors
- Adaptive Systems

##### Integration Points

Clear connection points for:
- Three.js integration
- React component lifecycle
- Event system handling
- Asset loading pipeline

##### Development Tools Integration

Sections for:
- Storybook integration
- Testing utilities
- Development helpers
- Performance monitoring

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Core
        CoreComponents[Core Components]
        ThreeJS[Three.js Integration]
        ReactFiber["@react-three/fiber"]
    end

    subgraph Features
        direction TB
        Cameras["Cameras"]:::cameras
        Controls["Controls"]:::controls
        Gizmos["Gizmos"]:::gizmos
        Shapes["Shapes"]:::shapes
        Materials["Materials"]:::materials
        Shaders["Shaders"]:::shaders
        Loaders["Loaders"]:::loaders
        Performance["Performance"]:::performance
        Staging["Staging"]:::staging
    end

    subgraph Platform
        Web["Web Components"]:::web
        Native["Native Components"]:::native
    end

    subgraph Development
        Storybook["Storybook"]:::dev
        Testing["Testing Utilities"]:::dev
        Monitor["Performance Monitoring"]:::dev
    end

    subgraph CameraComponents
        PerspectiveCamera["Perspective Camera"]:::component
        OrthographicCamera["Orthographic Camera"]:::component
        CubeCamera["Cube Camera"]:::component
    end

    subgraph ControlComponents
        OrbitControls["Orbit Controls"]:::component
        TransformControls["Transform Controls"]:::component
        PivotControls["Pivot Controls"]:::component
    end

    subgraph GizmoComponents
        GizmoHelper["Gizmo Helper"]:::component
        GizmoViewcube["Gizmo Viewcube"]:::component
        GizmoViewport["Gizmo Viewport"]:::component
    end

    CoreComponents --> Features
    ThreeJS --> CoreComponents
    ReactFiber --> CoreComponents

    Cameras --> CameraComponents
    Controls --> ControlComponents
    Gizmos --> GizmoComponents

    Features --> Platform
    Platform --> Development

    %% Click Events
    click CoreComponents "https://github.com/pmndrs/drei/tree/master/src/core/"
    click Cameras "https://github.com/pmndrs/drei/tree/master/docs/cameras/"
    click Controls "https://github.com/pmndrs/drei/tree/master/docs/controls/"
    click Gizmos "https://github.com/pmndrs/drei/tree/master/docs/gizmos/"
    click Shapes "https://github.com/pmndrs/drei/tree/master/docs/shapes/"
    click Materials "https://github.com/pmndrs/drei/tree/master/src/materials/"
    click Shaders "https://github.com/pmndrs/drei/tree/master/docs/shaders/"
    click Loaders "https://github.com/pmndrs/drei/tree/master/docs/loaders/"
    click Performance "https://github.com/pmndrs/drei/tree/master/docs/performances/"
    click Staging "https://github.com/pmndrs/drei/tree/master/docs/staging/"
    click Web "https://github.com/pmndrs/drei/tree/master/src/web/"
    click Native "https://github.com/pmndrs/drei/tree/master/src/native/"
    click Storybook "https://github.com/pmndrs/drei/tree/master/.storybook/"
    click Testing "https://github.com/pmndrs/drei/tree/master/test/"
    click PerspectiveCamera "https://github.com/pmndrs/drei/blob/master/src/core/PerspectiveCamera.tsx"
    click OrthographicCamera "https://github.com/pmndrs/drei/blob/master/src/core/OrthographicCamera.tsx"
    click CubeCamera "https://github.com/pmndrs/drei/blob/master/src/core/CubeCamera.tsx"
    click OrbitControls "https://github.com/pmndrs/drei/blob/master/src/core/OrbitControls.tsx"
    click TransformControls "https://github.com/pmndrs/drei/blob/master/src/core/TransformControls.tsx"
    click PivotControls "https://github.com/pmndrs/drei/tree/master/src/web/pivotControls/"
    click GizmoHelper "https://github.com/pmndrs/drei/blob/master/src/core/GizmoHelper.tsx"
    click GizmoViewcube "https://github.com/pmndrs/drei/blob/master/src/core/GizmoViewcube.tsx"
    click GizmoViewport "https://github.com/pmndrs/drei/blob/master/src/core/GizmoViewport.tsx"
    click Monitor "https://github.com/pmndrs/drei/blob/master/src/core/PerformanceMonitor.tsx"

    %% Styling
    classDef core fill:#2374ab
    classDef cameras fill:#2a9d8f
    classDef controls fill:#e9c46a
    classDef gizmos fill:#f4a261
    classDef shapes fill:#e76f51
    classDef materials fill:#606c38
    classDef shaders fill:#283618
    classDef loaders fill:#bc6c25
    classDef performance fill:#dda15e
    classDef staging fill:#606c38
    classDef web fill:#219ebc
    classDef native fill:#023047
    classDef dev fill:#8ecae6
    classDef component fill:#95d5b2

    %% Legend
    subgraph Legend
        L1[Core]:::core
        L2[Cameras]:::cameras
        L3[Controls]:::controls
        L4[Gizmos]:::gizmos
        L5[Shapes]:::shapes
        L6[Materials]:::materials
        L7[Shaders]:::shaders
        L8[Loaders]:::loaders
        L9[Performance]:::performance
        L10[Staging]:::staging
        L11[Web]:::web
        L12[Native]:::native
        L13[Development]:::dev
        L14[Component]:::component
    end
```
