# emotion-js/emotion architecture

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

- Interactive diagram: https://gitdiagram.com/emotion-js/emotion
- Repository: https://github.com/emotion-js/emotion

## Overview

Emotion is a CSS-in-JS library: application code supplies string or object styles, and Emotion provides APIs and tooling to compose and process them. The main runtime layers represented here are the React and standalone CSS APIs, style serialization, caching, and stylesheet insertion; the repository also includes styled/native variants, server rendering, a Babel transform, and ecosystem integrations. The README establishes the product workflow and optional Babel-plugin role; source excerpts and the index establish only the specific internal links shown, so other runtime links are omitted or marked unverified.

Main entry points: [`packages/serialize/src/index.ts`](https://github.com/emotion-js/emotion/blob/main/packages/serialize/src/index.ts) (Style serialization), [`packages/cache/src/index.ts`](https://github.com/emotion-js/emotion/blob/main/packages/cache/src/index.ts) (Style cache), [`packages/css/src/create-instance.ts`](https://github.com/emotion-js/emotion/blob/main/packages/css/src/create-instance.ts) (CSS instance API), [`packages/babel-plugin/src/index.js`](https://github.com/emotion-js/emotion/blob/main/packages/babel-plugin/src/index.js) (Babel transform)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_api["Styling APIs"]
  node_react["React API<br/>[index.ts]"]
  node_styled["Styled components<br/>[base.tsx]"]
  node_cssapi["CSS instance API<br/>[create-instance.ts]"]
  node_native["Native API<br/>[index.js]"]
  node_primitives["Primitives API<br/>[index.ts]"]
end

subgraph group_runtime["Style Runtime"]
  node_serialize["Style serialization<br/>[index.ts]"]
  node_cache["Style cache<br/>[index.ts]"]
  node_sheet["Stylesheet insertion<br/>[index.ts]"]
  node_hash["Style hashing<br/>[index.ts]"]
end

subgraph group_tooling["Transforms and Tooling"]
  node_babel["Babel transform<br/>[index.js]"]
  node_babelmacros["Transform macros<br/>[core-macro.js]"]
  node_babelutils["Transform utilities<br/>[index.js]"]
  node_eslint["ESLint rules<br/>[index.ts]"]
  node_jest["Jest serializers"]
  node_prettifier["CSS prettifier<br/>[index.ts]"]
end

subgraph group_platform["Platform Integrations"]
  node_server["Server rendering<br/>[index.js]"]
end

node_developer(("Application developer"))

node_developer -->|"styles with"| node_react
node_developer -.->|"optionally transforms"| node_babel
node_react -->|"creates cache"| node_cache
node_cssapi -->|"creates cache"| node_cache
node_cssapi -->|"serializes styles"| node_serialize
node_cssapi -->|"uses stylesheet"| node_sheet
node_cssapi -->|"inserts styles"| node_cache
node_cache -->|"creates stylesheet"| node_sheet
node_serialize -->|"hashes styles"| node_hash
node_babel -->|"dispatches transforms"| node_babelmacros
node_babel -->|"uses utilities"| node_babelutils
node_babelmacros -->|"uses utilities"| node_babelutils
node_jest -->|"formats CSS"| node_prettifier
node_styled -.->|"serializes styles"| node_serialize
node_server -.->|"uses cache"| node_cache
node_native -.->|"serializes styles"| node_serialize
node_primitives -.->|"serializes styles"| node_serialize

click node_react "https://github.com/emotion-js/emotion/blob/main/packages/react/src/index.ts"
click node_styled "https://github.com/emotion-js/emotion/blob/main/packages/styled/src/base.tsx"
click node_cssapi "https://github.com/emotion-js/emotion/blob/main/packages/css/src/create-instance.ts"
click node_native "https://github.com/emotion-js/emotion/blob/main/packages/native/src/index.js"
click node_primitives "https://github.com/emotion-js/emotion/blob/main/packages/primitives-core/src/index.ts"
click node_serialize "https://github.com/emotion-js/emotion/blob/main/packages/serialize/src/index.ts"
click node_cache "https://github.com/emotion-js/emotion/blob/main/packages/cache/src/index.ts"
click node_sheet "https://github.com/emotion-js/emotion/blob/main/packages/sheet/src/index.ts"
click node_hash "https://github.com/emotion-js/emotion/blob/main/packages/hash/src/index.ts"
click node_server "https://github.com/emotion-js/emotion/blob/main/packages/server/src/create-instance/index.js"
click node_babel "https://github.com/emotion-js/emotion/blob/main/packages/babel-plugin/src/index.js"
click node_babelmacros "https://github.com/emotion-js/emotion/blob/main/packages/babel-plugin/src/core-macro.js"
click node_babelutils "https://github.com/emotion-js/emotion/blob/main/packages/babel-plugin/src/utils/index.js"
click node_eslint "https://github.com/emotion-js/emotion/blob/main/packages/eslint-plugin/src/index.ts"
click node_jest "https://github.com/emotion-js/emotion/blob/main/packages/jest/src/create-serializer.js"
click node_prettifier "https://github.com/emotion-js/emotion/blob/main/packages/css-prettifier/src/index.ts"

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_react,node_styled,node_cssapi,node_native,node_primitives toneBlue
class node_serialize,node_cache,node_sheet,node_hash toneAmber
class node_babel,node_babelmacros,node_babelutils,node_eslint,node_jest,node_prettifier toneMint
class node_server toneRose
class node_developer toneIndigo
```

## Components

### Styling APIs

- [React API](https://github.com/emotion-js/emotion/blob/main/packages/react/src/index.ts): `packages/react/src/index.ts`
- [Styled components](https://github.com/emotion-js/emotion/blob/main/packages/styled/src/base.tsx): `packages/styled/src/base.tsx`
- [CSS instance API](https://github.com/emotion-js/emotion/blob/main/packages/css/src/create-instance.ts): `packages/css/src/create-instance.ts`
- [Native API](https://github.com/emotion-js/emotion/blob/main/packages/native/src/index.js): `packages/native/src/index.js`
- [Primitives API](https://github.com/emotion-js/emotion/blob/main/packages/primitives-core/src/index.ts): `packages/primitives-core/src/index.ts`

### Style Runtime

- [Style serialization](https://github.com/emotion-js/emotion/blob/main/packages/serialize/src/index.ts): `packages/serialize/src/index.ts`
- [Style cache](https://github.com/emotion-js/emotion/blob/main/packages/cache/src/index.ts): `packages/cache/src/index.ts`
- [Stylesheet insertion](https://github.com/emotion-js/emotion/blob/main/packages/sheet/src/index.ts): `packages/sheet/src/index.ts`
- [Style hashing](https://github.com/emotion-js/emotion/blob/main/packages/hash/src/index.ts): `packages/hash/src/index.ts`

### Transforms and Tooling

- [Babel transform](https://github.com/emotion-js/emotion/blob/main/packages/babel-plugin/src/index.js): `packages/babel-plugin/src/index.js`
- [Transform macros](https://github.com/emotion-js/emotion/blob/main/packages/babel-plugin/src/core-macro.js): `packages/babel-plugin/src/core-macro.js`
- [Transform utilities](https://github.com/emotion-js/emotion/blob/main/packages/babel-plugin/src/utils/index.js): `packages/babel-plugin/src/utils/index.js`
- [ESLint rules](https://github.com/emotion-js/emotion/blob/main/packages/eslint-plugin/src/index.ts): `packages/eslint-plugin/src/index.ts`
- [Jest serializers](https://github.com/emotion-js/emotion/blob/main/packages/jest/src/create-serializer.js): `packages/jest/src/create-serializer.js`
- [CSS prettifier](https://github.com/emotion-js/emotion/blob/main/packages/css-prettifier/src/index.ts): `packages/css-prettifier/src/index.ts`

### Platform Integrations

- [Server rendering](https://github.com/emotion-js/emotion/blob/main/packages/server/src/create-instance/index.js): `packages/server/src/create-instance/index.js`

### Other components

- **Application developer**

## Connections

- Application developer → React API: styles with (evidence: `README.md`)
- Application developer → Babel transform: optionally transforms (evidence: `README.md`)
- React API → Style cache: creates cache
- CSS instance API → Style cache: creates cache (evidence: `packages/css/src/create-instance.ts`)
- CSS instance API → Style serialization: serializes styles (evidence: `packages/css/src/create-instance.ts`)
- CSS instance API → Stylesheet insertion: uses stylesheet (evidence: `packages/css/src/create-instance.ts`)
- CSS instance API → Style cache: inserts styles (evidence: `packages/css/src/create-instance.ts`)
- Style cache → Stylesheet insertion: creates stylesheet (evidence: `packages/cache/src/index.ts`)
- Style serialization → Style hashing: hashes styles (evidence: `packages/serialize/src/index.ts`)
- Babel transform → Transform macros: dispatches transforms (evidence: `packages/babel-plugin/src/index.js`)
- Babel transform → Transform utilities: uses utilities (evidence: `packages/babel-plugin/src/index.js`)
- Transform macros → Transform utilities: uses utilities (evidence: `packages/babel-plugin/src/core-macro.js`)
- Jest serializers → CSS prettifier: formats CSS (evidence: `packages/jest/src/create-serializer.js`)
- Styled components → Style serialization: serializes styles
- Server rendering → Style cache: uses cache
- Native API → Style serialization: serializes styles
- Primitives API → Style serialization: serializes styles
