How anirudh-os/rustytasks works
Project type and purpose
• RustyTasks is a peer-to-peer, CRDT-backed command-line To-Do list application written in Rust.
• It is a monolithic CLI application that can run offline or in “interactive” P2P mode over TCP using Tokio, with Automerge as the CRDT engine.
File structure
Top-level files:
• Cargo.toml / Cargo.lock: Rust dependencies and metadata
• README.md: project description, usage, features
src/ directory modules:
• main.rs: CLI entry point and orchestration
• cli.rs: definition of command-line interface (clap config)
• tasks.rs: Task data model and local in-memory operations
• crdt.rs: Integration with Automerge document API
• identity.rs: Peer keypair/identity creation
• network.rs: Low-level P2P TCP layer (Tokio)
• peer.rs: Peer management, connection handling
• sync.rs: High-level sync logic (CRDT change exchange)
• .rs: Interactive display/UI logic
README for additional insights
• Uses Automerge for conflict-free merges (CRDT)
• Persists state to autocommit_doc.automerge on disk
• Async communications via Tokio over TCP
• Modules are explicitly designed to be extensible
Components
a. Main components
1. CLI Layer
– cli.rs / main.rs
2. Task Management Layer
– tasks.rs (Task CRUD API)
3. CRDT Layer
– crdt.rs (Automerge document)
4. Persistence
– Local disk file I/O (autocommit_doc.automerge)
5. Networking Layer
– identity.rs (peer identity / keys)
– network.rs (Tokio/TCP sockets)
– peer.rs (connection & peer table)
– sync.rs (CRDT change exchange protocol)
6. / Interactive UI
– display.rs (optional TUI or console rendering)
b. Relationships and interactions
– The CLI Layer receives user commands (add/remove/done/list/interactive).
– For any CRUD, CLI invokes Task Management, which updates the Automerge doc via the CRDT Layer.
– After each local change, Persistence writes the Automerge doc to disk.
– In “interactive” mode, the Networking Layer uses identity.rs to load/create peer identity, network.rs to open a TCP listener, peer.rs to manage connections, and sync.rs to exchange change deltas.
– Incoming remote CRDT changes are applied via the CRDT Layer, then merged into tasks.rs, and persisted.
– display.rs taps into Task Management and CRDT state to render an interactive console UI or prompt.
c. Architectural patterns / design principles
– Modular separation: CLI / Task / CRDT / Network / Persistence / UI
– Layered architecture with clear data flow: User → CLI → Task → CRDT → Persistence / Network
– Asynchronous & event-driven using Tokio for non-blocking I/O
– CRDT pattern for decentralized conflict-free data replication
– Single binary; all modules compiled into one executable
d. Key technologies & libraries
– Rust / Cargo
– clap (for cli.rs)
– Automerge (crdt.rs)
– tokio (network.rs, async runtime)
– TCP sockets (peer.rs)
– Local file I/O (std::fs for persistence)