This document describes the architecture of the Ditto CoT library, a multi-language system for translating between Cursor-on-Target (CoT) XML events and Ditto-compatible CRDT documents.
Quick Navigation: CRDT Optimization | Performance Analysis | API Reference | Integration Guide
- System Overview
- Repository Structure
- Core Components
- Data Flow
- Language Implementations
- Schema Management
- Integration Points
The Ditto CoT library provides a unified approach to handling CoT events across multiple programming languages, with a focus on:
- Data Preservation: 100% preservation of all CoT XML elements
- CRDT Optimization: Efficient synchronization in P2P networks
- Cross-Language Compatibility: Consistent behavior across Java, Rust, and C#
- Type Safety: Schema-driven development with strong typing
┌─────────────────┐ ┌──────────────────┐ ┌─────────────────┐
│ CoT XML │────▶│ Ditto CoT Lib │────▶│ Ditto Document │
│ Events │◀────│ (Java/Rust/C#) │◀────│ (CRDT) │
└─────────────────┘ └──────────────────┘ └─────────────────┘
│
▼
┌──────────────┐
│ JSON Schema │
│ (Shared) │
└──────────────┘
ditto_cot/
├── schema/ # Shared schema definitions
│ ├── cot_event.xsd # XML Schema for CoT events
│ └── ditto.schema.json # JSON Schema for Ditto documents
├── rust/ # Rust implementation
│ ├── src/
│ │ ├── cot_events/ # CoT event handling
│ │ ├── ditto/ # Ditto document types
│ │ └── lib.rs # Library entry point
│ └── tests/ # Integration tests
├── java/ # Java implementation
│ └── ditto_cot/
│ └── src/main/java/ # Java source code
└── csharp/ # C# implementation (planned)
Purpose: Parse and generate CoT XML events
Key Types:
CotEvent- Main event structurePoint- Geographic coordinates with accuracyDetail- Extensible detail section
Features:
- XML parsing with full element preservation
- Builder pattern for event creation
- Validation against CoT schema
Purpose: Handle duplicate XML elements for CRDT compatibility
Key Components:
- Stable key generation algorithm
- Two-pass parsing for duplicate detection
- Metadata optimization for bandwidth efficiency
Implementation:
- Java:
CRDTOptimizedDetailConverter - Rust:
crdt_detail_parser
Purpose: Type-safe representation of different CoT event types
Document Types:
MapItem- Location updates and map graphicsChat- Chat messagesFile- File sharing eventsApi- API/emergency eventsGeneric- Fallback for unknown types
Purpose: Bridge between CoT documents and Ditto SDK
Features:
- Observer document conversion
- R-field reconstruction
- DQL (Ditto Query Language) support
CoT XML → Parse → CotEvent → Transform → CotDocument → Serialize → Ditto CRDT
- Parse: XML parsed into structured
CotEvent - Transform: Event type determines document type
- Serialize: Document converted to CRDT-compatible format
Ditto CRDT → Deserialize → CotDocument → Transform → CotEvent → Generate → CoT XML
- Deserialize: CRDT document to typed structure
- Transform: Document converted back to event
- Generate: Event serialized to XML
Ditto Observer → Map<String,Object> → SDK Converter → Typed Document → Application
Build System: Cargo with custom build.rs for code generation
Key Features:
- Zero-copy XML parsing
- Compile-time type safety
- Async Ditto integration
- Performance-optimized
Dependencies:
quick-xmlfor XML processingserdefor serializationchronofor time handlingdittolive_dittofor SDK integration
Build System: Gradle with code generation
Key Features:
- Builder pattern APIs
- Jackson-based JSON handling
- Android compatibility
- Comprehensive test coverage
Dependencies:
- JAXB for XML processing
- Jackson for JSON
- Apache Commons for utilities
Status: Planned
Build System: .NET SDK
Location: schema/ditto.schema.json
Purpose:
- Define Ditto document structure
- Generate type-safe code
- Ensure cross-language compatibility
Code Generation:
- Rust:
typifycrate in build.rs - Java: JSON Schema to POJO
- C#: NJsonSchema (planned)
Location: schema/cot_event.xsd
Purpose:
- Validate CoT XML structure
- Document CoT event format
- Reference for implementations
Rust:
use dittolive_ditto::prelude::*;
let collection = ditto.store().collection("cot_events");
collection.upsert(doc).await?;Java:
DittoStore store = ditto.getStore();
store.execute("INSERT INTO cot_events DOCUMENTS (?)", dittoDoc);- Documents designed for CRDT merge semantics
- Stable keys enable differential sync
- Last-write-wins conflict resolution
- Type-safe document access
- Builder patterns for creation
- Observer pattern for updates
- Round-trip conversion support
- Schema-First: All data structures derived from schemas
- Cross-Language Parity: Identical behavior across implementations
- Performance: Optimize for P2P network efficiency
- Type Safety: Compile-time guarantees where possible
- Extensibility: Support for custom CoT extensions
- Schema Evolution: Version migration strategies
- Custom Extensions: Plugin system for domain-specific CoT types
- Performance: Further CRDT optimizations
- Tooling: CLI utilities for debugging and migration
- CRDT Optimization - Deep dive into CRDT algorithms and optimization techniques
- Performance Analysis - Benchmarks and performance characteristics
- Ditto SDK Integration - Real-world integration patterns
- Getting Started - Quick setup for development
- Schema Reference - Complete document schema specification
- API Reference - Complete API documentation for all languages