|
| 1 | +--- |
| 2 | +name: architecture |
| 3 | +description: Explain the react-native-css architecture, compiler pipeline, and key files. Use when a contributor wants to understand how the codebase works. |
| 4 | +allowed-tools: Read, Grep, Glob |
| 5 | +--- |
| 6 | + |
| 7 | +You are explaining the architecture of **react-native-css** to a contributor. |
| 8 | + |
| 9 | +Start by reading `DEVELOPMENT.md` for the full architecture overview, then supplement with source code as needed. |
| 10 | + |
| 11 | +## How to explain |
| 12 | + |
| 13 | +1. **Start with the big picture**: react-native-css is a standalone CSS polyfill for React Native. It works independently of Tailwind — any `.css` file can be used. Nativewind v5 depends on this as its core engine. |
| 14 | + |
| 15 | +2. **Show the compiler pipeline**: Walk through how a CSS rule becomes a React Native style: |
| 16 | + - Metro transformer intercepts `.css` files (`src/metro/metro-transformer.ts`) |
| 17 | + - lightningcss parses the CSS AST |
| 18 | + - `compile()` processes rules, media queries, keyframes, variables (`src/compiler/compiler.ts`) |
| 19 | + - Output is a `ReactNativeCssStyleSheet` (JSON) |
| 20 | + - Injection code registers styles with the native runtime (`src/metro/injection-code.ts`) |
| 21 | + |
| 22 | +3. **Explain the babel plugin**: It rewrites React Native imports so components get `className` support: |
| 23 | + - `import { View } from 'react-native'` → `import { View } from 'react-native-css/components'` |
| 24 | + |
| 25 | +4. **Explain the runtime**: |
| 26 | + - Reactive style system (`src/native/reactivity.ts`) — observables for media queries, color scheme |
| 27 | + - StyleCollection singleton (`src/native-internal/`) — isolated to avoid circular deps |
| 28 | + - Platform-aware: different outputs for native (JSON) vs web (browser CSS) |
| 29 | + |
| 30 | +5. **Show relevant code**: Read source files to illustrate. The compiler and runtime are the most complex parts. |
| 31 | + |
| 32 | +6. **Clarify the boundary**: This repo owns compilation, runtime, babel, and Metro integration. Nativewind adds Tailwind-specific theming on top. |
0 commit comments