A React Native module that integrates MGit (Medical Git) functionality into iOS applications using a Go framework. MGit enables secure, self-custodial medical data management with Nostr public key authentication.
react-native-mgit
bridges MGit's Go implementation with React Native iOS apps through a compiled Go framework (MGitBridge.xcframework
). This approach provides:
- Direct Go function calls (no binary execution)
- Full logging visibility for debugging
- Secure execution within the iOS app sandbox
- Comprehensive MGit functionality for medical record management
React Native App
↓
react-native-mgit (Bridge)
↓
MGitBridge.xcframework (Go Framework)
↓
MGit Go Implementation
- iOS Development: Xcode, CocoaPods
- Go Development: Go 1.21+,
gomobile
tool - React Native: 0.60+ (autolinking support)
- MGit Framework: Pre-built
MGitBridge.xcframework
Since this is a local development module:
# Using yarn (recommended)
yarn add file:../react-native-mgit
# Using npm
npm install --save ../react-native-mgit
The module requires MGitBridge.xcframework
to be present in ios/frameworks/
:
# From react-native-mgit directory
./copy-mgit-framework.sh
This copies the framework from ../mgit-ios-bridge/MGitBridge.xcframework
to the correct location.
For React Native 0.60+, autolinking handles most setup. If needed, manually add to your iOS project:
# ios/Podfile - usually handled automatically
pod 'react-native-mgit', :path => '../node_modules/react-native-mgit'
The MGitBridge.xcframework
is built from the mgit-ios-bridge
package:
# In mgit-ios-bridge directory
go mod tidy
gomobile bind -target ios -o MGitBridge.xcframework .
When MGit functionality changes:
- Update
mgit-ios-bridge/bridge.go
with new functions - Rebuild framework:
gomobile bind -target ios -o MGitBridge.xcframework .
- Copy to react-native-mgit:
./copy-mgit-framework.sh
- Test in your React Native app
import { NativeModules } from 'react-native';
const MGitModule = NativeModules.MGitModule;
// Test framework integration
async function testFramework() {
try {
// Get MGit help text
const helpResult = await MGitModule.help();
console.log('Help text:', helpResult.helpText);
// Test logging functionality
const logResult = await MGitModule.testLogging();
console.log('Logging test:', logResult.result);
// Test basic computation
const mathResult = await MGitModule.simpleAdd(2, 2);
console.log('2 + 2 =', mathResult.result); // Should be 4
} catch (error) {
console.error('Framework test failed:', error);
}
}
import MGitService from 'react-native-mgit/src/services/MGitService';
async function testMGitConnection() {
try {
const isConnected = await MGitService.testConnection();
console.log('MGit module connected:', isConnected);
} catch (error) {
console.error('Connection test failed:', error);
}
}
help()
- Returns MGit help text and usage informationtestLogging()
- Comprehensive logging test for debuggingsimpleAdd(a, b)
- Basic arithmetic test (returns a + b)
The following methods are planned for implementation:
clone(url, localPath, options)
- Clone MGit repositoriescommit(repositoryPath, message, options)
- Create commits with Nostr signaturespull(repositoryPath, options)
- Pull changes from remote repositoriescreateMCommit(...)
- Create medical commits with enhanced metadata
# Work on Go functionality
cd mgit-ios-bridge
# Edit bridge.go to add new functions
gomobile bind -target ios -o MGitBridge.xcframework .
# Update React Native module
cd react-native-mgit
./copy-mgit-framework.sh
# Test in your app
cd your-app
npx expo run:ios
View native logs in Xcode Console (Window > Devices and Simulators > Select Device > Open Console).
// Enable comprehensive logging
const result = await MGitModule.testLogging();
// Check both console.log and Xcode Console for output
react-native-mgit/
├── ios/
│ ├── MGitModule.h # Native module header
│ ├── MGitModule.m # Native module implementation
│ └── frameworks/ # Framework location
│ └── MGitBridge.xcframework # Go framework
├── src/
│ └── services/
│ └── MGitService.ts # JavaScript service layer
├── copy-mgit-framework.sh # Framework update script
├── react-native-mgit.podspec # iOS dependency configuration
└── package.json
Framework not found:
# Ensure framework is in correct location
ls ios/frameworks/MGitBridge.xcframework
# If missing, copy from mgit-ios-bridge
./copy-mgit-framework.sh
Build errors:
# Clean build
cd ios && rm -rf build/ Pods/ Podfile.lock
cd .. && npx expo run:ios
No native logs:
- Check Xcode Console (not Simulator console)
- Filter by "MGitModule" or "MedicalBinder"
- Ensure device/simulator is selected in Console app
- Module loads:
NativeModules.MGitModule
should not be undefined - Framework works:
await MGitModule.help()
should return help text - Logging visible: Check Xcode Console for "MGitModule:" messages
- Go side: Add function to
mgit-ios-bridge/bridge.go
- Framework: Rebuild with
gomobile bind
- Native side: Add RCT_EXPORT_METHOD to
MGitModule.m
- JavaScript side: Add method to
MGitService.ts
- Test: Verify end-to-end functionality
// Template for testing new methods
async function testNewMethod() {
try {
const result = await MGitModule.yourNewMethod(params);
console.log('Success:', result);
} catch (error) {
console.error('Error:', error);
}
}
- iOS: 11.0+
- React Native: 0.60+
- Go: 1.21+ (for framework development)
- Xcode: Latest stable version
[Add your license information here]
- MGit: Core Git implementation for medical records
- mgit-ios-bridge: Go package providing iOS framework
- MedicalBinder: Reference React Native app using this module