Introduction
What Total.js framework v5 is, what the total5 package includes and the main concepts of a Total.js application.
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@betaOne 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:
| Area | Modules | Main API |
|---|---|---|
| HTTP server and routing | http.js, routing.js, controller.js | ROUTE(), the controller $ |
| Actions and schemas | builders.js, jsonschema.js | NEWACTION(), ACTION(), NEWSCHEMA() |
| Views and templates | viewengine.js, tangular.js, templates.js, markdown.js | $.view(), TEMPLATE() |
| WebSocket | websocket.js | ROUTE('SOCKET ...'), WEBSOCKETCLIENT() |
| NoSQL embedded database | nosql.js, nosql-*.js | NOSQL() |
| Query builder for SQL databases | querybuilder.js | DATA, DB(), NEWDB() |
| File storage | filestorage.js | FILESTORAGE() |
| Outgoing HTTP requests | utils.js, builders.js | REQUEST(), RESTBuilder, AJAX() |
mail.js | MAIL(), HTMLMAIL(), Mail | |
| Scheduling | cron.js | CRON() |
| Images | images.js | Image |
| Plugins and components | index.js, components.js | plugins/ directory, NEWCOMPONENT() |
| Flow engine | flow.js, flowstream.js, flow-flowstream.js | FlowStream, flow5 |
| Total.js Message Service | tms.js | NEWPUBLISH(), NEWSUBSCRIBE(), PUBLISH(), SUBSCRIBE() |
| API services | api.js | API(), NEWAPI() |
| Workers and threads | workers.js, cluster.js | NEWTHREAD(), NEWTHREADPOOL() |
| Python scripts | pypeline.js | PYPELINE() |
| Utilities | utils.js, htmlparser.js, minificators.js, macros.js | U, NEWMACRO() |
| AI models | aimodel.js | NEWAIMODEL(), AIMODEL(), AIPARSER() |
| Proxy | proxy.js | PROXYSERVER(), PROXYCLIENT() |
| Other modules | ldap.js, cms.js, uibuilder.js, openclient.js, bundles.js, edit.js | LDAP(), OPENCLIENT(), bundles, remote editing |
| Start and watcher | debug.js, release.js | Total.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
- Installation and first app: install the package, write the start script and the first route.
- Application structure: the full list of directories and files.
- Routing and Actions: the two parts every application uses.