Skip to content

File Structure

Chris edited this page Mar 1, 2017 · 3 revisions

Root Directory

This repository hosts the code for the Manticore web application. Inside it contains server code, a Dockerfile, HTML and Javascript for testing the API, and a build NodeJS file that signals to Nomad to run the docker container. The /docs folder contains documentation about an overview of Manticore and the API it exposes. The /consul-template folder has the HAProxy template that is used as a base to automatically make a config file for HAProxy. The Dockerfile is meant for the maintainers of Manticore.

Server Directory

The entry point to the application is index.js. All dependencies and meta information is described in package.json. There are two main directories here. The /app folder contains all of the logic related to responding to API requests. The /lib folder contains a set of useful classes that are needed across multiple modules in /app. Those modules get put together in the Context class which gets passed around to most other modules.

App Directory

The entry point of all the endpoints are located in controller.js. That file is where middleware routes are included, such as authentication and request body validation. Any logic that needs to happen as a result starts in controller-logic.js. Once inside controller-logic.js, anything that requires extra logic that is necessary but loosely related to the end results is split into additional folders and modules. For instance, there are three folders named requestCore, requestLogs, and watches. The rule is that each of these folders will contain three files: shell.js, core.js, and core-test.js. Optionally, there can be additional functionality for that folder by splitting into more folders, each following the rule stated above. This is demonstrated in the watches folder.

shell.js is the module that the parent directory's NodeJS files will require when they want to use submodules' functionality. Any function in shell.js that has logic which requires (almost) no dependencies will be split into core.js, and shell.js will require core.js for that logic. The reasoning for this is that anything inside core.js can easily be testable through unit tests since there are no external dependencies. That's why each subfolder that has core.js will have core-test.js testing the functions inside core.js. Mocha is the testing framework used and will look for all files names *-test.js. Anything inside /lib that needs unit tests will have an additional test folder at /lib/tests

Clone this wiki locally