TUM-Dev / Campus-Backend

New backend written in go with gRPC as an API interface
GNU General Public License v3.0
15 stars 7 forks source link

Campus-Backend

This repository holds the following components:

The API is publicly available for anyone, but most notably, it's the main backend system for the TUM Campus Apps (Android, iOS, and Windows).

Running the Server (without Docker)

Installing Requirements

The backend uses MySQL as its backend for storing data. While it is possible to install mysql natively (instructions are on their website), we recommend the following:

docker run

Setting up the DB

To setup the DB, connect to your DB server or use mysql to connect to it locally.

DROP DATABASE campus_backend; -- Drop an eventually existing old DB
CREATE DATABASE campus_backend; -- Create a new DB for the backend

CREATE USER 'gorm'@'localhost' IDENTIFIED BY 'gorm'; -- Create a new user called `gorm`.
GRANT ALL PRIVILEGES ON campus_backend.* TO 'gorm'@'localhost'; -- Garant our `gorm` user access to the `campus_backend` DB.
ALTER USER 'gorm'@'localhost' IDENTIFIED BY 'GORM_USER_PASSWORD'; -- Set a password for the `gorm` user.
FLUSH PRIVILEGES;

Starting

To start the server there are environment variables, as well as command line options available for configuring the server behavior.

cd  server
export DB_DSN="Your gorm DB connection string for example: gorm:GORM_USER_PASSWORD@tcp(localhost:3306)/campus_db?charset=utf8mb4&parseTime=True&loc=Local"
export DB_NAME="The DB-name from above string for example: campus_backend"
go run ./main.go

Environment Variables

There are a few environment variables available:

Running the Server (Docker)

docker compose -f docker-compose.local.yml up -d

The docker compose will start the server and a mysql instance (=> without routing/certificates to worry about) The server will be available at localhost:50051 and the mysql instance at localhost:3306. Additionally, docker creates the volume campus-db-data to persist the data of the mysql instances.

Environment Variables

The following environment variables need to be set for the server to work properly:

Metrics

Our service uses prometheus to collect metrics to display in grafana. To see the metrics we aggregate, head over to http://localhost:50051/metrics

iOS Push Notifications Service

The iOS Push Notifications Service can be used to send push notifications to iOS devices.

Visual Studio Code

There are already predefined Visual Studio Code launch tasks for debugging the client and server. Take a look at the launch.json file for more details.

Please be respectful with its usage!

pre-commit

To ensure that that common pitfalls which can be automated are not done, we recommend you to install pre-commit. You can do so via

python -m venv venv
source venv/bin/activate
pip install pre-commit
pre-commit install

Certain pre-commit hooks will now be run on every commit where you change specific files. If you want to run all files instead, run pre-commit run -a