π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
Update CLAUDE.md documentation to reflect current codebase
Manav Rathi187a72901329
diff --git a/rust/CLAUDE.md b/rust/CLAUDE.mdindex 572604aaa6..98ffd62dfc 100644--- a/rust/CLAUDE.md+++ b/rust/CLAUDE.md@@ -24,19 +24,23 @@ cargo fmt --check```**Why CI might fail even after running these:**+- Skipping any command above- Assuming auto-fix tools handle everything (they don't)- Not fixing warnings that clippy reports- Making changes after running the checks### Commit & PR Message Rules+**These rules apply to BOTH commit messages AND pull request descriptions**+- Keep messages CONCISE (no walls of text)- Subject line under 72 chars (no body text unless critical)- NO emojis- NO promotional text or links (except Co-Authored-By line)### Additional Guidelines+- Check `git status` before committing to avoid adding temporary/binary files- Never commit to main branch- All CI checks must pass - run the checklist commands above before committing or creating PR@@ -74,61 +78,76 @@ The codebase must pass the GitHub Actions workflow at `../.github/workflows/rust## Architecture Overview-This is a Rust CLI for ente.io, providing encrypted photo backup and export functionality. The project is migrating from a Go implementation and follows a modular architecture:+CLI for ente.io with end-to-end encryption, multi-account and multi-app support.### Core Modules**`api/`** - HTTP client for ente.io API- `client.rs`: Base HTTP client with auth token management-- Authentication uses SRP (Secure Remote Password) protocol-- Handles retry logic and rate limiting+- `auth.rs`: SRP (Secure Remote Password) authentication implementation+- `methods.rs`: API method implementations (collections, files, user info)+- `models.rs`: API request/response data structures+- `retry.rs`: Retry logic with exponential backoff for rate limiting**`crypto/`** - Cryptographic operations using libsodium- `argon.rs`: Argon2id key derivation- `chacha.rs`: ChaCha20-Poly1305 encryption/decryption+- `stream.rs`: XChaCha20-Poly1305 streaming decryption for large files- `kdf.rs`: Blake2b key derivation- All crypto MUST use `libsodium-sys-stable` (statically linked)**`storage/`** - SQLite persistence layer- `schema.rs`: Database schema for accounts, files, collections-- `account.rs`: Account CRUD operations-- `sync.rs`: Sync state management+- `account.rs`: Account CRUD operations with multi-app support+- `sync.rs`: Sync state management (last sync times, file tracking)+- `config.rs`: Key-value configuration store- Uses `rusqlite` with bundled SQLite for portability-**`cli/`** - Command-line interface+**`cli/`** - Command-line argument parsing-- `account.rs`: Account management (add, list, update)-- `export.rs`: Photo export orchestration+- `account.rs`: Account command argument structures+- `export.rs`: Export command argument structures+- `version.rs`: Version information constants- Uses `clap` for argument parsing+**`commands/`** - Command implementation logic++- `account.rs`: Account management implementation (add, list, update, get-token)+- `export.rs`: Photo export orchestration with filtering support+- `sync.rs`: Synchronization logic execution+**`models/`** - Data structures- `account.rs`: Account model with encrypted credentials- `file.rs`: File metadata and encryption info-- `collection.rs`: Albums/collections+- `collection.rs`: Albums/collections with sharing support+- `metadata.rs`: Decrypted file metadata (title, timestamps, location)+- `filter.rs`: Export filtering options (shared/hidden albums, emails)- `error.rs`: Error types using `thiserror`**`sync/`** - Synchronization engine-- Handles incremental sync with ente servers-- File download and decryption-- Collection management+- `engine.rs`: Core sync orchestration and state management+- `files.rs`: File synchronization logic+- `download.rs`: File download and decryption implementation-### Key Implementation Details+**`utils/`** - Utility functions-1. **Authentication Flow**: SRP-based authentication storing tokens in SQLite-2. **Multi-Account Support**: HashMap-based token storage per account-3. **File Organization**: Export to `YYYY/MM-Month/` directory structure-4. **Encryption**: All files encrypted with ChaCha20-Poly1305, keys derived via Argon2/Blake2b-5. **Async Runtime**: Uses tokio with full features-6. **Error Handling**: Propagate errors with `?` operator, use `anyhow` for context+- `mod.rs`: Config directory management with platform-specific defaults-## Current Status+### Key Implementation Details-The project has completed foundational components (crypto, storage, models) and is currently implementing the API client for authentication and sync. See `CONVERSION_PLAN.md` for detailed implementation roadmap.+1. **Authentication Flow**: SRP-based authentication storing tokens in SQLite, supports multiple apps (photos, locker, auth)+2. **Multi-Account Support**: SQLite-based storage with per-account/per-app token management+3. **File Organization**: Export to `export_dir/AlbumName/filename` structure (files in "Uncategorized" if no album)+4. **Export Filtering**: Support for filtering by shared/hidden albums and specific user emails+5. **Encryption**: Files encrypted with ChaCha20-Poly1305, streaming decryption for large files, keys derived via Argon2/Blake2b+6. **Async Runtime**: Uses tokio with full features for concurrent operations+7. **Error Handling**: Propagate errors with `?` operator, use `anyhow` for context+8. **Configuration**: Platform-specific config directories (Linux: ~/.config/ente-cli, macOS: ~/Library/Application Support/ente-cli, Windows: %APPDATA%/ente-cli)## Security Guidelines@@ -144,5 +163,4 @@ The project has completed foundational components (crypto, storage, models) and## Environment Variables- `ENTE_CLI_CONFIG_DIR`: Override default config directory-- `ENTE_LOG`: Set log level (debug, info, warn, error)-- `RUST_LOG`: Alternative log level configuration+- `RUST_LOG`: Set log level (debug, info, warn, error, trace)diff --git a/rust/CONVERSION_PLAN.md b/rust/CONVERSION_PLAN.mddeleted file mode 100644index 8f7bd5785c..0000000000--- a/rust/CONVERSION_PLAN.md+++ /dev/null@@ -1,288 +0,0 @@-# Ente CLI Rust Conversion Plan--## Current Status-The Rust CLI has achieved **feature parity with the Go CLI for photos app** core functionality! Export, sync, and incremental updates are fully working with proper file decryption, metadata handling, progress indicators, and deduplication.--### β Photos App Core Features - COMPLETE-- **Export**: Full workflow with decryption, metadata, deduplication, live photos-- **Sync**: Full and incremental sync with downloads, progress tracking-- **Account**: Multi-account support with SRP authentication-- **Storage**: SQLite with efficient schema and indexing-- **Crypto**: All encryption/decryption working (Argon2, XChaCha20-Poly1305, XSalsa20-Poly1305)--### π Photos App Remaining Features-- Export filters (by album, date range, shared/hidden)-- Resume interrupted downloads-- EXIF/location data preservation-- Thumbnail generation-- Album symlinks--### β Not Planned (Auth App Features)-- Locker export-- 2FA/Auth export-These features are specific to the auth app and not needed for photos functionality.--## Completed Components β--### Core Infrastructure-- β Project structure and dependencies (libsodium-sys-stable for crypto)-- β SQLite storage layer with schema for accounts, files, collections-- β Data models (Account, File, Collection, Error types)-- β CLI command structure (account, export, version commands)--### Cryptography Module (`/rust/src/crypto/`)-- β Argon2 key derivation (`argon.rs`)-- β Blake2b login key derivation (`kdf.rs`)-- β XSalsa20-Poly1305 (secret_box) for key decryption (`chacha.rs`)-- β **Streaming XChaCha20-Poly1305** for file decryption (`stream.rs`)-- β Chunked decryption for large files (4MB chunks)-- β libsodium initialization and helpers--### API Client (`/rust/src/api/`)-- β **Base HTTP client with token management** (`client.rs`)-- β **Request/Response models** (`models.rs`)- - β Collection models- - β File models with metadata- - β User and auth response models-- β **Core API methods** (`methods.rs`)- - β `get_collections()` - Fetch collections- - β `get_collection_files()` - Fetch files with pagination- - β `download_file()` - Download encrypted files--### Export Command (`/rust/src/commands/export.rs`)-- β **Full export workflow implemented**-- β Load stored credentials from SQLite-- β Decrypt collection keys using master key-- β Decrypt file keys using collection keys-- β Decrypt file data using streaming XChaCha20-Poly1305-- β Decrypt and parse metadata for original filenames-- β **Public magic metadata support for renamed files**-- β Create date-based directory structure (YYYY/MM-Month/)-- β Skip already exported files (local deduplication)-- β **Hash-based deduplication to prevent duplicate exports**-- β **Live photo extraction from ZIP archives**-- β Progress indicators with file counts and progress bars-- β Export summary with statistics--### Account Management (`/rust/src/commands/account.rs`)-- β **Account list** - Display all configured accounts-- β **Account add** - Full SRP authentication implemented-- β Store encrypted credentials in SQLite-- β 2FA/OTP support-- β Proper key derivation with Argon2--### Metadata Handling (`/rust/src/models/metadata.rs`, `/rust/src/models/file.rs`)-- β **Metadata decryption and parsing**-- β Extract original filenames-- β File type detection (Image, Video, LivePhoto)-- β Public magic metadata support for renamed files-- β Edited name prioritization (public magic metadata β regular metadata)--## Recently Completed π--### Sync Command (`/rust/src/commands/sync.rs`) - β COMPLETE-- β **Full sync workflow implemented**-- β Metadata-only mode for fast syncing-- β Full mode with file downloads-- β Per-collection incremental sync tracking-- β Store sync state in SQLite-- β Handle deleted files/collections-- β **Integrated file downloads with progress indicators**-- β Hash-based deduplication during downloads-- β Correct counting logic for new/updated/deleted items--### File Download Manager (`/rust/src/sync/download.rs`) - β COMPLETE-- β Download individual files with decryption-- β Parallel download infrastructure (tokio tasks)-- β **Progress bars using indicatif**-- β **Live photo extraction from ZIP archives**-- β Proper error handling and retry logic-- β Memory-efficient streaming downloads-- β Hash-based deduplication--## Remaining Components π--### Database and Storage (`/rust/src/storage/`) - β COMPLETE-- β **Platform-specific config directory** (`~/.config/ente-cli/`)-- β Avoid conflicts with Go CLI path-- β SQLite schema with proper foreign keys-- β Collections and files storage-- β Per-collection sync state tracking-- β Content hash storage for deduplication-- β Efficient indexes for lookups--### Account Management Enhancements-- [ ] **Account remove** - Delete account and credentials-- [ ] **Token refresh** - Handle expired tokens--### Advanced Export Features-- [ ] Export filters (by album, date range)-- [ ] Shared album support-- [ ] Hidden album handling-- β **Live photos (ZIP file extraction)** - Implemented-- [ ] Thumbnail generation-- [ ] Export to different formats--### API Client Enhancements-- [ ] Retry logic with exponential backoff-- [ ] Rate limiting (429 status codes)-- [ ] Request/response logging-- [ ] Error recovery-- [ ] Connection pooling--### File Processing-- [ ] EXIF data extraction-- [ ] Location data handling-- [ ] Creation/modification time preservation-- [ ] Symlink creation for albums-- β **Duplicate detection by hash** - Implemented with SHA-512--### Download Manager Enhancements-- β **Parallel downloads** - Using tokio tasks-- [ ] Resume interrupted downloads-- [ ] Bandwidth throttling-- β **Progress tracking per file** - Using indicatif progress bars-- [ ] Temp file management--## Testing Status π§ͺ--### Successfully Tested β-- β Export with real account-- β Small file decryption (JPEG images)-- β Large file decryption (33MB RAW file)-- β Metadata extraction for filenames-- β Public magic metadata for renamed files-- β Date-based directory creation-- β File deduplication (local and hash-based)-- β Incremental sync (per-collection)-- β Live photo extraction from ZIP-- β Progress indicators during downloads-- β Hash-based duplicate detection--### Manual Testing Checklist-- [x] Can export from existing Ente account-- [x] Lists all albums/collections correctly-- [x] Downloads files to correct folder structure (YYYY/MM-Month/)-- [x] Correctly decrypts files-- [x] Extracts original filenames from metadata-- [x] Handles renamed files from public magic metadata-- [x] Sync command fetches collections and files-- [x] Metadata-only sync mode works-- [x] Full sync mode with file downloads-- [x] Database stored in ~/.config/ente-cli/-- [x] Handles incremental sync (only new files)-- [x] Hash-based deduplication prevents duplicates-- [x] Live photos extracted correctly-- [x] Progress bars show download progress-- [ ] Resumes interrupted downloads-- [ ] Multi-account export works-- [ ] Export filters (by album, date range) work--## Migration from Go CLI--### Feature Parity Progress (Photos App)-- [x] Multi-account support (storage)-- [x] Photos export (complete with all features)-- [x] Sync command (full implementation with downloads)-- [x] Album organization-- [x] Deduplicated storage (hash-based)-- [x] Platform-specific config paths-- [x] SRP authentication (fully implemented)-- [x] Full sync with file downloads-- [x] Incremental sync (per-collection tracking)-- [x] Public magic metadata support-- [x] Live photo extraction-- [x] Progress indicators-- [ ] Export filters (albums, shared, hidden)-- [ ] Shared album support--### Not Planned (Auth App Features)-- [ ] Locker export (auth app)-- [ ] Auth (2FA) export (auth app)--### Data Migration-- [ ] BoltDB to SQLite migration tool-- [ ] Preserve sync state-- [ ] Migrate account credentials--## Recent Achievements π--1. **Full Sync Implementation with Downloads**- - Complete sync engine with per-collection tracking- - Incremental sync with proper timestamp management- - Integrated file downloads with progress bars- - Hash-based deduplication prevents duplicate downloads- - Live photo extraction from ZIP archives--2. **Public Magic Metadata Support**- - Handles renamed files correctly- - Prioritizes edited names over original names- - Decrypts both regular and public magic metadata--3. **Progress Indicators**- - Download progress bars using indicatif- - Real-time status updates during sync- - Accurate counting of new/updated/deleted items--4. **Hash-Based Deduplication**- - SHA-512 content hashing for files- - Prevents duplicate exports across collections- - Efficient database indexing for hash lookups- - Tested and verified with duplicate files--## Next Actions π--### Photos App - Remaining Features--1. **Export Filters**- - Filter by album/collection name- - Filter by date range- - Export only specific albums- - Support for shared albums- - Support for hidden albums--2. **Resume Capability**- - Track partially downloaded files- - Resume interrupted downloads- - Verify partial file integrity--3. **Advanced Features**- - Thumbnail generation- - EXIF data preservation- - Location data handling- - Creation/modification time preservation- - Symlink creation for album organization--4. **Performance Optimizations**- - Connection pooling for API requests- - Bandwidth throttling options- - Configurable parallel download limits- - Memory usage optimization for large exports--### Infrastructure Improvements--1. **Error Handling**- - Retry logic with exponential backoff- - Better rate limiting (429 handling)- - Graceful recovery from network errors--2. **Account Management**- - Account remove command- - Token refresh mechanism- - Multiple endpoint support--3. **Data Migration**- - BoltDB to SQLite migration tool- - Preserve sync state during migration- - Account credential migration--## Environment Variables-- `ENTE_CLI_CONFIG_DIR` - Override config directory location-- `ENTE_LOG` / `RUST_LOG` - Set log level (debug, info, warn, error)--## Key Implementation Notes-1. **Crypto**: Successfully using libsodium-sys-stable for all operations-2. **Streaming**: Proper streaming XChaCha20-Poly1305 implementation-3. **Storage**: SQLite working well for account and credential storage-4. **Async**: Tokio runtime properly configured-5. **Memory**: Chunked processing prevents memory issues with large files\ No newline at end of filediff --git a/rust/src/utils/mod.rs b/rust/src/utils/mod.rsindex 434b450e8b..45841f7d90 100644--- a/rust/src/utils/mod.rs+++ b/rust/src/utils/mod.rs@@ -8,11 +8,6 @@ pub fn get_cli_config_dir() -> crate::Result<PathBuf> {return Ok(PathBuf::from(config_dir));}- // For backward compatibility- if let Ok(config_dir) = std::env::var("ENTE_CLI_CONFIG_PATH") {- return Ok(PathBuf::from(config_dir));- }-// Use platform-specific config directory// On Linux: ~/.config/ente-cli// On macOS: ~/Library/Application Support/ente-cli