Why Mobile Developers Need AI Coding Rules
You are a mobile developer. You build iOS apps with Swift, Android apps with Kotlin, or cross-platform apps with React Native or Flutter. Your constraints: different from web developers. Memory is limited (you cannot leak it). Network is unreliable (you must handle offline). Battery is finite (you cannot waste CPU cycles). App store reviewers reject apps that violate platform guidelines. Without AI rules: the AI generates code that works on your laptop simulator but fails on a real device with 2GB RAM, spotty cellular, and 15% battery.
With AI rules: the AI generates mobile-optimized code by default. AI rule: 'All images use lazy loading. All network requests include timeout and retry with exponential backoff. All lists use virtualized rendering (FlatList, not ScrollView with map). Cache first, network second — always show cached data while fetching fresh data.' Every AI-generated screen: performs well on real devices. Every network interaction: handles failure gracefully. The code: production-ready for the constraints of mobile, not just the comfort of a simulator.
The mobile-specific benefit: platform guidelines are complex and change with each OS release. AI rules encode the current platform requirements. When iOS 19 introduces a new required privacy API: update one rule. Every AI-generated feature: uses the new API automatically. The team: adapts to platform changes by updating rules, not by auditing every screen in the app.
How AI Rules Enforce Platform-Specific Patterns
Navigation patterns: each platform has conventions. AI rule (React Native): 'Use React Navigation with typed routes. Stack navigator for hierarchical flows. Tab navigator for top-level sections. Never nest more than 3 navigation levels. Back button behavior: Android hardware back navigates up, iOS swipe-from-edge navigates back.' The AI: generates platform-appropriate navigation. The developer: describes the flow. The AI: implements it with the correct navigation pattern for each platform.
State management for mobile: AI rule: 'Use Zustand for client state with persist middleware for offline support. Server state uses TanStack Query with staleTime: 5 minutes and cacheTime: 30 minutes. Optimistic updates for all write operations — show the result immediately, sync in the background.' The AI: generates state management that works offline and responds instantly. The user: never sees a loading spinner for data that was previously fetched. The app: feels fast because cached data renders immediately while fresh data loads in the background.
Platform permissions: mobile apps request permissions (camera, location, notifications). AI rule: 'Request permissions lazily — at the moment of use, not at app launch. Always provide a rationale screen before the system dialog. Handle denial gracefully — degrade the feature, never crash. Store permission state to avoid re-requesting denied permissions.' The AI: generates permission flows that follow platform best practices. The app: never requests all permissions at launch (the #1 reason users uninstall new apps). AI rule: 'Mobile platform patterns change with every OS release. Rules encoded in CLAUDE.md: updated once when the platform changes. Every AI-generated feature: automatically uses the updated patterns. The team: adapts to platform evolution through rule updates, not code audits.'
App launches. Immediately asks for camera, location, notifications, and contacts. User reaction: uninstall (they have not even seen what the app does yet). AI rule: 'Request permissions at point of use with a rationale screen first.' User opens the camera feature: 'We need camera access to scan QR codes' → system dialog. User grants permission because the context makes sense. Studies show: contextual permission requests have 2-3x higher grant rates than launch-time requests. One rule: 30% fewer uninstalls, 2x permission grants.
AI Rules for Mobile Performance Enforcement
Render performance: mobile screens must render at 60fps (16ms per frame). AI rule: 'No inline anonymous functions in render (create named callbacks). No object/array literals in JSX props (extract to useMemo). FlatList: always provide keyExtractor, getItemLayout, and maxToRenderPerBatch. Image components: specify width and height to prevent layout shifts.' The AI: generates performant render code by default. The developer: does not need to profile and optimize — the AI avoids the common performance pitfalls from the start.
Bundle size: mobile apps are downloaded over cellular connections. AI rule: 'Maximum bundle size: 5MB for initial download. Use dynamic imports for features not needed on first launch. Tree-shake all imports — import specific functions, not entire libraries (import { format } from "date-fns", not import * as dateFns). No dev dependencies in production bundle.' The AI: generates size-efficient code. The app: downloads quickly on cellular. The app store: does not warn users about large download size.
Memory management: mobile devices have limited RAM. AI rule: 'All event listeners and subscriptions must be cleaned up in useEffect return or componentWillUnmount. Large data sets: paginate (fetch 20 items, load more on scroll). Image caching: use FastImage with memory and disk cache limits. Never hold references to large objects (bitmaps, response bodies) beyond the current screen.' The AI: generates memory-safe code that prevents leaks. The app: does not crash after 30 minutes of use due to accumulated memory pressure. AI rule: 'Performance rules are not optimizations — they are requirements. A web app that loads in 3 seconds: acceptable. A mobile app that loads in 3 seconds: uninstalled. AI rules: encode mobile performance requirements so the AI generates fast code by default, not as an afterthought.'
onPress={() => handlePress(item.id)} — looks harmless. Reality: creates a new function object on every render. React: sees a new prop, re-renders the child component. FlatList with 100 items: 100 unnecessary re-renders per frame. The 60fps target: missed. The scroll: janky. AI rule: 'No inline anonymous functions in render. Extract to named callbacks with useCallback.' The same list: renders once per data change, scrolls at 60fps. The developer: never notices the problem because the AI prevents it. Users: never experience the jank.
AI Rules for Offline-First Mobile Development
Offline data strategy: AI rule: 'All read operations: cache-first (show cached data immediately, update from network in background). All write operations: queue locally, sync when online. Conflict resolution: last-write-wins with server timestamp. Show sync status indicator when operations are pending.' The AI: generates offline-capable features by default. The user: interacts with the app seamlessly regardless of connectivity. The data: eventually consistent with the server.
Local storage patterns: AI rule: 'Use MMKV for key-value storage (faster than AsyncStorage). Use WatermelonDB for relational data with sync support. Schema migrations: required for every storage schema change (never delete and recreate). All stored data: encrypted at rest using the device keychain.' The AI: generates efficient and secure local storage. The developer: does not need to choose between storage libraries — the rules encode the team's decisions.
Network state handling: AI rule: 'Use NetInfo to detect connectivity changes. Queue all API requests when offline. Retry queued requests with exponential backoff when connectivity returns. Show user-visible indicator for offline mode (banner, icon, or status text). Never show error messages for expected offline scenarios — degrade gracefully.' The AI: generates robust network handling. The app: works reliably in elevators, subways, and rural areas. AI rule: 'Offline-first is not a feature — it is a quality attribute. Mobile users lose connectivity constantly: elevators, tunnels, poor cell towers, airplane mode. AI rules that enforce offline-first patterns: ensure the app works everywhere the user goes, not just where WiFi is strong.'
Web developers treat offline as an error. Mobile developers must treat offline as normal. Users open your app: in elevators (no signal), on subways (intermittent signal), in rural areas (weak signal), on airplanes (no signal). If the app shows an error when offline: it is broken for these real-world scenarios. AI rule: 'Cache-first reads, queued writes, sync on reconnect.' The app: always shows data (cached). Always accepts input (queued). Always syncs (when possible). Offline-first is not a feature — it is the minimum viable mobile experience.
Mobile Developer Quick Reference for AI Coding
Quick reference for mobile developers using AI coding tools.
- Core benefit: AI rules enforce mobile-specific constraints (memory, battery, network) that simulator testing misses
- Navigation: typed routes, platform-appropriate patterns, maximum 3 navigation levels deep
- State: Zustand with persist for client state, TanStack Query for server state, optimistic updates everywhere
- Permissions: lazy requests at point of use, rationale screens, graceful denial handling, never at launch
- Render performance: no inline functions in render, virtualized lists, specified image dimensions — 60fps by default
- Bundle size: 5MB maximum initial download, dynamic imports, tree-shaken imports, no dev deps in production
- Memory: cleanup all subscriptions, paginate large datasets, limit image cache — no leaks after 30 minutes
- Offline-first: cache-first reads, queued writes, sync on reconnect, graceful degradation — works everywhere