This guide helps AI assistants understand the Panda CSS codebase structure, conventions, and best practices.
Panda CSS is a CSS-in-JS framework with static extraction capabilities. The project is a monorepo managed by pnpm with workspace support.
/packages/ # Core packages published to npm
/core/ # CSS processing, rule generation, optimization (PostCSS/LightningCSS)
/node/ # Node.js APIs, config resolution, file watching
/cli/ # CLI tool (@pandacss/dev package)
/parser/ # Static analysis and extraction
/generator/ # Code generation for styled-system
/fixture/ # Shared test fixtures and utilities
/postcss/ # PostCSS plugin
/preset-*/ # Design system presets
/sandbox/ # Integration tests and examples
/codegen/ # Generated code validation tests
/vite-ts/ # Vite integration example
/next-js-*/ # Next.js examples
/playground/ # Interactive playground application
/website/ # Documentation site
- Static Extraction: Panda analyzes source files to extract styles at build time
- Design Tokens: Type-safe design tokens defined in config
- Recipes: Reusable component style patterns (like variants)
- Conditions: Responsive and state-based styling (e.g.,
_hover,md:,_dark) - CSS Optimization: Uses PostCSS (default) or LightningCSS (optional) for CSS processing
NEVER accept changes that modify CSS output snapshots without explicit user approval:
- Run tests BEFORE and AFTER any dependency updates
- If snapshots change, investigate why and get user confirmation
- The test
packages/core/__tests__/atomic-rule.test.tsis the primary CSS output validator - CSS output consistency is more important than using latest package versions
Always run tests from the project root:
# ✅ Correct
pnpm test packages/core
pnpm test packages/parser
# ❌ Incorrect
cd packages/core && pnpm testKey test commands:
pnpm test <path> # Run tests for specific package/file
pnpm test packages/core # Test all core package tests
pnpm build # Build all packages
pnpm build-fast # Fast build without type definitionsUse --ignore-scripts for dependency updates:
pnpm install --ignore-scripts
pnpm update <package> --ignore-scriptsWhen updating PostCSS or browserslist-related packages:
- Update package.json versions
- Run
pnpm install --ignore-scripts - Run
pnpm test packages/coreto verify CSS output unchanged - Check for browserslist warnings in sandbox projects
- Create changeset if changes affect users
- PostCSS ecosystem: Coordinate updates across all PostCSS plugins to avoid CSS output changes
- browserslist: Updates affect
postcss-merge-rulesbehavior - test thoroughly - lightningcss: Used optionally via
config.lightningcssflag, depends on browserslist for targets - Node.js packages: Core packages (
@pandacss/core,@pandacss/node, etc.) must stay in sync
- Read relevant source files in
/packages/<name>/src/ - Understand the change impact (does it affect CSS output?)
- Make changes
- Run tests:
pnpm test packages/<name> - If tests fail, investigate and fix (don't just update snapshots)
- Create changeset for user-facing changes
- Check current versions in package.json
- Research latest compatible versions
- Update package.json files
- Run
pnpm install --ignore-scripts - Run CSS output tests first:
pnpm test packages/core/__tests__/atomic-rule.test.ts - If snapshots change, investigate the root cause
- Run broader test suite:
pnpm test packages/core - Create changeset documenting the update
# Changesets are in .changeset/ directory
# Create a new file: .changeset/<descriptive-name>.mdFormat:
---
'@pandacss/package-name': patch|minor|major
---
Brief description of the change and its impact.
- Detail 1
- Detail 2Changeset types:
patch: Bug fixes, dependency updates, non-breaking changesminor: New features, backwards-compatible changesmajor: Breaking changes
- User config →
packages/config/→ Config resolution - Config hooks →
packages/types/src/config.ts - Context creation →
packages/node/src/→PandaContext - Code generation →
packages/generator/
- Style objects →
packages/core/src/rule-processor.ts - CSS generation →
packages/core/src/stylesheet.ts - Optimization →
packages/core/src/optimize.ts- PostCSS path:
optimize-postcss.ts - LightningCSS path:
optimize-lightningcss.ts
- PostCSS path:
packages/fixture/contains shared test utilitiescreateContext()andcreateRuleProcessor()are used throughout tests- Fixtures provide a base config with design tokens and recipes
Snapshot mismatches:
- Compare expected vs received CSS output carefully
- Look for media query ordering, selector merging, or whitespace changes
- Identify which dependency update caused the change
- Common culprits:
postcss-merge-rules,postcss-nested,browserslist
Build failures:
- Check TypeScript errors in
packages/*/src/ - Run
pnpm build-fastfor faster iteration without type checking - Use
pnpm typecheckfor type-only validation
Use search tools strategically:
- Grep for function names, class names, or specific strings
- Check both
/src/and/__tests__/directories - Look in
/packages/types/src/for type definitions - Config options are defined in
packages/types/src/config.ts
- Circular dependencies: Be careful when adding imports between core packages
- Browser compatibility: Changes to browserslist affect CSS transformation
- PostCSS plugin order: Order matters in
optimize-postcss.ts - Workspace protocol: Internal packages use
workspace:*in dependencies - Multiple package.json: Each package has its own, plus root package.json
- Sandbox warnings: Even if main packages are fine, check sandbox projects for warnings
- TypeScript version sync: The TypeScript version in the root
package.jsonmust match the version used byts-morph's dependency. Mismatches can cause parsing errors and type issues. Always verifyts-morphcompatibility when updating TypeScript.
@pandacss/dev (CLI)
├─ @pandacss/node (core runtime)
│ ├─ @pandacss/core (CSS processing)
│ ├─ @pandacss/parser (static analysis)
│ ├─ @pandacss/generator (codegen)
│ └─ @pandacss/config (config resolution)
└─ @pandacss/postcss (PostCSS plugin)
@pandacss/core
├─ postcss (CSS processing)
├─ lightningcss (optional, faster CSS processing)
├─ browserslist (browser targets)
└─ postcss-* plugins (optimization)
- Main documentation:
/website/(documentation source) - Type definitions:
packages/types/src/(comprehensive types) - Integration examples:
/sandbox/(real-world usage) - Test patterns:
packages/fixture/andpackages/core/__tests__/
- Always read before writing: Understand existing patterns before making changes
- Test incrementally: Run tests after small changes, not just at the end
- Preserve CSS output: When in doubt, prioritize CSS output stability
- Use workspace knowledge: Remember this is a monorepo - changes may affect multiple packages
- Document breaking changes: If CSS output must change, explain why clearly
- Check sandboxes: Don't just test main packages - verify sandbox projects too
If a change breaks things:
git checkout packages/ # Revert package.json changes
pnpm install --ignore-scripts # Restore dependencies
pnpm test packages/core # Verify tests passLast Updated: 2025-01-17 Project Version: 1.4.2