A real-time messaging application built with React Native (Expo) and Firebase. Features include one-on-one and group messaging, native Firestore offline support, read receipts, presence indicators, image sharing, push notifications, and AI-powered smart communication assistance including auto-translation, cultural context, slang definitions, smart replies, and tone adjustment.
- Node.js 18.x or higher
- Android Studio (for Android development)
- Git
- Firebase account
-
Java Development Kit (JDK)
- Android Studio includes a JDK at:
C:\Program Files\Android\Android Studio\jbr - Set
JAVA_HOMEenvironment variable:setx JAVA_HOME "C:\Program Files\Android\Android Studio\jbr" - Restart your terminal after setting
- Android Studio includes a JDK at:
-
Android Emulator
- Install and configure via Android Studio
- Create a virtual device (e.g., Pixel 7, API 35)
- Start the emulator before running the app
-
Clone the repository
git clone <repository-url> cd message-ai
-
Install dependencies
npm install
-
Configure Firebase
Follow the detailed guide in _docs/FIREBASE_SETUP.md, or quick steps:
- Create a Firebase project at console.firebase.google.com
- Add iOS and Android apps to your Firebase project
- Download
google-services.json(Android) andGoogleService-Info.plist(iOS) - Place both files in the project root
- Copy
.env.templateto.envand fill in your Firebase credentials:cp .env.template .env
- Edit
.envwith your Firebase config values
-
Verify Firebase files are in place
ls google-services.json GoogleService-Info.plist .env
β οΈ These files should NEVER be committed to git!
-
Start the Android emulator in Android Studio
-
Run the app
npx expo run:android
First build takes 3-5 minutes. Subsequent builds are faster.
-
If you encounter "JAVA_HOME not set" error:
export JAVA_HOME="/c/Program Files/Android/Android Studio/jbr" export PATH="$JAVA_HOME/bin:$PATH" npx expo run:android
Windows cannot build iOS locally. Use EAS Build:
npm install -g eas-cli
eas login
eas build --platform ios --profile developmentmessage-ai/
βββ app/ # Expo Router screens (to be implemented)
βββ src/ # Source code
β βββ config/
β β βββ firebase.ts # Firebase initialization (with offline persistence)
β βββ components/ # Reusable UI components
β βββ services/ # Business logic
β β βββ firebase/ # Firebase services
β β βββ messaging/ # Messaging logic
β β βββ ai/ # AI features (translation, context, definitions)
β β βββ user/ # User services
β βββ utils/ # Helper functions
β βββ hooks/ # Custom React hooks
β βββ types/ # TypeScript definitions
β βββ store/ # State management
βββ assets/ # Images, fonts, etc.
βββ android/ # Native Android project (generated)
TypeScript compilation check runs automatically before each commit. If there are TypeScript errors, the commit is blocked.
To skip (not recommended):
git commit --no-verifynpm startMessageAI uses Firebase Cloud Functions for server-side operations that can't be reliably handled on the client. The following functions are deployed:
What it does:
- Automatically mirrors user online/offline status from Realtime Database to Firestore
- Ensures presence indicators work even when the app crashes or loses connection
- Runs completely server-side (no client code needed)
How it works:
- Listens to changes in
/status/{uid}in RTDB - When RTDB detects a disconnect (via
onDisconnect()handlers), the function updates Firestore - Result: UI always shows accurate presence status
What they do:
- translateMessage: Translates messages to a target language using OpenAI
- explainContext: Provides cultural context and explanations for messages
- defineSlang: Defines slang terms and idioms in messages
How they work:
- Client calls Cloud Function with message text
- Function sends request to OpenAI API (gpt-4o-mini by default)
- Result is cached in Firestore
aiMetafield for instant reloads - Rate limiting prevents abuse (10 requests/min per user)
Configuration:
- See _docs/AI_SETUP.md for setup instructions
- Requires OpenAI API key in Firebase environment config
- Model can be overridden via environment variable
User Guide:
- See _docs/AI_FEATURES.md for usage instructions
- Long-press any message to access AI features
- Translations appear inline, explanations/definitions in modals
What it does:
- Sends push notifications when users receive new messages
- Uses Expo Push API for reliable delivery across platforms
- Automatically cleans up invalid/expired tokens
Features:
- Supports both direct and group conversations
- Special formatting for image messages ("π· Sent an image")
- Filters out sender (you don't get notifications for your own messages)
- Notification collapsing by conversation (prevents spam)
- Deep linking (tap notification β open conversation)
Cloud Functions are already deployed to production. If you need to redeploy:
# From project root
firebase deploy --only functionsRequirements:
- Firebase Blaze (pay-as-you-go) plan
- Expected cost: $0/month (well within free tier)
For detailed setup instructions, testing procedures, and troubleshooting, see CLOUD_FUNCTIONS_SETUP.md.
If you see "The process cannot access the file because it is being used by another process":
cd android
./gradlew --stop
cd ..
taskkill //F //IM java.exe
npx expo run:android# Find and kill the process
netstat -ano | grep ":8081"
taskkill //F //PID <process-id>-
Clean build directories:
rm -rf android/build android/app/build
-
Rebuild:
npx expo run:android
Check that your .env file has all required variables:
cat .envVerify Firebase SDK initializes:
- Look for "β Firebase initialized successfully" in Metro bundler output
The following files contain secrets and are in .gitignore:
.env- Firebase credentialsgoogle-services.json- Android Firebase configGoogleService-Info.plist- iOS Firebase config
For team members: Download these files from Firebase Console individually.
- _docs/FIREBASE_SETUP.md - Complete Firebase project configuration
- _docs/CLOUD_FUNCTIONS_SETUP.md - Cloud Functions deployment, testing, and troubleshooting
- Presence tracking setup
- Push notifications configuration
- Cost monitoring and optimization
- _docs/EMULATOR_TESTING.md - Local Firebase emulator testing
- memory-bank/ - Project context, decisions, and architecture
- projectbrief.md - Project overview and goals
- activeContext.md - Current status and next steps
- systemPatterns.md - Architecture and design patterns
- techContext.md - Technology stack details
- progress.md - Implementation progress tracker
- productContext.md - Product requirements and UX
- planning/ - Product Requirements Documents (PRDs)
- tasks/ - Feature-specific task lists and completion status
- Framework: React Native with Expo SDK 54.x
- Language: TypeScript 5.x
- Backend: Firebase (Auth, Firestore with offline persistence, Realtime Database, Storage, FCM)
- Navigation: Expo Router 6.x
- State Management: React Context API
- AI Services: OpenAI GPT-4 (translation, context, definitions)
expo- Expo SDKfirebase- Firebase JavaScript SDK (with offline persistence)expo-router- File-based navigationexpo-notifications- Push notificationsexpo-image-picker- Image selection@react-native-community/netinfo- Network status monitoringexpo-dev-client- Development builds with native modules
- β Project setup and infrastructure
- β Email/Password + Google authentication
- β One-on-one messaging
- β Firestore offline persistence (automatic caching + write queue)
- β Group chat
- β Read receipts and presence (RTDB-based)
- β Image sharing
- β Foreground push notifications (Expo Push API)
- β AI-Powered Translation: Translate messages to your language (long-press message)
- β Cultural Context: Understand cultural nuances and idioms (long-press message)
- β Slang Definitions: Get explanations of unfamiliar terms (long-press message)
- β Smart Caching: Instant results for previously translated messages
- β Cost Monitoring: Track OpenAI token usage and costs
- β Rate Limiting: 10 requests/min per user to prevent abuse
Status: Deployed and working! All three Cloud Functions are live. Long-press any message to access AI features.
- β Auto-Translation: Real-time automatic translation of incoming messages
- β Language Detection: Automatic detection of message languages using OpenAI
- β User Preferences: Per-user preferred language with profile integration
- β Per-Conversation Settings: Toggle auto-translate per conversation
- β Translation UI: Globe icon toggle with animation and visual feedback
- β Offline Support: Firestore offline persistence for seamless offline access
- β Push Notification Translation: Real-time translation for push notifications
- β Cultural Context Enhancement: Language-aware cultural explanations
- β Architecture Simplification: Removed ~1000 lines of SQLite code, single source of truth
- β Cloud Functions Refactoring: Centralized utility functions for maintainability
- β UI/UX Improvements: Enhanced user experience with simplified interfaces
Status: Deployed and working! Auto-translation is live with comprehensive UI/UX enhancements.
- β RAG Pipeline: 8-step Retrieval-Augmented Generation pipeline for context-aware smart replies
- β AI Context Analysis: OpenAI-powered analysis of conversation topics, sentiment, entities, language, tone
- β Smart Replies: Context-aware reply suggestions in user's preferred language
- β Service Layer Architecture: Singleton pattern for all business logic with clear separation of concerns
- β Cloud Functions Refactoring: Unified message processing, smart replies, and notifications
- β Real-time Regeneration: Smart replies automatically update when conversation changes
- β User Language Preferences: Respects each user's target language for personalized suggestions
- β Intelligent Caching: 5-minute cache per conversation per user
- β Performance Optimization: Rate limiting, cost monitoring, and offline support
- β Code Cleanup: Removed 15+ obsolete files and functions, improved maintainability
- β TypeScript Compliance: 100% TypeScript compliance with strict mode
Status: Deployed and working! Smart replies with RAG pipeline are live with comprehensive AI assistance.
- β Slang Definitions: Now provide explanations in user's preferred language
- β Cultural Context: Enhanced to respect user language preferences
- β Translation Services: All AI features consistently use user's target language
- β Consistent Interface: Unified pattern across all AI functions (translate, explain, define)
- β Language-Aware Prompts: AI receives clear instructions about target language
- β Cultural Preservation: Maintains original text while explaining in user's language
- β Fallback Handling: Graceful degradation to English when user language not specified
Status: Deployed and working! All AI features now provide personalized responses in the user's preferred language.
- Make changes
- Stage changes:
git add . - Commit (TypeScript check runs automatically):
git commit -m "feat: your message" - If TypeScript errors exist, fix them and try again
- Push:
git push
- Follow conventional commit format:
feat:,fix:,chore:, etc. - Ensure TypeScript compilation passes before committing
- Keep code type-safe
MIT License - see the LICENSE file for details
MessageAI now includes powerful AI-powered features:
- Auto-Translation π - Automatically translate incoming messages in real-time (NEW!)
- Manual Translation - Translate specific messages to your preferred language
- Explain Context π‘ - Get cultural understanding and context
- Define Slang π - Understand unfamiliar terms and idioms
What is it?
Auto-translation automatically translates incoming messages based on your preferences. Enable it once, and all future messages in other languages are automatically translated!
How to use:
- Open any conversation
- Tap the π globe icon in the header
- Toggle "Auto-Translate Messages" ON
- Select your target language (e.g., English)
- Tap "Save"
Features:
- β Automatic language detection (< 1s)
- β Smart translation (only translates if needed)
- β Toggle to view original text
- β Rate translations with π/π
- β Per-conversation settings
- β Real-time sync across devices
- β Visual indicator in header
Supported Languages:
English, Spanish, French, German, Italian, Portuguese, Japanese, Korean, Chinese, Arabic, Russian, Hindi, and more!
For detailed documentation, see _docs/AI_FEATURES.md
Long-press any message in a conversation to:
- Translate to your preferred language
- Explain Context for cultural understanding
- Define Slang for unfamiliar terms
If you're deploying to a new Firebase project, you'll need to configure the OpenAI API key:
-
Get OpenAI API Key
- Sign up at platform.openai.com
- Create an API key
-
Configure Cloud Functions
cd functions firebase functions:config:set openai.key="your_api_key_here" firebase functions:config:set openai.model="gpt-4o-mini" # optional, this is the default
-
Deploy AI Functions
firebase deploy --only functions:translateMessage,functions:explainContext,functions:defineSlang,functions:detectLanguage,functions:autoTranslateOrchestrator
- Setup Guide: _docs/AI_SETUP.md
- User Guide: _docs/AI_FEATURES.md
- Implementation Status: _docs/AI_IMPLEMENTATION_STATUS.md
# In functions/.env or Firebase config
OPENAI_API_KEY=your_key_here
OPENAI_MODEL=gpt-4o-mini # Optional: default is gpt-4o-mini- Manual Translation: ~$0.00001 per message
- Auto-Translation: ~$0.01-0.02 per message (includes detection + translation)
- Explanation: ~$0.00002 per message
- Definition: ~$0.00001 per message
- Caching: Subsequent views are free (auto-translated results cached)
- Check _docs/FIREBASE_SETUP.md for Firebase issues
- Check _docs/AI_SETUP.md for AI features setup
- Check memory-bank/techContext.md for technical details
- Review tasks/ for feature requirements
Phase: PRD 2.3.1 Complete (Context-Aware Smart Replies with RAG + Service Layer Architecture) Phase 1: β Complete (Full MVP with messaging, groups, presence, images, notifications) Phase 2: PRD 2.3.1 Complete - Smart replies with RAG pipeline, service layer architecture, Cloud Functions refactoring Android: β Building and running with full functionality + AI features + smart replies iOS: β Working in Expo Go
PRD 2.2: Auto-Translation & Language Detection (October 23-24, 2025)
- β Automatic language detection using OpenAI
- β Real-time auto-translation orchestration with Firestore triggers
- β User preferred language integration with profile
- β Per-conversation auto-translate settings
- β Translation UI with globe icon toggle and animation
- β Firestore offline persistence for seamless offline support
- β Real-time translation for push notifications
- β Language-aware cultural context explanations
- β Cloud Functions refactoring for maintainability
- β Enhanced UI/UX with pull-to-refresh, modal fixes, and performance optimizations
- β
Architecture Simplification: Removed ~1000 lines of SQLite code
- Deleted: sqliteService, offlineQueueService, syncService, networkService
- Single source of truth: Firestore with native offline persistence
- Fixed all timestamp handling inconsistencies
- Simplified codebase for better maintainability
PRD 2.1: AI Foundation Features
- β OpenAI integration with gpt-4o-mini
- β On-demand message translation (long-press β Translate)
- β Cultural context explanations (long-press β Explain Context)
- β Slang and idiom definitions (long-press β Define Slang)
- β Firestore caching to reduce API costs
- β Rate limiting (10 requests/min per user)
- β Cost monitoring and token usage tracking
- β Three Cloud Functions deployed and tested
- β Complete UI/UX integration in chat screen
PRD 2.3.1: Context-Aware Smart Replies with RAG (December 2024)
- β Complete RAG pipeline with 8 steps: Retrieval, Context Analysis, Relevance Scoring, Entity Recognition, Augmentation, Generation, Post-Processing, Caching
- β AI-powered context analysis using OpenAI for topics, sentiment, entities, language detection, and tone analysis
- β Service layer architecture with singleton pattern for maintainability and testability
- β Unified Cloud Functions reducing complexity and improving performance
- β Smart replies generation respecting user language preferences and conversation context
- β Comprehensive error handling and fallback mechanisms
- β Code cleanup: Removed ~2000 lines of obsolete code and 15+ files
- β 100% TypeScript compliance with strict mode
Previous Phase (PRD 08): Push Notifications
- β Expo Push Notifications with Cloud Functions
- β Deep linking and notification grouping
- β Authentication persistence
Ready for PRD 2.4: UX & Engagement Features!