Backend > Overview




This section describes and documents CloudForest’s (primary) backend server, cfserver. We discuss how it works, how it is installed and can be configured, and include our technical documentation as derived from jsDocs3 in the code itself.

The cfserver Repository

cfserver is hosted at

https://bitbucket.org/circleresearch/cfserver

The essential layout is

cfserver
|__ assets ...
|__ node_modules ...
|__ scripts ... 
|__ src ...
|__ service ... 
|__ tests ...
|__ conf.json
|__ package.json
Here and elsewhere we use ... in notating directory trees to denote a directory we don't list the contents of.

We cover each directory below, in its own section.

assets

assets contains templates for useful static assets served by cfserver, including scripts that we make publically accessible.

|__ assets
    |__ cfcli.sh
    |__ cfscp.sh
    |__ cfssh.sh
    |__ cfstart.sh
    |__ cfsave.sh

node_modules

This is the typical node.js modules installation that will be created by running

user@cfserver$ npm install

in the repo directory.

scripts

The scripts folder

|__ scripts
    |__ makedocs.sh
    |__ makeopts.sh
    |__ install.sh
    |__ createUnitFile.sh

src

This folder contains all of the source code making up cfserver.

|__ src
    |__ index.js
    |__ config.js
    |__ mongodb.js
    |__ server
        |__ server.js
        |__ apis ... 
    |__ utilities
        |__ awsutils.js
        |__ commutils.js
        |__ getters.js
        |__ logger.js
        |__ metricutils.js
        |__ mongodb.js
        |__ sockets.js
        |__ utilities.js

server

The server directory contains code for the express server cfserver uses to respond to HTTP requests:

|__ server
    |__ server.js
    |__ apis
        |__ aws ... 
        |__ communications ... 
        |__ groups ... 
        |__ instances ... 
        |__ misc ... 
        |__ requests ... 
        |__ users ... 
        |__ volumes ... 

This includes server definition (server.js) and subfiles that define specific APIs defining routes, methods, and actions.

service

cfserver runs using a systemd service defined in service. The service is comprised of four files:

|__ service
    |__ cfserver.env
    |__ cfserver.start
    |__ cfserver.stop
    |__ cfserver.service
  • service/cfserver.env: environment variables used to define the service installation
  • service/cfserver.start: the script to run to start the service
  • service/cfserver.stop: the script to run when stopping the service
  • service/cfserver.service: the systemd unit file that defines the service

The relevant environment variables are

  • CFSERVER_NODE=...: the specific node.js executable to use (/usr/local/bin/node by default)
  • CFSERVER_HOME=...: the location cfserver was installed at (/etc/cloudforest/cfserver by default)
  • CFSERVER_LOGS=...: the location to store cfserver logs (/var/log/cloudforest/cfserver by default)

These variables are used in the other files.

tests