# Save App Arch ```graphviz digraph { rankdir=LR sync[label="Sync Server"]; android[label="Android Kotlin"]; ios[label="iOS Swift"]; daemon[label="P2P Daemon Rust"]; syncGroup[label="P2P Sync Group"]; peer[label="Other peers"] admin[label="Sync Admin"] repo[label="Data Repo"] personal[label="Personal Data"] external[label="External"] daemon -> syncGroup; android -> daemon[label="RPC"]; ios -> daemon[label="RPC"]; peer -> syncGroup [label="Add archives"]; syncGroup -> peer[label="View, Replicate"]; sync -> syncGroup; syncGroup -> sync; admin -> sync[label="View/Remove\nVia veilid?"]; { rank=same; daemon -> sync[style=dashed label="Code reuse"] } repo -> personal; repo -> external; daemon -> repo; } ``` ## P2P connections ```graphviz digraph { irohReplication; irohDocs; irohCollections; veilidTunnels; veilidKeyValue; groupId; groupId -> veilidKeyValue [label="Find peers"]; veilidKeyValue -> veilidTunnels; veilidTunnels -> irohReplication; irohReplication -> irohDocs irohReplication -> irohCollections irohDocs -> groupDoc irohDocs -> personalRepo groupDoc -> personalRepo personalRepo -> irohCollections } ``` ## Components ### Groups Peers will discover each other within secret groups. Groups work using veilid [DHT keys]( https://veilid.gitlab.io/developer-book/apps/api/dht_schema.html) for discovery and [Iroh Documents](https://iroh.computer/docs/layers/documents) for data sync. Basically: - set up a secret to share with a group - the secret should somehow map to an iroh document private key - hash the secret to get the dht key - encrypt values placed in the dht with the secret - peers set up tunnels for others to connect to them and encrypt the tunnel address with the shared key + add it to the dht - before going offline peers should remove themselves from the dht Peers will then bootstrap into the group by looking up peers and attempt to dial into them. These connections will be used to replicate iroh data. Initially peers will ask to sync the group's Iroh document to get up to date on the other users. ### Personal Data Each peer will create their own Iroh document for tracking all the data they share. They will add just the public key to the group doc. ### External Data Peers will track other peers' data repos and optionally download all or some of the blobs for backups. ### Daemon All the p2p interaction will be placed in a rust daemon that runs in a seperate process or thread from the main app and uses some sort of RPC API to talk to the main app. Likely HTTP to simplify code on client side. ## Further Reading - How to track a set of people allowed to replicate: https://github.com/consento-org/group/tree/hypercoreV1 - Natakanu file sharing app. uses gossip and data stores: https://github.com/Wapikoni-Technique/Natakanu/blob/master/app/core/Database.js - USHIN social deliberation. Uses Hypercore for personal databases and gossip for peer discovery: https://git.sr.ht/~breatheoutbreathein/ushin-db/tree/master/item/USHINBase.js - Android Java service for running an IPFS daemon via FFI/JNI. https://github.com/AgregoreWeb/agregore-mobile/blob/default/patches/0001-AG-IPFS-Daemon.patch#L151