# covidshield/mobile architecture

> Architecture diagram of the GitHub repository covidshield/mobile, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-03-30). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/covidshield/mobile
- Repository: https://github.com/covidshield/mobile

## Overview

##### Main Components
- Native Platforms: Represent both Android and iOS. Indicate that each platform has its own native code base (found in the “android” and “ios” directories) to handle platform-specific implementations, integrations, and asset management.
- React Native Bridge: Highlight the bridging layer that connects the React Native JS code (in “src/bridge” and related files) with the native modules, such as the Exposure Notification and Push Notification modules.
- UI/Presentation Layer: Include the user interface components, screens, and navigation views. Use the “src/screens”, “src/components”, and “src/navigation” directories to illustrate this layer. Also note localization support in “src/locale” and theming in “src/shared/theme”.
- Services and Business Logic Layer: Identify services like “BackendService”, “ExposureNotificationService”, “StorageService”, “BackgroundSchedulerService”, and the test mode components. These encapsulate data fetching, storage, scheduling, and coordination of exposure notifications.
- Assets and Design Resources: Reference the “design” folder for animations, illustrations, and other design assets. Also include localization/translations and theme assets.
- External Integrations: Mark the integration points for Apple/Google Exposure Notification APIs and mention test mode functionality that simulates or overrides real exposures.

##### Relationships and Interactions
- Bidirectional interaction between the React Native bridge and native modules (found under “android/app/src/main/java/app/covidshield” and the iOS project structure) to demonstrate how notifications and system events are propagated.
- Separation between the presentation logic (React Native components) and backend communication, including the asynchronous data flow from backend endpoints.
- Workflows like the Test Mode flow, where tapping on UI elements accesses the test menu, bypassing some API checks.

##### Architectural Patterns
- Layered Architecture: Emphasize clear separations between native (platform-specific), bridging, UI, and services layers.
- Modular Design: Note that the project uses a modular approach where each service (Backend, Exposure Notification, Storage, etc.) is separated by its own directory under “src/services”. This facilitates testing and potential future enhancements.
- Separation of Concerns: The design distinguishes between UI (in “src/screens” and “src/components”), business logic (services), and bridging/native integrations.
- Dependency Injection/Providers: Mention usage of provider patterns seen in files like StorageServiceProvider.tsx and ExposureNotificationServiceProvider.tsx to supply services throughout the React component tree.

##### Relevant Technologies and Frameworks
- React Native for cross-platform mobile development.
- JavaScript/TypeScript in the “src” directory for the main application logic.
- Native Android (Java/Kotlin) and iOS (Objective-C/Swift) modules to integrate with key platform-specific Exposure Notification APIs.
- External libraries such as react-native-config, for environment configuration, and others indicated by configurations (e.g., Babel, Metro, ESLint, Prettier).
- Build and dependency management tools like Yarn, Cocoapods, and Gradle.

##### Final Touches
- Provide notes for any non-obvious interactions (for example, explaining that test mode toggles allow bypassing of real exposure notifications for development purposes).

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% UI/Presentation Layer
    subgraph "UI/Presentation Layer"
        UI_Screens["Screens (src/screens)"]:::ui
        UI_Components["Components (src/components)"]:::ui
        UI_Navigation["Navigation (src/navigation)"]:::ui
        UI_Localization["Localization (src/locale)"]:::ui
        UI_Theming["Theming (src/shared/theme)"]:::ui
    end

    %% Services and Business Logic Layer
    subgraph "Services and Business Logic"
        S_Backend["Backend Service (src/services/BackendService)"]:::services
        S_Exposure["Exposure Notification Service (src/services/ExposureNotificationService)"]:::services
        S_Storage["Storage Service (src/services/StorageService)"]:::services
        S_Scheduler["Background Scheduler Service (src/services/BackgroundSchedulerService)"]:::services
        S_TestMode["Test Mode Components (src/testMode)"]:::services
    end

    %% React Native Bridge
    Bridge["React Native Bridge (src/bridge)"]:::bridge

    %% Native Platforms
    subgraph "Native Platforms"
        Native_Android["Android Native (android/app/src/main/java/app/covidshield)"]:::native
        Native_iOS["iOS Native (ios/CovidShield)"]:::native
    end

    %% Assets and Design Resources
    subgraph "Assets and Design Resources"
        Assets_Design["Design Files (design)"]:::assets
        Assets_Media["Media/Animations (src/assets)"]:::assets
    end

    %% External Integration
    External_EN_API["Exposure Notification API (Apple/Google)"]:::external

    %% Connections between UI and Services
    UI_Screens -->|"fetches"| S_Backend
    UI_Screens -->|"notifies"| S_Exposure
    UI_Screens -->|"updates_state"| S_Storage
    UI_Navigation -->|"test_toggle"| S_TestMode
    S_Backend -->|"cache"| S_Storage

    %% UI to Bridge Communication
    UI_Components -->|"bridge_call"| Bridge
    UI_Screens -->|"bridge_call"| Bridge

    %% Services interact with Bridge
    S_Exposure -->|"trigger"| Bridge

    %% Bridge and Native Platforms interaction (bidirectional)
    Bridge <-->|"native_comm"| Native_Android
    Bridge <-->|"native_comm"| Native_iOS

    %% External Integration with Native Platforms
    External_EN_API <-->|"API_calls"| Native_Android
    External_EN_API <-->|"API_calls"| Native_iOS

    %% UI uses Assets
    UI_Theming -->|"uses_assets"| Assets_Design
    UI_Theming -->|"uses_assets"| Assets_Media

    %% Class Definitions for styling with colours
    classDef ui fill:#a8d0e6,stroke:#333,stroke-width:2px;
    classDef services fill:#f76c6c,stroke:#333,stroke-width:2px;
    classDef bridge fill:#ffbf69,stroke:#333,stroke-width:2px;
    classDef native fill:#6a994e,stroke:#333,stroke-width:2px;
    classDef assets fill:#bc6ff1,stroke:#333,stroke-width:2px;
    classDef external fill:#ffd166,stroke:#333,stroke-width:2px;

    %% Click Events
    click Native_Android "https://github.com/covidshield/mobile/tree/master/android/app/src/main/java/app/covidshield"
    click Native_iOS "https://github.com/covidshield/mobile/tree/master/ios/CovidShield"
    click Bridge "https://github.com/covidshield/mobile/tree/master/src/bridge"
    click UI_Screens "https://github.com/covidshield/mobile/tree/master/src/screens"
    click UI_Components "https://github.com/covidshield/mobile/tree/master/src/components"
    click UI_Navigation "https://github.com/covidshield/mobile/tree/master/src/navigation"
    click UI_Localization "https://github.com/covidshield/mobile/tree/master/src/locale"
    click UI_Theming "https://github.com/covidshield/mobile/tree/master/src/shared/theme"
    click S_Backend "https://github.com/covidshield/mobile/tree/master/src/services/BackendService"
    click S_Exposure "https://github.com/covidshield/mobile/tree/master/src/services/ExposureNotificationService"
    click S_Storage "https://github.com/covidshield/mobile/tree/master/src/services/StorageService"
    click S_Scheduler "https://github.com/covidshield/mobile/tree/master/src/services/BackgroundSchedulerService"
    click S_TestMode "https://github.com/covidshield/mobile/tree/master/src/testMode"
    click Assets_Design "https://github.com/covidshield/mobile/tree/master/design"
    click Assets_Media "https://github.com/covidshield/mobile/tree/master/src/assets"
```
