Introducing a new way to review your PRs.

Read the announcement

chakra-ui / panda

🐼 Universal, Type-Safe, CSS-in-JS Framework for Design Systems ⚡️

View on GitHub

19 documents · Updated Sep 23, 2026

docs / compiler-pipeline

Panda compiler pipeline

The Panda compiler turns a project's styling configuration and source usage into generated styling artifacts. It resolves the project rules, finds the source files in scope, extracts styling calls and components, converts them into style data, and writes CSS and supporting code for the application to use.

Pipeline overview

The pipeline keeps four concerns separate. Configuration defines the styling system and the source boundary. Extraction and parsing identify how the application uses that system. Generation turns the collected usage and configured theme into CSS and code artifacts. Output handling writes those artifacts for the application and its build tools.

The end-to-end flow is:

flowchart LR
    A[Project configuration] --> B[Resolved compiler context]
    B --> C[Configured source files]
    C --> D[Extracted style usage]
    D --> E[Encoded style data]
    B --> F[Theme and static style data]
    E --> G[Generated CSS and code artifacts]
    F --> G
    G --> H[Project output]

The main boundary is the compiler context. It carries the resolved configuration, the source project, the style encoder, the generator, and the output rules. This lets the source side report style usage without deciding how files are laid out, while the generation side can combine usage with global theme data.

Configuration boundary

Configuration resolution

Configuration resolution changes user input into the complete rule set used by compilation. The process loads the project configuration, adds the applicable presets, merges plugin and user hooks, validates the result, and keeps the configuration dependencies available for later rebuilds. See Configuration resolution for the configuration lifecycle.

The resolved configuration controls both sides of the pipeline. Its source patterns decide which files are read. Its theme, recipes, patterns, conditions, and output settings decide how extracted usage becomes generated styling.

References: packages/…/load-config.ts• L1-11 packages/…/resolve-config.ts• L16-81 packages/…/config.ts• L11-33

Compiler context

The compiler context is the shared boundary between configuration, parsing, generation, and output. It creates a source project from the resolved configuration, owns the generator, and provides the operations that parse files and write CSS. packages/…/create-context.ts• L13-46.

This context also keeps file matching and output paths consistent. A build entry point can therefore run the same lifecycle for a full build, a selected artifact, or a changed source file.

References: packages/…/create-context.ts• L13-46 packages/…/create-context.ts• L61-117 packages/…/generator.ts• L46-53

Source usage boundary

Source discovery

Source discovery defines the set of application files that can contribute styling usage. The compiler applies the configured include and exclude patterns relative to the project working directory, then loads those files into the source project. packages/…/create-context.ts• L61-64, packages/…/project.ts• L60-89.

This boundary prevents unrelated files from affecting the output. It also gives watch and build integrations one shared source set to refresh when files are added, changed, or removed.

References: packages/…/create-context.ts• L61-64 packages/…/project.ts• L68-89 packages/…/create-context.ts• L195-216

Extraction and parsing

Extraction and parsing turn source syntax into a structured parser result. The parser identifies supported imports and usage forms, evaluates values that can be known at build time, and records CSS calls, recipes, patterns, tokens, and JSX style props. See Source extraction and parsing for this boundary.

The parser result is the hand-off to style generation. As each result is recorded, its style data is passed to the encoder. The encoder collects the atomic rules and recipe data that the generator later decodes into CSS. Unresolvable or runtime-only values remain represented as usage data instead of being treated as fixed build-time CSS.

References: packages/…/project.ts• L137-182 packages/…/parser.ts• L25-53 packages/…/parser-result.ts• L5-25 packages/…/parser-result.ts• L54-120

Generation boundary

Artifact generation

Artifact generation converts resolved theme data and encoded source usage into files that support the configured styling API. It can produce CSS layers for resets, tokens, static styles, global styles, keyframes, and parsed utility rules. It can also produce generated JavaScript, JSX helpers, types, theme data, and other API artifacts. See CSS artifact generation for the output lifecycle.

The generator uses the same context as the parser, so generated rules follow the resolved tokens, conditions, recipes, patterns, and layer names. This keeps a style call in source aligned with the API and CSS files generated for that project.

References: packages/…/generator.ts• L51-89 packages/…/generator.ts• L209-232 packages/…/codegen.ts• L4-24

CSS assembly

CSS assembly combines baseline project styles with rules collected from source usage. The full build adds layer order, optional preflight, token variables, static styles, global styles, keyframes, and parser CSS before it serializes the stylesheet. packages/…/generate.ts• L7-24.

The compiler can write one styles.css file or split output into layer, recipe, and theme files with an index that connects the files. The output engine creates needed directories and avoids rewriting a file when its content has not changed.

References: packages/…/generator.ts• L70-99 packages/…/generator.ts• L128-207 packages/…/create-context.ts• L110-173 packages/…/output-engine.ts• L23-59

Compilation lifecycle

Initial build

An initial build loads and resolves configuration before it creates the compiler context. It then generates configuration-derived artifacts, parses the configured source files, assembles CSS, and writes the result. This order makes generated APIs available alongside CSS and ensures that source usage is interpreted against the final configuration.

The lifecycle is coordinated by generate. Its build step first runs code generation. It then parses files and writes the stylesheet unless the project only requests token output.

References: packages/…/generate.ts• L7-24 packages/…/generate.ts• L26-29 packages/…/config.ts• L11-33

Incremental rebuilds

Watch mode preserves the same boundaries while reducing the amount of work. A configuration change reloads the context and regenerates affected artifacts. A source file change refreshes only that file's parsed state before the compiler rewrites the CSS output. packages/…/generate.ts• L30-72.

The build integration also tracks file metadata and configuration dependencies. If neither configuration nor an included source file changed, extraction can be skipped. This keeps incremental builds aligned with the full build without treating stale source data as current.

References: packages/…/generate.ts• L30-72 packages/…/builder.ts• L52-95 packages/…/builder.ts• L151-177

Change checklist

When these files or sections are changed, remember to consider these:

  • Keep the source include and exclude contract aligned between configuration resolution, file discovery, and watch mode.
  • Keep parser result categories aligned with encoder collection and generator decoding so a new style usage form reaches CSS.
  • Keep generated artifact identifiers aligned with the code-generation writer and any incremental artifact selection.
  • Keep CSS layer names and split-file imports aligned between stylesheet assembly and the files written to disk.
  • Keep configuration dependency tracking aligned with config reload behavior so preset or imported config changes rebuild the context.

Important failure modes

TriggerConsequenceGuard
A source file is outside the configured include set or is excludedIts styling usage is absent from parser CSSReview the resolved source patterns and the project working directory used for matching.
A configuration or preset dependency changes without a context reloadNew theme or API rules do not reach the next outputTrack configuration dependencies and reload the resolved context before generation.
A parser result is recorded without passing its style data to the encoderThe source usage appears in parser data but produces no CSS rulePreserve the parser-result to encoder hand-off for each supported result category.
Split CSS files and the main index use different layer or file namesThe application imports incomplete or incorrectly ordered stylesDerive both the split files and index from the same layer and artifact definitions.
A changed source file is not refreshed before parsingCSS remains based on old source contentRefresh or add the source file in the project before the incremental parse.

Key files

FileWhy to read it
packages/…/generate.tsShows the full-build and watch-build orchestration.
packages/…/create-context.tsDefines the shared boundary for source discovery, parsing, and CSS output.
packages/…/resolve-config.tsShows how user settings, presets, hooks, and validation become the resolved configuration.
packages/…/project.tsShows how configured files enter the parser project and how file parsing is coordinated.
packages/…/parser.tsShows the source usage categories that feed parser results.
packages/…/parser-result.tsShows the hand-off from parsed usage to encoded style data.
packages/…/generator.tsShows how baseline styles, parser CSS, and split CSS artifacts are assembled.
packages/…/codegen.tsShows how generated artifacts are selected and written.
packages/…/output-engine.tsShows the final file-writing boundary and unchanged-file behavior.