Refactor: split oversized API files and move to a Server struct with a store layer #42

Open
opened 2026-10-09 12:42:38 +00:00 by niklas · 0 comments
Owner

Remaining structural items from the Oct 2026 review (none urgent; do alongside other work in the same files):

  • teams.go (~1000 lines) holds teams, members, integrations, deadman CRUD: split into teams.go, members.go, integrations.go, deadman_api.go. settings.go and signup.go contain unrelated handlers (rename team, invite CRUD, test notification, onboarding); oidc.go mixes the HTTP flow with provisioning and group sync; notifier.go mixes the outbox with ntfy rendering; escalation.go has two near-duplicate view layers.
  • Handlers take (db, notify, cfg, publicURL) by hand (~80 constructors) with SQL inline: a Server struct holding db/config/notifier/limiter and a small store per resource.
  • loginLimiter serves signup, SSO and device login too; three router instances share one table: one rateLimiter with key prefixes.
  • Settings machinery (settings.go) decodes map[string]any with float coercion and keeps bounds and defaults in two places; make it a typed struct. Config lives in env, the settings table, per-team tables and chart values: pick two tiers.
  • Reminders and escalation overlap and there are two fallback topics (install-wide NtfyFallbackTopic, per-team fallback_topic): model reminders as the implicit one-level policy with one per-team fallback.
  • The device flow issues a browser-style session to a CLI and hard-codes HasPassword: false (device.go): mint an expiring API key instead.
  • Error bodies are {"error": msg} with ad hoc reason/machine codes: {"error":{"code","message"}} everywhere, and one rule for 204 vs body.
  • Database wait is implemented twice (Go ping retry and the chart's wait-for-postgres init container).
Remaining structural items from the Oct 2026 review (none urgent; do alongside other work in the same files): - `teams.go` (~1000 lines) holds teams, members, integrations, deadman CRUD: split into `teams.go`, `members.go`, `integrations.go`, `deadman_api.go`. `settings.go` and `signup.go` contain unrelated handlers (rename team, invite CRUD, test notification, onboarding); `oidc.go` mixes the HTTP flow with provisioning and group sync; `notifier.go` mixes the outbox with ntfy rendering; `escalation.go` has two near-duplicate view layers. - Handlers take `(db, notify, cfg, publicURL)` by hand (~80 constructors) with SQL inline: a `Server` struct holding db/config/notifier/limiter and a small store per resource. - `loginLimiter` serves signup, SSO and device login too; three router instances share one table: one `rateLimiter` with key prefixes. - Settings machinery (`settings.go`) decodes `map[string]any` with float coercion and keeps bounds and defaults in two places; make it a typed struct. Config lives in env, the `settings` table, per-team tables and chart values: pick two tiers. - Reminders and escalation overlap and there are two fallback topics (install-wide `NtfyFallbackTopic`, per-team `fallback_topic`): model reminders as the implicit one-level policy with one per-team fallback. - The device flow issues a browser-style session to a CLI and hard-codes `HasPassword: false` (`device.go`): mint an expiring API key instead. - Error bodies are `{"error": msg}` with ad hoc `reason`/machine codes: `{"error":{"code","message"}}` everywhere, and one rule for 204 vs body. - Database wait is implemented twice (Go ping retry and the chart's `wait-for-postgres` init container).
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: niklas/terdut-server#42