A complete monorepo project featuring a native Android application that forwards device events (like SMS and battery status) to a serverless API running on Cloudflare Workers, which then sends formatted email notifications.
This project demonstrates a modern, full-stack development approach using a single repository (monorepo) to manage both a mobile application and its backend API. The core functionality is to capture events on an Android device (including SMS and WhatsApp messages) and securely forward them as nicely formatted emails with intelligent routing, all powered by the Cloudflare Edge network.
- Monorepo Structure: Manages the API and mobile app in one place for unified versioning and simplified dependency management using
pnpmworkspaces. - Serverless API: A lightweight, high-performance API built with Hono and deployed globally on Cloudflare Workers.
- Native Android App: A simple Android application built to capture system broadcasts and communicate with the backend.
- Multi-Platform Messaging: Supports both SMS and WhatsApp message forwarding with intelligent routing and formatting.
- Flexible Email Routing: Configure multiple email destinations for different message types and sources.
This project is built with a modern, efficient technology stack:
| Area | Technology |
|---|---|
| API | Cloudflare Workers, Hono, TypeScript, Wrangler CLI |
| Mobile App | Native Android (Java), Android SDK, Gradle |
| Tooling | pnpm Workspaces, Git, GitHub Actions |
The project is organized into distinct applications within the apps directory, promoting separation of concerns while enabling code sharing.
MessageMail/
βββ .github/
β βββ workflows/
β βββ deploy-worker.yml # CI/CD for the Cloudflare API
β βββ release-android.yml # CI/CD for building the Android release
βββ apps/
β βββ api-cloudflare-worker/ # The Hono-based Cloudflare Worker API
β βββ app-android/ # The native Android application project
βββ .gitignore
βββ package.json # Root package definition
βββ pnpm-workspace.yaml # pnpm workspace configuration
To get a local copy up and running, follow these steps.
- Node.js (v18 or later)
- pnpm (
npm install -g pnpm) - Android Studio (for the mobile app)
- A Cloudflare account
-
Clone the repository:
git clone https://github.com/alenalex/MessageMail.git cd MessageMail -
Install dependencies: This command will install dependencies for all projects in the monorepo.
pnpm install
-
Navigate to the worker directory:
cd apps/api-cloudflare-worker -
Set up local environment variables: Create a file named
.dev.varsin theapps/api-cloudflare-workerdirectory. This file is for local development secrets and is ignored by Git.# .dev.vars TARGET_EMAIL="[email protected]" SOURCE_EMAIL="[email protected]" FROM_EMAIL="[email protected]" WA_PH_ID="your-whatsapp-business-phone-id" WA_TARGETS_NOS="+1234567890,+0987654321" WA_ACCESS_TOKEN="your-whatsapp-business-api-token" LOG_BODY=true ALLOW_ALL_USER_AGENT=true
-
Start the local development server:
pnpm dev
Your API will be available at
http://localhost:8787.
-
Open the Android project: In Android Studio, select "Open" and navigate to the
MessageMail/apps/app-androiddirectory. -
Configure the API Endpoint: You will need to update the API URL in the Android app's source code to point to your deployed Cloudflare Worker's URL (for production) or
http://localhost:8787(for local testing with an emulator). -
Build and Run: Use Android Studio to build and run the app on an emulator or a physical device.
The worker requires several environment variables to be configured in your Cloudflare dashboard:
- Navigate to Workers & Pages in your Cloudflare dashboard.
- Select your worker.
- Go to Settings > Variables.
- Add the following Environment Variables:
TARGET_EMAIL: The primary email address that will receive forwarded messagesSOURCE_EMAIL: The email address used for WhatsApp message notificationsFROM_EMAIL: The sender address for outgoing emails (must be verified with your email service)
WA_PH_ID: The WhatsApp Business phone number ID from your Meta Developer accountWA_TARGETS_NOS: Comma-separated list of target phone numbers for WhatsApp message forwardingWA_ACCESS_TOKEN: WhatsApp Business API access token for authentication with Meta's API
LOG_BODY: Set totrueto enable request body logging for debuggingALLOW_ALL_USER_AGENT: Set totrueto bypass user agent restrictions
The wrangler.jsonc file contains the Cloudflare Worker deployment configuration:
LOG_BODY: Controls whether incoming request bodies are logged for debugging purposesALLOW_ALL_USER_AGENT: When enabled, allows requests from any user agent (useful for development)FROM_EMAIL: Default sender email address for notificationsTARGET_EMAIL: Primary recipient email address for SMS forwardingSOURCE_EMAIL: Dedicated email address for WhatsApp message notificationsWA_PH_ID: WhatsApp Business phone number ID from your Meta Developer accountWA_TARGETS_NOS: Target phone numbers for WhatsApp message routing (comma-separated)WA_ACCESS_TOKEN: Authentication token for WhatsApp Business API integration
The configuration includes two email service bindings:
targetMailer: Handles SMS and general message forwardingsourceMailer: Dedicated to WhatsApp message routing
store_id: References the KV namespace for storing application statesecret_name: Points to the encrypted credentials for email services
The project includes a Node.js script (scripts/prep-wrangler-jsonc.mjs) that:
- Pre-processes Configuration: Validates and transforms the wrangler.jsonc configuration before deployment
- Environment Substitution: Replaces placeholder values with environment-specific configurations
- Secret Management: Ensures sensitive data is properly handled during the build process
- Deployment Preparation: Optimizes the configuration for Cloudflare Workers runtime
This script runs automatically during the CI/CD pipeline to ensure consistent deployments across environments.
This project uses GitHub Actions for automated building and deployment.
deploy-worker.yml: This workflow is triggered on any push tomasterthat includes changes in theapps/api-cloudflare-workerdirectory. It automatically deploys the latest version of the API to Cloudflare.release-android.yml: Triggered on changes toapps/app-android, this workflow builds, versions, and signs a release-ready APK. It then creates a new GitHub Release and attaches the APK for easy distribution.
Distributed under the MIT License. See LICENSE.md for more information.