fireproof-storage / fireproof-alpha

🔥 Cloudless realtime database
https://fireproof.storage
Other
81 stars 4 forks source link

Sharing a database between peers, browser only #131

Open swedieman opened 1 year ago

swedieman commented 1 year ago

I've read through the documentation, looked at some videos with Chris and am somewhat familiar with IPFS.

I still have some questions of some things that I think is pretty basic but that I couldn't find any clear answers to. I hope it's ok that I ask it here as it could potentially be beneficial to other people. If not, just close this issue.

My scenario in mind is (starting with) creating a simple app/webpage in lets say React which has a bunch of members. Not all members are visible to all other members and some content is public while some is tied to specific user roles.

I need several instances of the page/app (peer). But how do I sync the data between the instances? To me it seems that this can be done in several ways, but how? I would prefer if the database would be replicated and stored on the IPFS network (i.e. IPFS peers dedicated for the application) but most importantly it should not be able to just take down. To my understanding Fireproof is already built to do that, correct?

So I'm thinking that while the basic user application could be more or less just a thin client running in the browser there would need to be at least one peer to which it connects which in turn runs an IPFS node. That way it is not necessary to run an IPFS node on each peer facing the user. Is this a feasible approach?

Then, since it's all "front end code", at least for some of the peers, the peer needs some way to connect to other peers. Here I was hitting a wall when looking at other IPFS solutions since I couldn't find a good way to connect to other peers without using some kind of back end which connects to other peers rather than directly from the browser (the direct-browser connectivity to other peers doesn't seem to be finished). But Fireproof have (or at least is supposed to have it in the future) support for WebRTC and other ways to connect to a different peer, right?

How would I go about setting up a peer network like this?

Also; given that some content should not be publicly available, even if you are part of the app's peer network, would this be solved by using UCANs? Because it is built-in encryption (handled by the IPFS protocol) in the sense that if you don't have the correct UCAN token the data is encrypted to you, right? So that I cannot just build a "fake" peer that skips the UCAN checks and then has access to all data from the distributed database. This is perhaps a question more suited for the UCAN developers, but do you know if works that way?

I think projects seems very awesome, especially the simplicity for using it in the simple use cases (better than I would have come up with myself), so thank you very much for that! I hope it also fits my use case in the way I'm imagining.

Thank you in advance for any help!

swedieman commented 1 year ago

I have been doing some more reading, coding and researching and to me it seems that if I create a hosted web3.storage account that would pretty much do what I need.

Fireproof automatically sync the local database (browsers locale storage in my case) with a web3.storage account, right? Or at least it's meant to do that if I read the documentation correct, right?

Can someone please give me a hint of how to accomplish this? Wait, is it implemented yet? Because I saw this issue: https://github.com/fireproof-storage/fireproof/issues/30

I'm happy to help if I can. I want it to be possible to sync the data (i.e. upload the CAR files) through the browser. But I guess it's a good idea to also make it possible to do this via a back end (e.g. from the Node.js web server when using Next.js or when using Electron).

I don't even know where to find the CAR files (somewhere in locale storage when using the browser I suppose), but I might figure it out if I make some effort to learn the Fireproof code.

jchris commented 1 year ago

Apologies for not responding sooner! I've been on family vacation and at the same time with my head in a clean codebase as I take the lessons learned in Fireproof alpha and apply them to something that is more of a foundation.

As far as current status, the new version (beta) is a fresher codebase than alpha, so it's some code away from being more stable than alpha. However, that may only take a few days as I have time right now to finish up the loose ends.

I'd like to be able to answer your questions in detail and learn more about what you are building. I've love it if you schedule a call via my calendar. Alternatively, I just opened up discussions on the new repo.

jchris commented 1 year ago

Also, the browser peer vision is very much in line with what I am building. Here is an old toy game / proof of concept: https://game.fireproof.storage