name: code-review description: Use to review Go backend changes for correctness, security, modular-monolith boundaries, error handling, SQL safety, domain invariants, and missing tests. Trigger when the user asks for code review, PR review, audit findings, or correctness/security review.
Code Review Skill
You are reviewing Go code in the VMARBLE Warehouse Management Service (modular monolith).
Review checklist
Architecture & Module boundaries
- Module does NOT import another module package (black box rule)
- Cross-module deps use interfaces in
deps.go, wired only inmain.go - Business logic is in
service.go, NOT inhandler.goorpgstore.go - HTTP concerns stay in
handler.go(param binding, error mapping) - SQL stays in
pgstore.go(queries, row mapping)
Go conventions
-
gofmtformatted - Import grouping: stdlib → third-party → local
- No stutter in names (e.g.,
inventory.Servicenotinventory.InventoryService) - Only
iface.goexports andinternal/domain/are exported; rest unexported - Explicit names in business logic (
planIDnotpID)
Error handling
- Uses sentinel errors from
internal/domain/errors.go - Wraps with
NewBizError(sentinel, humanMessage)for domain failures - No raw
pgx/SQL errors leaked to handlers - Error wrapping with
fmt.Errorf("...: %w", err), no double-wrapping BizError - Correct HTTP status mapping (400/404/409/412/422)
Context & IO
-
context.Contextaccepted in store/service methods touching IO - Handlers pass
c.Request.Context() - No
context.Background()in request flows
Database
-
QueryRow/Scanfor single-row; checkspgx.ErrNoRows→ErrNotFound - Transactions for multi-write atomicity
- SQL parameterized, no string concatenation with user input
-
RETURNINGpreferred over follow-up selects
Domain invariants (must NOT violate)
- WorkOrder state machine:
PLANNED → IN_CUTTING → IN_PROCESSING → COMPLETED → COSTED - Area conservation:
used_area + remnant_area <= source_area - Remnant lineage:
parent_board_id+ optionalparent_remnant_id - Costing immutability: finalized records are immutable (BR-C04)
- Metal requirement:
requires_metal=trueneeds METAL consumption before COMPLETED
Testing
- Table-driven tests where practical
- Deterministic (no sleeps, no time dependencies)
- Unit tests for
service.gowith mocked store/deps -
make lintclean
Output format
Provide findings as:
- Critical — must fix (invariant violations, data loss risks)
- Important — should fix (convention violations, error handling gaps)
- Suggestion — nice to have (readability, naming improvements)
Include file:line references and suggested fixes.