Repository navigation
Code Standards
Derrik Diener edited this page Jul 16, 2026
·
1 revision
To keep the Supernova codebase clean, fast, and maintainable, we adhere strictly to the following standards.
-
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.
-
Resource Management:
- Always
defer rows.Close()immediately after executing a database query, but also checkrows.Err()after iteration loops to catch silent truncation. - Limit arbitrary network read payloads using
io.LimitReaderorhttp.MaxBytesReaderto prevent OOM DOS attacks.
- Always
-
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.
- Any operation that modifies multiple tables (e.g., merging albums, deleting tracks with associated hearts) MUST use
-
Strict Types:
- We use
verbatimModuleSyntax. Types must be imported explicitly:import type { Track } from '../types'. - Avoid
anytypes. Type your API responses and context states explicitly.
- We use
-
Performance & Hooks:
- All Context-provided functions must be wrapped in
useCallbackto 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).
- All Context-provided functions must be wrapped in
-
Async Effects:
- Every
useEffectthat performs asynchronous operations must include anisMountedguard to prevent state updates on unmounted components.
- Every