Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,16 @@ target/
# Generated Rust code from JSON schema
rust/src/ditto/schema.rs

# Swift build artifacts and dependencies
swift/.build/
swift/Package.resolved

# Generated Swift code from JSON schema
swift/Sources/DittoCoTCore/Generated/

.env
rust/.env
java/.env
swift/.env


63 changes: 63 additions & 0 deletions CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,14 @@ Multi-language libraries (starting from a single managed JSON Schema) for transl

- Follow C# and .NET coding conventions and idioms

### Swift/SwiftUI Specific

- Follow Swift API Design Guidelines
- Use protocol-oriented design patterns
- Prefer value types where appropriate
- Use modern concurrency (async/await) patterns
- Follow SwiftUI best practices for state management

### Documentation

- Do not create documentation files unless explicitly requested
Expand All @@ -78,6 +86,61 @@ https://docs.ditto.live
For Rust SDK: https://software.ditto.live/rust/Ditto/4.11.0/x86_64-unknown-linux-gnu/docs/dittolive_ditto/index.html
For Java SDK: https://software.ditto.live/java/ditto-java/4.11.0-preview.1/api-reference/
For C# SDK: https://software.ditto.live/dotnet/Ditto/4.11.0/api-reference/
For Swift SDK: https://software.ditto.live/swift/Ditto/4.11.0/index.html

## Swift/SwiftUI Integration Plan

The Swift implementation for Ditto CoT library follows a 7-phase approach:

### Phase 1: Foundation & Schema Integration (2-3 weeks)
- Swift Package Manager setup with proper module structure
- Schema code generation (JSON Schema → Swift Codable types)
- Build integration with existing Makefile system
- CI/CD pipeline extension for Swift builds and tests

### Phase 2: Core CoT Event Handling (3-4 weeks)
- CoTEvent model with builder pattern (similar to Rust implementation)
- XML parsing/serialization using XMLCoder or custom parser
- Event validation against XSD schema
- Type-safe event builders for each CoT event type

### Phase 3: Ditto SDK Integration (2-3 weeks)
- Document conversion following established CRDT optimization patterns
- Observer integration with Combine framework
- Async/await support for modern Swift concurrency
- R-field reconstruction handling

### Phase 4: SwiftUI Integration Layer (2-3 weeks)
- ObservableObject wrappers for CoT event streams
- View models for common CoT event display patterns
- Data binding utilities for real-time updates
- SwiftUI-specific convenience APIs

### Phase 5: Testing Infrastructure (3-4 weeks)
- Unit tests using XCTest framework
- Integration tests with mock Ditto instances
- Cross-language validation tests against Java/Rust implementations
- SwiftUI UI tests for interface components
- Performance benchmarks using XCTMetric

### Phase 6: Documentation & Examples (1-2 weeks)
- Swift-specific documentation following existing patterns
- Example iOS/macOS app demonstrating full integration
- Migration guides from other Ditto SDK patterns
- API reference generation using Swift-DocC

### Phase 7: Advanced Features & Optimization (2-3 weeks)
- CRDT optimization refinements for Swift-specific patterns
- Memory management optimization for iOS constraints
- Background processing support for iOS/macOS apps
- SwiftUI performance optimizations for large event lists

### Implementation Principles
- Protocol-oriented design following Swift best practices
- Value types where appropriate for thread safety
- Reference types for stateful components (stores, converters)
- Modern concurrency with async/await and actors where beneficial
- Platform-specific considerations for iOS/macOS/watchOS/tvOS

### When in Doubt, Ask First

Expand Down
79 changes: 74 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

# Build all languages
.PHONY: all
all: rust java csharp
all: rust java csharp swift

# Rust targets
.PHONY: rust
Expand Down Expand Up @@ -75,9 +75,34 @@ clean-csharp:
echo "C# build files not found. Skipping."; \
fi

# Swift targets
.PHONY: swift
swift:
@echo "Generating Swift types from schema..."
@if [ -f "swift/Package.swift" ]; then \
cd swift && \
swift build --product ditto-cot-codegen && \
.build/debug/ditto-cot-codegen --schema-path ../schema --output-path Sources/DittoCoTCore/Generated; \
echo "Building Swift library..."; \
swift build; \
echo "Building macOS example app..."; \
./build_macos_app.sh; \
else \
echo "Swift Package.swift not found. Skipping."; \
fi

.PHONY: clean-swift
clean-swift:
@echo "Cleaning Swift library..."
@if [ -f "swift/Package.swift" ]; then \
cd swift && swift package clean && rm -rf Sources/DittoCoTCore/Generated/*.swift; \
else \
echo "Swift Package.swift not found. Skipping."; \
fi

# Test targets
.PHONY: test
test: test-rust test-java test-csharp
test: test-rust test-java test-csharp test-swift

.PHONY: test-cross-lang
test-cross-lang: java-test-client
Expand Down Expand Up @@ -107,9 +132,18 @@ test-csharp:
echo "C# build files not found. Skipping tests."; \
fi

.PHONY: test-swift
test-swift:
@echo "Testing Swift library..."
@if [ -f "swift/Package.swift" ]; then \
cd swift && swift test; \
else \
echo "Swift Package.swift not found. Skipping tests."; \
fi

# Clean all
.PHONY: clean
clean: clean-rust clean-java clean-csharp
clean: clean-rust clean-java clean-csharp clean-swift
@echo "All libraries cleaned."

# Example targets
Expand All @@ -123,6 +157,35 @@ example-java:
@echo "Running Java example..."
@cd java && ./gradlew :example:runIntegrationClient

.PHONY: example-swift
example-swift:
@echo "Running Swift GUI example..."
@if [ -f "swift/Package.swift" ]; then \
cd swift && swift run CoTExampleApp & \
echo "App started in background. GUI should appear shortly."; \
echo "To stop: pkill -f CoTExampleApp"; \
else \
echo "Swift Package.swift not found. Skipping."; \
fi

.PHONY: build-macos-app
build-macos-app:
@echo "Building macOS CoTExampleApp.app bundle..."
@if [ -f "swift/Package.swift" ]; then \
cd swift && ./build_macos_app.sh; \
else \
echo "Swift Package.swift not found. Skipping."; \
fi

.PHONY: launch-macos-app
launch-macos-app:
@echo "Building and launching macOS CoTExampleApp.app..."
@if [ -f "swift/Package.swift" ]; then \
cd swift && ./build_macos_app.sh --launch; \
else \
echo "Swift Package.swift not found. Skipping."; \
fi

# Integration test target
.PHONY: test-integration
test-integration: example-rust example-java
Expand All @@ -139,17 +202,23 @@ help:
@echo " rust - Build Rust library"
@echo " java - Build Java library"
@echo " csharp - Build C# library"
@echo " swift - Build Swift library"
@echo " test - Run tests for all libraries"
@echo " test-rust - Run tests for Rust library"
@echo " test-java - Run tests for Java library"
@echo " test-csharp - Run tests for C# library"
@echo " test-swift - Run tests for Swift library"
@echo " test-cross-lang - Run cross-language multi-peer test"
@echo " example-rust - Run Rust example client"
@echo " example-java - Run Java example client"
@echo " example-rust - Run Rust example client"
@echo " example-java - Run Java example client"
@echo " example-swift - Run Swift GUI example app (terminal)"
@echo " build-macos-app - Build proper macOS app bundle"
@echo " launch-macos-app - Build and launch macOS app bundle"
@echo " test-integration - Run cross-language integration test"
@echo " clean - Clean all libraries"
@echo " clean-rust - Clean Rust library"
@echo " clean-java - Clean Java library"
@echo " clean-csharp - Clean C# library"
@echo " clean-swift - Clean Swift library"
@echo " java-test-client - Build Java test client for cross-language tests"
@echo " help - Show this help message"
32 changes: 30 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ ditto_cot = { git = "https://github.com/getditto-shared/ditto_cot" }
</dependency>
```

**Swift**:
```swift
.package(url: "https://github.com/getditto-shared/ditto_cot", from: "1.0.0")
```

**C#** (planned):
```xml
<PackageReference Include="Ditto.Cot" Version="1.0.0" />
Expand Down Expand Up @@ -54,6 +59,26 @@ CotEvent event = CotEvent.builder()
DittoDocument doc = event.toDittoDocument();
```

**Swift**:
```swift
import DittoCoT

let event = ApiDocument(
_id: "USER-123",
_c: 1,
_r: false,
a: "peer-123",
b: Date().timeIntervalSince1970 * 1000,
d: "USER-123",
e: "ALPHA-1",
contentType: "application/json",
data: "sample-data",
// ... other required fields
)

let unionDoc = DittoCoTDocument.api(event)
```

## 📁 Repository Structure

```
Expand All @@ -65,15 +90,16 @@ ditto_cot/
│ └── reference/ # API reference, schemas
├── schema/ # Shared schema definitions
├── rust/ # Rust implementation
├── java/ # Java implementation
├── java/ # Java implementation
├── swift/ # Swift implementation
└── csharp/ # C# implementation (planned)
```

## ✨ Key Features

- **🔄 100% Data Preservation**: All duplicate CoT XML elements maintained vs 46% in legacy systems
- **⚡ CRDT-Optimized**: 70% bandwidth savings through differential field sync
- **🌐 Cross-Language**: Identical behavior across Java, Rust, and C#
- **🌐 Cross-Language**: Identical behavior across Rust, Java, Swift, and C#
- **🛡️ Type-Safe**: Schema-driven development with strong typing
- **📱 SDK Integration**: Observer document conversion with r-field reconstruction
- **🔧 Builder Patterns**: Ergonomic APIs for creating CoT events
Expand All @@ -97,6 +123,7 @@ For detailed information, see our comprehensive documentation:
- **[Ditto SDK Integration](docs/integration/ditto-sdk.md)** - Observer patterns and DQL
- **[Rust Examples](docs/integration/examples/rust.md)** - Rust-specific patterns
- **[Java Examples](docs/integration/examples/java.md)** - Java-specific patterns
- **[Swift Examples](docs/integration/examples/swift.md)** - Swift/SwiftUI patterns
- **[Migration Guide](docs/integration/migration.md)** - Version upgrades and legacy system migration

### 📖 Reference
Expand All @@ -107,6 +134,7 @@ For detailed information, see our comprehensive documentation:
### 🎯 Language-Specific READMEs
- **[Rust Implementation](rust/README.md)** - Rust-specific APIs and patterns
- **[Java Implementation](java/README.md)** - Java-specific APIs and patterns
- **[Swift Implementation](swift/README.md)** - Swift/SwiftUI APIs and patterns

## 🚀 Quick Start

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ void setUp() throws JAXBException {
}

@Property
@Report(Reporting.GENERATED)
void fuzzValidCoTXmlShouldAlwaysParse(
@ForAll @AlphaChars @StringLength(min = 1, max = 50) String uid,
@ForAll @From("validCoTTypes") String type,
Expand All @@ -49,7 +48,6 @@ void fuzzValidCoTXmlShouldAlwaysParse(
}

@Property
@Report(Reporting.GENERATED)
void fuzzCoordinateEdgeCases(
@ForAll @AlphaChars @StringLength(min = 1, max = 20) String uid,
@ForAll @DoubleRange(min = -1000.0, max = 1000.0) double lat,
Expand Down Expand Up @@ -82,7 +80,6 @@ void fuzzSpecialDoubleValues(
}

@Property
@Report(Reporting.GENERATED)
void fuzzLargeStrings(
@ForAll @StringLength(min = 1000, max = 10000) String largeString
) {
Expand Down
6 changes: 6 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
Loading
Loading