@umituz/react-native-firebase
v1.13.99
Published
Unified Firebase package for React Native apps - Auth and Firestore services using Firebase JS SDK (no native modules).
Maintainers
Readme
@umituz/react-native-firebase
Comprehensive Firebase package for React Native applications using Firebase JS SDK (no native modules required). Built with Domain-Driven Design (DDD) architecture.
🚀 Quick Start
Read First: Before using this package, read the CONTRIBUTING.md for development guidelines and AI instructions.
Installation
npm install @umituz/react-native-firebase firebase
# Required peer dependencies
npm install expo-apple-authentication expo-crypto @umituz/react-native-storageBasic Usage Strategy
- Initialize Firebase once at app startup
- Use hooks for authentication state
- Use repositories for database operations
- Follow module-specific guidelines in each README
📦 Modules
Auth Module
Location: src/auth/README.md
Provides authentication functionality:
- Anonymous, Google, Apple, Email/Password authentication
- Auth state management with React hooks
- Account deletion and reauthentication
- Auth guards for protected routes
Key Strategy: Never use Firebase Auth SDK directly in UI. Always use the provided hooks and services.
Firestore Module
Location: src/firestore/README.md
Database operations with repository pattern:
- Base, Query, and Paginated repositories
- Quota management and tracking
- Middleware for caching and monitoring
- Request logging and analytics
Key Strategy: Always access Firestore through repositories. Never bypass the repository layer.
Storage Module
Location: src/storage/README.md
File storage operations:
- Base64 and file uploads
- Single and batch deletion
- Metadata management
Key Strategy: Always clean up old files. Use organized path structures.
Admin Scripts
Location: scripts/README.md
Backend utilities:
- User management and cleanup
- Firestore collection operations
- Storage file management
Key Strategy: Use for admin operations, not in client apps.
🏗️ Architecture
This package follows Domain-Driven Design (DDD) principles.
Layer Structure
├── domain/ # Business logic (entities, errors, value objects)
├── infrastructure/ # External dependencies (Firebase, APIs)
└── presentation/ # UI integration (React hooks, components)Key Design Patterns
- Repository Pattern - Data access through repository abstractions
- Middleware Pattern - Cross-cutting concerns (logging, caching)
- Service Layer - Business logic encapsulation
- Factory Pattern - Object creation and initialization
✅ Required Practices
For All Modules
- Type Safety: Use TypeScript strict mode
- Error Handling: Handle all errors appropriately
- Documentation: Keep README files in sync with code
- Testing: Write tests for new functionality
- File Size: Keep files under 200 lines
For Authentication
- Use hooks (never Firebase SDK directly in UI)
- Protect routes with auth guards
- Handle auth state changes properly
- Clean up auth listeners on unmount
For Firestore
- Always use repositories for data access
- Use pagination for large datasets
- Track quota usage with middleware
- Create appropriate indexes in Firebase Console
- Use query builders for complex queries
For Storage
- Clean up old files before uploading new ones
- Use organized path structures
- Add metadata to files for tracking
- Handle deletion errors gracefully
🚫 Forbidden Practices
Architecture Violations
- ❌ Mixing architectural layers (e.g., infrastructure importing from domain)
- ❌ Bypassing repositories to access Firestore directly
- ❌ Using Firebase SDK directly in UI components
- ❌ Creating circular dependencies between modules
- ❌ Putting business logic in presentation layer
Code Quality Issues
- ❌ Files larger than 200 lines
- ❌ Duplicated code
- ❌ Using
anytype - ❌ Magic numbers or strings (use constants)
- ❌ Hardcoded configuration values
Anti-Patterns
- ❌ Hardcoded credentials or API keys
- ❌ Console.log in production code
- ❌ Swallowing errors silently
- ❌ Ignoring TypeScript errors
🤖 For AI Agents
When Writing Code
- READ the module-specific README first
- FOLLOW existing patterns in the codebase
- RESPECT architectural boundaries
- CHECK file size limits (max 200 lines)
- USE established utilities and services
Before Generating Code
- Search for similar existing functionality
- Check if a utility already exists
- Read the relevant module README
- Understand the architectural layer
Code Generation Rules
- Keep files under 200 lines
- Follow TypeScript strict mode
- Use proper naming conventions
- Handle all errors
- Add JSDoc comments for public APIs
📚 Documentation
- Development Guidelines - Must read before contributing
- Auth Module - Authentication strategies and rules
- Firestore Module - Database operations and patterns
- Storage Module - File storage guidelines
- Infrastructure - Core setup and configuration
🎯 Usage Strategies
Authentication Strategy
- Initialize Firebase once at app startup
- Use
useFirebaseAuthhook for auth state - Use specific auth hooks for different providers
- Protect routes with auth guards
- Handle auth errors with user-friendly messages
Database Strategy
- Create repositories extending base repository classes
- Use pagination for large datasets
- Register middleware for quota tracking
- Use query builders for complex queries
- Monitor quota usage regularly
File Storage Strategy
- Use organized path structures (e.g.,
users/{userId}/avatar.jpg) - Delete old files before uploading new ones
- Add metadata for tracking
- Handle upload/deletion errors appropriately
🔧 Environment Setup
Required Environment Variables
EXPO_PUBLIC_FIREBASE_API_KEY=your-api-key
EXPO_PUBLIC_FIREBASE_PROJECT_ID=your-project-id
EXPO_PUBLIC_FIREBASE_STORAGE_BUCKET=your-bucketFirebase Console Setup
- Create Firebase project
- Enable required services (Auth, Firestore, Storage)
- Configure authentication providers
- Set security rules for Firestore and Storage
📋 Module Documentation
Each module has comprehensive documentation including:
- Purpose and responsibilities
- Architecture overview
- Usage strategies
- Required practices
- Forbidden practices
- AI agent instructions
Read the module-specific README before working on that module.
🛠️ Development
Type Checking
npm run typecheckLinting
npm run lintBuilding
npm run build:scripts📝 Contributing
- Read CONTRIBUTING.md
- Read module-specific README
- Follow architectural patterns
- Keep files under 200 lines
- Update documentation if behavior changes
- Ensure all tests pass
📄 License
MIT License - see LICENSE for details.
🆘 Support
- Issues: GitHub Issues
- Email: [email protected]
Last Updated: 2025-01-08 Version: 1.13.58 Maintainer: Ümit UZ [email protected]
