Architecture Overview
Rainbow is built with a modern, scalable architecture that prioritizes type safety, performance, and developer experience.State Management
Rainbow uses custom store creators built on top of Zustand, providing a unified approach to state management across the application.Store Types
Rainbow Store
General-purpose store with optional MMKV persistence for client state
Query Store
Combines data fetching + state in one store with reactive parameters
Derived Store
Read-only store that composes other stores for computed state
Rainbow Store (Client State)
General-purpose store with optional MMKV persistence. Use for client-side state that needs to persist across app restarts.Query Store (Server State)
Combines data fetching and state management. Reactive$ parameters automatically refetch when dependencies change.
These in-repo creators are being replaced by the external
stores package with the same APIs (createBaseStore, createQueryStore, createDerivedStore).Derived Store (Computed State)
Read-only store that composes other stores for aggregated or computed state.Legacy State Systems
Some legacy systems are still in use during the migration:- React Query (
src/react-query/) - Server state caching, being replaced bycreateQueryStore - Redux (
src/redux/) - Only used for: charts, contacts, ENS registration, gas, and settings
Source Code Organization
The codebase is mid-migration toward domain-organized architecture.New Structure (Feature-Based)
New code goes insrc/features/ with clear layer separation:
Legacy Structure (Flat)
Legacy code lives in flat top-level directories:components/- Shared React componentsscreens/- Screen-level componentshooks/- Custom React hookshelpers/- Helper functionsutils/- Utility functions
Key Directories
src/framework/
src/framework/
App-agnostic infrastructure including:
- HTTP client
- Safe math utilities
- UI primitives
- Core utilities
src/__swaps__/
src/__swaps__/
Swap feature implementation
- Aliased as
@/swapsin tsconfig - Self-contained feature module
src/graphql/
src/graphql/
GraphQL codegen workspace
- Separate yarn workspace
- Generated types and queries
src/state/
src/state/
Domain-specific stores
- One store per domain
- Custom store creators
Code Conventions
Rainbow enforces strict code conventions for maintainability and performance.No Barrel Exports
Type-Only Imports
Use thetype annotation for type-only imports (ESLint-enforced):
TypeScript Over JavaScript
Write all new files in.ts/.tsx.
- Remaining JS files are checked against an error baseline
- Run
yarn lint:js-typesto check JavaScript type errors - Don’t regress the error baseline
Tech Stack
Core Technologies
| Technology | Version | Purpose |
|---|---|---|
| React Native | 0.79.5 | Mobile app framework |
| React | 19.0.0 | UI library |
| TypeScript | 5.9.3 | Type safety |
| Node.js | 22+ | JavaScript runtime |
State & Data
- Zustand (4.5.5) - State management foundation
- @storesjs/stores (0.8.7) - Custom store creators
- @tanstack/react-query (4.2.1) - Server state (legacy)
- React Redux (7.2.1) - Redux integration (legacy)
Blockchain
- viem (2.38.0) - Ethereum interactions
- ethers.js (5.8.0) - Ethereum library
- @rainbow-me/swaps - Swap functionality
- @walletconnect - WalletConnect integration
UI & Animation
- @shopify/react-native-skia - Canvas rendering
- react-native-reanimated (3.19.4) - Animations
- @shopify/flash-list (1.8.2) - Performant lists
- expo (53.0.20) - Expo modules
Navigation
- @react-navigation/stack - Stack navigation
- @react-navigation/material-top-tabs - Tab navigation
Verification Commands
Rainbow provides comprehensive verification tools:Performance Features
Flash List
High-performance lists with @shopify/flash-list
Skia Rendering
Native rendering with React Native Skia
Reanimated
60fps animations on the native thread
MMKV Storage
Fast, synchronous storage with react-native-mmkv
Testing
Rainbow uses multiple testing strategies:Unit Testing
- Jest for unit tests
- Run with
yarn test - Located throughout the codebase
E2E Testing
- Maestro for end-to-end tests
- iOS and Android support
- Located in
e2e/directory - See the Debugging Guide for E2E testing details
Type Coverage
Rainbow maintains 99%+ TypeScript coverage:Next Steps
Setup Guide
Get your development environment ready
Running the App
Learn how to run Rainbow locally
Building
Build for production
Debugging
Debug and troubleshoot issues