Branch Code Review
Review code changes on a feature branch, checking for:
- Pattern consistency with existing codebase
- Code duplication that should be factored out
- Unnecessary temporary variables
- Proper use of existing functions and utilities
- Potential N+1 query patterns or looped API/DB calls (frontend AND backend)
- Type safety issues (avoiding
as anycasts) - Error handling consistency
- API vs model layer separation (backend)
- Raw PyMongo usage instead of Girder Model methods (backend)
- Missing
exc=Trueon model loads (backend) - Broad exception handling (backend)
- Access control and permission escalation (backend)
- Redundant validation that duplicates framework behavior
- API calls placed directly in Vue components instead of API files (frontend)
- Frontend code compensating for backend issues
Usage
/branch-review [base-branch]
Arguments:
base-branch(optional): The branch to compare against. Defaults tomaster.
Review Process
Step 1: Gather Context
git diff [base-branch]...HEAD --stat
git diff [base-branch]...HEAD
Step 2: Read Changed Files
For each significantly changed file, read the full file to understand context:
- Use the
Readtool to examine new/modified files - Look at surrounding code to understand existing patterns
- Check imports and dependencies
Step 3: Load Feature Documentation
Check references/feature-documentation-index.md to find relevant architecture docs for the feature area being changed. Read those docs before reviewing to understand expected patterns.
Step 4: Pattern Analysis
Compare new code against existing patterns:
- Store Modules: Check
vuex-module-decoratorspatterns - API Clients: Verify error handling patterns, check that API calls live in API files (not components)
- Vue Components: Ensure structure consistency (props, computed, methods order)
- Backend API: Check for looped DB queries, proper input conversion at API boundary,
exc=Trueusage - Backend Models: Check Girder plugin patterns, verify no
RestExceptionimports, no HTTP concerns - Access Control: Verify mutation endpoints check WRITE/ADMIN access, consider permission escalation
Codebase-specific review guidelines are in CLAUDE.md - read them before reviewing.
Step 5: Provide Actionable Feedback
For each issue:
- Quote the specific code location (
file:line) - Explain why it's an issue
- Provide a concrete suggestion or code example
- Note the severity (must fix vs. nice to have)
Issue Categories
| Category | Description |
|---|---|
| Pattern Consistency | Code that doesn't follow established patterns |
| Code Duplication | Logic that should be extracted to shared utilities |
| Unnecessary Variables | Temporary variables used only once |
| Missing Abstractions | Opportunities to use existing utilities |
| Performance Issues | N+1 queries, looped API/DB calls, missing batch endpoints |
| Type Safety | as any casts, missing types, unsafe assertions |
| Error Handling | Inconsistent or duplicate error handling |
| Layer Violation | API concerns in models or model concerns in API |
| Security / Access Control | Missing permission checks, bypassed access control |
| Raw PyMongo | Using Model().collection.find() instead of Model().find() |
| Redundant Validation | Checks that duplicate framework behavior |
Backend-Specific Checks
When reviewing changes to devops/girder/plugins/AnnotationPlugin/, apply these additional checks:
1. Looped Database Queries
Search for patterns like for ... in ...: Model().load( or [Model().load(id) for id in ids]. These should use $in queries instead.
2. API vs Model Layer
- Models (
server/models/) must NOT import or raiseRestException. They should raiseValueErrororValidationException. - API files (
server/api/) should handle all input parsing/conversion at the top of the method, then pass clean data to models. - Input conversion (string → ObjectId, JSON body parsing) should happen once at the API boundary, not in utility functions or models.
3. Raw PyMongo Access
Flag any use of Model().collection.find() — should be Model().find(). The only exception is collection.aggregate() for aggregation pipelines.
4. Model Loading
- Flag
Model().load(id, ...)followed byif result is None: raise .... Should useexc=Trueparameter instead. - Flag
Model().load(id, force=True)unless there's a clear comment explaining why access checks are bypassed.
5. Broad Exception Handling
Flag except Exception: or bare except:. These swallow errors like KeyboardInterrupt, MemoryError, etc. Catch specific exception types.
6. Access Control
- Check that mutation endpoints (POST, PUT, DELETE) verify the user has
WRITEorADMINaccess on the affected resource. - Check for permission escalation: can a user with WRITE access grant themselves broader access?
- Security enforcement must be in the backend. Frontend permission checks are cosmetic, not security.
7. Code Factorization
- Flag identical code blocks appearing in multiple API files — extract to a shared helper.
- Flag functions that re-fetch data already available in the calling context — pass as parameter instead.
8. Redundant Validation
- Flag ObjectId validity checks before
ObjectId()conversion (the conversion itself raises on invalid input). - Flag null checks after
Model().load(..., exc=True)(exc=True already raises).
9. Naming
- Flag functions whose names reference parameters they no longer use.
- Flag generic variable names like
id,item,datawhen a more specific name is possible.
Frontend-Specific Checks
When reviewing changes to src/, apply these additional checks:
1. API Calls in Components
Flag any direct this.girderRest.get(...) or this.girderRest.post(...) calls in Vue components. These should be methods in GirderAPI.ts, AnnotationsAPI.ts, or the appropriate API file.
2. Looped Frontend API Calls
Flag Promise.all(items.map(item => api.updateItem(item))) patterns. Suggest using or creating a batch endpoint instead.
3. Frontend Compensating for Backend
Flag fallback patterns like "try new API, catch error, try old API". The frontend should trust the backend API. Double implementations create maintenance debt.
4. Store Organization
New state for distinct feature areas should go in a new store module, not src/store/index.ts (already 2000+ lines).
Example Output Format
## Code Review: [branch-name]
### Overall Assessment
[Brief summary of code quality and main concerns]
### Issues to Address
#### 1. [Issue Title]
**File:** `src/store/example.ts:42`
**Severity:** High/Medium/Low
**Current code:**
\`\`\`typescript
// problematic code
\`\`\`
**Suggestion:**
\`\`\`typescript
// improved code
\`\`\`
**Rationale:** [Why this change improves the code]
---
### Minor Observations
- [Small improvements that aren't blocking]
### Questions for Clarification
- [Anything that needs discussion]
### Summary Table
| Category | Status |
|----------|--------|
| Pattern Consistency | pass/warn |
| Code Duplication | pass/warn |
| ...etc |
References
- Codebase-specific review guidelines:
CLAUDE.md - Feature documentation index:
references/feature-documentation-index.md
Converted and distributed by TomeVault — claim your Tome and manage your conversions.