3.9 KiB
3.9 KiB
Code Style Profile (Go + JSX/Next.js)
This document captures your current coding style as seen in the repository and lists questions to refine your preferred style rules.
Go Style (Observed)
What is consistent
- Clear layered architecture:
handlers -> services -> repositories. - Short, readable functions with early returns over deep nesting.
- Explicit request/response DTO structs in handlers with Gin binding tags.
- Business logic mostly lives in
services, SQL mostly inrepositories. - Error mapping style is pragmatic (
models.ErrBadRequest,ErrForbidden, etc.). - Naming is mostly clear and domain-driven (
AssignPosition,RecordUserConsent,GetUserPositions).
Style characteristics
- You prefer practical over abstract code (few interfaces beyond service boundaries).
- You accept some inline structs for one-off request payloads.
- You keep SQL as raw strings in repository methods (not hidden behind ORM abstractions).
- You usually avoid over-commenting; code is expected to be self-explanatory.
- You follow
gofmtdefaults and avoid stylistic tricks.
JSX / Next.js Style (Observed)
What is consistent
- Functional components with hooks (
useState,useForm,useTranslations). - Strong TypeScript typing for props and form data.
- UI composition via reusable primitives (
Dialog,Table,Button, custom fields). - Local optimistic state updates after server actions.
- Short handlers with readable names (
handleCreated,handleUpdated,handleDelete). - Frequent early exits on failure (
if (!result.success) { ... return }).
Style characteristics
- You favor compact code and inlined JSX in places where intent is obvious.
- You rely on server actions for API calls and keep transport details in
actions/*. - You use translation keys heavily (good i18n discipline).
- You keep component files focused on one domain workflow.
Your Answers (Captured)
Go
- Error philosophy: undecided for now.
- Strict types over
any: undecided for now. - Authorization model: should be based on explicit permissions; admin role is a temporary service mechanism.
- Zero affected rows on update/delete: return
not_foundby default. - SQL approach: keep inline raw SQL in this project.
JSX / Next.js
- Component formatting: compact by default; multiline only when complexity justifies it.
- Mutation strategy today: optimistic updates currently used.
- Validation style: prefer schema-based validation over ad-hoc inline checks.
Pending Clarifications
-
Optimistic vs refetch default (Q7):
Recommendation: keep optimistic update as default for snappy UX, and use refetch for high-risk operations (complex server-side side effects, computed fields, permission-dependent payloads). -
Display naming policy (Q8, clarified):
Proposed rule: in UI, show user-facing label first (nameordescription) and fallback tocodeonly when label is empty.
Please confirm if you want this as a global rule.
Final Summary (Current)
Confirmed style rules
- Go authorization should move toward explicit permissions, not role-only checks.
- Go repositories should return
not_foundfor update/delete when0 rows affected. - Go SQL stays inline/raw in this project.
- JSX/Next components should be compact by default; multiline formatting is allowed when readability needs it.
- Frontend validation direction is schema-first.
Recommended defaults
- Mutation UX: optimistic updates by default; refetch only for risky mutations with possible server-side divergence.
- Action results: migrate from bare
{ success }to richer result objects:- success path:
{ success: true, data?: T } - error path:
{ success: false, errorCode: string, message?: string }
- success path:
Still open
- Go error-wrapping strictness (
fmt.Errorf("...: %w", err)everywhere vs selective). - Strict ban of
anyin all service/repository boundaries. - Global UI naming fallback rule (
name/descriptionfirst,codeas fallback).