Skip to content

Backend Structure

joelll-u edited this page Mar 10, 2024 · 9 revisions

The structure of the backend follows a modularised designed - using interfaces to communicate between services, this allows for easy scalability, expansion, and adaption.

Routes

Stored in backend/src/main/kotlin/com.kayak_backend/routes This contains the code for the route api, we aim to keep the actual logic in these sections minimal to promote the modularity. Here the routes are defined and the parameters are checked and modified. Each of these routes calls a service

Services

Each service provides an interface and at least one implementation, the implementation is produced in conf.kt based on what is configured in the file. Then the implementations may have their own configs which are default to null but can be added in if it is required. To add a new implementation simply create a new class which implements the service interface, add the option in the required conf.kt function (e.g if adding a new tide implementation change getTideService())

To add a new service, create a new package in the backend/src/main/kotlin/com.kayak_backend/services, create a interfaced and an implementation and set up a way to configure the service in conf.kt

Application setup

The backend uses ktor to run the routes, the backend is setup in backend/src/main/kotlin/com.kayak_backend/Application.kt and the routes are configured in backend/src/main/kotlin/com.kayak_backend/plugins/Routing.kt

Other packages

There are also other packages defined in backend/src/main/kotlin/com.kayak_backend, e.g the grib reader package which provides a grib reader, and serialisation which provides custom serialisation for certain classes.

Grib Reader

See main grib reader page

Models

This contain several models used to store require data. For example, wind data, tide data, grids of both wind and tide, locations etc.

Interpolator

The interpolator package contains a way for low resolution grids to be upscaled into higher resolution grids. Currently the only method implemented is a simple interpolator. This will simply upscale the resolution and keep the values the same

Grib Fetcher

This package fetches grib files from a determined source. It is scheduled to run every 6 hours on heroku or if the file doesn't exist

The grib files are currently sourced from openskiron.org which is a sailing website which provides free grib files on a huge variety of places including the English Channel. These grib files contain a forecast of the next 48 hours and are updated every 12 hours.

Warning: openskiron.org clearly states that the grib files provided are not to be used for commercial purposes, thus before any commercialisation of the app - the source would have to be changed likely to a paid provider of grib files or the requisite data

Clone this wiki locally