React & Next.js

How Instagram, WhatsApp, Uber & Netflix Would Be Built Today Using Expo Router

How to structure a large React Native app with Expo Router: feature modules, route groups and shared layouts, using apps like Instagram and Uber as examples.

How Instagram, WhatsApp, Uber & Netflix Would Be Built Today Using Expo Router

TL;DR: Simple folder structures collapse under real-world scale. This post walks through how production-grade mobile apps — modeled after Instagram, WhatsApp, Uber, and Netflix — would be architected today using Expo Router, feature-based separation, layered state management, and realtime-first design.

This post assumes solid knowledge of React Native and basic familiarity with Expo. It targets engineers building or scaling production apps.


Problem: Why Simple Structures Fail at Scale

Most React Native projects start like this:

/app
  index.tsx
  profile.tsx
  feed.tsx
/components
  Button.tsx
  Avatar.tsx
/utils
  helpers.ts

This works for 5 screens. At 50 screens, 8 developers, and 3 feature teams, it becomes a liability. No clear ownership. Business logic leaks into components. Navigation becomes a tangled graph. Changes in one feature break another.

The engineers at Instagram, WhatsApp, Uber, and Netflix didn’t stumble into scalable architecture — they built explicit systems for:

  • Feature isolation and ownership
  • Predictable navigation hierarchies
  • Layered data flow (remote → cache → UI)
  • Realtime sync without UI freezes
  • Cold start performance under 2 seconds

Expo Router, built on React Navigation’s file-system conventions, gives you the primitives to replicate this thinking from day one.


Solution: Production Architecture with Expo Router

The Core Mental Model

Think of your app in four layers:

  1. Navigation Shell — Route hierarchy, shared layouts, guards
  2. Feature Modules — Isolated domains (feed, chat, rides, content)
  3. Data Layer — API clients, caches, realtime subscriptions
  4. Shared Kernel — Design system, hooks, utilities, types

Each layer has a strict dependency direction: Features depend on the Data Layer and Kernel. The Navigation Shell depends on Features. Nothing flows backward.


Step 1: Folder Architecture — Feature-Based, Not Type-Based

Stop organizing by file type. Organize by feature domain.

/app                          ← Expo Router file-based routes
  (auth)/
    login.tsx
    signup.tsx
    _layout.tsx               ← Auth guard layout
  (app)/
    _layout.tsx               ← Tab navigator root
    (feed)/
      index.tsx               ← Instagram-style feed
      [postId].tsx            ← Dynamic post detail
      _layout.tsx
    (chat)/
      index.tsx               ← WhatsApp-style conversation list
      [conversationId].tsx    ← Individual chat room
      _layout.tsx
    (rides)/
      index.tsx               ← Uber-style map home
      tracking.tsx            ← Live ride tracking
      _layout.tsx
    (browse)/
      index.tsx               ← Netflix-style content grid
      [contentId].tsx         ← Content detail + player
      _layout.tsx
  _layout.tsx                 ← Root layout (fonts, providers)

/features
  feed/
    components/               ← FeedCard, StoryRow, MediaViewer
    hooks/                    ← useFeed, useInfiniteScroll
    store/                    ← feedSlice or feedAtom
    api/                      ← feedApi.ts
    types/                    ← Post, Story, MediaItem
  chat/
    components/               ← MessageBubble, TypingIndicator
    hooks/                    ← useMessages, usePresence
    socket/                   ← chatSocket.ts
    store/
    api/
    types/
  rides/
    components/               ← MapView, DriverCard, ETABadge
    hooks/                    ← useRideTracking, useLocationStream
    store/
    api/
    types/
  browse/
    components/               ← ContentCard, VideoPlayer, HeroRail
    hooks/                    ← useContentFeed, usePlayback
    store/
    api/
    types/

/shared
  ui/                         ← Button, Avatar, Skeleton, Text
  hooks/                      ← useAuth, useNetwork, useAppState
  lib/
    apiClient.ts              ← Axios/fetch base client
    queryClient.ts            ← React Query config
    storage.ts                ← AsyncStorage / MMKV abstraction
    socket.ts                 ← Shared WebSocket manager
  types/
    api.ts                    ← Shared API response types
    user.ts

/constants
  routes.ts
  config.ts

Each feature is a self-contained vertical slice. A new engineer can own /features/chat entirely without understanding /features/rides.


Step 2: Navigation Architecture — Auth Guards + Nested Routing

Expo Router uses layouts (_layout.tsx) to wrap route groups. This is where you enforce authentication.

// app/_layout.tsx — Root layout
import { Slot } from 'expo-router';
import { AuthProvider } from '@/shared/hooks/useAuth';
import { QueryClientProvider } from '@tanstack/react-query';
import { queryClient } from '@/shared/lib/queryClient';
import { GestureHandlerRootView } from 'react-native-gesture-handler';

export default function RootLayout() {
  return (
    <GestureHandlerRootView style={{ flex: 1 }}>
      <QueryClientProvider client={queryClient}>
        <AuthProvider>
          <Slot />
        </AuthProvider>
      </QueryClientProvider>
    </GestureHandlerRootView>
  );
}
// app/(app)/_layout.tsx — Protected route guard
import { Redirect, Tabs } from 'expo-router';
import { useAuth } from '@/shared/hooks/useAuth';
import { Ionicons } from '@expo/vector-icons';

export default function AppLayout() {
  const { session, isLoading } = useAuth();

  if (isLoading) return null; // Splash or skeleton
  if (!session) return <Redirect href="/(auth)/login" />;

  return (
    <Tabs screenOptions={{ headerShown: false }}>
      <Tabs.Screen name="(feed)" options={{ title: 'Feed', tabBarIcon: ({ color }) => <Ionicons name="home" color={color} size={24} /> }} />
      <Tabs.Screen name="(chat)" options={{ title: 'Chat', tabBarIcon: ({ color }) => <Ionicons name="chatbubbles" color={color} size={24} /> }} />
      <Tabs.Screen name="(rides)" options={{ title: 'Rides', tabBarIcon: ({ color }) => <Ionicons name="car" color={color} size={24} /> }} />
      <Tabs.Screen name="(browse)" options={{ title: 'Browse', tabBarIcon: ({ color }) => <Ionicons name="play-circle" color={color} size={24} /> }} />
    </Tabs>
  );
}

Auth state determines routing declaratively. No imperative navigation.navigate('Login') scattered across the app.


Step 3: API Layer — Typed, Centralized, Interceptable

// shared/lib/apiClient.ts
import axios from 'axios';
import { getAuthToken, refreshToken } from './auth';

export const apiClient = axios.create({
  baseURL: process.env.EXPO_PUBLIC_API_URL,
  timeout: 10000,
});

apiClient.interceptors.request.use(async (config) => {
  const token = await getAuthToken();
  if (token) config.headers.Authorization = `Bearer ${token}`;
  return config;
});

apiClient.interceptors.response.use(
  (response) => response,
  async (error) => {
    if (error.response?.status === 401) {
      await refreshToken();
      return apiClient.request(error.config);
    }
    return Promise.reject(error);
  }
);
// features/feed/api/feedApi.ts
import { apiClient } from '@/shared/lib/apiClient';
import type { Post, FeedPage } from '../types';

export const feedApi = {
  getFeed: async (cursor?: string): Promise<FeedPage> => {
    const { data } = await apiClient.get('/feed', { params: { cursor, limit: 20 } });
    return data;
  },
  likePost: async (postId: string): Promise<void> => {
    await apiClient.post(`/posts/${postId}/like`);
  },
};

Every feature gets its own API module. React Query sits above this, handling caching, background refetch, and pagination.


Step 4: Realtime Architecture — WhatsApp Chat + Uber Tracking

Realtime features share a single WebSocket manager. Feature-specific hooks subscribe to relevant channels.

// shared/lib/socket.ts
import { io, Socket } from 'socket.io-client';

let socket: Socket | null = null;

export const getSocket = (): Socket => {
  if (!socket) {
    socket = io(process.env.EXPO_PUBLIC_WS_URL!, {
      transports: ['websocket'],
      autoConnect: false,
    });
  }
  return socket;
};

export const connectSocket = (token: string) => {
  const s = getSocket();
  s.auth = { token };
  s.connect();
};

export const disconnectSocket = () => {
  getSocket().disconnect();
};
// features/chat/hooks/useMessages.ts
import { useEffect, useState } from 'react';
import { getSocket } from '@/shared/lib/socket';
import type { Message } from '../types';

export function useMessages(conversationId: string) {
  const [messages, setMessages] = useState<Message[]>([]);

  useEffect(() => {
    const socket = getSocket();
    socket.emit('join:conversation', { conversationId });

    socket.on('message:new', (message: Message) => {
      setMessages((prev) => [message, ...prev]);
    });

    return () => {
      socket.emit('leave:conversation', { conversationId });
      socket.off('message:new');
    };
  }, [conversationId]);

  return { messages };
}
// features/rides/hooks/useRideTracking.ts
import { useEffect, useState } from 'react';
import { getSocket } from '@/shared/lib/socket';

interface DriverLocation { lat: number; lng: number; heading: number; }

export function useRideTracking(rideId: string) {
  const [driverLocation, setDriverLocation] = useState<DriverLocation | null>(null);
  const [eta, setEta] = useState<number | null>(null);

  useEffect(() => {
    const socket = getSocket();
    socket.emit('rides:subscribe', { rideId });

    socket.on('driver:location', (payload: DriverLocation) => {
      setDriverLocation(payload);
    });

    socket.on('ride:eta', ({ seconds }: { seconds: number }) => {
      setEta(seconds);
    });

    return () => {
      socket.emit('rides:unsubscribe', { rideId });
      socket.off('driver:location');
      socket.off('ride:eta');
    };
  }, [rideId]);

  return { driverLocation, eta };
}

Step 5: Offline-First Caching — Instagram & Netflix

For media-heavy apps, MMKV + React Query’s persistQueryClient gives you fast synchronous reads with background hydration.

// shared/lib/queryClient.ts
import { QueryClient } from '@tanstack/react-query';
import { createSyncStoragePersister } from '@tanstack/query-sync-storage-persister';
import { persistQueryClient } from '@tanstack/react-query-persist-client';
import { MMKV } from 'react-native-mmkv';

const storage = new MMKV();

const mmkvStorage = {
  getItem: (key: string) => storage.getString(key) ?? null,
  setItem: (key: string, value: string) => storage.set(key, value),
  removeItem: (key: string) => storage.delete(key),
};

export const queryClient = new QueryClient({
  defaultOptions: {
    queries: {
      staleTime: 1000 * 60 * 5,      // 5 minutes
      gcTime: 1000 * 60 * 60 * 24,   // 24 hours on disk
      retry: 2,
    },
  },
});

const persister = createSyncStoragePersister({ storage: mmkvStorage });

persistQueryClient({ queryClient, persister, maxAge: 1000 * 60 * 60 * 24 });

With this setup, a content grid can render straight from the on-disk cache and a feed stays available offline. Stale data is shown immediately, then replaced in the background, so cached screens appear without waiting for the network.


Step 6: App Startup Optimization

App startup is a product metric. Every millisecond of cold start has measurable impact on retention.

// app/_layout.tsx — Optimized startup sequence
import { useEffect, useState } from 'react';
import * as SplashScreen from 'expo-splash-screen';
import * as Font from 'expo-font';
import { preloadCriticalData } from '@/shared/lib/startup';

SplashScreen.preventAutoHideAsync();

export default function RootLayout() {
  const [appReady, setAppReady] = useState(false);

  useEffect(() => {
    async function prepare() {
      try {
        // Parallel: fonts + critical cached data
        await Promise.all([
          Font.loadAsync({ 'Inter-Bold': require('../assets/fonts/Inter-Bold.ttf') }),
          preloadCriticalData(), // Hydrate MMKV → queryClient
        ]);
      } catch (e) {
        console.error('Startup failed:', e);
      } finally {
        setAppReady(true);
        await SplashScreen.hideAsync();
      }
    }
    prepare();
  }, []);

  if (!appReady) return null;
  return <Slot />;
}

Loading fonts and hydrating the cache in parallel, instead of one after the other, shortens startup. Measure the gain on a mid-range Android device, where startup is slowest.


Results

What this architecture is designed to give you:

  • Faster cold starts, because startup work runs in parallel and the first screen reads from the MMKV cache
  • Cached screens that render before the network responds (offline-first)
  • Feature code isolated per folder, so shipping a chat change doesn’t touch the rides feature
  • Faster onboarding, because a new engineer can learn one feature folder instead of the whole app
  • A smaller blast radius: a bug in /features/rides stays out of /features/chat

Trade-offs

Decision Benefit Cost
Feature-based folders Clear ownership, isolated changes More boilerplate per feature
Single WebSocket manager Efficient connections, shared auth More complex event routing
MMKV + persistQueryClient Fast synchronous cache reads Stale data risk; needs careful invalidation
Expo Router file-based routing Predictable, zero-config navigation Less flexibility than manual React Navigation setup
Axios interceptors for token refresh Transparent auth handling Retry loops possible if refresh logic fails

Persisted query cache requires disciplined cache key design. If your keys aren’t deterministic, you’ll serve stale data silently. Build explicit invalidation strategies per feature.


Conclusion

The difference between an app that falls apart at scale and one that doesn’t isn’t the framework — it’s the decisions made before writing the first screen. Feature-based architecture, explicit navigation guards, a layered data flow, and a shared realtime kernel give your team the structure to move fast without breaking each other’s work.

Expo Router’s file-system conventions align perfectly with this model. Routes map to features. Layouts enforce guards. Groups isolate concerns.

Next step: Take one existing feature in your app and migrate it to the structure above. Measure cold start before and after adding MMKV persistence. The numbers will tell you whether to continue.


Further Reading

This blog is part of ThitaInfo, a software development company. See what we build at thitainfo.com.