Sign inSign up

syafa/kibooz-backend

By syafa

•Updated 3 days ago

REST API for Kibooz, a kindergarten app that tracks moods and rewards trash sorting

Image
Languages & frameworks
0

10K+

syafa/kibooz-backend repository overview

⁠Kibooz Backend

REST API for Kibooz, the kindergarten app that lets teachers record children's moods, lets parents follow them, and rewards trash sorting with points on a class leaderboard.

The source code, issues and documentation are on GitHub⁠. The API reference, with every route, field, limit and error code, is at https://docs.kibooz.syafahadyan.com⁠. The project is licensed under GPL-3.0.

Apps that call the API should read the client guide⁠ on the tokens, the device token and the rate limits.

⁠Tags

TagWhat it is
latestThe newest build of the main branch
x.y.z, x.y, xA release, for example 0.4.0, 0.4 and 0. Pin x.y.z in production
sha-<commit>The build of one commit
pr-<number>The build of a pull request, for testing only

⁠About the image

  • A single static Go binary on a distroless base image, about 11 to 13 MB compressed depending on the platform
  • Runs as a non-root user (UID 65532) and listens on port 8080
  • Built for linux/amd64 and linux/arm64, so it also runs on Apple silicon and ARM servers. Releases up to 0.3.0 are linux/amd64 only
  • Has a built-in health check that calls /healthz, which answers 200 when the database is up even if Redis is down
  • SQL migrations are embedded in the binary and applied on startup

⁠What it needs

  • PostgreSQL 15, which is required
  • Redis 7, which is optional. Without it the API still works and /healthz reports degraded
  • An S3 compatible bucket for avatars and trash photos, which is optional. Uploads are off when it is not configured

⁠Quick start

The repository ships a production Compose stack with the API, PostgreSQL and Redis.

curl -O https://raw.githubusercontent.com/SyafaHadyan/kibooz-backend/main/compose.yml
curl -o .env https://raw.githubusercontent.com/SyafaHadyan/kibooz-backend/main/.env.example
# edit .env and set DB_NAME, DB_USERNAME, DB_PASSWORD, REDIS_PASSWORD, JWT_SECRET_KEY and S3_*
docker compose up -d

To run only the API against a PostgreSQL you already have, use this.

docker run -d --name kibooz-backend -p 8080:8080 \
  -e DB_HOST=your-postgres-host -e DB_NAME=kibooz -e DB_USERNAME=kibooz -e DB_PASSWORD=change-me \
  -e JWT_SECRET_KEY=at-least-32-random-characters \
  syafa/kibooz-backend:latest

⁠Configuration

Every setting is an environment variable. The main ones are below, and the full list is in the README⁠.

VariableDefaultPurpose
DB_HOST, DB_PORT127.0.0.1, 5432PostgreSQL address
DB_NAME, DB_USERNAME, DB_PASSWORDrequiredPostgreSQL database and credentials
JWT_SECRET_KEYrequiredSigning key, at least 32 characters
REDIS_ADDRESS, REDIS_PORT, REDIS_PASSWORD127.0.0.1, 6379Optional Redis, set REDIS_TLS=true for hosted Redis that needs TLS
S3_*emptyOptional object storage for uploads
APP_PORT8080HTTP port
APP_TIMEZONEAsia/JakartaSchool timezone used for "today" and the weekly chart
USER_LIMITER_MAX, AUTH_LIMITER_MAX120, 10Requests per minute for each signed-in user and for each account on login, register, refresh and logout
DEVICE_TOKEN_TTL_DAYS90Days that a device token from login stays valid, so a returning device keeps its own login limit

⁠Running it in production

Put a reverse proxy with TLS in front of the API. The API does not set Strict-Transport-Security, so enable it on the proxy. Rate limits count users and accounts and never IP addresses, so add a request limit on the proxy or CDN to protect the public auth routes from floods.

Tag summary

Content type

Image

Digest

sha256:7c1dc5be2…

Size

12.4 MB

Last updated

3 days ago

docker pull syafa/kibooz-backend