How mattermost/mattermost-mobile works
Project type and purpose
• This is the Mattermost Mobile v2 application: a cross-platform React Native client for Mattermost chat servers.
• It bundles three “front-ends” in one repo:
• A JavaScript/TypeScript layer under app/ and share_extension/ powered by React Native.
• Native Android code under android/ (Gradle, Kotlin/Java helpers, WatermelonDB schema, push handlers, call integrations).
• Native iOS code under ios/ (Swift/Objective-C wrappers, push extensions, WatermelonDB integration).
• It communicates with external services: a Mattermost Server over REST and WebSocket, a Push Notification Proxy (for APNS/FCM), and a VoIP/calls subsystem via WebRTC or Voximplant.
File structure
• Top-level directories:
• app/ – JS business logic: actions (remote, local, websocket), client wrappers, components, screens, database operator/manager, state stores, hooks, utils, queries, schema, migrations.
• android/ & ios/ – native platform shells, native modules, build configurations, asset catalogs, database bridges, push handlers, call services.
• libraries/ – custom React Native native modules (@mattermost/hardware-keyboard, rnshare, rnutils).
• share_extension/ – a small React Native bundle for iOS share extension.
• CI/CD: .github/workflows, fastlane/, scripts/, detox/ for e2e tests.
• Architectural patterns: Flux/Redux-style actions → state stores → React views; persistent data via WatermelonDB (SQLite) with separate “app” and “server” schema layers; a clear split between UI (components/screens), business logic (actions/managers), data layer (database/operator), network layer (client/rest & client/websocket).
Key insights from README
• The mobile app requires its own Push Proxy for notifications.
• Communicates with server API v4 (REST + WebSocket).
• Supports monthly releases and community contributions, but no embedded server—pure client.
Components
a. JS/UI Layer
• React Native bundle (app/ + share_extension/)
• Screens & UI components (screens/, components/)
• Hooks & context providers
b. State & Data Layer
• Actions (remote, local, websocket) → dispatch to stores (app/store/…)
• Stores / Ephemeral state vs. persisted state
• Database manager & operators (WatermelonDB / SQLite under app/database/)
• Query layer (app/queries/)
c. Network Layer
• REST client (app/client/rest/)
• WebSocket client (app/client/websocket/)
• Push Notification Bridge (native modules + Push Proxy)
• Calls subsystem (native integration + app/products/calls/)
d. Native Platforms
• Android shell (Gradle projects, custom Java/Kotlin helpers, AndroidManifest, assets)
• iOS shell (Xcode project, Swift/Obj-C code, Share extension)
• Native modules (libraries/@mattermost/*)
e. External Services
• Mattermost Server (REST API & WebSocket)
• Mattermost Push Proxy (APNS / FCM)
• Third-party call servers (e.g., Voximplant)
• CDNs / asset hosting (for fonts, emojis, i18n JSON)
Relationships and data flows
• UI triggers user actions → dispatch to Action layer →
→ Local actions mutate DB via Operators & Managers → Store updates → UI re-renders.
→ Remote actions call REST/WebSocket client → Server → response persisted to DB → Stores updated → UI.
• WebSocket pushes from server → WebSocket client → dispatch as WebSocket Actions → DB & Stores → UI.
• Push Proxy → platform push SDK → native push handler → JS event → navigate or update Stores.
• Calls subsystem: JS triggers call actions → native module opens WebRTC channel → media flow outside JS.
• Share extension: isolated RN bundle with its own state, network calls, then hands off to main app via deep link or shared storage.
Architectural patterns & design principles
• Flux/Redux pattern for one-way data flow.
• Separation of concerns: UI (components/screens), business logic (actions/managers), persistence (database), network (client).
• Native-JS bridging: React Native modules isolate platform specifics.
• Modular directory structure by feature (e.g., app/products/calls/, app/screens/channel/, libraries/ modules).
• CI/CD pipelines automate builds, tests, code analysis (GitHub Actions + Fastlane + Detox/E2E).