Skip to content

RFS-0/ch.resrc.backend-experiments

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Backend Experiments

The goal of this repository is compare platforms, languages and frameworks/libraries by implementing the same API on each of them. For each of them the following is implemented:

  • A REST-API conforming to the aforementioned API

  • Persistence with a SQL database (PostgreSQL)

The same API is implemented in each experiment. See [Petstore API] for details.

Currently an implementation is available in the following combinations of platforms, languages and frameworks:

Platform

Language

Framework/Library

Deno

Typescript

x/oak, x/postgres

Candidates for future experiments are:

Go

Go

Gin

JVM

Kotlin

Quarkus

JVM

Scala

JVM

Clojure

.NET

F#

All the implementations use the same structure:

root of experiment (e.g. deno)
|_ adapters
  |_ rest
  |_ database
|_ domain
  |_ entities
  |_ value_objects
|_ use-cases
  |_ manage_users

API Specification

The API is specified according to the OpenAPI Specification (v3.0.3). This API can be found here. This API specification is a modified version of the Swagger Petstore API which can be found here.

To start the Swagger UI for the API specification of the petstore execute (TODO: repackage this as service in docker-compose):

docker run -p 4001:8080 -d --rm -e URL=/api-spec.yaml -v <absolute-path-to-repository>/ch.resrc.backend-experiments/api/api-spec.yaml:/usr/share/nginx/html/api-spec.yaml swaggerapi/swagger-ui

To generate models for the API the openapi-generator could be used:

openapi-generator-cli generate \
  -i api-spec.yaml \
  -g typescript \
  -o typescript \
  -c config.json

Operations

Everything to do with running the backend experiments is defined in operations/. The container-images/ folder contains all information on how executable artifacts are defined and built. The deployment/ folder contains all information on how executable artifacts are deployed.

Container Images

Defines one image per experiment.

Deployment

Docker for Developing

To implement a new experiment access to a PostgreSQL database is helpful. For this use case the docker-compose.yaml is convenient as it exposes the following on localhost:

  • a PostgreSQL database

  • an Adminer instance

Check the docker-compose.yaml for the ports.

To deploy it execute:

docker-compose up ./operations/deployment/docker-compose.yaml

To access the db you can navigate to:

http://localhost:4002/?pgsql=database&username=user&db=experiments&ns=public

Use the credentials defined in database.env to log in.

Kubernetes

You can use minikube to deploy everything locally. You can install it by following these instructions.

To start minikube execute:

minikube start

To access the dashboard of your local Kubernetes cluster execute:

minikube dashboard

To deploy everything navigate to operations/deployment/ and execute:

kustomize build . | kubectl apply -f -

To access the database execute the following command and navigate to the displayed port on localhost:

minikube service adminer --url

Helpful Commands to Interact with the Kubernetes Cluster

To access any service execute the following command and navigate to the displayed port on localhost:

minikube service <service> --url

To decode a secret with <name> and <path> execute:

kubectl get secret <name> --output="jsonpath=<path>" | base64 --decode

Backend Experiments

Deno

This chapter assumes the working directory to be /deno.

Deno is a simple, modern and secure runtime for JavaScript, TypeScript, and WebAssembly that uses V8 and is built in Rust.

Installation

See here. For Mac/Linux:

curl -fsSL https://deno.land/install.sh | sh

To automatically restart the application when a file changes install Denon

deno install -qAf --unstable https://deno.land/x/denon/denon.ts

Use the denon instead of the deno command to use it.

Execution

Make sure you have the following environment variables set (Note: they have to match what is used for the database service):

DB_HOST=database
DB_PORT=5432
DB_NAME=experiments
DB_USER=user
DB_PASSWORD=user123

You can set them by running:

export $(cat /operations/deployment/database.env | xargs)

Once the environment variables are setup you can execute the applicatino with:

deno run --allow-net --allow-env application.ts --port 8000

Testing

There is a minimal test suite which verifies that the endpoints work as defined in the spec. To run the test suite the application has to be running. You can execute the tests with:

deno test --allow-net -- --baseUrl 'http://localhost:8000/petstore'

Debugging

Execute this command if you want to stop execution at the first line:

deno run --allow-net --allow-env --inspect-brk application.ts --port 8000

or if you do not want to stop execution at the first line

deno run --allow-net --allow-env --inspect application.ts --port 8000

and navigate to:

chrome://inspect

Building

Note
because of how the docker build context works, you have to execute the build from within ch.resrc.backend-experiments/deno

Execute (docker can be used instead of podman):

podman build -t registry.resrc.ch/backend-experiments/deno:latest -f ../operations/container-images/deno/Containerfile .

Go

This chapter assumes the working directory to be /go.

Go is an open source programming language supported by Google.

Installation

See here.

Execution

Kotlin

This chapter assumes the working directory to be /kotlin.

Kotlin is a modern programming language that makes developers happier.

Installation

See here.

Execution

About

Same API implemented on different platforms and languages

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published