# Project structure of a Total.js 5 application

> The folders of a Total.js 5 project, what each one contains and which files the framework loads automatically.

Framework: total5
Product: Total.js 5 (total5@0.0.19)
Language: en
Content-SHA256: 7c79aecbd0fa3cbd1e8f2b82806a67c9622e0956e59e284a881e124a3594e84d
Snapshot: c0700e321579725c5cf4f5ace1ad7d2866d1b4f93c24a63c0b41b6b7998e976c
Sources: total5-installed@total5@0.0.19
Review: not-recorded

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.

| Folder | What 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()`. |
| `config` | The 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.

```js extensions/marker.js
(MAIN.loaded = MAIN.loaded || []).push('extensions');
```

```js modules/marker.js
(MAIN.loaded = MAIN.loaded || []).push('modules');
module.exports.id = 'modules-file';
```

```js actions/marker.js
(MAIN.loaded = MAIN.loaded || []).push('actions');
```

```js schemas/marker.js
(MAIN.loaded = MAIN.loaded || []).push('schemas');
```

```js models/marker.js
(MAIN.loaded = MAIN.loaded || []).push('models');
```

```js definitions/marker.js
(MAIN.loaded = MAIN.loaded || []).push('definitions');
```

```js controllers/marker.js
(MAIN.loaded = MAIN.loaded || []).push('controllers');
```

```js middleware/marker.js
(MAIN.loaded = MAIN.loaded || []).push('middleware');
```

```js 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()
		}
	});
}
```
