DocHub
Progressive content sync — handshake protocol, speed gating, multi-phase download orchestration

Sync System

Overview

The sync system keeps local content in sync with the server using a handshake-based protocol with progressive downloading.

Handshake Flow

  1. Speed test — app measures internet speed; sync is skipped if below 1.5 Mbps
  2. Build payload — app calculates MD5 checksums of all local JSON files
  3. Send handshake — payload sent to /functions/v1/handshake
  4. Receive manifest — server responds with list of updates needed
  5. Progressive sync — orchestrator coordinates multi-phase updates

Handshake Endpoint

POST https://kagtryxgjwavupzlmlzv.supabase.co/functions/v1/handshake

The request payload includes checksums for all system JSONs. The server compares these against its current versions and returns a manifest of what needs updating.

Progressive Sync Phases

Phase Description
1. Analyze Compare local vs server versions
2. Storage check Verify device has enough free space
3. Download courses CourseDownloader handles large files with progress tracking
4. Update system JSONs Each updater handles its own JSON type

System JSONs (never deleted)

These files cannot be deleted by the user or the sync process — they are always present:

  • ads.json
  • background.json
  • core_segments.json
  • FAQs.json
  • shop.json

Data Storage

Location Purpose
AppData/ Bundled assets (shipped with the APK)
Device internal storage Runtime copy — GeneralSettingsService copies from AppData on first run

Internal storage mirrors the AppData folder structure. The app always reads from internal storage at runtime.

Audio Encryption

Audio files are stored encrypted on the device. Encryption/decryption is handled by lib/utils/audio_encryption.dart.