# expo-community/expo-firebase-starter architecture

> Architecture diagram of the GitHub repository expo-community/expo-firebase-starter, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-05-15). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/expo-community/expo-firebase-starter
- Repository: https://github.com/expo-community/expo-firebase-starter

## Overview

##### Project Type and Purpose
- This is a React Native (Expo) mobile application starter template that uses Firebase JS SDK v9 to implement email/password authentication (signup, login, password reset).
- It is fundamentally a client‐side app (mobile UI) that delegates backend services (Auth) to Firebase in the cloud.

##### File Structure Analysis
- Top level:
- App.js – the root entry point where you wire up providers and the navigation root
- app.config.js / babel.config.js – Expo and build configurations
- config/ – initialization modules (firebase setup, theming, image constants)
- providers/ – React Context provider for authenticated user state based on Firebase’s onAuthStateChanged
- navigation/ – React Navigation stacks (AuthStack, AppStack) and a RootNavigator to switch between them
- screens/ – screen components for Login, Signup, ForgotPassword, Home
- hooks/ – custom hook for toggling password visibility
- assets/ – static images, logos

##### Key Architecture Insights from README
- Uses Expo SDK 50 and React Navigation v6 for routing
- Firebase JS SDK handles the “backend” for auth flows
- Form management via Formik + Yup for validation and error display
- Context API + a custom provider to broadcast auth state throughout the app
- Environment variables via dotenv and expo-constants for Firebase config injection

##### Main Components
a. Mobile Application (Client)
- UI Layer: Screens → Components
- Navigation Layer: RootNavigator, AuthStack, AppStack
- State Management & Business Logic:
- AuthenticatedUserProvider (Context)
- Custom Hook (useTogglePasswordVisibility)
- Configuration Layer:
- .env (Expo Constants + dotenv)
- config/firebase.js (initializes Firebase Auth)
- config/theme.js, config/images.js
b. External Services (Cloud)
- Firebase Authentication Service (email/password)
- (Optionally) Firebase Firestore, Storage if used later
c. Tooling & Build
- Metro Bundler / Babel under the hood (optional to show)

##### Relationships & Data Flows
- User taps a button on a Screen → Component emits event (e.g., onPress)
- Screen’s Formik form calls Firebase Auth methods from config/firebase
- Firebase responds (success or error) → AuthenticatedUserProvider’s listener updates context
- RootNavigator observes context → switches stacks (AppStack vs AuthStack)
- Screens subscribe to auth context and render accordingly
- Custom hooks (e.g., useTogglePasswordVisibility) drive UI state changes within Components

##### Architectural Patterns & Principles
- Separation of Concerns:
- Presentation (components/) vs Navigation (navigation/) vs Configuration (config/) vs Business Logic (providers/, hooks/)
- Unidirectional Data Flow via Context API and React state
- Functional Components + React Hooks everywhere
- Environment‐based configuration for security (dotenv + expo‐constants)
- Modular, reusable UI and utility layers

##### Essential Elements
- App.js at the top of the client side, wrapping:
- AuthenticatedUserProvider
- RootNavigator
- Navigation stacks and their relationship: RootNavigator branches to AuthStack or AppStack
- Screens and which stack they belong to
- Components library feeding into Screens
- Config/firebase.js module as the bridge to Firebase Auth
- .env / expo-constants feeding config/firebase.js
- Firebase Auth service as external cloud service
- Custom Hook as a detail inside the Components or Logic layer

## Diagram (Mermaid)

```mermaid
flowchart TB
    classDef ui fill:#D0E8FF,stroke:#0366d6,color:#0366d6;
    classDef logic fill:#DFFFE0,stroke:#228B22,color:#228B22;
    classDef config fill:#FFF8B0,stroke:#DAA520,color:#DAA520;
    classDef external fill:#FFE4C4,stroke:#FF8C00,color:#FF8C00;

    subgraph "Device / App Runtime"
        direction TB

        App["App.js"]:::config
        click App "https://github.com/expo-community/expo-firebase-starter/blob/master/App.js"

        subgraph "Config Layer"
            direction TB
            ExpoConfig["app.config.js"]:::config
            click ExpoConfig "https://github.com/expo-community/expo-firebase-starter/blob/master/app.config.js"
            BabelConfig["babel.config.js"]:::config
            click BabelConfig "https://github.com/expo-community/expo-firebase-starter/blob/master/babel.config.js"
            EnvExample[".env.example"]:::config
            click EnvExample "https://github.com/expo-community/expo-firebase-starter/blob/master/.env.example"
            FirebaseConfig["config/firebase.js"]:::config
            click FirebaseConfig "https://github.com/expo-community/expo-firebase-starter/blob/master/config/firebase.js"
            ThemeConfig["config/theme.js"]:::config
            click ThemeConfig "https://github.com/expo-community/expo-firebase-starter/blob/master/config/theme.js"
            ImagesConfig["config/images.js"]:::config
            click ImagesConfig "https://github.com/expo-community/expo-firebase-starter/blob/master/config/images.js"
            ConfigIndex["config/index.js"]:::config
            click ConfigIndex "https://github.com/expo-community/expo-firebase-starter/blob/master/config/index.js"
        end

        subgraph "Business Logic Layer"
            direction TB
            AuthProvider["AuthenticatedUserProvider"]:::logic
            click AuthProvider "https://github.com/expo-community/expo-firebase-starter/blob/master/providers/AuthenticatedUserProvider.js"
            HookToggle["useTogglePasswordVisibility"]:::logic
            click HookToggle "https://github.com/expo-community/expo-firebase-starter/blob/master/hooks/useTogglePasswordVisibility.js"
        end

        subgraph "Navigation Layer"
            direction TB
            RootNav["RootNavigator"]:::ui
            click RootNav "https://github.com/expo-community/expo-firebase-starter/blob/master/navigation/RootNavigator.js"
            AuthStack["AuthStack"]:::ui
            click AuthStack "https://github.com/expo-community/expo-firebase-starter/blob/master/navigation/AuthStack.js"
            AppStack["AppStack"]:::ui
            click AppStack "https://github.com/expo-community/expo-firebase-starter/blob/master/navigation/AppStack.js"
            NavIndex["navigation/index.js"]:::ui
            click NavIndex "https://github.com/expo-community/expo-firebase-starter/blob/master/navigation/index.js"
        end

        subgraph "UI Layer"
            direction TB
            subgraph "Screens"
                direction TB
                LoginScreen["LoginScreen"]:::ui
                click LoginScreen "https://github.com/expo-community/expo-firebase-starter/blob/master/screens/LoginScreen.js"
                SignupScreen["SignupScreen"]:::ui
                click SignupScreen "https://github.com/expo-community/expo-firebase-starter/blob/master/screens/SignupScreen.js"
                ForgotPwdScreen["ForgotPasswordScreen"]:::ui
                click ForgotPwdScreen "https://github.com/expo-community/expo-firebase-starter/blob/master/screens/ForgotPasswordScreen.js"
                HomeScreen["HomeScreen"]:::ui
                click HomeScreen "https://github.com/expo-community/expo-firebase-starter/blob/master/screens/HomeScreen.js"
                ScreensIndex["screens/index.js"]:::ui
                click ScreensIndex "https://github.com/expo-community/expo-firebase-starter/blob/master/screens/index.js"
            end
            subgraph "Components"
                direction TB
                ButtonComp["Button"]:::ui
                click ButtonComp "https://github.com/expo-community/expo-firebase-starter/blob/master/components/Button.js"
                TextInputComp["TextInput"]:::ui
                click TextInputComp "https://github.com/expo-community/expo-firebase-starter/blob/master/components/TextInput.js"
                IconComp["Icon"]:::ui
                click IconComp "https://github.com/expo-community/expo-firebase-starter/blob/master/components/Icon.js"
                FormErrorMsg["FormErrorMessage"]:::ui
                click FormErrorMsg "https://github.com/expo-community/expo-firebase-starter/blob/master/components/FormErrorMessage.js"
                LoadingIndicator["LoadingIndicator"]:::ui
                click LoadingIndicator "https://github.com/expo-community/expo-firebase-starter/blob/master/components/LoadingIndicator.js"
                LogoComp["Logo"]:::ui
                click LogoComp "https://github.com/expo-community/expo-firebase-starter/blob/master/components/Logo.js"
                ViewWrapper["View"]:::ui
                click ViewWrapper "https://github.com/expo-community/expo-firebase-starter/blob/master/components/View.js"
                ComponentsIndex["components/index.js"]:::ui
                click ComponentsIndex "https://github.com/expo-community/expo-firebase-starter/blob/master/components/index.js"
            end
        end

    end

    subgraph "Cloud Services"
        FirebaseAuth["Firebase Auth Service"]:::external
    end

    %% Connections
    App -->|wraps| AuthProvider
    App -->|wraps| RootNav

    RootNav -->|if unauthenticated| AuthStack
    RootNav -->|if authenticated| AppStack

    AuthStack --> LoginScreen
    AuthStack --> SignupScreen
    AuthStack --> ForgotPwdScreen

    AppStack --> HomeScreen

    LoginScreen -->|uses| ButtonComp
    LoginScreen -->|uses| TextInputComp
    LoginScreen -->|uses hook| HookToggle
    SignupScreen -->|uses| FormErrorMsg
    ForgotPwdScreen -->|uses| FormErrorMsg
    HomeScreen -->|uses| LogoComp

    LoginScreen -->|onSubmit calls| FirebaseConfig
    SignupScreen -->|onSubmit calls| FirebaseConfig
    ForgotPwdScreen -->|onSubmit calls| FirebaseConfig

    FirebaseConfig -->|calls| FirebaseAuth
    FirebaseAuth -->|onAuthStateChanged callback| AuthProvider
    AuthProvider -->|provides context to| RootNav
    AuthProvider -->|provides context to| LoginScreen
    AuthProvider -->|provides context to| HomeScreen
```
