Spanish Total.js
English
Documentation For AI agents
Contents

Introduction

What Total.js framework v5 is, what the total5 package includes and the main concepts of a Total.js application.

.md GitHub
On this page

Total.js framework v5 is a framework for the Node.js platform, written in pure JavaScript. The package README compares it with PHP's Laravel, Python's Django and ASP.NET MVC, and says it can be used for a web, desktop, service or IoT application.

It is published on npm as total5, under the MIT license, by Peter Širka. The source code lives in the totaljs/framework5 repository on GitHub.

$ npm install total5@beta

One package, no dependencies

The total5 package does not declare any npm dependency. Everything the framework needs is inside the package: the HTTP server, the router, the view engine, the database layers, the mailer, the image processing, the workers and the Flow engine. You load it once with require('total5') and the framework registers its API as globals (ROUTE(), NEWACTION(), NOSQL(), CONF, F and many more), so application files can use them without any require().

require('total5');

ROUTE('GET /', function($) {
    $.plain('Hello world');
});

F.http({ port: 8000 });

The package also installs two command-line tools, total5 and flow5. They are described in Command line.

What the package includes

The package is a set of modules. Each module covers one area of a typical application:

AreaModulesMain API
HTTP server and routinghttp.js, routing.js, controller.jsROUTE(), the controller $
Actions and schemasbuilders.js, jsonschema.jsNEWACTION(), ACTION(), NEWSCHEMA()
Views and templatesviewengine.js, tangular.js, templates.js, markdown.js$.view(), TEMPLATE()
WebSocketwebsocket.jsROUTE('SOCKET ...'), WEBSOCKETCLIENT()
NoSQL embedded databasenosql.js, nosql-*.jsNOSQL()
Query builder for SQL databasesquerybuilder.jsDATA, DB(), NEWDB()
File storagefilestorage.jsFILESTORAGE()
Outgoing HTTP requestsutils.js, builders.jsREQUEST(), RESTBuilder, AJAX()
Mailmail.jsMAIL(), HTMLMAIL(), Mail
Schedulingcron.jsCRON()
Imagesimages.jsImage
Plugins and componentsindex.js, components.jsplugins/ directory, NEWCOMPONENT()
Flow engineflow.js, flowstream.js, flow-flowstream.jsFlowStream, flow5
Total.js Message Servicetms.jsNEWPUBLISH(), NEWSUBSCRIBE(), PUBLISH(), SUBSCRIBE()
API servicesapi.jsAPI(), NEWAPI()
Workers and threadsworkers.js, cluster.jsNEWTHREAD(), NEWTHREADPOOL()
Python scriptspypeline.jsPYPELINE()
Utilitiesutils.js, htmlparser.js, minificators.js, macros.jsU, NEWMACRO()
AI modelsaimodel.jsNEWAIMODEL(), AIMODEL(), AIPARSER()
Proxyproxy.jsPROXYSERVER(), PROXYCLIENT()
Other modulesldap.js, cms.js, uibuilder.js, openclient.js, bundles.js, edit.jsLDAP(), OPENCLIENT(), bundles, remote editing
Start and watcherdebug.js, release.jsTotal.run() (F.run())

Main concepts

Application directory

A Total.js application is a directory with a start script and a set of known subdirectories (controllers, actions, schemas, plugins, public, views and others). The framework loads them automatically when it starts. See Installation and first app and Application structure.

Routes and the controller

A route maps an HTTP method and a URL to a handler. The handler receives the controller $, which holds the request and has the methods for the response ($.plain(), $.json(), $.html(), $.view(), $.file() and others).

exports.install = function() {
    ROUTE('GET /', function($) {
        $.plain('Hello world');
    });
};

See Routing and Controller. Static files, middleware and authorization are in Middleware, Static files and Authorization.

Actions

Actions are the business logic of the application. An action has a name, an optional input schema and a handler. Routes can call actions directly with the --> operator, so the same logic is reachable from HTTP, from other actions and from code.

NEWACTION('hello', {
    name: 'Say hello',
    action: function($) {
        $.success('Hello from an action');
    }
});

ROUTE('GET /api/hello/ --> hello');

See Actions and JSON schemas.

Views

The view engine renders HTML templates from the views directory with models, layouts and helpers. See Views and Localization.

Configuration

The config file in the application root holds key/value settings, read into the global CONF object. See Configuration.

Data

The framework includes an embedded NoSQL database stored in the databases directory (NOSQL()), a query builder for SQL databases (DATA, DB(), NEWDB()) and a file storage (FILESTORAGE()). See NoSQL, QueryBuilder and File storage.

Plugins and components

A plugin is a self-contained part of an application in plugins/<name>/, with its own controllers, actions, schemas and definitions. Components (NEWCOMPONENT()) compile reusable HTML components. See Plugins and components.

FlowStream

FlowStream is the Total.js visual programming engine: data flows between connected components in a flow schema. The flow5 binary runs flow schemas directly. See FlowStream.

TMS and APIs

The Total.js Message Service (TMS) publishes and subscribes messages between Total.js applications over WebSocket, and API() calls remote API services. See Message Service (TMS) and APIs.

AI models

The aimodel.js module registers AI model handlers with NEWAIMODEL() and builds requests for them with AIMODEL(): system and user messages, tools, streaming and callbacks. AIPARSER() parses AI responses. See AI models.

Everything else

WebSocket, outgoing HTTP requests, mail, scheduling and events, workers and threads, images and utilities each have their own guide: WebSockets, HTTP requests, Mail, Scheduling and events, Workers and threads, Images, Utilities, Prototypes, Proxy, LDAP, Markdown, HTML and XML parser, Macros, Tangular, Minification and CMS compiler.

Where to go next

  1. Installation and first app: install the package, write the start script and the first route.
  2. Application structure: the full list of directories and files.
  3. Routing and Actions: the two parts every application uses.
Made in Europe