Project structure - TrentoCrowdAI/crowdhub-api GitHub Wiki
Project structure:
src
├── authentication
├── blocks
│ ├── do-publish
│ │ └── platforms
│ │ ├── amt
│ │ │ └── render
│ │ ├── f8
│ │ │ └── render
│ │ │ └── resources
│ │ └── toloka
│ │ └── render
│ │ └── resources
│ ├── do-wait
│ │ └── platforms
│ │ ├── f8
│ │ └── toloka
│ └── lambda
├── config
├── controllers
├── dao
├── db
├── delegates
├── platform-api
│ ├── f8
│ └── toloka
└── utils
Above will be analyzed each folder specifying its contents.
-
src/authentication
: In this folder there are the files which implement the middleware used for authenticate the users. The Google OAuth logic is located in this folder: after registering a new user the middleware pass it to all the following routes in order to allow them to perform authorization functions.refs: Authentication
-
src/blocks
:This folder contains the definition of each block that could be inserted in a workflow design. The index.js file exports the list of blocks available, simply loading the index.js from each block folder. By default we have three different types of block:
- do-publish: its role is publishing a job to the specified crowdsourcing platform and starting it.
- do-wait: its role is, every tot minutes, check if a specified crowdsourcing job, previously started on a platform, has finished and collect the results.
- lambda: this block permits to execute custom javascript code which could elaborate the input obtained from the previous block.
refs: How to add a new block
-
src/config
:This folder contains the configuration of all the project. In the index.js file some ENV variables are mapped to an object in order to access them easily from the project's code.
-
src/controllers
:In this folder there are modules used to define the endpoints of the API. Each file refers to an entity, so it defines the endpoints of that entity and it is named as name-of-the-entity.controller.js. Each controller file has its own .spec.js file which contains the tests related to that controller.
-
src/dao
:This folder contains the DAO implementation for each entity of CrowdHub. These modules interact directly with the Postgres DB executing queries and retrieving the results. refs: DB entities
-
src/db
:The init.sql file is useful to recreate the Postgres DB of the entire project. The index.js file contains a wrapper method used to execute queries on the db using an easy argument replacing logic and a retry logic. There is even a table which defines the available table in the DB without writing the table's name as a string.
-
src/delegates
:Per each entity of the project there is a module inside this folder which has to check input data coming from the controllers, elaborate them and interact with the DAO modules if necessary. This folder contains almost all the logic of the entire project.
-
src/platform-api
:Each folder located in this directory is a crowdsourcing platform that the project supports. Every folder has a file that implements the calls of the API for the specific platform. By default, there are two folders: f8 and toloka.
-
src/utils
:This folder contains useful code shared among the entire project and not specifically related to some logic of CrowdHub. In particular two scripts, toloka-helper and f8-helper, are used in jest tests to finalize some crowdsourcing jobs without needing the interact of a user.