Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

The API uses Node along with Express to run the backend and routing logic. You will need to be pretty familiar with Express routing before getting into any code.

To access the database and to query it we use Knex, a query builder for multiple SQL implementations; we use PostgreSQL. Please go through Knex documentation on migrations and the api/db/migration folder to get an understanding of both the library and how the project goes about using it. The migration folder contains all the project's migrations-- the evolving definitions of the database’s schema from day one.

We use ObjectionJS to define the models in api/src/models.

The exports “package”

Within the api folder, the . Under packages/api/src there are folders for routes, middleware, controllers, and models.

Express defines the approach used for routes and middleware. Our routes and middleware generally follow RESTful API conventions for URLs and response codes.

Controllers and models are concepts borrowed from the MVC architecture pattern.

Controllers act as a kind of translator between the model(s) and the user interface. (The V in MVC is for View, an older approach to UI issues that React handles for us.) In general terms, a controller accepts input from the UI, converts it to commands to the model(s), transforms the results and responds to the UI. In terms specific to LiteFarm, a controller is a group of Express route handler functions that handle all routes related to a type of entity, such as farms. Via Express, the controller receives requests from the frontend in HTTP, following REST conventions. The farm controller makes appropriate calls to the farm model (and perhaps other models) to retrieve and/or modify database contents. The controller then sends the results back to the frontend via Express, usually in HTTP/JSON format.

A model is a dynamic data structure that directly manages the data, logic and rules of the application. We use ObjectionJS to define the models. Objection builds on Knex, a query builder for multiple SQL database platforms. We use the PostgreSQL database management system.

The exports “package”

The file packages/api/src/jobs/index.js is the entry point for a Node service that is run separately, as if it were a third package. This service monitors Redis-based work queues to receive and process requests for exports of certification information.

...