Skip to content

Latest commit

 

History

History
394 lines (251 loc) · 15.4 KB

architecture.adoc

File metadata and controls

394 lines (251 loc) · 15.4 KB

Architecture

Acknowledgements

This documentation is based on the arc42 template. The examples provided there and in "DokChess als Beispiel für arc42" act as templates for some sections. Many thanks to all contributors for your valuable work.

1 Introduction and Goals

Commuters using the Deutsche Bahn frequently face train delays and cancellations. Knowing the expected train delay or cancellation upfront allows to find alternative means of transportation so that the commuters reach their destination relaxed and on time.

The Train Delays system provides an easy mechanism to see train delays or cancellations early.

The Product Vision shows the long term goal for Train Delays.

1.1 Requirements Overview

At the moment, there is only one central functional requirement:

F1

Show expected next departure

The Train Delays application shows the expected departure time of the next train leaving the station Rösrath-Stümpen.

1.2 Quality Goals

The following table shows the quality goals of Train Delays. The order of the goals represents their priority roughly.

Low effort maintenance (Testability)

The risk that contributions break the system shall be low. In addition, it shall be easy for the maintainers to upgrade dependencies without breaking the system.

Low-cost operation (Resource Utilization)

Installing and running the system shall be very cheap. This allows the maintainers to provide the service for free while not having to pay too much for operations.

Easy to use (Learnability)

Users shall quickly be able to use the features of the system without error.

Easy for contributors to contribute (Modifiability)

It shall be easy for GitHub users to propose changes in form of pull requests.

2 Constraints

The following constraints apply for the Train Delays system:

Constraint Description and Background

Open source license

All parts of the system shall satisfy an open source license. The reason behind this is, that the system shall invite contributors. In addition, the code and concepts shall act as learning reference for the public.

Common technologies

The technologies used shall be widely known. This ensures that many other developers can understand the system. It also reduces the risk of complicated dependency updates and thereby simplifies maintenance.

3 Context and Scope

3.1 Business Context

Business Context Diagram
Figure 1. Business Context
Entity Description

User

The user is the commuter who wants to see the expected train delay or cancellation.

Deutsche Bahn Germany Open API Portal

This API portal is operated by Deutsche Bahn Germany. It provides the timetable data used by Train Delays.

3.2 Technical Context

3.2.1 Overview

Technical Context Diagram
Figure 2. Technical Context
Entity Description

Web Browser

The user opens the Train Delays application in the browser which retrieves the displayed page from the Train Delays system.

Deutsche Bahn Germany Open API Portal

Train Delays calls the APIs of the Deutsche Bahn Germany Open API Portal.

3.2.1 External Interfaces

Deutsche Bahn Germany Open API Portal

Section Subscribe to the DB API Marketplace Timetables API describes how to register for the API and subscribe to the used services.

The following links give detailed information on the API:

4 Solution Strategy

4.1 Guiding Principles and Architectural Approach

The following table relates the quality goals introduced in 1.2 Quality Goals:

Quality Goal Architectural Approach Supporting the Goal

Low effort maintenance (Testability)

  • Test coverage is high

    • For all features the happy path is tested by integration tests.

    • Boundary conditions and unhappy paths are tested - usually by unit tests.

    • Compatibility with the Deutsche Bahn Open API is tested using consumer driven API testing (Pact.io)

  • Automatic builds are started for every push and run all tests

Low-cost operation (Resource Utilization)

Easy to use (Learnability)

  • The user interface is designed to require a minimum number of interactions (clicks, touches)

Easy for contributors to contribute (Modifiability)

  • The system is constructed using mature and well-known technologies

  • Java is used for backend services

  • Readability and understandability are important aspects for new code

  • The architecture is described and updated frequently

5 Building Block View

The Train Delays application is a Spring Boot REST service. The structure is simple and can be found in the folder src/main/java/systems.boos.traindelays.

7 Deployment View

7.1 Overview

Deployment View
Element Description

Train Delays Docker Container

The Train Delays web application is a Java process running inside a docker container.

Cloud Run

The Train Delays Docker Container is hosted in the Google Cloud Run infrastructure.

Docker Image train-delays

This docker image is instantiated by Cloud Run when the Train Delays Docker Container is deployed. The image is automatically updated by Google Cloud Build whenever source code is pushed to the GitHub Repository wonderbird/train-delays.

Docker Repository

Google Cloud Run requires Docker images to be stored in a Docker Repository, which is part of the same Google project.

Artifact Repository

The Artifact Repository is the parent structure required when creating a Docker Repository in the Google Cloud.

Train Delays Project

This Google Cloud Console project is the container for all Google Cloud related configuration of the Train Delays system.

Source Code Repository wonderbird/train-delays

This repository contains the Java source code of the Train Delays web application.

Docker Image train-delays

This Docker image is built from the same sources as the image stored in the Docker Repository on Google. Hosting the image on dockerhub allows to share it with the Open Source Community.

Docker Repository boos

This public repository allows to share Docker images with the Open Source Community.

7.2 Initial Deployment (Disaster Recovery)

This section lists the steps to set up a deployment to Google Cloud Run from scratch. This is useful in the following scenarios:

  1. A new contributor has forked the Train Delays system and wants to deploy a system of her own.

  2. The Train Delays system has been destroyed without being able to recover.

7.2.1 Prerequisites

Subscribe to the DB API Marketplace Timetables API

The train-delays web application requires an access key for the DB API Marketplace. You can get one for free:

  1. Follow the instructions in So startest Du einfach mit den APIs (in German)

  2. From the Catalog of the DB API Marketplace subscribe to the Timetables API. Note: Specifying an OAuth2 Redirect URL is not necessary.

Warning
Store the Client Secret (the API Key) and the Client ID for APIs you subscribe to a password safe. The DB API Marketplace will not show the key later, but you can verify whether you have stored the correct key in DB API Marketplace / Applications.
Register with Google Cloud Platform and Install the gcloud CLI
  1. Register with Google Cloud Console

  2. Install the gcloud CLI

  3. Authenticate with gcloud (this is a part of the previous step)

    ```shell
    gcloud init
    ```

7.2.2 Setup Project and Continuous Deployment

  1. Follow the instructions in Store Docker container images in Artifact Registry to

  2. Create a service to automatically build the project by following Deploy a container to Cloud Run

    • When creating the service, connect to the (forked) GitHub repository

    • Create an environment variable named API_KEY and copy the DB API Client Secret into it

    • Create an environment variable named CLIENT_ID and copy the DB API Client ID into it

Note
You can review the applications registered with your DB API Marketplace account in DB API Marketplace / Applications.

8 Concepts

8.1 Build, Test, Deploy

Overview of the Build

For every change pushed to the GitHub repository, two build actions are triggered:

  1. The GitHub Build and Publish action builds and runs all tests. If successful, it updates the train-delays image on dockerhub.

  2. The Google Cloud Build action builds the docker image (again) and pushes it to the Docker repository within the Google project. From there, Cloud Run re-deploys the updated train delays instance.

8.2 Test Concepts

8.2.1 Acceptance Tests

Features and scenarios are specified using the Gherkin DSL and executed with Cucumber.

The following articles describe the used concepts:

8.2.2 API Verification

This application uses Pact tests to verify the following APIs:

8.2.3 Web Application UI Tests

Spring UI controllers are tested using HtmlUnit. In such tests, the backend services are stubbed using Spring `MockBean`s, so that only the UI controller is tested.

The HomeControllerTest.java gives an example.

8.2.4 Low Level Tests

JUnit5 based unit tests verify implementation details and most error scenarios.

8.2.5 References

8.3 Logging of the Production System

The production system logs are collected by Google Cloud Run and can be viewed in the Google Cloud Console.

For the current train-delays instance, the logs can be viewed at Google Cloud Run - Logs.

If you have created your own instance, then perform the following steps to view the logs:

  1. Open the Google Cloud Console

  2. Select the project in the dropdown at the top of the page

  3. Select the service

  4. Click on the "Logs" tab

9 Architecture Decisions

Architecture Decisions are documented in this section in the form of Architecture Decision Records (ADR). For more information, refer to the ADR GitHub Organization.

ADR-001 Deployment Platform: Google Cloud Run

status

accepted

date

July 3, 2022

Context and Problem Statement

The Train Delays web application shall be available as a permanent service with a fixed internet address.

Which deployment technology and hosting provider shall be selected?

Decision Drivers

From section 1.2 Quality Goals, especially the following quality attributes are important:

  • Low-cost operation (resource utilization)

  • Easy to use (learnability)

As described in section 2 Constraints, common technologies shall be used.

Considered Options

A short search on the internet brought up Geekflare: 10 Best Docker Hosting Platforms for your Containers dated June 30, 2022.

Decision Outcome: Google Cloud Run

From the list, Google Cloud Run has been tested shortly and selected. Other products have not been tested yet. This ADR shall be re-evaluated when the Google Cloud Run platform shows disadvantages or when other platforms seem to fit better.

The following properties of Google Cloud Run are matching the decision drivers:

  • Common technologies

    • The platform is compatible with the currently widely spread Docker container technology

    • An automatic deployment can be triggered by pushing changes to a GitHub repository

  • Low-cost operation (resource utilization)

    • Container instances are only paid when they are running

    • Docker containers are only created when there are pending requests

    • Docker containers are automatically shut down when idle

    • Request rate limits can be configured

    • The maximum number of running Docker containers can be configured

  • Easy to use (learnability)

Documentation of the Google Cloud Run Platform

The following links are presented in suggested reading order:

The following links show the tools provided by Google: