Customer application with Expo

8 modules · 11 lessons · 11 exercises · 22 available now

Week 4 overview

  1. Module 1 Expo app foundations
    • 4.1 React Native screen layoutCore components, Flexbox in React Native, StyleSheet, Safe area, KeyboardAvoidingView
    • 4.2 Expo Router navigationExpo Router, Layout route, Route group, Dynamic route, Protected route
    • 4.3 Expo device networkingExpo Go, Metro, LAN IP, EXPO_PUBLIC_ variables
    • 4.4 Expo app shell
  2. Module 2 API client and authentication
    • 4.5 Secure token storageexpo-secure-store, TokenStore
    • 4.6 Single-flight API refreshAPI client, Silent refresh, Single-flight refresh
    • 4.7 API client and auth screens
  3. Module 3 Paged data lists
    • 4.8 TanStack Query cachingTanStack Query, Query key, Infinite query, Focus and online managers, Polling, Query invalidation
    • 4.9 Virtualized list renderingFlatList, Virtualization, SectionList
    • 4.10 Restaurant list screen
    • 4.11 Restaurant menu screen
  4. Module 4 Shopping cart
    • 4.12 Persisting Zustand stateZustand, persist middleware, Hydration
    • 4.13 Persisted cart store
  5. Module 5 Menu configuration and checkout
    • 4.14 Live server validationDebounce, Server-side validation
    • 4.15 Item configurator screen
    • 4.16 Cart screen
  6. Module 6 Order history
    • 4.17 Orders tab and order detail screens
  7. Module 7 Mobile API capacity
    • 4.18 Estimating mobile API capacityCache hit rate, Payload budget
  8. Module 8 Client resilience extensions
    • 4.19 Resilient client patterns (optional)Idempotent method, Exponential backoff, Jitter, Injected timers, Query key factory, Optimistic update, Optimistic rollback
    • 4.20 API request retry utility (optional)
    • 4.21 Cart synchronization helper (optional)
    • 4.22 Restaurant search utilities (optional)

Weekly learning objectives

Weeks 1 to 3 built a backend that nobody can tap on. This week it gets its first customer client: an Expo app in app/ that runs on an Android emulator or phone. The backend does not change. You build the client through Expo app foundations, API client and authentication, Paged data lists, Shopping cart, Menu configuration and checkout, Order history, and Mobile API capacity. Client resilience extensions are optional.

By the end you will have:

  • An Expo app with customer screens running through Expo Router.
  • Authentication with secure token storage and silent refresh when the access token expires.
  • Restaurant and menu screens that load paged data and display menu items grouped into sections.
  • An item configurator that requests live prices through POST /v1/menu/price and displays selection errors.
  • A persisted cart and checkout flow that keeps an idempotency key until an order succeeds.
  • Order history with paged results and an event timeline, polled until WebSockets arrive in Week 5.
  • A mobile API capacity model that estimates demand from browsing, checkout, order polling and authentication.

System architecture and changes

A new Expo app on the phone, with Expo Router, TanStack Query, Zustand and secure storage, talks to the existing Go API over HTTP with JSON, a bearer token and an Idempotency-Key header. MySQL, Redis and Redpanda behind the API are unchanged from week 3. Order history polls for now; WebSockets come in week 5.A new Expo app on the phone, with Expo Router, TanStack Query, Zustand and secure storage, talks to the existing Go API over HTTP with JSON, a bearer token and an Idempotency-Key header. MySQL, Redis and Redpanda behind the API are unchanged from week 3. Order history polls for now; WebSockets come in week 5.

Three boundaries matter this week, and the diagram marks them:

  • Every request goes through one client. lib/api.ts adds the bearer token, refreshes it once when it expires, and turns HTTP failures into typed errors the screens can handle.
  • Idempotency starts on the phone. The cart creates the Idempotency-Key that the existing POST /v1/orders uses to recognize duplicate submissions. The key stays until an order succeeds.
  • The backend is a black box. The app never knows that MySQL, Redis or Redpanda exist. It only sees the HTTP API.

How to complete the coursework

Each module contains lessons followed by exercises. Lessons assume you know React on the web and explain the parts that differ on a phone.

Work in your editor inside the zomato-prep repository. Run make test W=W4 to execute every graded Week 4 test. Then run cd app && npx tsc --noEmit to check the app's TypeScript. The tests cover library code. Check the screens manually on the Android emulator and a phone.

Modules

  1. Module 1: Expo app foundations

    4 items

    You build an Expo app shell that keeps customer screens behind persisted authentication and runs on an emulator or phone.

    • 4.1React Native screen layoutLesson · 30 min

      You can build phone screens with native components and layout rules, giving the Expo app a usable starting point instead of a web page.

      Open lesson →
    • 4.2Expo Router navigationLesson · 30 min

      You can map route files and layouts to guarded screens, giving the app separate signed-out and signed-in navigation trees.

      Open lesson →
    • 4.3Expo device networkingLesson · 15 min

      You can open the Metro-served app on an emulator and phone and point it at your laptop's API over the LAN.

      Open lesson →
    • 4.4Expo app shellExercise · 70 min

      You build the Expo app shell with persisted auth state, guarded routes, and provider setup so later screens share a working foundation.

      Open exercise →
  2. Module 2: API client and authentication

    3 items

    You build the app's authenticated API layer so every screen shares token handling, typed errors, and silent refresh.

    • 4.5Secure token storageLesson · 20 min

      You can persist an access and refresh token pair in SecureStore while publishing session changes to the protected route.

      Open lesson →
    • 4.6Single-flight API refreshLesson · 30 min

      You can make authenticated requests through one API client and share a refresh across concurrent 401 responses.

      Open lesson →
    • 4.7API client and auth screensExercise · 110 min

      You build the API client and login and signup screens, sending authenticated requests and storing the returned token pair. Concurrent 401 responses must share one refresh.

      Open exercise →
  3. Module 3: Paged data lists

    4 items

    You build the app's paged restaurant list and render cached results smoothly as customers scroll.

    • 4.8TanStack Query cachingLesson · 35 min

      You configure cached queries and page fetching around the API client so the restaurant screen can load more data and refresh when the app reconnects.

      Open lesson →
    • 4.9Virtualized list renderingLesson · 20 min

      You render fixed-height rows efficiently with FlatList so the paged restaurant screen stays responsive as customers scroll.

      Open lesson →
    • 4.10Restaurant list screenExercise · 90 min

      You build the restaurant list screen with cached, paged restaurant data, pull-to-refresh and automatic refetch when the app returns online or to the foreground.

      Open exercise →
    • 4.11Restaurant menu screenExercise · 60 min

      You build the restaurant menu screen that fetches a restaurant's menu and displays orderable items in sections with their cheapest size prices. The configurator reuses the same cached menu query.

      Open exercise →
  4. Module 4: Shopping cart

    2 items

    You build a persisted cart that holds items from one restaurant, totals them in paise, and keeps the idempotency key for one checkout.

    • 4.12Persisting Zustand stateLesson · 25 min

      You can persist the cart across app restarts while keeping authentication tokens out of AsyncStorage, so checkout can reuse its idempotency key.

      Open lesson →
    • 4.13Persisted cart storeExercise · 60 min

      You build the persisted cart store that accepts cart lines for one restaurant and exposes their total in paise. It keeps an idempotency key until the cart is cleared or emptied.

      Open exercise →
  5. Module 5: Menu configuration and checkout

    3 items

    You build an item configurator and checkout flow that validates menu selections on the server before placing retry-safe orders.

    • 4.14Live server validationLesson · 25 min

      You can debounce form changes and display the server's current validation response, keeping the item configurator's price tied to its selections.

      Open lesson →
    • 4.15Item configurator screenExercise · 120 min

      You build an item configurator screen that takes a menu item and its selections, then displays the server's quote. Add to cart stays disabled until that quote matches the current selection and has no errors.

      Open exercise →
    • 4.16Cart screenExercise · 70 min

      You build the cart screen that submits the customer's cart as an order and opens the returned order. The cart and its idempotency key remain unchanged until the server confirms success.

      Open exercise →
  6. Module 6: Order history

    1 items

    You build order history screens that page through past orders and show a selected order's event timeline while its status can still change.

    • 4.17Orders tab and order detail screensExercise · 70 min

      You build the Orders tab and order detail screen, with paginated history and a timeline that polls while the order is visible and unfinished.

      Open exercise →
  7. Module 7: Mobile API capacity

    1 items

    You build a traffic model for the mobile app to estimate API demand from browsing, checkout, order polling and authentication.

    • 4.18Estimating mobile API capacityLesson · 50 min

      Estimate how Week 4 app behaviour translates into Go API request rates so you can set realistic load-test targets before measuring the backend.

      Open lesson →
  8. Module 8: Client resilience extensions

    4 items

    You add three optional app utilities that retry failed reads, update the cart optimistically, and debounce restaurant search.

    • 4.19Resilient client patternsLesson · 30 min · Optional

      You can decide when an API request is safe to retry and choose a bounded delay policy before implementing the retry utility.

      Open lesson →
    • 4.20API request retry utilityExercise · 45 min · Optional

      You build requestWithRetry, an API client wrapper that takes a path and request options and returns the response body. It retries eligible GET failures for up to three attempts by default, using jitter or retryAfterSec.

      Open exercise →
    • 4.21Cart synchronization helperExercise · 45 min · Optional

      You build cart synchronization helpers that update the Zustand cart immediately and save its restaurant ID and lines through CartApi. Failed saves restore the previous state without overwriting newer cart changes.

      Open exercise →
    • 4.22Restaurant search utilitiesExercise · 45 min · Optional

      You build app/lib/search.ts utilities that debounce input values, normalize search terms, create restaurant query keys, and determine when a term is long enough to search.

      Open exercise →

Completion checklist

What should be true at the end of the week.

  • Run make test W=W4 and verify that every graded Week 4 test passes.
  • Run cd app && npx tsc --noEmit without TypeScript errors.
  • Sign up and log in, verify that tokens survive an app restart, silent refresh recovers an expired access token, and logout clears the stored pair.
  • Load restaurant pages in order, open a menu, verify its sections and prices, and check that the configurator sends the expected quote request.
  • Restore a cart with its restaurant and idempotency key, then verify that checkout reuses the same key after a network failure and clears the cart only after success.
  • Verify that order history shows paged results and ordered events, polls non-final orders every 10 seconds, and stops polling final orders.

Week requirements

Rules every piece of code this week must follow.

  • Route app API requests through lib/api.ts. Send the bearer token only when a token pair exists. Refresh once after a 401, share concurrent refreshes, and do not retry indefinitely after a second 401.
  • Preserve API response and error behaviour: a 204 resolves to undefined, HTTP 429 exposes Retry-After, other HTTP errors expose their status and body, and network failures remain distinguishable from ApiError responses.
  • Persist complete access token and refresh token pairs through secure storage. Missing, corrupt or incomplete pairs read as signed out. Clearing tokens deletes the stored pair, and unsubscribed listeners receive no further notifications.
  • Fetch restaurant pages through the API client, use a limit of 20 for the first page, URL-encode later cursors, and stop when next_cursor is empty. Group menu items in menu order, use the lowest size price as the from price, and exclude items without sizes.
  • Match configurator controls to their selection groups: max 1 uses a radio group and other groups use checkboxes. Only offer stocked and correctly priced options, prefer size-specific prices, send the expected quote body, and associate selection errors with their groups.
  • Persist the cart's restaurant, lines and idempotency key. Refuse lines from another restaurant, preserve the key when changing quantities, and forget it when the last line is removed or the cart is cleared. Checkout sends the key without client prices, retains the cart after failures, reuses the key on retry, and clears the cart after success.
  • Keep order history pagination and event ordering intact. Map statuses to human labels, poll orders every 10 seconds while they are non-final, and stop polling delivered, cancelled or rejected orders. Optional utilities must use bounded GET retries, guarded optimistic rollback and trailing-edge debounced search with normalized query keys.
Customer application with ExpoWeek 4 · 22 items available
Start Module 1: Expo app foundations
Week 4: Customer application with Expo · Learn the Zomato tech stack from scratch