# callstack/linaria architecture

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

- Interactive diagram: https://gitdiagram.com/callstack/linaria
- Repository: https://github.com/callstack/linaria

## Overview

##### Main Components Overview

a) Core Processing Layer:
- @linaria/core - The foundation that handles CSS extraction
- @linaria/babel - Babel transformation pipeline
- Evaluators - For processing and evaluating styles at build time

b) Framework Integration Layer:
- @linaria/react - React-specific bindings
- Framework-specific processors (shown in processors directory)
- Server-side rendering support (@linaria/server)

c) Build Integration Layer:
- Bundler integrations (webpack, rollup, esbuild, vite)
- PostCSS processing (@linaria/postcss)
- Critical CSS extraction

##### Data Flow and Relationships

**Source Code**
- ↓
**Babel Transform (build time)**
- ↓
**CSS Extraction & Processing**
- ↓
**Generated Assets (CSS + JS)**
- ↓
**Runtime Integration**

##### Key Architectural Elements

Important architectural patterns:

a) Build-time Processing:
- How the CSS is extracted during build
- Zero-runtime nature of the solution
- Transformation of styled components to atomic CSS

b) CSS Variables Handling:
- How dynamic styles are converted to CSS variables
- Connection between component props and CSS variables

c) Integration Points:
- Bundler plugin architecture
- Server-side rendering flow
- Theming system integration

##### Component Details

Specific components:

**┌─ Build Process ─────────────────┐**
- ┌─────────┐    ┌─────────────┐ │
- Babel  │ -> │ CSS Extract │ │
- ┘    └─────────────┘ │
- ┘

**┌─ Runtime ──────────────────────┐**
- ┌─────────┐    ┌────────────┐ │
- React  │ <- │ CSS Vars   │ │
- ┘    └────────────┘ │
- ┘

##### Integration Points

Connections with:

- Various bundlers (webpack, rollup, etc.)
- Framework bindings (React, etc.)
- Build tools (Babel, PostCSS)
- Development tools (sourcemaps, linting)

This design captures Linaria's architecture while showing how it achieves zero-runtime CSS-in-JS through build-time processing and CSS variables for dynamic styles.

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph "Legend"
        direction TB
        L1[Core Processing]:::core
        L2[Framework Integration]:::framework
        L3[Build Integration]:::build
        L4[Runtime Artifacts]:::runtime
        L5["."]:::optional
        L6["—>"]:::flow
    end

    subgraph "Core Processing Layer"
        direction TB
        Core["@linaria/core"]:::core
        Babel["Babel Transform"]:::core
        Eval["Evaluators"]:::core
        
        Core --> Babel
        Babel --> Eval
    end

    subgraph "Framework Integration Layer"
        direction TB
        React["React Bindings"]:::framework
        SSR["Server-side Rendering"]:::framework
        Processors["Framework Processors"]:::framework
        
        React --> SSR
        React --> Processors
    end

    subgraph "Build Integration Layer"
        direction TB
        PostCSS["PostCSS Processing"]:::build
        Webpack["Webpack"]:::build
        Rollup["Rollup"]:::build
        ESBuild["ESBuild"]:::build
        Vite["Vite"]:::build
        
        PostCSS --> Webpack
        PostCSS --> Rollup
        PostCSS --> ESBuild
        PostCSS --> Vite
    end

    subgraph "Additional Components"
        direction TB
        Atomic["Atomic CSS"]:::core
        Stylelint["Styling Utilities"]:::build
        Interop["Framework Interop"]:::framework
        TestKit["Testing Infrastructure"]:::core
    end

    Core --> React
    Core --> PostCSS
    Eval --> Atomic
    React --> Interop
    PostCSS --> Stylelint
    TestKit --> Core

    classDef core fill:#blue,stroke:#333,stroke-width:2px
    classDef framework fill:#green,stroke:#333,stroke-width:2px
    classDef build fill:#orange,stroke:#333,stroke-width:2px
    classDef runtime fill:#purple,stroke:#333,stroke-width:2px
    classDef optional stroke-dasharray: 5 5
    classDef flow stroke-width:2px

    click Core "https://github.com/callstack/linaria/tree/master/packages/core/"
    click Babel "https://github.com/callstack/linaria/tree/master/packages/linaria/babel/"
    click Eval "https://github.com/callstack/linaria/tree/master/packages/linaria/evaluators/"
    click React "https://github.com/callstack/linaria/tree/master/packages/react/"
    click SSR "https://github.com/callstack/linaria/tree/master/packages/server/"
    click Processors "https://github.com/callstack/linaria/tree/master/packages/atomic/processors/"
    click PostCSS "https://github.com/callstack/linaria/tree/master/packages/postcss-linaria/"
    click Webpack "https://github.com/callstack/linaria/tree/master/examples/webpack5/"
    click Rollup "https://github.com/callstack/linaria/tree/master/examples/rollup/"
    click ESBuild "https://github.com/callstack/linaria/tree/master/examples/esbuild/"
    click Vite "https://github.com/callstack/linaria/tree/master/examples/vite/"
    click Atomic "https://github.com/callstack/linaria/tree/master/packages/atomic/"
    click Stylelint "https://github.com/callstack/linaria/tree/master/packages/stylelint/"
    click Interop "https://github.com/callstack/linaria/tree/master/packages/interop/"
    click TestKit "https://github.com/callstack/linaria/tree/master/packages/testkit/"
```
