You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This file defines the review standards for routatic-proxy. It is designed for LLM-based review tools, CI/CD pipelines, and human reviewers. Each check is tagged with its layer and severity.
Severity:
BLOCKER — must fix before merge
REQUIRED — should fix, merge only with justification
ADVISORY — best practice, consider
Layers:
[T] — Technical (Go idioms, safety, concurrency)
[L] — Logical (correctness, edge cases, data flow)
sync.Mutex embedded in structs, mu.Lock() / defer mu.Unlock() pattern
REQUIRED
rules/auto-detected/SYNC_MUTEX.md
T15
Separate mutexes for independent state (not one big lock)
ADVISORY
rules/auto-detected/SYNC_MUTEX.md
T16
Use sync.RWMutex when reads dominate writes
ADVISORY
rules/auto-detected/SYNC_MUTEX.md
T17
Ensure gofmt compliance (run make lint)
BLOCKER
CONTRIBUTING.md
T18
All files compile with CGO_ENABLED=0 go build (default)
BLOCKER
Makefile
1.2 Memory & Resource Safety
#
Check
Severity
Rationale
T19
defer is not used inside for/for-range loops (runs on function return, leaks resources)
BLOCKER
TOCTOU + leak pattern
T20
HTTP response bodies are closed explicitly (not deferred in loops)
BLOCKER
Resource leak
T21
Test-bind-then-close (TOCTOU) patterns are absent — listeners are bound once and kept
BLOCKER
Race condition
T22
defer cancel() or explicit cancel() present for every context.WithTimeout/WithCancel
REQUIRED
Context leak
T23
No goroutine leaks: goroutines have a shutdown signal (ctx.Done(), channel close, WaitGroup)
REQUIRED
Production reliability
T24
No panic() in library code; recover only at top-level HTTP handler boundaries
REQUIRED
Crash safety
1.3 Frontend (HTML/CSS/JS)
#
Check
Severity
Rationale
T25
No external CDN scripts or stylesheets — all assets bundled via //go:embed
REQUIRED
Offline capability, CSP, supply-chain
T26
CSP header restricts default-src 'self'; only 'unsafe-inline' for scripts and styles
REQUIRED
XSS mitigation
T27
No inline onclick/onchange handlers referencing undefined functions (check against app.js)
REQUIRED
Silent failures
T28
data-i18n keys exist in TRANSLATIONS.en (and TRANSLATIONS.zh if Chinese)
REQUIRED
i18n completeness
T29
Translations use t(key) function, not direct string references
REQUIRED
I18n correctness
T30
No confirm()/prompt()/alert() in production code — use modal or <select> instead
ADVISORY
UX quality
T31
Loading states shown during data fetches (spinner or skeleton)
ADVISORY
UX quality
T32
/api/* endpoints accessed by the frontend correspond to real backend handlers
REQUIRED
404 errors
1.4 Configuration & Secrets
#
Check
Severity
Rationale
T33
API keys loaded from env vars or config file, never hardcoded
BLOCKER
Security
T34
Config values support ${VAR} env interpolation
REQUIRED
internal/config/loader.go
T35
Provider-specific keys (*_API_KEY) take precedence over global; documented precedence chain
REQUIRED
CLAUDE.md
T36
Port numbers are configurable via env var or CLI flag, not hardcoded
ADVISORY
Deploy flexibility
T37
Config file writes are atomic (write temp, rename)
REQUIRED
Crash safety
1.5 Documentation Completeness
#
Check
Severity
Rationale
T38
Every exported symbol has a // <Name> doc comment — packages, types, funcs, consts, vars
REQUIRED
CONTRIBUTING.md, godoc
T39
Package-level doc comments describe the package's responsibility, not its file contents
REQUIRED
Go convention
T40
Non-obvious logic has inline comments explaining why, not what
REQUIRED
Maintainability
T41
Config changes (new fields, changed defaults, removed keys) update the example config and CLAUDE.md
REQUIRED
First-run UX, LLM accuracy
T42
API endpoint changes update any user-facing docs (README, ARCHITECTURE, CLAUDE.md)
REQUIRED
Alignment — code vs docs
T43
CHANGELOG or release notes updated for user-facing changes (new features, breaking changes, deprecations)
REQUIRED
Release readiness
T44
docs/ directory or inline .md files in the affected package are updated to reflect the change
ADVISORY
Discoverability
T45
Deprecated symbols use // Deprecated: doc comment with migration path
ADVISORY
API hygiene
1.6 Duplication & Reuse
#
Check
Severity
Rationale
T46
New code first searches for existing helpers, types, or packages that already serve the purpose — no reinventing
REQUIRED
DRY, consistency
T47
Shared logic (field mapping, type conversion, JSON construction) is extracted to named helpers, not duplicated inline
REQUIRED
Single source of truth
T48
Repeated field-map patterns between types use a helper function, not copy-paste blocks
REQUIRED
internal/catalog/migrate.go precedent
T49
New scenarios, fallbacks, or model configs use existing mechanisms (scenario map, config struct, catalog), not inline conditionals
REQUIRED
Config-driven architecture
T50
Common transformations (Anthropic↔OpenAI field renames, token math, cost lookups) use the existing internal/transformer/ or internal/catalog/ packages — no ad-hoc reimplementation
REQUIRED
Correctness, maintainability
T51
New types reuse existing project types (e.g. pkg/types.Message), not inline structs
REQUIRED
API contract integrity
T52
Existing constructor, error, logger, and mutex patterns are followed — not one-off alternatives
ADVISORY
rules/auto-detected/ consistency
2. Logical Layer
2.1 Correctness
#
Check
Severity
Rationale
L1
Map value mutations re-assign to map: v.Field = x; m[key] = v (value type semantics in Go)
BLOCKER
Silent data loss
L2
All branches of conditional assignments are complete — no omitted fields
REQUIRED
Data inconsistency
L3
Fallback chain iteration correctly identifies the primary model (index 0) vs fallbacks
REQUIRED
Routing correctness
L4
Circuit breaker counts only retryable errors (5xx), not 4xx or client cancellation
REQUIRED
internal/router/fallback.go
L5
Stream idle timeout is per-Read, not server-level WriteTimeout
REQUIRED
CLAUDE.md stream policy
L6
Client disconnects during stream are logged at Debug, not Error
REQUIRED
CLAUDE.md stream policy
L7
hasToolUsage checks only unambiguous tool-calling patterns, not everyday words like "bash"
REQUIRED
False positives
L8
Model fallbacks carry correct config (provider, temperature, max_tokens) — not just model_id
REQUIRED
Config-driven routing
2.2 Edge Cases
#
Check
Severity
Rationale
L9
Nil history.History or metrics.Metrics returns zero values, not panics
REQUIRED
CLAUDE.md nil safety
L10
Empty model chain returns an informative error, not panic/empty response
REQUIRED
First-run UX
L11
Zero token count, zero cost, empty trend data render as — not $NaN or undefined
REQUIRED
Analytics dashboard
L12
Headless mode (--headless, serve) does not attempt GUI operations
REQUIRED
Cross-platform
L13
Port-scan fallback (GUI port 3445→3454) notifies user, doesn't silently pick different port
ADVISORY
User awareness
L14
JSON body is limited with http.MaxBytesReader before parsing
REQUIRED
DOS prevention
L15
SSE stream transformers handle partial/incomplete JSON chunks without panic
Each review should produce findings under two independent axes:
Standards — does the code follow the documented rules (sections 1–3)? Distinguish hard violations (tagged BUILDER/REQUIRED) from judgement calls (ADVISORY/smells).
Spec — does the code faithfully implement what was asked? Identify missing requirements, scope creep, and wrong implementations separately.
Report them side by side, never reranked into a single score — a change can pass one axis and fail the other.
6. Quick Reference: File-to-Rule Mapping
Universal rules (all files): T38–T45 (documentation), T46 (search before invent), T47 (extract shared logic), T48 (no copy-paste mapping), T50 (reuse transformer/catalog), T51 (reuse project types), T52 (follow established patterns), S2 (no duplicated code), S6 (no repeated switches), S7 (shotgun surgery).