The API behind the TUM Campus Apps. One Go binary serves gRPC and REST, and also scrapes the campus for data.
Every time a student at the Technical University of Munich opens the TUM Campus App to check today's menu, rate a dish, find out how crowded the Mensa is, or see what TU Film is showing this week, the request ends up here.
The API is public. If you want to build something for campus, you can use it too. Please use it responsibly.
| Feature | Where the data comes from | |
|---|---|---|
| 🍝 | Canteens and dishes: menus, opening info, ratings with tags | eat-api + ratings from app users |
| 👥 | Live canteen head count: how full is the Mensa right now? | Estimated from LRZ Wi-Fi access point stats |
| 📰 | News and alerts from TUM sources | Scraped on a schedule by cron jobs |
| 🎬 | Movies from TU Film, with posters and metadata | tu-film.de + OMDb |
| 🏛️ | Student clubs directory | Scraped from the student council site |
| 💬 | Feedback with image uploads (gRPC streaming), sent out by email | App users |
| 📱 | Update notes and device registration | App users |
Campus apps ──gRPC──┐
▼
┌── :50051 (cmux) ──┐
│ │
application/grpc HTTP/1
│ ├── /v1/* → grpc-gateway ─┐
▼ ├── /swagger/ → Swagger UI │
gRPC server ◀────────────┼───────────────────────────────┘
│ ├── /metrics → Prometheus
▼ ├── /files/ → /Storage
CampusServer └── /health
│
▼
MySQL ◀── CronService (scrapers, polls `crontab` every 30 s)
In production, REST is served at api.tum.app and gRPC at api-grpc.tum.app:443.
- One proto, two protocols.
campus_backend.protois the single source of truth. gRPC stubs, the REST gateway and the OpenAPI spec are all generated from it. - One port.
cmuxlooks at each connection and sends it to gRPC or HTTP. - Built-in cron. Scrapers and downloaders run inside the same binary, scheduled from the
crontabtable. - Observability. Prometheus metrics, Sentry error reporting and structured logs via logrus.
You need Docker. That's it.
git clone https://github.com/TUM-Dev/Campus-Backend.git
cd Campus-Backend
docker compose -f docker-compose.local.yml up --watchThis starts MySQL and the backend at localhost:50051. With --watch, the server is rebuilt and restarted every time you save a file in server/. Changes to tests, test data and Markdown files are ignored. Use up -d instead if you just want it running in the background.
Now try it:
# REST
curl localhost:50051/v1/canteen/allCanteens
curl localhost:50051/v1/news/sources
# gRPC (server reflection is enabled)
grpcurl -plaintext localhost:50051 list
grpcurl -plaintext localhost:50051 api.Campus/ListCanteens| URL | What you get |
|---|---|
localhost:50051/v1/… |
REST API |
localhost:50051/swagger/ |
Swagger UI (see note) |
localhost:50051/metrics |
Prometheus metrics |
localhost:50051/health |
Health check |
localhost:3306 |
MySQL (data persists in the mysql-data volume) |
cd server
DB_DSN='root:secret_root_password@tcp(localhost:3306)/campus_db?charset=utf8mb4&parseTime=True&loc=Local' go run .All Go commands run from server/.
go build ./...
go test ./... # spins up a MySQL testcontainer, so Docker is required
bash api/generate.bash # regenerate gRPC, gateway and Swagger code from the protoTests that need a database start one MySQL container per test binary via testcontainers and give each test its own database with the production schema. To reuse a MySQL server that's already running:
TEST_MYSQL_DSN='root:secret_root_password@tcp(localhost:3306)/' go test ./...VS Code users get debug configs for free in .vscode/launch.json.
server/
├── main.go # entry point: cmux, gRPC, gateway, HTTP routes
├── api/tumdev/ # campus_backend.proto + generated code
├── backend/ # one file per domain: cafeteria.go, news.go, movie.go, …
│ ├── cron/ # scheduled scrapers and downloaders
│ └── migration/ # schema migrations (legacy Go + Atlas-generated sql/)
├── model/ # GORM models, one per table
└── utils/ # DB setup, test containers, telemetry, error mapping
client/ # example gRPC clients (separate Go module)
➕ Add a new endpoint
- Add an
rpcwith agoogle.api.httpoption, plus its request and reply messages, tocampus_backend.proto. - Run
bash api/generate.bashand commit the generated files. - Implement the method on
*CampusServerinserver/backend/<domain>.go. Start it withs.checkDevice(ctx)and returnstatus.Error(codes.X, …)errors.
main automatically opens a PR in Campus-Flutter.
🗄️ Change the database schema
Migrations are generated with Atlas from the GORM models and applied by the server on startup.
- Edit the model in
server/model/. If it's a new model, add it tomigration.Models(). - In
server/, runatlas migrate diff --env gorm <short_name>(install Atlas; Docker is required). It writesbackend/migration/sql/<version>_<short_name>.sqland updatesatlas.sum. - Review the generated SQL and commit it together with
atlas.sum.
For data changes, or for views and triggers (which Atlas' free edition doesn't manage), edit the generated file or create one with atlas migrate new --env gorm <short_name>, then run atlas migrate hash --env gorm.
The desired schema is the models plus legacy.sql, which declares production tables without a model. The Go migrations in backend/migration/ are frozen, including the post-baseline registry; a regression test rejects new Go migration IDs. Keep existing IDs for compatibility, but never duplicate an Atlas schema change in Go. CI fails, and comments the missing SQL on your PR, if the models change without a migration.
⏰ Add a cron job
- Add a type constant in
backend/cron/cronjobs.goand wire it into the query and theswitch. - Add the value to the
typeenum inmodel/crontab.go. - Generate the migration with
atlas migrate diff --env gorm <short_name>, append theINSERTfor thecrontabrow, then runatlas migrate hash --env gorm.
| Variable | Required | Purpose |
|---|---|---|
DB_DSN |
✅ | MySQL DSN. Docker Compose builds it from DB_NAME, DB_USER_NAME, DB_USER_PASSWORD and DB_PORT in .env. |
ENVIRONMENT |
dev or prod. Changes telemetry behavior. |
|
SENTRY_DSN |
Error reporting via Sentry | |
OMDB_API_KEY |
Movie metadata from OMDb | |
SMTP_URL, SMTP_PORT, SMTP_USERNAME, SMTP_PASSWORD, SMTP_FROM |
Sending feedback emails |
The committed .env contains only local dev defaults. Put real secrets in .env.local, which is gitignored.
Contributions are very welcome, whether that's a bug fix, a new scraper or a whole new feature for the apps.
- Install pre-commit so formatting,
goimports, proto regeneration andgo mod tidyrun automatically:pip install pre-commit && pre-commit install pre-commit run -a # optional: check every file once
- Make your change, add tests, and open a PR. CI runs the tests, golangci-lint and the migration checks.
Working with an AI coding agent? AGENTS.md has the full conventions.
/swagger/locally has no spec until you copyserver/api/tumdev/campus_backend.swagger.jsontoserver/swagger/swagger.json. The Dockerfile does this for you.docker-compose.ymlis the production deployment. Usedocker-compose.local.ymlfor local work.- Some legacy columns have odd names (
lastRun,barrierFree_moreInfo). Production relies on them, so leave them as they are.