How flourish-savings/flourish-sdk-react-native works
Project Type and Purpose
• This project is a React Native SDK that enables mobile apps to integrate Flourish’s functionality. Its primary role is to initialize a webview configured with given partner credentials (partnerId, secret, etc.), facilitate API communication, and handle a set of events (back button actions, game completion events, etc.).
• The README confirms that the SDK encapsulates loading a webview that connects to Flourish’s backend. There is also an “example” directory showcasing how to integrate this SDK into a mobile app.
File Structure
• Notice the separation into multiple logical parts:
• The “src” directory contains the core SDK implementation. Inside, separate subdirectories organize tests (__tests__), components, configurations (config), events, and service (API communication).
• The “example” directory provides a sample React Native app demonstrating integration and usage of the SDK.
• Other files (like babel.config.js, tsconfig.json) suggest the use of TypeScript and modern JavaScript tooling.
• Configuration files in “src/config” (for production and staging) and utility files (env.ts) are key parts that define how the SDK behaves in different environments.
• GitHub workflows and CI/CD configuration files indicate that the project is maintained through automated builds and tests.
Main Components
a. SDK Initialization Module:
• Located in the entry point (src/index.tsx), this component is responsible for receiving initialization parameters (partnerId, secret, language, environment, customer_code, category, and optional WebView options).
b. Configuration Management:
• The “src/config” folder contains environment-specific configurations (production, staging). Represent this as a separate block showing how environment settings are chosen during initialization.
c. API Service Component:
• Found in “src/service/api.ts” and “src/service/api.types.ts”, this module handles communication with Flourish’s backend (authentication, token retrieval, etc.).
d. Event Management System:
• The “src/events” folder contains files like eventManager.ts and eventStrategy.ts. This subsystem registers callbacks and manages events (like BACK_BUTTON_PRESSED, TRIVIA_GAME_FINISHED, etc.).
e. WebView & UI Components:
• The actual UI components (in “src/components” such as GenericErrorScreen, HomePage, RefreshTokenScreen) and the Flourish component that encapsulates the webview.
f. Example Integration:
• The “example” directory, with its own configuration (babel, metro, webpack), demonstrates the integration of the SDK in a full application. Represent it as an external consumer of the SDK.
Defining the Relationships and Data Flow
• Initialization process feeding into the Configuration Management component, which sets the environment (staging or production) accordingly.
• From initialization, the flow proceeds to the API Service component where credentials are used to authenticate with Flourish’s backend.
• Once authenticated, the Flourish component loads a webview that encapsulates the rendered Flourish functionality.
• Parallel to this, the Event Management System hooks into the webview; events fired during user interactions (such as back button presses or game events) are caught and routed back to the client via registered callback functions.
Important Architectural Patterns
• Modularity: the logical separation between configuration, API service, event management, and UI components.
• Separation between core SDK functionality (in “src”) and the integration example (in “example”).
• Dependency injection pattern where initialization parameters (credentials, environment, and options) are passed to configure the system.