Communitas Core
Core business logic library for the Communitas P2P collaboration platform.
Overview
Communitas Core is a Rust library that provides all the essential functionality for building decentralized collaboration applications. It's used by both the desktop application and headless daemon, providing a consistent API without any UI dependencies.
Features
- Post-Quantum Cryptography: ML-DSA signatures and ML-KEM key exchange
- Connection Words (four-word networking): Human-readable IP:port encoding for peer dialing
- Gossip Overlay Network: Distributed P2P communication layer
- CRDT Document Sync: Conflict-free collaborative editing with Yrs
- Encrypted Storage: Platform-specific secure credential storage (keyring)
- Presence Service: Real-time user availability tracking
- Message Synchronization: Reliable message delivery with retries
- Authentication: Passkey-based authentication with platform integration
- Storage Management: Virtual disks with content addressing (BLAKE3)
Architecture
Core Components
communitas-core/
├── auth_service.rs # Authentication and session management
├── core_context.rs # Main application context
├── crdt.rs # CRDT document operations
├── doc_replicator.rs # Document replication logic
├── encrypted_storage/ # Secure credential storage
├── gossip/ # P2P gossip overlay
│ ├── context.rs # Gossip network context
│ ├── coordinator.rs # Message coordination
│ ├── crdt_sync.rs # CRDT synchronization
│ ├── groups.rs # Group management
│ ├── identity.rs # Identity operations
│ ├── membership.rs # Membership tracking
│ ├── presence.rs # Presence detection
│ ├── pubsub.rs # Publish-subscribe messaging
│ ├── rendezvous.rs # Peer rendezvous
│ ├── transport.rs # Network transport
│ └── types.rs # Shared types
├── identity.rs # Identity + connection word encoding helpers
├── keystore.rs # Cryptographic key storage
├── local_storage.rs # Local data persistence
├── message_sync.rs # Message synchronization
├── presence_service.rs # Presence tracking service
├── security/ # Security primitives
└── storage/ # Storage abstractions
Quick Start
As a Library
Add to your Cargo.toml:
[]
= { = "../communitas-core" }
= { = "1.39", = ["full"] }
Basic Usage
use ;
async
Authentication System
Public-Key Identity & Connection Words
Identities are public keys (pubkey_hex). Four-word networking is used only to encode connection endpoints (IP:port) for friend-to-friend dialing.
use ;
use SocketAddr;
// Encode IP:port to connection words
let addr: SocketAddr = "192.168.1.100:9000".parse?;
let words = conn_words?;
// → "ocean-forest-moon-star"
// Decode words back to IP:port
let decoded = conn_from_words?;
assert_eq!;
Authentication Flow
use ;
let core_ctx = new.await?;
let auth = new.await?;
// Register new user
let session = auth.register.await?;
// Login existing user
let session = auth.login.await?;
// Logout
auth.logout.await?;
Gossip Network
Network Initialization
use ;
let core_ctx = new.await?;
let gossip = new.await?;
// Start gossip network
gossip.start.await?;
// Join a topic
gossip.subscribe.await?;
// Publish message
gossip.publish.await?;
Peer Discovery
// Discover peers via rendezvous
let peers = gossip.discover_peers.await?;
for peer in peers
// Check online presence
let is_online = gossip.is_online.await?;
CRDT Document Collaboration
Collaborative Editing
use ;
// Create shared document
let doc = new?;
// Apply local edit
doc.insert?;
doc.insert?;
// Get operations for sync
let ops = doc.get_operations_since?;
// Apply remote operations
for op in remote_ops
// Get current text
let text = doc.to_string?;
Document Replication
use DocReplicator;
let replicator = new.await?;
// Replicate document across peers
replicator.replicate_doc.await?;
// Subscribe to document updates
replicator.subscribe_doc.await?;
Encrypted Storage
Platform Integration
The encrypted storage system uses platform-specific credential managers:
- macOS: Keychain
- Windows: Windows Credential Manager
- Linux: Secret Service API (libsecret)
Storage Management
Virtual Disks
use ;
// Create virtual disk for entity
let disk = new.await?;
// Write file
disk.write.await?;
// Read file
let content = disk.read.await?;
// List files
let files = disk.list.await?;
Content Addressing
use ContentAddressed;
// Store content-addressed data
let hash = storage.store_content.await?;
// → BLAKE3 hash
// Retrieve by hash
let content = storage.get_content.await?;
Message Synchronization
Reliable Messaging
use MessageSync;
let sync = new.await?;
// Send message with automatic retry
sync.send_reliable.await?;
// Receive messages
let messages = sync.receive_since.await?;
for msg in messages
Presence Service
Online Status Tracking
use PresenceService;
let presence = new.await?;
// Set own status
presence.set_status.await?;
// Check peer status
let status = presence.get_status.await?;
println!;
// Subscribe to presence changes
presence.subscribe.await?;
Security
Post-Quantum Cryptography
All cryptographic operations use post-quantum algorithms:
use ;
// Create ML-DSA signer
let signer = new?;
// Sign data
let signature = signer.sign?;
// Verify signature
let verifier = from_public_key?;
let is_valid = verifier.verify?;
Key Exchange
use ;
// Alice generates keypair
let alice_kex = new?;
let alice_public = alice_kex.public_key;
// Bob generates keypair and creates shared secret
let bob_kex = new?;
let bob_public = bob_kex.public_key;
let bob_shared = bob_kex.derive_shared_secret?;
// Alice creates shared secret
let alice_shared = alice_kex.derive_shared_secret?;
assert_eq!;
Development
Building
Testing
# Run all tests
# Run with logging
RUST_LOG=debug
# Run specific test
# Run property-based tests
Linting
# Strict linting (enforces no panics in production)
# Format code
Configuration
Environment Variables
| Variable | Description | Default |
|---|---|---|
COMMUNITAS_DATA_DIR |
Data storage directory | ~/.communitas |
COMMUNITAS_LOG_LEVEL |
Logging level | info |
RUST_LOG |
Detailed logging filter | - |
Configuration File
Core can be configured via TOML:
[]
= "ocean-forest-moon-star"
= "Alice"
= "Desktop-01"
[]
= ["bootstrap.communitas.network:8080"]
= true
= 8080
[]
= "~/.communitas"
= 500
[]
= true
= 90
[]
= "info"
= "json"
API Documentation
Full API documentation is available via rustdoc:
Performance Characteristics
- Message Latency: <100ms local, <500ms remote
- Storage Operations: <100ms for content-addressed reads
- CRDT Sync: <200ms for typical document operations
- Memory Usage: ~50MB baseline, scales with active documents
- CPU Usage: <5% idle, scales with network activity
Security Considerations
- Zero-Panics Policy: Production code forbids
unwrap(),expect(), andpanic! - Post-Quantum Ready: All cryptography uses ML-DSA and ML-KEM
- Secure Storage: Platform-specific credential managers
- End-to-End Encryption: All messages encrypted by default
- Forward Secrecy: Perfect forward secrecy for all sessions
- No Trusted Third Parties: Fully decentralized architecture
Troubleshooting
Common Issues
Identity Generation Fails
# Check four-word-networking dictionary (connection words)
Gossip Network Won't Start
# Check port availability
# Enable debug logging
RUST_LOG=communitas_core::gossip=debug
Storage Errors
# Check permissions
# Reset storage (development only)
Authentication Issues
# Check keyring access
# Clear credentials (macOS)
Contributing
See ../../docs/development/contributing.md
License
Dual-licensed under AGPL-3.0-or-later and commercial license.
See Also
- Communitas Desktop - Desktop application using this core
- Communitas Headless - Headless daemon using this core
- Architecture Documentation - System architecture details
- API Reference - Complete API documentation