# ricardordzalt/tailwind-for-react-native architecture

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

- Interactive diagram: https://gitdiagram.com/ricardordzalt/tailwind-for-react-native
- Repository: https://github.com/ricardordzalt/tailwind-for-react-native

## Overview

1. This repository is a React Native utility-styling library, not an app. The core product is a small public API that lets consumers style RN components with Tailwind-like utility strings through `tw(...)`, `styled(Component)`, and an optional `TWRNProvider`.

2. The public entrypoints are thin wrappers at the repo root and in `src/index.tsx` / `index.ts`. They expose the main consumer-facing APIs while keeping the implementation under `src/`. The package is built and tested as a TypeScript-first library.

3. The main runtime boundary is the provider layer in `src/providers/tw-rn-provider.tsx`. `TWRNProvider` is optional, but when present it injects runtime theme state into the styling system: mode, custom colors, object presets, class aliases, and viewport conversion factors. The matching `.d.ts` file indicates the provider’s public type surface is part of the contract.

4. The hook layer in `src/hooks/use-tw.ts` is the primary access point for runtime styling. It returns `tw(...)` plus provider-backed helpers like `mode`, `toggleMode()`, `colors`, `wppx()`, and `hppx()`. In architecture terms, this is the bridge between React context and the style compiler.

5. The component wrapper layer in `src/functions/styled.tsx` builds reusable styled RN components from template literals. Its data flow is: template string + interpolations -> utility parsing -> generated RN style object -> merged with runtime `style` prop, with the runtime prop taking final precedence.

6. The style engine lives under `src/styles/`. This is the main mapping subsystem from utility names to React Native style properties. `src/styles/index.ts`, `prefixes.ts`, and the large `src/styles/properties/*` tree define the supported utilities, including layout, flexbox, borders, typography, shadows, media, and platform-specific helpers.

7. Utility-string parsing and resolution live under `src/utils/`. These helpers resolve nested aliases, extract style objects from strings, read properties by path, filter utilities by platform or mode, and split class lists. This is where the library turns a string like `dark:bg-black ios:p-2` into the subset of styles that apply in the current environment.

8. The theme-extension model is centered on three data shapes: `colors`, `styles`, and `classes`. `colors` provides token lookup, `styles` provides reusable object presets, and `classes` provides alias expansion to other utility strings. The README’s nested-path examples match the utility tree’s support for dotted references and circular-reference protection.

9. The library’s environment-sensitive behavior is a key architectural feature. `dark:*` utilities depend on mode state, `ios:*` and `android:*` depend on platform filtering, and viewport helpers (`wp`, `hp`, `wppx`, `hppx`) depend on window size plus provider conversion factors. This means style resolution is not purely static; it combines string parsing with runtime context.

10. `src/constants/colors.ts` holds the built-in color palette that backs default named tokens such as blue, slate, gray, etc. This gives the library a default design system even without a provider, and the provider can override or extend it.

11. The repository’s tests in `__tests__/` exercise the public APIs and integration behavior, including styled components, hook behavior, provider behavior, and platform/mode filtering. That test layout reflects the real architectural seams: parser, hook, provider, and component wrapper.

12. The `example/` directory is a full React Native app for manual validation and documentation. It contains Android and iOS projects, Jest config, Metro config, and a sample screen using the library, so it acts as an integration harness rather than part of the library runtime.

13. Tooling is standard for a RN TypeScript package: Babel and Metro for React Native bundling, Jest for tests, TypeScript configs for source and build output, and ESLint/Prettier for code quality. Nothing here suggests backend services or external infrastructure; the architecture is entirely client-side and local to the RN runtime.

Main entry points: [`src/hooks/use-tw.ts`](https://github.com/ricardordzalt/tailwind-for-react-native/blob/main/src/hooks/use-tw.ts) (useTw), [`src/utils/get-style-from-style-string.ts`](https://github.com/ricardordzalt/tailwind-for-react-native/blob/main/src/utils/get-style-from-style-string.ts) (style string), [`src/providers/tw-rn-provider.tsx`](https://github.com/ricardordzalt/tailwind-for-react-native/blob/main/src/providers/tw-rn-provider.tsx) (TWRNProvider), [`src/index.tsx`](https://github.com/ricardordzalt/tailwind-for-react-native/blob/main/src/index.tsx) (src/index.tsx)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_grp_public["Public API"]
  node_n_root_index["index.ts<br/>package entry<br/>[index.ts]"]
  node_n_src_index["src/index.tsx<br/>src entry<br/>[index.tsx]"]
end

subgraph group_grp_runtime["Runtime Core"]
  node_n_provider["TWRNProvider<br/>context provider<br/>[tw-rn-provider.tsx]"]
  node_n_use_tw["useTw<br/>hook<br/>[use-tw.ts]"]
  node_n_styled["styled()<br/>component wrapper<br/>[styled.tsx]"]
end

subgraph group_grp_styles["Style Engine"]
  node_n_styles_index["styles/index<br/>style registry<br/>[index.ts]"]
  node_n_prefixes["prefixes<br/>[prefixes.ts]"]
  node_n_props_index["properties index<br/>property catalog<br/>[index.ts]"]
  node_n_color_tokens["colors<br/>default tokens<br/>[colors.ts]"]
end

subgraph group_grp_utils["Resolution Utils"]
  node_n_style_string["style string<br/>parser"]
  node_n_nested_style["nested lookup<br/>resolver"]
  node_n_prop_lookup["prop lookup<br/>resolver"]
  node_n_mode_filter["mode filter"]
  node_n_platform_filter["platform filter"]
  node_n_separator["separator<br/>string utility"]
end

subgraph group_grp_validation["Validation"]
  node_n_tests["__tests__<br/>integration tests"]
  node_n_example["example app<br/>rn harness"]
end

subgraph group_grp_tooling["Tooling"]
  node_n_babel["babel config<br/>build config<br/>[babel.config.js]"]
  node_n_tsconfig["tsconfig<br/>typescript config<br/>[tsconfig.json]"]
  node_n_jest["jest config<br/>test config<br/>[jest.config.js]"]
end

node_n_root_index -->|"re-exports"| node_n_src_index
node_n_src_index -->|"exports"| node_n_provider
node_n_src_index -->|"exports"| node_n_use_tw
node_n_src_index -->|"exports"| node_n_styled
node_n_provider -->|"default colors"| node_n_color_tokens
node_n_provider -->|"theme input"| node_n_styles_index
node_n_use_tw -->|"resolves"| node_n_style_string
node_n_use_tw -->|"reads context"| node_n_provider
node_n_use_tw -->|"mode aware"| node_n_mode_filter
node_n_use_tw -->|"platform aware"| node_n_platform_filter
node_n_use_tw -->|"interprets"| node_n_prefixes
node_n_styled -->|"parses"| node_n_style_string
node_n_styled -->|"merges runtime"| node_n_provider
node_n_styled -->|"maps to"| node_n_props_index
node_n_style_string -->|"resolves aliases"| node_n_nested_style
node_n_style_string -->|"reads values"| node_n_prop_lookup
node_n_style_string -->|"filters by mode"| node_n_mode_filter
node_n_style_string -->|"filters by platform"| node_n_platform_filter
node_n_style_string -->|"splits"| node_n_separator
node_n_styles_index -->|"uses prefixes"| node_n_prefixes
node_n_styles_index -->|"composes"| node_n_props_index
node_n_props_index -->|"uses defaults"| node_n_color_tokens
node_n_tests -->|"covers"| node_n_provider
node_n_tests -->|"covers"| node_n_use_tw
node_n_tests -->|"covers"| node_n_styled
node_n_tests -->|"covers"| node_n_style_string
node_n_example -->|"demonstrates"| node_n_provider
node_n_example -->|"demonstrates"| node_n_use_tw
node_n_example -->|"demonstrates"| node_n_styled
node_n_babel -->|"builds"| node_n_src_index
node_n_tsconfig -->|"types source"| node_n_src_index
node_n_jest -->|"runs"| node_n_tests

click node_n_root_index "https://github.com/ricardordzalt/tailwind-for-react-native/blob/main/index.ts"
click node_n_src_index "https://github.com/ricardordzalt/tailwind-for-react-native/blob/main/src/index.tsx"
click node_n_provider "https://github.com/ricardordzalt/tailwind-for-react-native/blob/main/src/providers/tw-rn-provider.tsx"
click node_n_use_tw "https://github.com/ricardordzalt/tailwind-for-react-native/blob/main/src/hooks/use-tw.ts"
click node_n_styled "https://github.com/ricardordzalt/tailwind-for-react-native/blob/main/src/functions/styled.tsx"
click node_n_styles_index "https://github.com/ricardordzalt/tailwind-for-react-native/blob/main/src/styles/index.ts"
click node_n_prefixes "https://github.com/ricardordzalt/tailwind-for-react-native/blob/main/src/styles/prefixes.ts"
click node_n_props_index "https://github.com/ricardordzalt/tailwind-for-react-native/blob/main/src/styles/properties/index.ts"
click node_n_color_tokens "https://github.com/ricardordzalt/tailwind-for-react-native/blob/main/src/constants/colors.ts"
click node_n_style_string "https://github.com/ricardordzalt/tailwind-for-react-native/blob/main/src/utils/get-style-from-style-string.ts"
click node_n_nested_style "https://github.com/ricardordzalt/tailwind-for-react-native/blob/main/src/utils/get-nested-style-from-string.ts"
click node_n_prop_lookup "https://github.com/ricardordzalt/tailwind-for-react-native/blob/main/src/utils/get-prop-by-string.ts"
click node_n_mode_filter "https://github.com/ricardordzalt/tailwind-for-react-native/blob/main/src/utils/get-filtered-array-of-style-strings-by-mode.ts"
click node_n_platform_filter "https://github.com/ricardordzalt/tailwind-for-react-native/blob/main/src/utils/get-filtered-array-of-style-strings-by-platform.ts"
click node_n_separator "https://github.com/ricardordzalt/tailwind-for-react-native/blob/main/src/utils/styles-separator.ts"
click node_n_tests "https://github.com/ricardordzalt/tailwind-for-react-native/tree/main/__tests__"
click node_n_example "https://github.com/ricardordzalt/tailwind-for-react-native/tree/main/example"
click node_n_babel "https://github.com/ricardordzalt/tailwind-for-react-native/blob/main/babel.config.js"
click node_n_tsconfig "https://github.com/ricardordzalt/tailwind-for-react-native/blob/main/tsconfig.json"
click node_n_jest "https://github.com/ricardordzalt/tailwind-for-react-native/blob/main/jest.config.js"

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_n_root_index,node_n_src_index toneBlue
class node_n_provider,node_n_use_tw,node_n_styled toneAmber
class node_n_styles_index,node_n_prefixes,node_n_props_index,node_n_color_tokens toneMint
class node_n_style_string,node_n_nested_style,node_n_prop_lookup,node_n_mode_filter,node_n_platform_filter,node_n_separator toneRose
class node_n_tests,node_n_example toneIndigo
class node_n_babel,node_n_tsconfig,node_n_jest toneTeal
```

## Components

### Public API

Consumer-facing entrypoints and exported surface.

- [index.ts](https://github.com/ricardordzalt/tailwind-for-react-native/blob/main/index.ts): package entry · Top-level package entry that re-exports the library API. · `index.ts`
- [src/index.tsx](https://github.com/ricardordzalt/tailwind-for-react-native/blob/main/src/index.tsx): src entry · Main source entry that gathers and exposes the public API. · `src/index.tsx`

### Runtime Core

Provider, hook, and styled-component wrapper.

- [TWRNProvider](https://github.com/ricardordzalt/tailwind-for-react-native/blob/main/src/providers/tw-rn-provider.tsx): context provider · Optional runtime provider that injects theme and environment state. · `src/providers/tw-rn-provider.tsx`
- [useTw](https://github.com/ricardordzalt/tailwind-for-react-native/blob/main/src/hooks/use-tw.ts): hook · Hook that exposes tw() and provider-backed helpers to consumers. · `src/hooks/use-tw.ts`
- [styled()](https://github.com/ricardordzalt/tailwind-for-react-native/blob/main/src/functions/styled.tsx): component wrapper · Template-literal wrapper that composes utilities into styled RN components. · `src/functions/styled.tsx`

### Style Engine

Utility-to-style mapping and built-in tokens.

- [styles/index](https://github.com/ricardordzalt/tailwind-for-react-native/blob/main/src/styles/index.ts): style registry · Central style registry for utility-to-React Native property mapping. · `src/styles/index.ts`
- [prefixes](https://github.com/ricardordzalt/tailwind-for-react-native/blob/main/src/styles/prefixes.ts): utility prefixes · Shared utility prefixes and platform or mode markers. · `src/styles/prefixes.ts`
- [properties index](https://github.com/ricardordzalt/tailwind-for-react-native/blob/main/src/styles/properties/index.ts): property catalog · Aggregates style-property modules into the supported utility set. · `src/styles/properties/index.ts`
- [colors](https://github.com/ricardordzalt/tailwind-for-react-native/blob/main/src/constants/colors.ts): default tokens · Built-in color palette used when no provider overrides are present. · `src/constants/colors.ts`

### Resolution Utils

String parsing, filtering, and nested lookup helpers.

- [style string](https://github.com/ricardordzalt/tailwind-for-react-native/blob/main/src/utils/get-style-from-style-string.ts): parser · Converts utility strings into style objects and filters applicable utilities. · `src/utils/get-style-from-style-string.ts`
- [nested lookup](https://github.com/ricardordzalt/tailwind-for-react-native/blob/main/src/utils/get-nested-style-from-string.ts): resolver · Resolves dotted aliases and nested style references. · `src/utils/get-nested-style-from-string.ts`
- [prop lookup](https://github.com/ricardordzalt/tailwind-for-react-native/blob/main/src/utils/get-prop-by-string.ts): resolver · Reads values by path from objects and style definitions. · `src/utils/get-prop-by-string.ts`
- [mode filter](https://github.com/ricardordzalt/tailwind-for-react-native/blob/main/src/utils/get-filtered-array-of-style-strings-by-mode.ts): filter · Selects style strings that match the current mode. · `src/utils/get-filtered-array-of-style-strings-by-mode.ts`
- [platform filter](https://github.com/ricardordzalt/tailwind-for-react-native/blob/main/src/utils/get-filtered-array-of-style-strings-by-platform.ts): filter · Selects style strings that match the current platform. · `src/utils/get-filtered-array-of-style-strings-by-platform.ts`
- [separator](https://github.com/ricardordzalt/tailwind-for-react-native/blob/main/src/utils/styles-separator.ts): string utility · Shared separator used when splitting class lists and utility fragments. · `src/utils/styles-separator.ts`

### Validation

Tests and example app used to exercise the library.

- [__tests__](https://github.com/ricardordzalt/tailwind-for-react-native/tree/main/__tests__): integration tests · Public API and integration tests for provider, hook, and styled behavior. · `__tests__`
- [example app](https://github.com/ricardordzalt/tailwind-for-react-native/tree/main/example): rn harness · Full React Native sample app for manual validation and documentation. · `example`

### Tooling

Build, lint, bundling, and type configuration.

- [babel config](https://github.com/ricardordzalt/tailwind-for-react-native/blob/main/babel.config.js): build config · React Native and TypeScript transpilation configuration. · `babel.config.js`
- [tsconfig](https://github.com/ricardordzalt/tailwind-for-react-native/blob/main/tsconfig.json): typescript config · TypeScript configuration for source and build outputs. · `tsconfig.json`
- [jest config](https://github.com/ricardordzalt/tailwind-for-react-native/blob/main/jest.config.js): test config · Jest configuration used by the library test suite. · `jest.config.js`

## Connections

- index.ts → src/index.tsx: re-exports · Package entry forwards the library API from source.
- src/index.tsx → TWRNProvider: exports · Public API exposes the optional runtime provider.
- src/index.tsx → useTw: exports · Public API exposes the primary hook surface.
- src/index.tsx → styled(): exports · Public API exposes the styled-component wrapper.
- TWRNProvider → colors: default colors · Provider starts from built-in named color tokens.
- TWRNProvider → styles/index: theme input · Provider feeds theme state into style resolution.
- useTw → style string: resolves · Hook uses the style-string compiler for tw().
- useTw → TWRNProvider: reads context · Hook consumes provider-backed mode and theme state.
- useTw → mode filter: mode aware · Hook exposes utilities filtered by current mode.
- useTw → platform filter: platform aware · Hook exposes utilities filtered by platform.
- useTw → prefixes: interprets · Hook relies on utility prefixes such as dark/ios/android.
- styled() → style string: parses · Styled wrapper compiles template literals into styles.
- styled() → TWRNProvider: merges runtime · Styled wrapper respects provider context during resolution.
- styled() → properties index: maps to · Generated utility styles are backed by property modules.
- style string → nested lookup: resolves aliases · Parser expands nested class and style references.
- style string → prop lookup: reads values · Parser reads paths and values from style/theme objects.
- style string → mode filter: filters by mode · Parser selects mode-specific utilities.
- style string → platform filter: filters by platform · Parser selects platform-specific utilities.
- style string → separator: splits · Parser splits utility strings into tokens.
- styles/index → prefixes: uses prefixes · Style registry is organized by utility prefixes and variants.
- styles/index → properties index: composes · Registry composes the property catalog into the engine.
- properties index → colors: uses defaults · Property mappings reference built-in color tokens.
- __tests__ → TWRNProvider: covers · Tests exercise provider behavior and context injection.
- __tests__ → useTw: covers · Tests validate the hook surface and runtime helpers.
- __tests__ → styled(): covers · Tests validate styled component composition and precedence.
- __tests__ → style string: covers · Tests validate parsing and style resolution behavior.
- example app → TWRNProvider: demonstrates · Example app shows optional provider setup.
- example app → useTw: demonstrates · Example app consumes the hook-driven API.
- example app → styled(): demonstrates · Example app renders styled components for manual validation.
- babel config → src/index.tsx: builds · Babel supports the source entry and TypeScript transpilation.
- tsconfig → src/index.tsx: types source · TypeScript config governs the library source build.
- jest config → __tests__: runs · Jest configuration runs the repository test suite.
