An open API service indexing awesome lists of open source software.

https://github.com/max21dev/banter

Lightning-Fast Native Group Chat over Nostr
https://github.com/max21dev/banter

Last synced: 9 months ago
JSON representation

Lightning-Fast Native Group Chat over Nostr

Awesome Lists containing this project

README

          

# Banter: Lightning-Fast Native Group Chat over Nostr

> **Note:** This is a work in progress and is not ready for public release.

Banter is a native iOS/macOS application that implements the Nostr protocol for decentralized group chat. It delivers a seamless, instant messaging experience with real-time updates and smooth offline access, ensuring users enjoy responsive performance and uninterrupted conversations.

## ✨ Features

### Core Functionality
- **NIP-29 Group Chat Support** - Full implementation of NIP-29 group chat specification
- **Real-time Messaging** - Live message updates via WebSocket connections
- **Flexible Relay Connections** - Connect to any NIP-29 Nostr relay of your choice with seamless relay switching
- **User Profiles** - Rich user metadata with avatars and bios
- **Group Management** - Join, leave, and manage group memberships

### Advanced Caching System
- **3-Tier Cache Architecture** - Memory, disk, and network caching
- **Offline Support** - Access previously viewed content without internet
- **Smart Prefetching** - Intelligent loading of user profiles and images
- **Cache-First Loading** - Instant UI updates with background refresh
- **Automatic & Manual Cleanup** - Intelligent cache management and expiration, with options for users to trigger manual cache clearing

## 📱 Screenshots & Demos

### App Screenshots

#### macOS

mac_multipage

#### iOS

iPhone_profile
iPhone_messages
iPhone_members

### Screen Recordings

#### macOS

![mac_record](https://github.com/user-attachments/assets/52cf41ce-6392-46f3-a011-0cb3eca26b37)

#### iOS

![iPhone_record](https://github.com/user-attachments/assets/aa45f3c3-d4b1-4e01-b9c9-c8f0550e854e)

## 🏗️ Architecture

### Caching Components

```
┌─────────────────────┐
│ SwiftUI Views │
├─────────────────────┤
│ Cached Services │ ← CachedGroupChatService, CachedUserMetadataService
├─────────────────────┤
│ Cache Managers │ ← Group, Message, User, Image Cache Managers
├─────────────────────┤
│ Core Data Stack │ ← SQLite persistent storage
├─────────────────────┤
│ Network Layer │ ← NostrRelayManager, WebSocket connections
└─────────────────────┘
```

### Key Files

- **Services/**
- `CachedGroupChatService.swift` - Enhanced group chat with caching
- `CachedUserMetadataService.swift` - User profile caching
- `ImageCacheManager.swift` - Avatar and image caching
- `PersistenceManager.swift` - Core Data management
- `CachePolicyManager.swift` - Cache policies and cleanup

- **Models/**
- `BanterDataModel.xcdatamodeld` - Core Data model
- `NostrModels.swift` - Nostr protocol models

- **Views/**
- `CachedUserAvatarView.swift` - Cached avatar display
- `CacheStatusView.swift` - Cache monitoring UI

## 🚀 Getting Started

### Prerequisites
- iOS 15.0+ / macOS 12.0+
- Xcode 14.0+
- Swift 5.7+
- Basic understanding of Nostr protocol

### Installation

#### Option 1: Clone and Build
```bash
# Clone the repository
git clone https://github.com/max21dev/banter.git
cd banter

# Open in Xcode
open banter.xcodeproj

# Build and run
# Select your target device and press Cmd+R
```

#### Option 2: Build Server Setup (Advanced)
For advanced users who want to use the build server:

```bash
# Copy environment configuration
cp env.example .env

# Edit .env with your paths
nano .env

# Run setup script
chmod +x setup-buildserver.sh
./setup-buildserver.sh
```

### Configuration
The app automatically configures optimal caching settings. To customize:

```swift
// Modify cache policies in CachePolicyManager.swift
struct CachePolicy {
let userProfileExpiration: TimeInterval = 24 * 60 * 60 // 24 hours
let maxMessagesPerGroup: Int = 1000
let maxImageCacheSize: Int64 = 100 * 1024 * 1024 // 100 MB
}
```

## 📖 Usage

### Basic Operations
- **Join Groups**: Connect to NIP-29 relays, discover, and join groups
- **Send Messages**: Real-time messaging with other group members
- **View Profiles**: See user information and avatars
- **Search**: Find groups and messages across all cached content

### Cache Management
- **Automatic**: The app handles all caching automatically
- **Manual Cleanup**: Use the settings to clear the cache

## 🔧 Development

### Project Structure
```
banter/
├── banter/ # Main app source
│ ├── Assets.xcassets/ # App icons and colors
│ ├── Models/ # Data models
│ ├── Network/ # Network layer
│ ├── Services/ # Business logic
│ ├── Utils/ # Utilities
│ └── Views/ # SwiftUI views
├── banterTests/ # Unit tests
├── banterUITests/ # UI tests
└── Documentation/ # Project docs
```

### Building from Source
1. Ensure you have the latest Xcode version
2. Open `banter.xcodeproj` in Xcode
3. Select your target device (iOS Simulator, macOS, or physical device)
4. Press `Cmd+B` to build
5. Press `Cmd+R` to run

### Testing
```bash
# Run unit tests
xcodebuild test -project banter.xcodeproj -scheme banter -destination 'platform=iOS Simulator,name=iPhone 15'

# Run UI tests
xcodebuild test -project banter.xcodeproj -scheme banter -destination 'platform=iOS Simulator,name=iPhone 15' -only-testing:banterUITests
```

## 🤝 Contributing

We welcome contributions! Please see our [Contributing Guidelines](CONTRIBUTING.md) for details.

### Development Setup
1. Fork the repository
2. Create a feature branch: `git checkout -b feature/amazing-feature`
3. Make your changes
4. Add tests if applicable
5. Commit your changes: `git commit -m 'Add amazing feature'`
6. Push to the branch: `git push origin feature/amazing-feature`
7. Open a Pull Request

### Code Style
- Follow Swift API Design Guidelines
- Use SwiftLint for code formatting
- Write unit tests for new functionality
- Update documentation for API changes

## 📚 Technical Details

### Nostr Protocol Support
- **NIP-01**: Basic protocol implementation
- **NIP-29**: Group chat specification
- **WebSocket**: Real-time relay connections
- **Cryptography**: Event signing and verification

### Data Flow
1. **Cache Check**: Always check cache first
2. **UI Update**: Immediate display of cached data
3. **Network Fetch**: Background refresh from relays
4. **Cache Update**: Store new data for future use

### Error Handling
- Graceful fallbacks for network issues
- Cache corruption recovery
- Offline mode support
- Connection retry logic

## 🐛 Troubleshooting

### Common Issues

#### Build Errors
- Ensure you have the correct Xcode version
- Clean build folder: `Cmd+Shift+K`
- Reset package caches: `File > Packages > Reset Package Caches`

#### Runtime Issues
- Check relay connectivity in settings
- Verify Nostr identity is properly configured
- Monitor cache status for storage issues

#### Performance Issues
- Check cache hit rates in the status view
- Monitor memory usage
- Verify relay response times

## 📄 License

This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.

## 🙏 Acknowledgments

- Nostr protocol community and contributors
- NIP-29 specification authors
- Swift and SwiftUI development teams
- All contributors and testers