ForgeDocumentation
en

Documentation

Project structure of a Total.js 5 application

Total.js 5 · total5@0.0.19 guidestructurefolders Executed against Total.js 5

A Total.js application is a folder with a start script (index.js) and a set of folders with fixed names. You do not import your files: when the application starts, Total.js reads the folders below and loads every .js file in them (in a folder called plugins/ it loads the index.js of every subfolder). A file is a normal Node.js module; if it exports an install function, Total.js calls it after loading the file.

FolderWhat goes in it
controllers/Routes: exports.install = function() { ROUTE(...) }.
definitions/Code that runs at start and declares global things: actions with NEWACTION(), middleware, AUTH(), helpers, your own globals.
actions/Actions (NEWACTION()), when you prefer them apart from the other definitions.
schemas/Schemas (NEWSCHEMA()) with their actions.
models/Loaded at start like the others; Total.js only loads the files, what they contain is up to you.
middleware/Middleware (MIDDLEWARE()), loaded after the other folders.
modules/Reusable modules; the export may have an id (it is kept in MODS) and an install function.
extensions/Loaded at start like the others; Total.js only loads the files, what they contain is up to you.
plugins/Plugins: a folder per plugin with an index.js.
views/HTML views and the layout.html.
public/Static files served as they are, without any route.
resources/Translation files (.resource), see the localization recipe.
jsonschemas/Reusable input definitions (.txt or .json), see the schemas recipe.
databases/Files of the built-in NoSQL database and of MEMORIZE().
tmp/Temporary files and caches (PATH.tmp()).
logs/Log files.
private/Files that must not be public; send them with $.file() after a check.
workers/Files of NEWTHREAD() and NEWFORK().
configThe configuration file (a file, not a folder).

The helpers of PATH build the absolute path of each folder: PATH.root(), PATH.public(), PATH.private(), PATH.tmp(), PATH.logs(), PATH.databases(). They return the path without a trailing slash, and the folder of the views has no helper. The example puts a file in each of the folders that Total.js loads and reads back what was loaded.

extensions/marker.js
(MAIN.loaded = MAIN.loaded || []).push('extensions');
modules/marker.js
(MAIN.loaded = MAIN.loaded || []).push('modules');
module.exports.id = 'modules-file';
actions/marker.js
(MAIN.loaded = MAIN.loaded || []).push('actions');
schemas/marker.js
(MAIN.loaded = MAIN.loaded || []).push('schemas');
models/marker.js
(MAIN.loaded = MAIN.loaded || []).push('models');
definitions/marker.js
(MAIN.loaded = MAIN.loaded || []).push('definitions');
controllers/marker.js
(MAIN.loaded = MAIN.loaded || []).push('controllers');
middleware/marker.js
(MAIN.loaded = MAIN.loaded || []).push('middleware');
controllers/structure.js
exports.install = function() {
	ROUTE('GET /structure/', structure);
};

function structure($) {
	$.json({
		loaded: MAIN.loaded || [],
		modules: Object.keys(MODS),
		paths: {
			root: PATH.root(),
			public: PATH.public(),
			private: PATH.private(),
			tmp: PATH.tmp(),
			logs: PATH.logs(),
			databases: PATH.databases()
		}
	});
}