Nile Prototype 1.0.0
Explaining Nile’s architecture
We built this prototype to explain better the idea of Nile’s architecture. In order to get started run the following commands:
git clone firstname.lastname@example.org:nileorg/prototype.git
sudo docker-compose up
This is the repository nileorg/prototype
Nile Local Instance
The Nile instance is the director for all the local nodes (node = store). When a new node registers to the network, the node sends its IPFS Hash (containing the node information) to the Nile instance, this instance will verify and then eventually accepts the node inside the local network inserting a new value in a two column table: node_id, ipfs_hash; then the Nile instance will publish the table on IPFS (it will be used by the client to retrieve the list of nodes).
When you launch the instance the log will inform you about:
- someone joining / leaving the network: when someone connects or disconnects from the local instance’s WebSocket server
- a new nodes list published on ipfs: when a node registers to the local instance a new nodes list is published.
The node is the basic component of Nile, it is composed by:
- Basic information (name, location…)
- Actions: all the services that the node hosts. These actions are called directly be the client through a WebSockets connection. I’ll speak more about it in the section Actions.
- Components: the views that the clients load and use to call the actions. I’ll speak more about it in the section Components.
You can start the client app at
http://localhost:8010. You can do two task to get started with your node:
- registerNode: this function will first fill the node with the properties (basic info, components, actions) it needs in order to register to the local instance, and then it will actually send a registration request to the local instance. The local instance will return a token, that it will be logged into the browser’s console.
- loginNode: you can use the logged token in order to login.
The client is used to browse the nodes in the local instance and call their actions.
You can start the client app at
http://localhost:8011. Now the client will load the nodes list from ipfs. Once the list is loaded you will see something like this:
Notice the LOAD NODE button, it is visible only when the node is only, you can try to stop and start the node process, you will see in real time showing and hiding this button.
If you press the LOAD NODE button the client will retrieve the node information on ipfs, in particular you will see its parsed components
If you write something in the input component and press Call function1 button component the client will send a request to the node passing the input component value as parameter (we will see how to specify parameters in the next section) and the response will be displayed in the output component.
Notice the Data property displayed at the bottom of the node, when the node reply the values changes. Each node (I’m speaking about the node object in the client) has a data property, it is used to exchange information between the client and the node instance:
- In the case of an input, when you type something the data object will be filled with the content of the input, try to take a look at inp1.
- In the case of an output, when the node replies to your request it can fill the data property with values (I’ll show you how in the next section), try to take a look at out1.
The node can specify the components that the client will load, each component can use the data object (of the node object in the client) to retrieve or put information.
- The second component, type: “text” has a property called key with value inp1: it defines that the value of the text component should go to node.data[‘inp1’]
- The third component, type: “output” has a property called key with value out1: it defines that the value inside node.data[‘out1’] should be displayed in the output component
- The first component, type: “button” has a property parameters with value [‘inp1’]: it defines that when the client send the request to the node it should pass node.data[inp1]. Also the button specify which action the client will request when you pres the button with the action property, in this case function1
The node has actions, when you press the button in the client a request is sent to the node. The node processes these request directly inside the browser.
Inside the function you can use two element:
- parameters, its an object containing the parameters of the request
- reply, its a function that you can use to reply to the client, if you pass an object containing the _key and the _data properties, the node.data[_key] will be filled with the content of _data. This is how you can fill the data property of the node object (in the client).
In the next article we’ll explain how to handle authentication and a brief introduction to the queue system. Nile Prototype 1.1.0
Thanks for your time.
Thanks a lot for the time you spent reading this article, please feel free to comment here or on Discord!