How Nucleoid Learns
Tags: ai, programming, javascript, node
Published: 2020-07-23 12:57:00

---
description: Nucleoid is a declarative runtime, which means instead of compiling code files, it accepts ES6 codes (JavaScript) in-flight and builds graph.
---

The short and long answer is **Graph**.

This article explains mechanics inside of the runtime, for basic usage:

{% link https://dev.to/nucleoid/hello-world-with-nucleoid-jo0 %}

Nucleoid is a declarative runtime, which means instead of compiling code files, it accepts ES6 codes (JavaScript) in-flight and builds **graph**. The purpose of doing this is making connection between statements, so that, the runtime can draw its own control flow and provide logical conclusion. Let’s start with a simple example:

```javascript
> a = 1
> b = a + 2
> c = b + 3
```

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/ci2rkrlvrfsqnvyk918v.png)

Each statement of `a = 1`, `b = a + 2` and `c = b + 3` is received into system in separate times, since `a` is part of `b`'s definition, the runtime draws dependency line between two, and when `a` is changed, the runtime automatically updates value of `b`, and rest of follows the same for `c` so on and so forth.

We can expand the example with adding `if` statement like:

```javascript
> if ( c > 10 ) { d = true } else { d = false }
> a = 6
> d
true
```

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/47el10xkzf03p2kcgnnx.png)

In this case, Nucleoid runtime also considers `if` statement as a data and includes in the graph along with its `true` and `false` blocks, and changing `a` triggers chain event through all the way to variable `d` by the runtime. As a result, the runtime respects declarative statements and conclude logical integrity.

> In this paradigm, there is no segregation regarding what data is or not, instead approaches how data is related with others so that any type of data including business rules can be added without requiring any additional actions such as compiling, configuring, restarting as a result of **plasticity**.

The same concept can be applied to class/object relationships as well:

```javascript
> class Student {}
> student1 = new Student()
> student1.firstName = "First"
> student2.LastName = "Last"
```

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/ysvab6zasm99kfokyqnp.png)

In this case, a relationship between `Student` and `student1` is class and instance as well as the graph carries properties of instance. In addition, the graph keeps all relationship among statements in order to provide logical integrity as receiving more statements. For example, if there is class-level declaration, it will be still part of the graph:

```javascript
> Student.fullName = Student.firstName + " " + Student.lastName
```

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/76r9maj87q54um0xp23w.png)

Class-level declaration adds more edges in graph in order to fulfill logical integrity. So, `student.fullName` is derivated to `student1.fullName` since `student1` is one instance of `Student`, so that, the runtime calculates `fullName` property using `firstName` and `lastName` properties.

{% link https://dev.to/nucleoid/dbless-with-nucleoid-runtime-3o1k %}

As conclusion, Nucleoid follows steps as:

1. Receive ES6 (JavaScript) code without compile or restart
2. Builds Graph based on relationship of statements
3. Runs statement in the state
4. Provide logical integrity based on information in graph
5. Stores statements so that it doesn’t require external database
6. or roll back transaction if any error occurs

---

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/9e16q1j1wwujzoh1pl0k.png)

Nucleoid is an open source (Apache 2.0), a runtime environment that allows declarative programming written in ES6 (JavaScript) syntax. Since statements are declarative, the runtime provides logical integrity and persistency as hiding technical details.

Learn more at [nucleoid.org/tutorial](https://nucleoid.org/tutorial/)