This project is the Tronbyt Server, a Go-based application which manages Tronbyt devices (flashed Tidbyts) locally, providing a web UI and API for app management and rendering.
The core functionality involves serving WebP images to devices, generated by rendering Pixlet apps (Starlark scripts). The server integrates with the native Go pixlet library.
- Language: Go 1.26+
- Web Framework: Standard Library
net/httpwithServeMux(Go 1.22+ routing features). - Database: SQLite/Postgres/MySQL with GORM (ORM). Data is stored in a relational schema (Users, Devices, Apps).
- Templating:
html/template(standard library). - Rendering: Native Go integration with
github.com/tronbyt/pixlet. - Authentication: Session-based (secure cookies via
gorilla/sessions) with Argon2id password hashing. WebAuthn/passkey support viago-webauthn. - Internationalization:
go-i18n(JSON translation files). - Monitoring: Prometheus metrics via
prometheus/client_golang(application metrics + GORM database stats).
cmd/boot/: Entry point for containers.cmd/server/: Main entry point for the server binary.cmd/migrate/: Tool to migrate legacy SQLite databases to the new schema.internal/apps/: App metadata and discovery.internal/auth/: Authentication logic (password hashing).internal/config/: Configuration loading (env vars).internal/data/: Data models and GORM setup.internal/firmware/: Device firmware generation.internal/gitutils/: Utilities for git operations (apps repositories).internal/legacy/: Helpers for reading legacy Python-based data structures.internal/migration/: Migration tooling from earlier versions.internal/renderer/: Pixlet rendering integration.internal/server/: HTTP handlers, middleware, routing, and business logic.internal/sync/: Event hub for websockets.internal/version/: Version information.web/i18n/: Translation files (e.g.,de.json).web/static/: Static assets (CSS, JS, images).web/templates/: HTML templates.
- Dependencies: Ensure Go 1.26+ and C build tools (gcc) are installed.
- Run with
go run(for development):go run ./cmd/server -db data/tronbyt.db -data . - Build and Run (for production/deployment):
go build -o tronbyt-server ./cmd/server ./tronbyt-server -db data/tronbyt.db -data .
go test ./...
- Build:
docker build -t tronbyt-server . - Run:
docker run -p 8000:8000 -v $(pwd)/data:/app/data tronbyt-server
- Formatting: Use
go fmt ./...for Go anddjlint --profile=golang --reformatfor HTML templates. - Linting: Use
golangci-lint runfor Go anddjlint --profile=golang --lintfor HTML templates. - Pre-commit hooks: The repository uses
pre-commithooks that automatically rungo fmt,go test,golangci-lint, anddjlinton commit. - Logging: Use
log/slogfor structured logging. - Templates: Use
{{ t .Localizer "MessageID" }}for translated strings. - Database: Use GORM for DB interactions. Ensure migrations are updated in
cmd/migrateor auto-migrated inserver.goif appropriate.- Generics API: Strongly prefer the new Generics API (e.g.,
gorm.G[data.User](db).First(...)) over the old interface-based API (db.Model(&data.User{}).First(...)) for better type safety and clarity. - Updates Pattern: When updating single columns or a subset of fields on a model that has preloaded associations (like
Device.Apps), ALWAYS use a lightweight struct with only the ID:s.DB.Model(&data.Device{ID: device.ID}).Update(...). Passing the fully populated structs.DB.Model(&device)can trigger GORM to unintentionally re-save preloaded associations, potentially causing race conditions (e.g., deleted apps reappearing).
- Generics API: Strongly prefer the new Generics API (e.g.,
- Testing: Use the
testifylibrary (assertandrequire) in unit tests.