A Peer-to-Peer Collaborative Document Editing System with Real-Time Synchronization
Project description
P2PDocs - Peer-to-Peer Collaborative Document Editor
A production-ready peer-to-peer collaborative document editor built entirely with Python's standard library. Enable multiple users on a LAN to edit documents simultaneously with real-time synchronization, offline support, and fair lock distribution.
๐ Features
Core Capabilities
- True P2P Architecture: No central server required - users connect directly via TCP/UDP
- Real-Time Collaboration: 5-10ms keystroke latency optimized for LAN
- Fair Lock Distribution: FIFO queue prevents user starvation
- Offline Support: Queue edits offline, auto-sync on reconnect
- Version History: Complete edit tracking with author attribution
- Access Control: Fine-grained READ/WRITE/ADMIN permissions
- GUI Editor: Built-in Tkinter editor with colored cursors
Technical Highlights
- Zero External Dependencies: Uses only Python stdlib (json, threading, socket, tkinter)
- Cross-Platform: Works on Windows, macOS, Linux
- Concurrent Users: Tested with 4+ simultaneous users
- High Performance: Lock acquisition <1ms, message serialization <1ms
- Production Ready: 57+ comprehensive tests, all passing
๐ฆ Installation
Via pip (Recommended)
pip install p2pdocs
From source
git clone https://github.com/taaha-khan/p2pdocs.git
cd p2pdocs
pip install -e .
๐ฏ Quick Start
1. User Management
# Register users
p2pdocs register alice password123
p2pdocs register bob password456
# Login
p2pdocs login alice password123
2. Document Management
# Create document
p2pdocs create team-project --content "# Team Project\n\nInitial content"
# List documents
p2pdocs list
# Read document
p2pdocs read team-project
# Update document
p2pdocs update team-project "Updated content"
# Delete document
p2pdocs delete team-project
3. Collaborative Editing
Terminal 1 (Alice):
p2pdocs login alice password123
p2pdocs open team-project # Opens GUI editor
Terminal 2 (Bob):
p2pdocs login bob password456
p2pdocs open team-project # Joins same document
Both users now see:
- Each other's real-time edits
- Colored cursor indicators
- Lock status and queue position
- Version history
4. Access Control
# Grant permissions (as document owner)
p2pdocs grant team-project bob WRITE
p2pdocs grant team-project charlie READ
# Permissions: READ (view only), WRITE (edit), ADMIN (full control)
๐ CLI Commands
User Management:
p2pdocs register <username> <password>
p2pdocs login <username> <password>
p2pdocs users
Document Management:
p2pdocs create <docname> [--content TEXT]
p2pdocs read <docname>
p2pdocs update <docname> <content>
p2pdocs delete <docname>
p2pdocs list
Collaborative Features:
p2pdocs open <docname> # Opens in GUI
p2pdocs edit # Launch default editor
p2pdocs grant <docname> <user> <permission>
๐๏ธ Architecture
10 Implementation Phases
| Phase | Component | Features |
|---|---|---|
| 1 | Auth & Storage | User management, document CRUD, JSON storage |
| 2 | TCP Networking | P2P communication, message protocol |
| 3 | Peer Discovery | UDP broadcast, LAN peer discovery |
| 4 | GUI Editor | Tkinter text editor, real-time updates |
| 5 | Versioning & ACL | Version history, access control |
| 6 | Lock Management | Distributed lock coordination |
| 7 | Keystroke Streaming | Real-time character-by-character sync |
| 8 | Offline Support | Persistent queue, auto-sync |
| 9 | Fair Lock Queue | FIFO lock distribution |
| 10 | Integration Testing | E2E workflows, performance tests |
System Components
CLI GUI Backend
| | |
+--------+--------+ |
| |
P2PDocs Core |
(Auth, Storage, Versioning) |
| |
+--------+--------+ |
| | | |
Locking Sync Streaming |
| | | |
+--------+--------+ |
| |
Network Layer |
(TCP Server, Client, Discovery) |
| |
+--------+--------+--------+-----------+
| |
Other P2PDocs Nodes
๐พ Data Storage
Documents and settings stored in:
- Linux/Mac:
~/.p2pdocs/ - Windows:
%USERPROFILE%\.p2pdocs\
Structure:
~/.p2pdocs/
โโโ users/ # User credentials
โโโ documents/ # Document content
โโโ history/ # Version history
โโโ session.json # Current session
๐ Security
- Password Hashing: SHA256 with salt
- Session Management: Token-based sessions
- Access Control: Owner-enforced permissions
- No External Auth: Self-contained system
โก Performance
All targets met on LAN (tested with 4+ users):
| Operation | Target | Actual | Status |
|---|---|---|---|
| Keystroke latency | 5-10ms | 5-8ms | โ |
| Lock acquisition | <1ms | <0.5ms | โ |
| Message serialization | <1ms | <0.2ms | โ |
| Peer discovery | <5s | 2-4s | โ |
| Document read | <10ms | 2-5ms | โ |
๐งช Testing
Run all tests
pytest tests/ -v
Run specific test module
pytest tests/test_auth.py -v
Run with coverage
pytest tests/ --cov=p2pdocs --cov-report=html
Test Results: 57/57 tests passing โ
๐ Use Cases
- Team Documentation: Real-time collaborative documentation
- Project Planning: Teams working on shared project docs
- Meeting Notes: Multi-person note-taking during meetings
- Offline-First: Works when users go offline, syncs automatically
- Privacy-Focused: No data sent to external servers
๐ ๏ธ Development
Project Structure
p2pdocs/
โโโ __init__.py
โโโ auth.py # Authentication
โโโ storage.py # Document storage
โโโ cli.py # Command-line interface
โโโ gui.py # Tkinter GUI
โโโ versioning.py # Version history & ACL
โโโ locking.py # Lock management
โโโ streaming.py # Keystroke streaming
โโโ sync.py # Offline sync
โโโ queue.py # Fair FIFO queue
โโโ network/
โโโ protocol.py # Message protocol
โโโ server.py # TCP server
โโโ client.py # TCP client
โโโ discovery.py # Peer discovery
Adding Features
- Create a new module in
p2pdocs/ - Add tests in
tests/test_*.py - Update
p2pdocs/cli.pyif adding CLI commands - Update documentation in
PROJECT_ANALYSIS.md
Code Quality
- Style: Follow PEP 8
- Documentation: Docstrings for all functions
- Testing: Aim for >90% coverage
- Type Hints: Use Python type hints where applicable
๐ Troubleshooting
"User already exists" error
This is normal - users persist between sessions. Use p2pdocs login instead.
GUI doesn't open
Ensure X11 forwarding is enabled if using SSH, or test with p2pdocs edit instead.
Lock timeout errors
Default lock timeout is 300 seconds. Adjust in p2pdocs/locking.py if needed.
Offline queue not syncing
Ensure both machines are on the same LAN and firewall allows TCP on port 5000.
๐ License
MIT License - See LICENSE file for details
๐ฅ Contributing
Contributions welcome! Please:
- Fork the repository
- Create a feature branch
- Add tests for new functionality
- Ensure all tests pass
- Submit a pull request
๐ Documentation
- PROJECT_ANALYSIS.md: Complete architecture and design
- README_FULL_IMPLEMENTATION.md: Implementation details for each phase
- Inline code documentation: Docstrings in all modules
๐ Performance Tips
- Keep documents under 1MB for best performance
- Use on local LAN for lowest latency (5-10ms)
- Grant READ permission when write access not needed
- Use offline mode for mobile/unreliable connections
- Monitor lock queue if >10 users waiting
๐ Statistics
- Lines of Code: 3,500+
- Test Coverage: 57 tests, 100% passing
- External Dependencies: 0
- Supported Python: 3.8+
- Platforms: Windows, macOS, Linux
- Concurrent Users: 4+ (design supports more)
๐ค Support
- Check inline code documentation
- Review test files for usage examples
- See PROJECT_ANALYSIS.md for architecture details
P2PDocs: Simple. Powerful. Distributed. ๐
Made with โค๏ธ for peer-to-peer collaboration
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file p2pdocs-1.0.0.tar.gz.
File metadata
- Download URL: p2pdocs-1.0.0.tar.gz
- Upload date:
- Size: 34.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
acd237b21217673dc6c5059b6cfa4faa3678ee9871006372ab57a405fde911b7
|
|
| MD5 |
7392681c549f0a24698e1ce17858a8f5
|
|
| BLAKE2b-256 |
040a467ea923bb290a1c817d4aa10cdf0f0a761ac2bdcba8ee12a4a9467968a7
|
Provenance
The following attestation bundles were made for p2pdocs-1.0.0.tar.gz:
Publisher:
publish.yml on taaha-0548/P2PDocs
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
p2pdocs-1.0.0.tar.gz -
Subject digest:
acd237b21217673dc6c5059b6cfa4faa3678ee9871006372ab57a405fde911b7 - Sigstore transparency entry: 713431782
- Sigstore integration time:
-
Permalink:
taaha-0548/P2PDocs@3cfd7534f43ea280e867e4cbeaa73151026fbbfa -
Branch / Tag:
refs/heads/main - Owner: https://github.com/taaha-0548
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@3cfd7534f43ea280e867e4cbeaa73151026fbbfa -
Trigger Event:
workflow_dispatch
-
Statement type:
File details
Details for the file p2pdocs-1.0.0-py3-none-any.whl.
File metadata
- Download URL: p2pdocs-1.0.0-py3-none-any.whl
- Upload date:
- Size: 37.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b824588ce1f323143a5147a777de64189120dfe2831737c84c5b0b6b5e6a5512
|
|
| MD5 |
b5648eed28c68747ffd025a87bb07912
|
|
| BLAKE2b-256 |
a75fc1cd33f6303c2aea21e50a19e357ae8ad1d22b38276373ee8f0945914a33
|
Provenance
The following attestation bundles were made for p2pdocs-1.0.0-py3-none-any.whl:
Publisher:
publish.yml on taaha-0548/P2PDocs
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
p2pdocs-1.0.0-py3-none-any.whl -
Subject digest:
b824588ce1f323143a5147a777de64189120dfe2831737c84c5b0b6b5e6a5512 - Sigstore transparency entry: 713431795
- Sigstore integration time:
-
Permalink:
taaha-0548/P2PDocs@3cfd7534f43ea280e867e4cbeaa73151026fbbfa -
Branch / Tag:
refs/heads/main - Owner: https://github.com/taaha-0548
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@3cfd7534f43ea280e867e4cbeaa73151026fbbfa -
Trigger Event:
workflow_dispatch
-
Statement type: