Mobile App Architecture (React Native)
Relevant source files
The following files were used as context for generating this wiki page: - [apps/mobile/app/app.tsx](https://github.com/ever-co/ever-teams/blob/HEAD/apps/mobile/app/app.tsx) - [apps/mobile/app/navigators/app-navigator.tsx](https://github.com/ever-co/ever-teams/blob/HEAD/apps/mobile/app/navigators/app-navigator.tsx) - [apps/mobile/app/models/root-store.ts](https://github.com/ever-co/ever-teams/blob/HEAD/apps/mobile/app/models/root-store.ts) - [apps/mobile/app/services/api/api.ts](https://github.com/ever-co/ever-teams/blob/HEAD/apps/mobile/app/services/api/api.ts) - [apps/mobile/README.md](https://github.com/ever-co/ever-teams/blob/HEAD/apps/mobile/README.md) - [apps/mobile/BRANDING.md](https://github.com/ever-co/ever-teams/blob/HEAD/apps/mobile/BRANDING.md) - [apps/mobile/app/i18n/en.ts](https://github.com/ever-co/ever-teams/blob/HEAD/apps/mobile/app/i18n/en.ts)The Ever Teams mobile application for iOS and Android is a cross-platform solution built with React Native and Expo, based on the Ignite boilerplate. It provides users with core work and project management functionalities on the go, integrating with the main Ever Teams platform. The architecture is designed to be scalable and maintainable, featuring a clear separation of concerns between UI, state management, navigation, and services.
Key architectural pillars include MobX-State-Tree for robust and type-safe state management, React Navigation for handling complex screen flows, and a dedicated API service layer for communicating with the backend. The application also incorporates features like theming, internationalization, debugging tools, and crash reporting.
Core Technologies
The mobile application is built upon a modern stack for React Native development.
| Technology | Purpose | Source |
|---|---|---|
| React Native | Core framework for building native apps with JavaScript and React. | README.md |
| Expo | A framework and platform for universal React applications, simplifying development and deployment. | README.md |
| Ignite Boilerplate | Provides a pre-configured project structure, including navigation, state management, and utility helpers. | apps/mobile/README.md |
| MobX-State-Tree | For managing application state in a structured, observable, and type-safe manner. | apps/mobile/app/models/root-store.ts |
| React Navigation | Handles routing and navigation between different screens. | apps/mobile/app/navigators/app-navigator.tsx |
| Apisauce | A wrapper around Axios for simplified API communication. | apps/mobile/app/services/api/api.ts |
| React Native Paper | A library of UI components following Material Design guidelines. | apps/mobile/app/app.tsx:12 |
| i18n-js | Manages internationalization and translations. | apps/mobile/app/app.tsx:9 |
Application Initialization
The main entry point of the application is app.tsx. It orchestrates the initialization of various services, providers, and the root component before rendering the UI.
The diagram below illustrates the startup sequence of the mobile application.
Sources: apps/mobile/app/app.tsx:23-119
Initialization Steps
- Crash Reporting:
initCrashReporting()is called to initialize Sentry for error monitoring. - Debugging:
setupReactotron()configures Reactotron for inspecting and debugging the app state, API calls, and performance. - Resource Loading: The app concurrently loads essential assets and restores state:
- Fonts:
useFonts(customFontsToLoad)loads custom application fonts. - State Rehydration:
useInitialRootStoreinitializes the MobX-State-Tree root store and rehydrates its state fromAsyncStorage. - Navigation State:
useNavigationPersistencerestores the last navigation state, allowing users to return to the screen they were on when they last closed the app.
- Fonts:
- Rendering: The app renders
nulluntil all resources are loaded and the state is ready (rehydrated,isNavigationStateRestored,areFontsLoadedare all true). Once ready, it renders theAppNavigatorwrapped in several essential providers.
Sources: apps/mobile/app/app.tsx:23-94
State Management
State management is handled by MobX-State-Tree (MST). A central RootStore aggregates different domain-specific stores.
Root Store
The RootStore is the single source of truth for the application's state. It is defined in apps/mobile/app/models/root-store.ts and is composed of smaller, feature-specific stores.
This class diagram shows the composition of the RootStore.
The useStores hook provides components with access to the RootStore instance, while useInitialRootStore handles its setup and rehydration from persistent storage.
Sources: apps/mobile/app/models/root-store.ts:40, apps/mobile/app/app.tsx:81-88
Navigation
Navigation is managed by React Navigation. The primary navigator, AppNavigator, determines which set of screens to display based on the user's authentication status.
Navigation Flow
The AppNavigator conditionally renders one of two main navigation stacks:
- LoginNavigator: Shown when the user is not authenticated (
isLoggedInis false). It contains screens for login and team creation. - AuthenticatedNavigator: Shown when the user is authenticated. It contains the main application screens like "Work", "Tasks", and "Settings".
The diagram below shows the high-level navigation flow.
Navigation Persistence
The app persists the navigation state to AsyncStorage. The useNavigationPersistence hook is responsible for saving the state on change and restoring it on app launch. The persistence key is defined as NAVIGATION_PERSISTENCE_KEY.
Sources: apps/mobile/app/app.tsx:50, 71-74
API Service Layer
All communication with the backend API is centralized in the Api class, located at apps/mobile/app/services/api/api.ts. This class uses apisauce to perform HTTP requests.
API Client Setup
The Api class has a setup method that configures the apisauce instance. This method is called from the RootStore after it has been rehydrated, ensuring that the authentication token is available.
Key configurations include:
- Base URL: Set from
Config.API_URL. - Headers: The
Authorizationheader is automatically set with theBearertoken from theAuthenticationStore. - Monitors: A monitor is attached to log API requests to Reactotron for debugging.
The following sequence diagram illustrates how a component fetches data using the API service.
UI and Theming
The UI is built using React Native Paper, a component library that implements Material Design. The application supports both light and dark themes.
The theme is dynamically selected in app.tsx based on the isDarkMode property from the AuthenticationStore. The selected theme is then passed to the PaperProvider, which makes it available to all components in the tree.
// in apps/mobile/app/app.tsx
const theme = isDarkMode ? customDarkTheme : customLightTheme;
return (
<PaperProvider theme={theme}>
{/* ... other components */}
</PaperProvider>
);
Sources: apps/mobile/app/app.tsx:98-101
Branding and Configuration
The application supports branding customization through environment variables. These variables control the app name, company name, logos, and various URLs.
| Variable | Default Value | Description |
|---|---|---|
APP_NAME | "Ever Teams" | The name of the application. |
COMPANY_NAME | "Ever Co. LTD" | The name of the company. |
APP_LOGO_URL | https://app.ever.team/assets/ever-teams.png | URL for the app logo. |
APP_WEBSITE_URL | https://ever.team/ | The app's main website. |
These variables are consumed by the configuration system and used throughout the app to display brand-specific information.
Sources: apps/mobile/BRANDING.md
Internationalization (i18n)
The app is localized using i18n-js. Translation strings are stored in files under apps/mobile/app/i18n/, with one file per language (e.g., en.ts, fr.ts). The i18n service is initialized at the app's entry point.
Sources: apps/mobile/app/app.tsx:9, apps/mobile/app/i18n/en.ts