# DeFinMa - API This is the API to access the database of the digital fingerprint of plastics project. A deep insight into the project structure can be gained in the [Bachelor Thesis](https://definma.apps.de1.bosch-iot-cloud.com/assets/docs/Veit-Lukas_Bachelor-Thesis.pdf). ## API documentation The API is documented using the Open API Specification 3.0.2 in the [api](./api) and hosted together with the API under the `/api-doc` path. The online version can be found [here](https://definma-api.apps.de1.bosch-iot-cloud.com/api-doc). The files are automatically bundled and validated when starting the server. ## Testing Testing is done with mocha and can be executed using `npm test`. ## General structure [index.ts](./src/index.ts) is executed when starting the server. It includes all setup tasks, registers middleware, routes and error handlers. Setting the `NODE_ENV` environment variable allows starting the server either in `production`, `development` or `test` mode. All route files including the corresponding test files are in the [routes](./src/routes) folder. The [validate](./src/routes/validate) folder stores Joi validations for data input and output. [models](./src/models) keeps all Mongoose database collection models. [helpers](./src/helpers) includes functions needed in multiple places like the authorization done for every route, csv conversion and object flattening as well as a mail service, registering an email address using the mail service on the BIC and replacing it with a logging statement in development. [test](./src/test) holds files for testing like the test database `db.json` loaded freshly for every test case and a helper utilized for easier testing. `loadDev` loads the `db.json` into the `development` database for a fresh start.