A React Native mobile application starter project implementing Clean Architecture with the MVVM (Model-View-ViewModel) pattern.
This project is built using React Native and follows a modular, scalable architecture to improve maintainability, testability, and separation of concerns.
- Clean Architecture: Layers separate concerns into
data
,domain
, andpresentation
. - MVVM Pattern: Presentation logic is managed through
ViewModels
that connect Views (Screens
) with domain/business logic. - TypeScript: Typed codebase for better developer experience and fewer runtime errors.
- Dependency Injection: Shared services and repositories are injected via a factory to promote loose coupling.
- Authentication: Login, Logout and Session.
- View Profile.
- Supports multiple backend data sources:
- Firebase
- REST API
- Switch seamlessly between Local, Firebase or REST API implementations using dependency injection and repository factories.
This project architecture is inspired by the principles described in the book:
Clean Architecture: A Craftsman's Guide to Software Structure and Design
by Robert C. Martin (Uncle Bob)
- Handles data sources, DTOs (Data Transfer Objects), mappers, and repository implementations.
- Interacts with external systems such as REST APIs, Firebase, or local storage.
- Transforms data formats between external and domain models.
- Contains core business models like
UserModel
. - Defines abstract repository interfaces.
- Hosts Use Cases (application/business rules) that orchestrate domain logic — currently a placeholder and should be fully implemented to encapsulate business workflows.
- Houses UI components including screens, styles, and ViewModels.
- ViewModels manage UI state and serve as an intermediary between Views and domain logic.
- Organized by feature modules (auth, map, notifications, products, profile, root, splash).
- Contains app-wide configurations (app, Firebase, data sources).
- Provides dependency injection support (
RepositoryFactory
). - Includes enums, helpers, hooks, and TypeScript types for reuse.
Below is a diagram illustrating the MVVM pattern adapted in this project:
- Node.js (v16 or higher)
- React Native CLI
- Xcode (for iOS development)
- Android Studio (for Android development)
- CocoaPods (for iOS dependencies)
-
Clone the repository:
git clone [email protected]:zvhir3/react-native-mvvm.git cd react-native-mvvm
-
Install dependencies:
npm install
-
Install iOS dependencies (iOS only):
cd ios && pod install && cd ..
-
Environment Setup:
cp .env.example .env
Then edit the
.env
file with your configuration values.
For iOS:
npx react-native run-ios
For Android:
npx react-native run-android
For Metro bundler (if needed separately):
npx react-native start
The application uses environment variables for configuration. Make sure to set up your .env
file with the following variables:
# API Configuration
API_BASE_URL=https://your-api-url.com
API_KEY=your-api-key
# Firebase Configuration (if using Firebase)
FIREBASE_PROJECT_ID=your-project-id
FIREBASE_API_KEY=your-firebase-api-key
FIREBASE_AUTH_DOMAIN=your-project.firebaseapp.com
FIREBASE_STORAGE_BUCKET=your-project.appspot.com
FIREBASE_MESSAGING_SENDER_ID=123456789
FIREBASE_APP_ID=1:123456789:web:abcdef123456
# Data Source Selection
DATA_SOURCE=firebase # Options: 'local', 'firebase', 'api'
Metro bundler cache issues:
npx react-native start --reset-cache
iOS build issues:
cd ios
rm -rf Pods Podfile.lock
pod install
cd ..
Android build issues:
cd android
./gradlew clean
cd ..
- Use Cases Implementation: Currently missing or minimal. Complete implementation of use cases will better encapsulate business rules and app logic.
- Unit Testing: Adding comprehensive tests for ViewModels, Use Cases, and Repositories would improve code quality and reliability.
- Error Handling: Implement comprehensive error handling and user feedback mechanisms.
- Offline Support: Add offline capabilities with data synchronization.
- Performance Optimization: Implement performance monitoring and optimization strategies.
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature
) - Commit your changes (
git commit -m 'Add some amazing feature'
) - Push to the branch (
git push origin feature/amazing-feature
) - Open a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.
Feel free to contribute or suggest enhancements!