Introduction

The Turbo 360 platform is organized into three broad areas:

  • Vertex

    Vertex is the full stack deployment environment of Turbo 360. Built on a serverless architecture, Vertex immediately provides flexibility and scale at very low cost.

  • Vectors

    Vectors are serverless functions that can be used in multiple projects - Turbo or otherwise. Vector functions can be monetized, offered for free, or restricted to authorized users only.

  • Turbo SDK

    The Turbo SDK supports the entire Turbo 360 ecosystem with a core set of functionality "out of the box" such as email notification or user registration.

Installation

Begin by installing the necessary libraries globally to run the Turbo build commands:

$ sudo npm install webpack -g
$ sudo npm install gulp -g


Next, install the Turbo CLI:

$ sudo npm install turbo-cli -g

Vertex

Scaffolding Projects

Vertex projects are the default format for scaffolds. To create a new project:

$ turbo new <PROJECT_NAME>


Next, change directory into the project and install dependencies:

$ cd <PROJECT_NAME>
$ npm install


Create a project in your Turbo dashboard then copy the APP_ID from the upper right corner of the admin console:

Turbo 360

Back in the terminal, connect your local source code the project on Turbo:

$ turbo app <APP_ID>


Run the devsever

$ turbo devserver
then navigate to http://localhost:3000 and you should see this:

Turbo 360

Project Structure

The Vertex project structure closely follows the patterns and conventions of a Node & Express architecture. View templates are stored in the VIEWS directory and route logic is under the ROUTES folder.

Turbo 360

Routes

The route files determine how your app responds to incoming requests. Routes can render plain text, JSON, a view template or redirect the request to another url. Route files are stored in the ROUTES directory and connect in the app.js file of the root level like so:

FILE: app.js
In this snippet, the route files are imported on lines 7-8 and connected on lines 11-12. A sample API route rendering JSON is shown below:

FILE: routes/api.js


Views

View templates are rendered using Mustache templating. The following code renders a template called "about.mustache" from the index route:

FILE: routes/index.js

In line 7, 'about' refers to the mustache template about.mustache in the VIEWS directory. The JSON object passed in the next argument, {text: 'This is about page'} provides a source of dnyamic data that can be rendered in the template. To do so, the the template itself should contain placeholders to render the data like so:

FILE: views/about.mustache

In this example, the dyanmic text is rendered in line 12 and when loaded into a browser, looks like this:

Turbo 360

Static Assets

Static assets (images, pdf, js, css, etc) are stored in the PUBLIC directory. When linking to static assets in templates, the 'public' directory is implicit.

For example, the following tags should be configured as follows:
BAD: <img src="/public/images/example.jpg" />
GOOD: <img src="/images/example.jpg" />

BAD: <link rel="stylesheet" href="/public/dist/css/bootstrap.min.css">
GOOD: <link rel="stylesheet" href="/dist/css/bootstrap.min.css">

React Template

Vertex also comes with a full React/Redux template out of the box. To create a React/Redux project, simply add the --react flag when scaffolding:

$ turbo new <PROJECT_NAME> --react
The React and Redux source code is located under the SRC directory in the root level of the project. A webpack config file is also provided in the root level and the index.mustache file under the VIEWS directory is where the compiled React source is mounted.

Themes

Vertex projects come with one-command theme integration. To view currently available themes:

$ turbo themes

This will render a list of themes currently integrated into the Vertex scaffold engine. New themes are added regularly so be sure to update the Turbo CLI every few days for an updated themes list. To integrate a theme:
$ turbo theme <THEME_NAME>

For example, the following command integrates the Hyperspace theme from HTML5UP:
$ turbo theme hyperspace

Vectors

Turbo 360 Vectors are stand-alone units of functionality that can be deployed on the Turbo platform. Vectors are completely de-coupled from any web service and therefore can be re-used in multiple projects without re-deploying. As such, Vectors are best suited for broad areas of functionality that are common to many apps, such as email notification or web-scraping.

Creating Vectors

Vectors are created using the Vector project scaffold option:

$ turbo new <VECTOR_GROUP_NAME> --vector

This creates a project with two Vector runtimes: Javascript (Node) and Python. Next, change directory into the project root and install dependencies:
$ cd <VECTOR_GROUP_NAME>
$ npm install

Finally, create an app on the Turbo 360 dashboard and connect the APP_ID to the Vectors project codeabse:
$ turbo app <APP_ID>

Javascript

The Javascript Vectors are found the '..vectors/js/index.js' file:



REQ

Each Vector has a unique name and takes two arguments: req and res. The 'req' argument is the http request that triggers the function and has the following attributes:

AttributeTypeDescription
queryObjectThe parameters included in the http request. If there are no parameters, this is an empty object, NOT null.
bodyObjectThe parameters included in the http POST request body. If there are no body parameters, this is an empty object, NOT null.
headersObjectThe request headers included in the http request.


RES

Vector payloads are sent back in the 'res' argument. This typically a JSON object containing a data payload but can also be raw data types such as strings and numbers. The 'res' argument has the following methods:

MethodArg TypeDescription
sendTextSends back a plain text response to the client calling the Vector.
jsonObjectSends back a json object response to the client calling the Vector.
statusNumberSet the http status code of the response. Can be chained with another
method such as 'json' or 'send'.


NPM Modules

Including NPM modules with your Vectors is done by running an install command from the root directory of your project:

$ turbo install <MODULE_NAME>
IMPORTANT: Even if you already installed the module via NPM, this command is still necessary to include with your function.



Deploy

To deploy your Javascript Vectors, from the root directory simply type:

$ turbo vectors
Once the deployment completes, Turbo will provide an HTTP endpoint for your Vectors which typically looks like this:

https://production.turbo360-vector.com/demo-y07bj1/<VECTOR_NAME>

where the VECTOR_NAME string is the name of your Javascript Vector.



Example

The following example queries the Google Maps API with a given address and returns only the latitude/longitude coordinates. The Google Maps API returns a large amount of data when querying for address coordinates and this function "extracts" only the latitude and longitude data for a simpler payload:

..vectors/js/index.js

Python

Turbo Vectors can also be exectued via a Python runtime environment. This can be found in the '..vectors/py/index.js' file:



Event

Each Vector has a unique name and takes an event argument. The 'event' argument is the http request that triggers the function and has the following attributes:

AttributeTypeDescription
queryObjectThe parameters included in the http request. If there are no parameters, this is an empty object, NOT null.
bodyObjectThe parameters included in the http POST request body. If there are no body parameters, this is an empty object, NOT null.
headersObjectThe request headers included in the http request.

Responses are send in the return object which is typically a JSON object.



Example

The following example sends an SMS message using the Twilio API. It assumes Python 3.6 runtime environment:

..vectors/py/app.py

Turbo SDK

The Turbo SDK provides a core set of functionality out-of-the-box which tremendously reduces the amount of time required to create, configure and deploy a full stack application. Though Turbo projects (Vertex and Vectors) are not required to use the SDK, they are designed to work together in a complementary fashion. The following areas of functionality are provided by the Turbo SDK:


Function Description Sample Code
Datastore Custom object datastore Click HERE
User Management User registration, login, password management Click HERE
File Storage Storage for static files (images, pdf, video, etc) Click HERE
Blog Blogging platform  
Email Send emails programmatically  

Contact

If you have any questions, comments or feedback, feel free to contact us at matthew@turbo360.co