How to build an App on SAFE Network?

SAFE Apps are programs which run on the user’s device (client) and access data stored on the SAFE Network (decentralised server). Input of user credentials and authorisation are handled by a separate program, the SAFE App Launcher, which passes authorisation to the App so that it can access the network.

To create a SAFE App you will need:

  • access to the SAFE Network, either via the API or as a virtual drive mounted on the user device file system.

  • a development system (programming tools) that can create programs for all the devices (e.g. PC, tablet, smartphone) and operating systems (e.g. Windows, OS X, Linux, Android) you wish to support. This FAQ does not discuss selection of a development system, which is often a matter of personal choice, and because a very wide range of possibilities will be available. You will need to make sure your choice can access the SAFE Network (see below), and create Apps for the target systems you require

SAFE API

The following is my understanding based on MaidSafe-API, MaidSafe-Drive, MaidSafe-Network-Filesystem and MaidSafe-Ports repos, and some help from the devs. Errors and omissions are all mine! ~ @happybeing

The API is primarily in Rust (and some low level libraries in C++), a range of other languages are also supported (see Ports below). An alternative to using the programmatic API is by accessing a virtual drive mounted on the client device file system (see MaidSafe-Drive below).

Overview of SAFE Network API:

  • MaidSafe-API: enables an App to register a session with the network (via the SAFE App Launcher) and retrieve a list of directories it is authorised to access (using DirectoryInfo objects). See MaidSafe-Network-Filesystem.
  • Maidsafe-Network-Filesystem: allows the App to treat SAFE Network as a file system using a RESTful style API (GET/POST/PUT/DELETE). Access is obtained via the RegisterSession API (see above) and via the SAFE Launcher, which handles user credentials and network authorisation. The MaidSafe-Network-Filesystem is different from the virtual drive provided by MaidSafe-Drive.
  • MaidSafe-Ports: contains support for several languages, with API wrappers to the MaidSafe-API & MaidSafe-Network-Filesystem from languages other than Rust.
  • MaidSafe-Drive: provides access to SAFE Network storage as a virtual drive mounted on the user’s device operating system, accessible through standard file system library calls (for Windows, OSX, Linux) as supported by the development system used to create an App.
  • SAFE API Documentation & Examples: documentation, including sample code for each function and data structure, can be found for the entire API within the ‘docs’ folder of each MaidSafe library. This documentation is included within the source and automatically generated by the Rust cargo build system (and code samples checked by the Rust compiler).
  • SAFE App Examples: there is no sample code at present, but some helpful information. At least one complete sample App will be provided in source form to help developers understand the API from a working example written in Rust. In the mean time, we have:
    • examples documentation showing how to set up a local test network.
    • an old video showing the UI for typical App functionality (authentication, file sharing, messaging etc.) though the plan is that authentication will happen separately in the SAFE App Launcher, which will pass authentication to individual Apps.
  • SAFE App Builder Documentation: there is an App Builder section in the System Docs which acts as a starting point for access to all the resources available to build Apps on SAFE Network.

SAFE Software Stack Showing API

This diagram is from the MaidSafe blog: What Is The Architecture of the SAFE Network

What Tools and Languages Can I Use?

You can use any tools for the platform(s) (mobile, tablet, PC etc.), and operating systems you wish your App to run on.

Rust

The SAFE API libraries are written in Rust, so if you want to use Rust that’s a no brainer. Rust is a very new language (v1.0 launched in May 2015) so in the early days the build environments are limited, but some options to consider for UIs are:

*If you have feedback on any of the above please post it on this thread so I can incorporate or refer to it.

Other Programming Languages

MaidSafe provide wrappers for different languages for the APIs (in MaidSafe-Ports), or you can write your own wrapper for languages that are not supported (and share it by submitting a git pull request to the MaidSafe repo!)

“Web” Apps

There’s no reason you can’t build true web Apps on SAFE by writing them entirely in HTML and JavaScript to load directly from SAFE Network and run in a standard web browser, either from the user’s SAFE Drive, or via a SAFE URL if the browser has a suitable plugin to access SAFE Network URLs directly, and to authenticate the use for PUTs to their private storage.

Such an App would be stored entirely on the network and run just like a normal web service, but without a server, so they are entirely secure from data theft, snooping, malware etc. and load fast, directly from a user’s SAFE storage.

There is no JavaScript library to support this yet, but who knows, maybe someone is working on one ;-). For simple Apps it wouldn’t be hard to write yourself, because you can use the SAFE REST API very much like a normal web App/service.

Can you help?

This post is editable by anyone, so please fix any errors and omissions, and update it as things change.

27 Likes

This is really, really important, Mark. Thanks for articulating it. :heart_eyes:

3 Likes

I think we’ll just have to wait for a bit

1 Like

The RegisterAppSession function isn’t a wrapper to anything. It merely helps someone connect to the launcher app to authenticate the current app and retrieve it’s DirectoryInfo objects which it can then use to store/retrieve data to those folders in the network via the NFS API.

boost-filesystem is just a C++ helper lib(obv a very useful helper lib but in essence just a helper lib) to access the filesystem in a machine. It doesn’t have anything specific to the network. Actually even in C++ you’ll only be using boost-filesystem if you wanted to access the VFS/Native drive from a C++ app. Now there are other filesystem helper libs in C++ too, so this is just one example. If we take a different language via the port’s, they would use their own helper libs to access the system’s filesystem.

It’s easier to think of Ports as the equivalent to the current C++/RUST API’s for non C++/RUST App devs. So in essence the Ports project doesnt by itself set an objective to make stuff “easier”. We can have a completely detached project have it as it’s objective but Ports project merely opens the door to app devs coming from different languages to the network.

I think this might now be clearer after the previous answer as to the objective of the Ports project. So exposing the NFS API which was in C++ was indeed one of the things the Ports project dealt with for non C++ languages.

Sample code/examples will now almost get integrated as part of the individual projects themselves with rust which has a dedicated examples section for each module and in-line documentation examples. We should also see detached Examples/Slightly more full-fledged apps showcasing various features of the network.

Hope this helps :smile:

3 Likes

@viv first thanks for taking the time to answer - it certainly does help :slight_smile: and I’ve updated the FAQ to where I think we are. Let me know if I need to change anything or feel free to edit it (as it is now a wiki post).

I have more questions but if you need to leave this aside for the time being no worries, we can pick it up later and leave these as place holders for how:

  • I’m wondering now if what I’ve written is pretty much it for the time being, or if there is an intention to provide a more extensive and stable/recommended API, that handles more than the simple RESTful style operations? Particularly what may or may not be planned in terms of NoSQL (e.g. Redis style) support, but also, for other areas.

  • Obviously an App could make use of any part of the MaidSafe libraries, but it will be helpful for App developers to be pointed to the most relevant areas of code, and guided to stable App interfaces, and have potentially unstable inter-library interfaces hidden away (or documented separately). Do you think this can be done within the source code documentation?

That’ll do for now I think! I can’t wait to see that full sample code SAFE App I’ve committed you to delivering :wink: Want!

Is it possible ta make some apps in SAFE at this moment?

1 Like

Yes, though it would be wise to focus on the parts that are independent of the API in case things change until the devs clarify what can be regarded as stable and what are the recommended ways of interfacing with the network. It is not possible to test those apps right now, but once testnet3 is here this will become possible.

2 Likes

I just added this to the OP:

What Tools and Languages Can I Use?

You can use any tools for the platform(s) (mobile, tablet, PC etc.), and operating systems you wish your App to run on.

Rust

The libraries are written in Rust, so if you want to use Rust that’s a no brainer. Rust is a very new language (v1.0 launched in May 2015) so in the early days the build environments are limited, but some options to consider for UIs are:

  • [KISS-UI][11]. (happybeing evaluation status: sounds promising but not tried yet)
  • [PistonDevelopers/Conrod][10] (written in Rust). (happybeing evaluation status: examples working)
  • [Qt5 via qmlrs][9]. (happybeing evaluation status: example working)

*If you have feedback on any of the above please post it on this thread so I can incorporate or refer to it.

Other Programming Languages

MaidSafe provide wrappers for different languages for the APIs (in MaidSafe-Ports), or you can write your own wrapper for languages that are not supported (and share it by submitting a git pull request to the MaidSafe repo!)

“Web” Apps

There’s no reason you can’t build true web Apps on SAFE by writing them entirely in HTML and JavaScript to load directly from SAFE Network and run in a standard web browser (either from the user’s SAFE Drive, or via a SAFE URL if the browser has a suitable plugin to access SAFE Network URLs directly.

Such an App would be stored entirely on the network and run just like a normal web service, but without a server, so they are entirely secure from data theft, snooping, malware etc. and load fast, directly from a user’s SAFE storage.

There is no JavaScript library to support this yet, but who knows, maybe someone is working on one ;-). For simple Apps it wouldn’t be hard to write yourself, because you can use the SAFE REST API very much like a normal web App/service.

1 Like

If you use qmlrs you also need to be able to write C++ and understand QML (a simple declarative language). Furthermore, it is helpful to have a good understanding of javascript to effectively code in QML (and therefore in qmlrs). Besides that qmlrs, beatifully uses rust’s ability to be easily integrate into other languages. But it is more a proof of concept than anything else. Besides that, it looks awesome and very promising.

At the time beeing, you can only call rust functions which receive arguments or return results of i64 or String type. To understand how qmlrs works, I experimented with adding a boolean type here: https://github.com/Liamsi/qmlrs/commit/c9356c814b8dd225783e225dd887f21d5617cf8a
But adding complex stucts or objects and using QT’s signal mechanisms should be more complex (and needs more C++ at the moment)

And as you included even included KISS-UI and Conrod, you should also mention: https://github.com/rust-gnome/gtk
Here is a very basic example: https://github.com/Azdle/hello-gtk.rs
It looks quite mature already.

1 Like

Thanks @Liamsi, I’ve added it. If you have any more mods feel free to edit the OP yourself as it is a “Wiki” post anyone can edit it.

1 Like

OK, maybe I will mod it tomorow. I think you should also explain, what “(happybeing evaluation status: example working)” means. Which example is that? The quality of the listed rust UI kits is quite diverse. And by quality I mean Look&Feel and maturity/capabilities of the kit.
Thank you and good night :sleeping:

The examples they too the examples in the referenced installations. Great to have your input, thanks :slight_smile:

1 Like

Great, I just saw maidsafe is looking for an UI dev. I am going to apply asap ! :slight_smile:

2 Likes

Same 'ere…UI stands for unqualified and inept right? :smiley:

@al_kafir apply, you’re sure to be hired.

I think the office needs a lick o’ paint :wink:

1 Like

Lol…yes and there’s the added bonus of having me on hand to correct any wrong-headedness. :smiley:
Funnily enough, I think most of my repeat custom is from house wives and religious people,who just love chatting to me…weird I know…I’m actually quite liked in real life believe it or not…lol… :smiley:

2 Likes

Easily believable man, easily :slight_smile:

3 Likes

Aw…shucks thanks… :blush:

I reckon I’d like you, especially painting my boat :wink:

1 Like