# facebook/stylex architecture

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

- Interactive diagram: https://gitdiagram.com/facebook/stylex
- Repository: https://github.com/facebook/stylex

## Overview

##### Main Components

a) Core Library Layer
- StyleX Core (`@stylexjs/stylex`)
- Shared Utilities (`@stylexjs/shared`)
- Types and Interfaces

b) Build Tool Integration Layer
- Babel Plugin
- Webpack Plugin
- Rollup Plugin
- ESBuild Plugin
- Next.js Plugin

c) Development Tools Layer
- CLI Tools
- Dev Runtime
- ESLint Plugin

##### Component Relationships

**┌─────────────────────────────────────────────────────────────┐**
- Application Layer                        │
- ┬─────────────────────────────────┘

**┌───────────────────────────┴─────────────────────────────────┐**
- Build Integration Layer                     │
- ┌─────────┐  ┌─────────┐  ┌─────────┐  ┌──────────────┐   │
- Babel  │  │ Webpack │  │ Rollup  │  │  Next.js     │   │
- Plugin  │  │ Plugin  │  │ Plugin  │  │  Plugin      │   │
- ┬────┘  └────┬────┘  └────┬────┘  └──────┬───────┘   │
- ┼───────────┼───────────┼───────────────┼────────────┘

**┌───────┼───────────┼───────────┼───────────────┼────────────┐**
- Core StyleX Layer   │               │            │
- ┌────┴────────────┴────────┬─┴───────────────┴────┐      │

- StyleX Runtime       │    Shared Utilities   │      │

- ┬──────────┴───────────┬───────────┘      │

- ┌──────────────┴──────────┐ ┌─────────┴───────────┐      │
- Type System         │ │   CSS Generation     │      │
- ┘ └─────────────────────┘      │
- ┘

##### Additional Details

Important aspects:
- Style Definition Flow
- Theme System Integration
- Variable Management
- CSS Output Generation
- Development Mode Features

##### Implementation Notes

- The compile-time optimization nature of StyleX
- The plugin-based architecture
- The type system integration
- The development tooling ecosystem

Remember to maintain a balance between detail and clarity, focusing on the architectural relationships while avoiding overwhelming implementation details.

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph "Application Layer"
        APP[Application Code]
    end

    subgraph "Build Integration Layer"
        BABEL[Babel Plugin]
        WEBPACK[Webpack Plugin]
        ROLLUP[Rollup Plugin]
        NEXT[Next.js Plugin]
        ESBUILD[ESBuild Plugin]
    end

    subgraph "Core Layer"
        CORE[StyleX Runtime]
        SHARED[Shared Utilities]
        TYPES[Type System]
        CSS[CSS Generation]
    end

    subgraph "Development Tools Layer"
        CLI[CLI Tools]
        DEV[Dev Runtime]
        ESLINT[ESLint Plugin]
    end

    %% Connections from Application to Build Layer
    APP --> BABEL
    APP --> WEBPACK
    APP --> ROLLUP
    APP --> NEXT
    APP --> ESBUILD

    %% Build Layer to Core Layer
    BABEL --> CORE
    WEBPACK --> CORE
    ROLLUP --> CORE
    NEXT --> CORE
    ESBUILD --> CORE

    %% Core Layer Internal
    CORE --> SHARED
    CORE --> TYPES
    CORE --> CSS

    %% Dev Tools Connections
    CLI --> CORE
    DEV --> CORE
    ESLINT --> CORE

    %% Component Mappings
    click CORE "https://github.com/facebook/stylex/tree/main/packages/stylex/"
    click SHARED "https://github.com/facebook/stylex/tree/main/packages/shared/"
    click TYPES "https://github.com/facebook/stylex/blob/main/packages/stylex/src/StyleXTypes.d.ts"
    click BABEL "https://github.com/facebook/stylex/tree/main/packages/babel-plugin/"
    click WEBPACK "https://github.com/facebook/stylex/tree/main/packages/webpack-plugin/"
    click ROLLUP "https://github.com/facebook/stylex/tree/main/packages/rollup-plugin/"
    click ESBUILD "https://github.com/facebook/stylex/tree/main/packages/esbuild-plugin/"
    click NEXT "https://github.com/facebook/stylex/tree/main/packages/nextjs-plugin/"
    click CLI "https://github.com/facebook/stylex/tree/main/packages/cli/"
    click DEV "https://github.com/facebook/stylex/tree/main/packages/dev-runtime/"
    click ESLINT "https://github.com/facebook/stylex/tree/main/packages/eslint-plugin/"

    %% Styling
    classDef default fill:#f9f9f9,stroke:#333,stroke-width:2px
    classDef core fill:#dae8fc,stroke:#6c8ebf
    classDef build fill:#d5e8d4,stroke:#82b366
    classDef dev fill:#ffe6cc,stroke:#d79b00

    class CORE,SHARED,TYPES,CSS core
    class BABEL,WEBPACK,ROLLUP,NEXT,ESBUILD build
    class CLI,DEV,ESLINT dev

    %% Legend
    subgraph Legend
        L1[Core Components]:::core
        L2[Build Plugins]:::build
        L3[Development Tools]:::dev
    end
```
