Skip to content

Code Standards

Derrik Diener edited this page Jul 16, 2026 · 1 revision

Code Standards

To keep the Supernova codebase clean, fast, and maintainable, we adhere strictly to the following standards.

Go (Backend)

  1. Error Handling:
    • Never ignore errors.
    • Do not leak internal Go error strings (err.Error()) to the frontend. Return generic HTTP messages (e.g. http.Error(w, "failed to fetch data", 500)) and log the actual error internally.
  2. Resource Management:
    • Always defer rows.Close() immediately after executing a database query, but also check rows.Err() after iteration loops to catch silent truncation.
    • Limit arbitrary network read payloads using io.LimitReader or http.MaxBytesReader to prevent OOM DOS attacks.
  3. Database Transactions:
    • Any operation that modifies multiple tables (e.g., merging albums, deleting tracks with associated hearts) MUST use db.BeginTx() and ensure proper rollback on failure.

React/TypeScript (Frontend)

  1. Strict Types:
    • We use verbatimModuleSyntax. Types must be imported explicitly: import type { Track } from '../types'.
    • Avoid any types. Type your API responses and context states explicitly.
  2. Performance & Hooks:
    • All Context-provided functions must be wrapped in useCallback to prevent cascading re-renders across the app.
    • State objects passed into Context Providers must be wrapped in useMemo.
    • Do not pass inline objects or functions down to heavily repeated components (like track rows).
  3. Async Effects:
    • Every useEffect that performs asynchronous operations must include an isMounted guard to prevent state updates on unmounted components.

Clone this wiki locally