@tinkcarlos/skillora 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.claude/skills/.temp-skill-index.md +245 -0
- package/.claude/skills/SKILL.md +264 -0
- package/.claude/skills/api-scaffolding/SKILL.md +431 -0
- package/.claude/skills/api-scaffolding/agents/backend-architect.md +282 -0
- package/.claude/skills/api-scaffolding/agents/django-pro.md +144 -0
- package/.claude/skills/api-scaffolding/agents/fastapi-pro.md +156 -0
- package/.claude/skills/api-scaffolding/agents/graphql-architect.md +146 -0
- package/.claude/skills/api-scaffolding/skills/fastapi-templates/SKILL.md +171 -0
- package/.claude/skills/api-testing-observability/SKILL.md +583 -0
- package/.claude/skills/api-testing-observability/agents/api-documenter.md +146 -0
- package/.claude/skills/api-testing-observability/commands/api-mock.md +1320 -0
- package/.claude/skills/brainstorming/SKILL.md +283 -0
- package/.claude/skills/bug-fixing/SKILL.md +382 -0
- package/.claude/skills/bug-fixing/references/backend-guide.md +132 -0
- package/.claude/skills/bug-fixing/references/bug-guide.md +354 -0
- package/.claude/skills/bug-fixing/references/bug-record-template.md +134 -0
- package/.claude/skills/bug-fixing/references/bug-records.md +88 -0
- package/.claude/skills/bug-fixing/references/code-review-gate.md +81 -0
- package/.claude/skills/bug-fixing/references/common-bugs.md +140 -0
- package/.claude/skills/bug-fixing/references/complete-workflow.md +361 -0
- package/.claude/skills/bug-fixing/references/config-driven-fixes.md +136 -0
- package/.claude/skills/bug-fixing/references/context-isolation-protocol.md +268 -0
- package/.claude/skills/bug-fixing/references/cross-surface-regression.md +120 -0
- package/.claude/skills/bug-fixing/references/database-investigation.md +129 -0
- package/.claude/skills/bug-fixing/references/dependency-and-integrity-protocol.md +369 -0
- package/.claude/skills/bug-fixing/references/fix-completeness-checklist.md +239 -0
- package/.claude/skills/bug-fixing/references/frontend-guide.md +219 -0
- package/.claude/skills/bug-fixing/references/fullstack-joint-guide.md +123 -0
- package/.claude/skills/bug-fixing/references/functional-breakage.md +117 -0
- package/.claude/skills/bug-fixing/references/ide-lint-errors-guide.md +176 -0
- package/.claude/skills/bug-fixing/references/impact-analysis.md +511 -0
- package/.claude/skills/bug-fixing/references/investigation-checklist.md +263 -0
- package/.claude/skills/bug-fixing/references/knowledge-extraction-guide.md +531 -0
- package/.claude/skills/bug-fixing/references/knowledge-workflow.md +212 -0
- package/.claude/skills/bug-fixing/references/post-edit-quality-gate.md +30 -0
- package/.claude/skills/bug-fixing/references/python-env-and-testing.md +126 -0
- package/.claude/skills/bug-fixing/references/rca-guide.md +428 -0
- package/.claude/skills/bug-fixing/references/similar-bug-patterns.md +113 -0
- package/.claude/skills/bug-fixing/references/skill-delegation-guide.md +350 -0
- package/.claude/skills/bug-fixing/references/skill-orchestration.md +155 -0
- package/.claude/skills/bug-fixing/references/testing-strategy.md +350 -0
- package/.claude/skills/bug-fixing/references/tooling-build-scripts.md +162 -0
- package/.claude/skills/bug-fixing/references/user-input-validation.md +77 -0
- package/.claude/skills/bug-fixing/references/ux-patterns.md +158 -0
- package/.claude/skills/bug-fixing/references/windows-terminal-hygiene.md +106 -0
- package/.claude/skills/bug-fixing/references/zero-regression-matrix.md +239 -0
- package/.claude/skills/bug-fixing/references/zero-risk-protocol.md +102 -0
- package/.claude/skills/bug-fixing/scripts/format_code.py +611 -0
- package/.claude/skills/bug-fixing/scripts/generate_report_template.py +74 -0
- package/.claude/skills/bug-fixing/scripts/lint_check.py +816 -0
- package/.claude/skills/bug-fixing/scripts/requirements.txt +36 -0
- package/.claude/skills/cicd-pipeline/SKILL.md +300 -0
- package/.claude/skills/code-review/SKILL.md +535 -0
- package/.claude/skills/code-review/references/anti-pattern-scan.md +102 -0
- package/.claude/skills/code-review/references/automated-analysis.md +456 -0
- package/.claude/skills/code-review/references/backend-common-issues.md +589 -0
- package/.claude/skills/code-review/references/backend-expert-guide.md +415 -0
- package/.claude/skills/code-review/references/backend-review.md +868 -0
- package/.claude/skills/code-review/references/batch-processing-strategy.md +198 -0
- package/.claude/skills/code-review/references/call-chain-analysis-protocol.md +166 -0
- package/.claude/skills/code-review/references/common-patterns.md +321 -0
- package/.claude/skills/code-review/references/configuration-review.md +425 -0
- package/.claude/skills/code-review/references/control-flow-completeness.md +114 -0
- package/.claude/skills/code-review/references/database-review.md +298 -0
- package/.claude/skills/code-review/references/dependency-and-integrity-protocol.md +313 -0
- package/.claude/skills/code-review/references/external-standards.md +51 -0
- package/.claude/skills/code-review/references/feature-review.md +329 -0
- package/.claude/skills/code-review/references/file-review-template.md +326 -0
- package/.claude/skills/code-review/references/frontend-advanced.md +654 -0
- package/.claude/skills/code-review/references/frontend-common-issues.md +482 -0
- package/.claude/skills/code-review/references/frontend-expert-guide.md +342 -0
- package/.claude/skills/code-review/references/frontend-review.md +783 -0
- package/.claude/skills/code-review/references/fullstack-consistency.md +418 -0
- package/.claude/skills/code-review/references/fullstack-review.md +477 -0
- package/.claude/skills/code-review/references/functional-completeness.md +386 -0
- package/.claude/skills/code-review/references/hidden-bugs-detection.md +473 -0
- package/.claude/skills/code-review/references/ide-lint-errors-guide.md +173 -0
- package/.claude/skills/code-review/references/infrastructure-review.md +453 -0
- package/.claude/skills/code-review/references/iteration-review.md +264 -0
- package/.claude/skills/code-review/references/job-review.md +335 -0
- package/.claude/skills/code-review/references/layered-checklist-protocol.md +157 -0
- package/.claude/skills/code-review/references/logic-completeness.md +535 -0
- package/.claude/skills/code-review/references/mandatory-checklist.md +288 -0
- package/.claude/skills/code-review/references/multi-language-guide.md +800 -0
- package/.claude/skills/code-review/references/new-project-review.md +226 -0
- package/.claude/skills/code-review/references/non-code-files-review.md +451 -0
- package/.claude/skills/code-review/references/overlooked-issues.md +657 -0
- package/.claude/skills/code-review/references/platform-specific-review.md +195 -0
- package/.claude/skills/code-review/references/precision-analysis-protocol.md +260 -0
- package/.claude/skills/code-review/references/python-patterns.md +494 -0
- package/.claude/skills/code-review/references/rca-techniques.md +362 -0
- package/.claude/skills/code-review/references/report-template.md +430 -0
- package/.claude/skills/code-review/references/resource-limits-and-degradation.md +137 -0
- package/.claude/skills/code-review/references/review-dimensions.md +311 -0
- package/.claude/skills/code-review/references/review-guide.md +202 -0
- package/.claude/skills/code-review/references/review-knowledge-workflow.md +257 -0
- package/.claude/skills/code-review/references/review-progress-tracker-protocol.md +172 -0
- package/.claude/skills/code-review/references/review-record-template.md +195 -0
- package/.claude/skills/code-review/references/skill-orchestration.md +143 -0
- package/.claude/skills/code-review/references/ui-ux-review.md +470 -0
- package/.claude/skills/containerization/SKILL.md +313 -0
- package/.claude/skills/database-migrations/agents/database-admin.md +142 -0
- package/.claude/skills/database-migrations/agents/database-optimizer.md +144 -0
- package/.claude/skills/database-migrations/commands/migration-observability.md +408 -0
- package/.claude/skills/database-migrations/commands/sql-migrations.md +492 -0
- package/.claude/skills/finishing-a-development-branch/SKILL.md +319 -0
- package/.claude/skills/frontend-design/LICENSE.txt +177 -0
- package/.claude/skills/frontend-design/SKILL.md +587 -0
- package/.claude/skills/frontend-design/references/color-consistency.md +487 -0
- package/.claude/skills/frontend-design/references/color-palettes-full.md +657 -0
- package/.claude/skills/frontend-design/references/design-system-generator.md +285 -0
- package/.claude/skills/frontend-design/references/font-pairings-full.md +705 -0
- package/.claude/skills/frontend-design/references/industry-anti-patterns.md +281 -0
- package/.claude/skills/frontend-design/references/layout-anti-patterns.md +582 -0
- package/.claude/skills/frontend-design/references/motion-patterns.md +659 -0
- package/.claude/skills/frontend-design/references/pre-delivery-checklist.md +153 -0
- package/.claude/skills/frontend-design/references/responsive-design.md +555 -0
- package/.claude/skills/frontend-design/references/style-modification-rules.md +335 -0
- package/.claude/skills/frontend-design/references/ui-styles-full.md +383 -0
- package/.claude/skills/frontend-design/references/ui-styles-rating.md +191 -0
- package/.claude/skills/frontend-design/references/ux-guidelines.md +640 -0
- package/.claude/skills/fullstack-developer/SKILL.md +512 -0
- package/.claude/skills/fullstack-developer/references/api-contract-guide.md +312 -0
- package/.claude/skills/fullstack-developer/references/api-response-patterns.md +223 -0
- package/.claude/skills/fullstack-developer/references/async-patterns.md +220 -0
- package/.claude/skills/fullstack-developer/references/bug-prevention.md +914 -0
- package/.claude/skills/fullstack-developer/references/code-quality-checklist.md +271 -0
- package/.claude/skills/fullstack-developer/references/complete-development-workflow.md +278 -0
- package/.claude/skills/fullstack-developer/references/context-isolation-protocol.md +256 -0
- package/.claude/skills/fullstack-developer/references/database-migration.md +331 -0
- package/.claude/skills/fullstack-developer/references/dependency-and-integrity-protocol.md +390 -0
- package/.claude/skills/fullstack-developer/references/development-phases.md +333 -0
- package/.claude/skills/fullstack-developer/references/expert-guide.md +214 -0
- package/.claude/skills/fullstack-developer/references/file-import-patterns.md +114 -0
- package/.claude/skills/fullstack-developer/references/graceful-degradation-patterns.md +78 -0
- package/.claude/skills/fullstack-developer/references/ide-lint-errors-guide.md +183 -0
- package/.claude/skills/fullstack-developer/references/integration-testing.md +301 -0
- package/.claude/skills/fullstack-developer/references/mock-api-patterns.md +307 -0
- package/.claude/skills/fullstack-developer/references/phase-gate-template.md +249 -0
- package/.claude/skills/fullstack-developer/references/post-edit-quality-gate.md +30 -0
- package/.claude/skills/fullstack-developer/references/python-engineering.md +79 -0
- package/.claude/skills/fullstack-developer/references/skill-orchestration.md +214 -0
- package/.claude/skills/fullstack-developer/references/skill-router-table.md +304 -0
- package/.claude/skills/fullstack-developer/references/state-sync.md +217 -0
- package/.claude/skills/fullstack-developer/references/ui-testing-checklist.md +292 -0
- package/.claude/skills/fullstack-developer/scripts/format_code.py +611 -0
- package/.claude/skills/fullstack-developer/scripts/lint_check.py +816 -0
- package/.claude/skills/fullstack-developer/scripts/requirements.txt +36 -0
- package/.claude/skills/performance-optimization/SKILL.md +250 -0
- package/.claude/skills/product-requirements/SKILL.md +357 -0
- package/.claude/skills/product-requirements/references/acceptance-criteria.md +335 -0
- package/.claude/skills/product-requirements/references/answer-first-questioning-protocol.md +299 -0
- package/.claude/skills/product-requirements/references/competitive-analysis-guide.md +183 -0
- package/.claude/skills/product-requirements/references/document-accuracy-protocol.md +253 -0
- package/.claude/skills/product-requirements/references/document-management-protocol.md +278 -0
- package/.claude/skills/product-requirements/references/external-standards.md +62 -0
- package/.claude/skills/product-requirements/references/feature-spec-template.md +359 -0
- package/.claude/skills/product-requirements/references/knowledge-acquisition-protocol.md +251 -0
- package/.claude/skills/product-requirements/references/plan-execution-protocol.md +334 -0
- package/.claude/skills/product-requirements/references/plan-generation-protocol.md +264 -0
- package/.claude/skills/product-requirements/references/prioritization-frameworks.md +80 -0
- package/.claude/skills/product-requirements/references/requirement-decomposition-protocol.md +291 -0
- package/.claude/skills/product-requirements/references/user-story-examples.md +297 -0
- package/.claude/skills/product-requirements/references/workflow-templates.md +266 -0
- package/.claude/skills/react-best-practices/SKILL.md +198 -0
- package/.claude/skills/react-best-practices/references/advanced-patterns.md +94 -0
- package/.claude/skills/react-best-practices/references/bundle-optimization.md +182 -0
- package/.claude/skills/react-best-practices/references/client-data-fetching.md +112 -0
- package/.claude/skills/react-best-practices/references/complete-guide.md +2249 -0
- package/.claude/skills/react-best-practices/references/eliminating-waterfalls.md +169 -0
- package/.claude/skills/react-best-practices/references/javascript-performance.md +256 -0
- package/.claude/skills/react-best-practices/references/rendering-performance.md +230 -0
- package/.claude/skills/react-best-practices/references/rerender-optimization.md +214 -0
- package/.claude/skills/react-best-practices/references/server-performance.md +182 -0
- package/.claude/skills/security-audit/SKILL.md +226 -0
- package/.claude/skills/shared-references/advanced-debugging-techniques.md +186 -0
- package/.claude/skills/shared-references/code-quality-checklist.md +218 -0
- package/.claude/skills/shared-references/code-review-efficiency-guide.md +125 -0
- package/.claude/skills/shared-references/mcp-dependency-compatibility-protocol.md +276 -0
- package/.claude/skills/shared-references/skill-call-graph.md +230 -0
- package/.claude/skills/shared-references/skill-orchestration-protocol.md +281 -0
- package/.claude/skills/shared-references/subagent-dispatch-templates.md +199 -0
- package/.claude/skills/skill-expert-skills/LICENSE.txt +204 -0
- package/.claude/skills/skill-expert-skills/QUICK_NAVIGATION.md +374 -0
- package/.claude/skills/skill-expert-skills/SKILL.md +247 -0
- package/.claude/skills/skill-expert-skills/docs/_index.md +91 -0
- package/.claude/skills/skill-expert-skills/references/deep-research-methodology.md +389 -0
- package/.claude/skills/skill-expert-skills/references/docs-generation-workflow.md +398 -0
- package/.claude/skills/skill-expert-skills/references/domain-expertise-protocol.md +343 -0
- package/.claude/skills/skill-expert-skills/references/domain-knowledge/_index.md +54 -0
- package/.claude/skills/skill-expert-skills/references/domain-knowledge/backend-expertise.md +517 -0
- package/.claude/skills/skill-expert-skills/references/domain-knowledge/bug-fixing-expertise.md +363 -0
- package/.claude/skills/skill-expert-skills/references/domain-knowledge/code-review-expertise.md +392 -0
- package/.claude/skills/skill-expert-skills/references/domain-knowledge/frontend-expertise.md +410 -0
- package/.claude/skills/skill-expert-skills/references/domain-knowledge-template.md +503 -0
- package/.claude/skills/skill-expert-skills/references/examples.md +782 -0
- package/.claude/skills/skill-expert-skills/references/integration-examples.md +655 -0
- package/.claude/skills/skill-expert-skills/references/knowledge-validation-checklist.md +246 -0
- package/.claude/skills/skill-expert-skills/references/latest-knowledge-acquisition.md +461 -0
- package/.claude/skills/skill-expert-skills/references/mcp-tools-guide.md +439 -0
- package/.claude/skills/skill-expert-skills/references/official-best-practices.md +616 -0
- package/.claude/skills/skill-expert-skills/references/patterns.md +218 -0
- package/.claude/skills/skill-expert-skills/references/plugin-skills-guide.md +432 -0
- package/.claude/skills/skill-expert-skills/references/requirement-elicitation-protocol.md +290 -0
- package/.claude/skills/skill-expert-skills/references/skill-creator-SKILL.md +353 -0
- package/.claude/skills/skill-expert-skills/references/skill-templates.md +583 -0
- package/.claude/skills/skill-expert-skills/references/skills-knowledge-base.md +561 -0
- package/.claude/skills/skill-expert-skills/references/tools-guide.md +379 -0
- package/.claude/skills/skill-expert-skills/references/troubleshooting.md +378 -0
- package/.claude/skills/skill-expert-skills/references/universality-guide.md +205 -0
- package/.claude/skills/skill-expert-skills/references/writing-style-guide.md +466 -0
- package/.claude/skills/skill-expert-skills/scripts/__pycache__/quick_validate.cpython-313.pyc +0 -0
- package/.claude/skills/skill-expert-skills/scripts/__pycache__/universal_validate.cpython-313.pyc +0 -0
- package/.claude/skills/skill-expert-skills/scripts/analyze_trigger.py +425 -0
- package/.claude/skills/skill-expert-skills/scripts/diff_with_official.py +188 -0
- package/.claude/skills/skill-expert-skills/scripts/init_skill.py +349 -0
- package/.claude/skills/skill-expert-skills/scripts/package_skill.py +156 -0
- package/.claude/skills/skill-expert-skills/scripts/quick_validate.py +493 -0
- package/.claude/skills/skill-expert-skills/scripts/requirements.txt +2 -0
- package/.claude/skills/skill-expert-skills/scripts/universal_validate.py +182 -0
- package/.claude/skills/skill-expert-skills/scripts/upgrade_skill.py +431 -0
- package/.claude/skills/subagent-driven-development/SKILL.md +268 -0
- package/.claude/skills/test-driven-development/SKILL.md +246 -0
- package/.claude/skills/test-driven-development/references/testing-anti-patterns.md +192 -0
- package/.claude/skills/using-git-worktrees/SKILL.md +266 -0
- package/.claude/skills/using-skillstack/SKILL.md +127 -0
- package/.claude/skills/vercel-deploy/SKILL.md +166 -0
- package/.claude/skills/vercel-deploy/scripts/deploy.sh +249 -0
- package/.claude/skills/verification-before-completion/SKILL.md +305 -0
- package/.claude/skills/writing-plans/SKILL.md +259 -0
- package/README.md +69 -0
- package/bin/cli.js +468 -0
- package/lib/init.js +333 -0
- package/package.json +29 -0
|
@@ -0,0 +1,868 @@
|
|
|
1
|
+
# Backend Code Review - Complete Guide
|
|
2
|
+
|
|
3
|
+
Comprehensive backend code review covering multi-language patterns, runtime behavior, architecture, and production readiness.
|
|
4
|
+
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
## 🎯 Backend Review Philosophy
|
|
8
|
+
|
|
9
|
+
### Core Perspective: Business Logic → System Architecture → Runtime Behavior
|
|
10
|
+
|
|
11
|
+
Backend CR evaluates code from multiple layers, **simulating production scenarios** including load, failure, and concurrency.
|
|
12
|
+
|
|
13
|
+
```
|
|
14
|
+
Review Layers:
|
|
15
|
+
┌─────────────────────────────────────────┐
|
|
16
|
+
│ Layer 1: Business Logic │
|
|
17
|
+
│ - Requirements implementation │
|
|
18
|
+
│ - Domain model correctness │
|
|
19
|
+
│ - Edge case handling │
|
|
20
|
+
└─────────────────────────────────────────┘
|
|
21
|
+
↓
|
|
22
|
+
┌─────────────────────────────────────────┐
|
|
23
|
+
│ Layer 2: System Architecture │
|
|
24
|
+
│ - Module coupling/cohesion │
|
|
25
|
+
│ - Service boundaries │
|
|
26
|
+
│ - Data flow design │
|
|
27
|
+
└─────────────────────────────────────────┘
|
|
28
|
+
↓
|
|
29
|
+
┌─────────────────────────────────────────┐
|
|
30
|
+
│ Layer 3: Runtime Behavior │
|
|
31
|
+
│ - Performance under load │
|
|
32
|
+
│ - Failure recovery │
|
|
33
|
+
│ - Concurrent operation safety │
|
|
34
|
+
└─────────────────────────────────────────┘
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
### Language-Agnostic Principles
|
|
38
|
+
|
|
39
|
+
| Principle | Description | Application |
|
|
40
|
+
|-----------|-------------|-------------|
|
|
41
|
+
| **SOLID** | Single responsibility, Open-closed, etc. | All OOP languages |
|
|
42
|
+
| **DRY** | Don't Repeat Yourself | All languages |
|
|
43
|
+
| **KISS** | Keep It Simple, Stupid | All languages |
|
|
44
|
+
| **YAGNI** | You Aren't Gonna Need It | All languages |
|
|
45
|
+
|
|
46
|
+
### Language-Specific Considerations
|
|
47
|
+
|
|
48
|
+
| Language | Key Focus Areas |
|
|
49
|
+
|----------|-----------------|
|
|
50
|
+
| **Java** | GC tuning, thread pool sizing, memory model |
|
|
51
|
+
| **Node.js** | Single-thread blocking, event loop, Promise handling |
|
|
52
|
+
| **Go** | Goroutine lifecycle, channel deadlock, race conditions |
|
|
53
|
+
| **Python** | GIL limitations, async/sync mixing, memory leaks |
|
|
54
|
+
| **C#** | Async context, IDisposable, LINQ efficiency |
|
|
55
|
+
|
|
56
|
+
---
|
|
57
|
+
|
|
58
|
+
## 🛠️ Tool Stack by Language
|
|
59
|
+
|
|
60
|
+
### Mandatory Pre-Review Scans
|
|
61
|
+
|
|
62
|
+
#### Java
|
|
63
|
+
|
|
64
|
+
```bash
|
|
65
|
+
# Static Analysis
|
|
66
|
+
mvn spotbugs:check # Bug patterns
|
|
67
|
+
mvn pmd:check # Code style violations
|
|
68
|
+
mvn checkstyle:check # Style enforcement
|
|
69
|
+
|
|
70
|
+
# Security
|
|
71
|
+
mvn dependency-check:check # OWASP dependency scan
|
|
72
|
+
|
|
73
|
+
# Coverage
|
|
74
|
+
mvn jacoco:report # Target: >80%
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
#### Node.js / TypeScript
|
|
78
|
+
|
|
79
|
+
```bash
|
|
80
|
+
# Static Analysis
|
|
81
|
+
npx eslint . --max-warnings 0
|
|
82
|
+
npx tsc --noEmit
|
|
83
|
+
|
|
84
|
+
# Security
|
|
85
|
+
npm audit # Vulnerability scan
|
|
86
|
+
npx snyk test # Deep security scan
|
|
87
|
+
|
|
88
|
+
# Coverage
|
|
89
|
+
npx jest --coverage --coverageThreshold='{"global":{"lines":80}}'
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
#### Go
|
|
93
|
+
|
|
94
|
+
```bash
|
|
95
|
+
# Static Analysis
|
|
96
|
+
golangci-lint run # Comprehensive linter
|
|
97
|
+
go vet ./... # Common mistakes
|
|
98
|
+
staticcheck ./... # Advanced checks
|
|
99
|
+
|
|
100
|
+
# Race Detection
|
|
101
|
+
go test -race ./...
|
|
102
|
+
|
|
103
|
+
# Coverage
|
|
104
|
+
go test -cover ./...
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
#### Python
|
|
108
|
+
|
|
109
|
+
```bash
|
|
110
|
+
# Static Analysis
|
|
111
|
+
pylint src/
|
|
112
|
+
flake8 src/
|
|
113
|
+
mypy src/ --strict
|
|
114
|
+
|
|
115
|
+
# Security
|
|
116
|
+
bandit -r src/ # Security linter
|
|
117
|
+
safety check # Dependency vulnerabilities
|
|
118
|
+
|
|
119
|
+
# Coverage
|
|
120
|
+
pytest --cov=src --cov-report=html --cov-fail-under=80
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
#### Universal Tools
|
|
124
|
+
|
|
125
|
+
```bash
|
|
126
|
+
# SonarQube (Multi-language)
|
|
127
|
+
sonar-scanner
|
|
128
|
+
|
|
129
|
+
# Git Hooks
|
|
130
|
+
pre-commit run --all-files
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
---
|
|
134
|
+
|
|
135
|
+
## 🏗️ Architecture Review
|
|
136
|
+
|
|
137
|
+
### Module Dependency Analysis
|
|
138
|
+
|
|
139
|
+
```markdown
|
|
140
|
+
## Dependency Review Checklist
|
|
141
|
+
|
|
142
|
+
### Circular Dependencies
|
|
143
|
+
- [ ] No circular imports between modules
|
|
144
|
+
- [ ] No bidirectional service calls
|
|
145
|
+
- [ ] Dependency flow is unidirectional
|
|
146
|
+
|
|
147
|
+
### Coupling Analysis
|
|
148
|
+
| Module A | Module B | Coupling Type | Severity |
|
|
149
|
+
|----------|----------|---------------|----------|
|
|
150
|
+
| UserService | OrderService | Direct call | 🟡 Medium |
|
|
151
|
+
| PaymentService | NotificationService | Event-based | ✅ Low |
|
|
152
|
+
| AuthService | *All Services* | Shared | 🔴 High |
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
### Service Communication Patterns
|
|
156
|
+
|
|
157
|
+
```markdown
|
|
158
|
+
## Service Communication Review
|
|
159
|
+
|
|
160
|
+
### REST API
|
|
161
|
+
| Endpoint | Idempotent | Safe | Issues |
|
|
162
|
+
|----------|------------|------|--------|
|
|
163
|
+
| POST /orders | ❌ No | ❌ No | ⚠️ Need idempotency key |
|
|
164
|
+
| PUT /orders/{id} | ✅ Yes | ❌ No | ✅ OK |
|
|
165
|
+
| GET /orders/{id} | ✅ Yes | ✅ Yes | ✅ OK |
|
|
166
|
+
| DELETE /orders/{id} | ✅ Yes | ❌ No | ⚠️ Soft delete? |
|
|
167
|
+
|
|
168
|
+
### gRPC
|
|
169
|
+
| Service | Method | Streaming | Timeout Set |
|
|
170
|
+
|---------|--------|-----------|-------------|
|
|
171
|
+
| UserService | GetUser | No | ✅ 5s |
|
|
172
|
+
| OrderService | StreamOrders | Server | ⚠️ No timeout |
|
|
173
|
+
```
|
|
174
|
+
|
|
175
|
+
### Database Access Patterns
|
|
176
|
+
|
|
177
|
+
```markdown
|
|
178
|
+
## ORM/Database Review
|
|
179
|
+
|
|
180
|
+
### N+1 Query Detection
|
|
181
|
+
| Code Location | Pattern | Impact | Fix |
|
|
182
|
+
|---------------|---------|--------|-----|
|
|
183
|
+
| user_service.py:45 | Loop fetch | 100 users = 101 queries | Use JOIN/prefetch |
|
|
184
|
+
| order_repo.py:78 | Lazy load | Each order triggers query | Eager load |
|
|
185
|
+
|
|
186
|
+
### Transaction Boundaries
|
|
187
|
+
| Operation | Isolation Level | Scope | Issues |
|
|
188
|
+
|-----------|-----------------|-------|--------|
|
|
189
|
+
| CreateOrder | Read Committed | Service | ✅ OK |
|
|
190
|
+
| TransferFunds | Serializable | Repository | ⚠️ Deadlock risk |
|
|
191
|
+
```
|
|
192
|
+
|
|
193
|
+
---
|
|
194
|
+
|
|
195
|
+
## 🔄 Concurrency Model Review
|
|
196
|
+
|
|
197
|
+
### 1. Singleton vs Request Scope (CRITICAL)
|
|
198
|
+
**Anti-Pattern**: Modifying shared singleton instances (Services, cached Models) with request-specific data.
|
|
199
|
+
|
|
200
|
+
```python
|
|
201
|
+
# ❌ DANGEROUS: Modifying shared agent object
|
|
202
|
+
async def chat(self, user_input, llm_id=None):
|
|
203
|
+
# 'agent' is loaded once and shared across requests
|
|
204
|
+
if llm_id:
|
|
205
|
+
self.agent.llm_provider_id = llm_id # RACE CONDITION! Affects other users
|
|
206
|
+
await self.executor.run(self.agent, user_input)
|
|
207
|
+
|
|
208
|
+
# ✅ CORRECT: Pass request data as arguments
|
|
209
|
+
async def chat(self, user_input, llm_id=None):
|
|
210
|
+
# Pass llm_id explicitly to the executor, don't mutate agent
|
|
211
|
+
await self.executor.run(self.agent, user_input, override_llm_id=llm_id)
|
|
212
|
+
```
|
|
213
|
+
|
|
214
|
+
### 2. Background Task Safety
|
|
215
|
+
**Anti-Pattern**: Fire-and-forget tasks without error handling (Silent Failures).
|
|
216
|
+
|
|
217
|
+
```python
|
|
218
|
+
# ❌ Silent Failure
|
|
219
|
+
asyncio.create_task(send_email()) # If fails, exception is swallowed/logged to void
|
|
220
|
+
|
|
221
|
+
# ✅ With Exception Callback
|
|
222
|
+
task = asyncio.create_task(send_email())
|
|
223
|
+
def handle_error(t):
|
|
224
|
+
if not t.cancelled() and t.exception():
|
|
225
|
+
logger.error(f"Background task failed: {t.exception()}")
|
|
226
|
+
task.add_done_callback(handle_error)
|
|
227
|
+
|
|
228
|
+
# ✅ Or use TaskGroup (Python 3.11+)
|
|
229
|
+
async with asyncio.TaskGroup() as tg:
|
|
230
|
+
tg.create_task(send_email())
|
|
231
|
+
```
|
|
232
|
+
|
|
233
|
+
### Java Thread Safety
|
|
234
|
+
|
|
235
|
+
```java
|
|
236
|
+
// ❌ Not thread-safe
|
|
237
|
+
public class Counter {
|
|
238
|
+
private int count = 0;
|
|
239
|
+
public void increment() {
|
|
240
|
+
count++; // Read-modify-write not atomic
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
// ✅ Thread-safe options
|
|
245
|
+
public class Counter {
|
|
246
|
+
// Option 1: AtomicInteger
|
|
247
|
+
private final AtomicInteger count = new AtomicInteger(0);
|
|
248
|
+
public void increment() {
|
|
249
|
+
count.incrementAndGet();
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
// Option 2: synchronized
|
|
253
|
+
private int count = 0;
|
|
254
|
+
public synchronized void increment() {
|
|
255
|
+
count++;
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
```
|
|
259
|
+
|
|
260
|
+
### Go Goroutine Safety
|
|
261
|
+
|
|
262
|
+
```go
|
|
263
|
+
// ❌ Race condition
|
|
264
|
+
var counter int
|
|
265
|
+
func increment() {
|
|
266
|
+
counter++ // Not safe with multiple goroutines
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
// ✅ Use sync primitives
|
|
270
|
+
var (
|
|
271
|
+
counter int
|
|
272
|
+
mu sync.Mutex
|
|
273
|
+
)
|
|
274
|
+
func increment() {
|
|
275
|
+
mu.Lock()
|
|
276
|
+
defer mu.Unlock()
|
|
277
|
+
counter++
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
// ✅ Or use channels
|
|
281
|
+
func counter(ch chan int) {
|
|
282
|
+
count := 0
|
|
283
|
+
for delta := range ch {
|
|
284
|
+
count += delta
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
```
|
|
288
|
+
|
|
289
|
+
### Node.js Event Loop Blocking
|
|
290
|
+
|
|
291
|
+
```typescript
|
|
292
|
+
// ❌ Blocking the event loop
|
|
293
|
+
app.get('/heavy', (req, res) => {
|
|
294
|
+
const result = heavyComputation(); // Blocks all requests!
|
|
295
|
+
res.json(result);
|
|
296
|
+
});
|
|
297
|
+
|
|
298
|
+
// ✅ Use worker threads for CPU-intensive tasks
|
|
299
|
+
import { Worker } from 'worker_threads';
|
|
300
|
+
|
|
301
|
+
app.get('/heavy', async (req, res) => {
|
|
302
|
+
const worker = new Worker('./heavy-worker.js');
|
|
303
|
+
worker.on('message', (result) => res.json(result));
|
|
304
|
+
worker.postMessage({ data: req.body });
|
|
305
|
+
});
|
|
306
|
+
```
|
|
307
|
+
|
|
308
|
+
---
|
|
309
|
+
|
|
310
|
+
## 📊 Runtime & Non-Functional Review
|
|
311
|
+
|
|
312
|
+
### Load Testing Requirements
|
|
313
|
+
|
|
314
|
+
```markdown
|
|
315
|
+
## Performance Review Checklist
|
|
316
|
+
|
|
317
|
+
### Load Testing Setup
|
|
318
|
+
- [ ] Tool selected (JMeter/k6/Locust)
|
|
319
|
+
- [ ] Test scenarios defined
|
|
320
|
+
- [ ] Baseline metrics established
|
|
321
|
+
|
|
322
|
+
### Key Metrics
|
|
323
|
+
| Metric | Target | Actual | Status |
|
|
324
|
+
|--------|--------|--------|--------|
|
|
325
|
+
| P50 latency | <100ms | 85ms | ✅ |
|
|
326
|
+
| P95 latency | <500ms | 620ms | ❌ |
|
|
327
|
+
| P99 latency | <1s | 1.2s | ❌ |
|
|
328
|
+
| Throughput | >1000 RPS | 950 RPS | ⚠️ |
|
|
329
|
+
| Error rate | <0.1% | 0.05% | ✅ |
|
|
330
|
+
|
|
331
|
+
### Bottleneck Analysis
|
|
332
|
+
| Component | CPU | Memory | I/O | Issue |
|
|
333
|
+
|-----------|-----|--------|-----|-------|
|
|
334
|
+
| API Server | 45% | 60% | 10% | ✅ OK |
|
|
335
|
+
| Database | 85% | 70% | 90% | 🔴 Bottleneck |
|
|
336
|
+
| Cache | 20% | 80% | 5% | ⚠️ Memory pressure |
|
|
337
|
+
```
|
|
338
|
+
|
|
339
|
+
### Connection Pool Configuration
|
|
340
|
+
|
|
341
|
+
```markdown
|
|
342
|
+
## Connection Pool Review
|
|
343
|
+
|
|
344
|
+
### Database Pool
|
|
345
|
+
| Setting | Value | Recommendation | Status |
|
|
346
|
+
|---------|-------|----------------|--------|
|
|
347
|
+
| Min connections | 5 | 10 | ⚠️ Too low |
|
|
348
|
+
| Max connections | 100 | 50-100 | ✅ OK |
|
|
349
|
+
| Idle timeout | 30s | 60s | ⚠️ Adjust |
|
|
350
|
+
| Max lifetime | None | 300s | ❌ Must set |
|
|
351
|
+
| Acquire timeout | 5s | 10s | ✅ OK |
|
|
352
|
+
|
|
353
|
+
### HTTP Client Pool
|
|
354
|
+
| Setting | Value | Issue |
|
|
355
|
+
|---------|-------|-------|
|
|
356
|
+
| Max per route | 2 | 🔴 Default too low |
|
|
357
|
+
| Max total | 20 | ⚠️ May be insufficient |
|
|
358
|
+
| Connection timeout | 10s | ✅ OK |
|
|
359
|
+
| Socket timeout | 30s | ✅ OK |
|
|
360
|
+
```
|
|
361
|
+
|
|
362
|
+
### Caching Strategy Review
|
|
363
|
+
|
|
364
|
+
```markdown
|
|
365
|
+
## Cache Review
|
|
366
|
+
|
|
367
|
+
### Cache Configuration
|
|
368
|
+
| Cache | Type | TTL | Eviction | Status |
|
|
369
|
+
|-------|------|-----|----------|--------|
|
|
370
|
+
| User sessions | Redis | 24h | LRU | ✅ |
|
|
371
|
+
| API responses | Local | 5m | TTL | ✅ |
|
|
372
|
+
| DB query cache | Redis | 1h | TTL | ⚠️ No invalidation |
|
|
373
|
+
|
|
374
|
+
### Cache Issues Checklist
|
|
375
|
+
- [ ] Cache penetration protection (bloom filter)
|
|
376
|
+
- [ ] Cache avalanche prevention (jitter TTL)
|
|
377
|
+
- [ ] Cache breakdown protection (mutex lock)
|
|
378
|
+
- [ ] Cache warming strategy
|
|
379
|
+
- [ ] Cache invalidation on write
|
|
380
|
+
|
|
381
|
+
### Cache Penetration Example
|
|
382
|
+
```python
|
|
383
|
+
# ❌ No protection - null values not cached
|
|
384
|
+
def get_user(user_id):
|
|
385
|
+
cached = redis.get(f"user:{user_id}")
|
|
386
|
+
if cached:
|
|
387
|
+
return cached
|
|
388
|
+
user = db.query(User).get(user_id)
|
|
389
|
+
if user:
|
|
390
|
+
redis.set(f"user:{user_id}", user, ex=3600)
|
|
391
|
+
return user # Null not cached, repeated DB queries
|
|
392
|
+
|
|
393
|
+
# ✅ Cache null values
|
|
394
|
+
def get_user(user_id):
|
|
395
|
+
cached = redis.get(f"user:{user_id}")
|
|
396
|
+
if cached == "NULL":
|
|
397
|
+
return None
|
|
398
|
+
if cached:
|
|
399
|
+
return cached
|
|
400
|
+
user = db.query(User).get(user_id)
|
|
401
|
+
if user:
|
|
402
|
+
redis.set(f"user:{user_id}", user, ex=3600)
|
|
403
|
+
else:
|
|
404
|
+
redis.set(f"user:{user_id}", "NULL", ex=60) # Short TTL for null
|
|
405
|
+
return user
|
|
406
|
+
```
|
|
407
|
+
```
|
|
408
|
+
|
|
409
|
+
---
|
|
410
|
+
|
|
411
|
+
## 📝 Observability Review
|
|
412
|
+
|
|
413
|
+
### Structured Logging
|
|
414
|
+
|
|
415
|
+
```markdown
|
|
416
|
+
## Logging Review
|
|
417
|
+
|
|
418
|
+
### Log Format Checklist
|
|
419
|
+
- [ ] Structured format (JSON)
|
|
420
|
+
- [ ] Correlation ID / Trace ID
|
|
421
|
+
- [ ] Timestamp in ISO 8601
|
|
422
|
+
- [ ] Log level appropriate
|
|
423
|
+
- [ ] No sensitive data
|
|
424
|
+
|
|
425
|
+
### Example: Proper Structured Log
|
|
426
|
+
```json
|
|
427
|
+
{
|
|
428
|
+
"timestamp": "2024-01-15T10:30:00.123Z",
|
|
429
|
+
"level": "INFO",
|
|
430
|
+
"service": "order-service",
|
|
431
|
+
"trace_id": "abc123",
|
|
432
|
+
"span_id": "def456",
|
|
433
|
+
"user_id": "user_789",
|
|
434
|
+
"action": "create_order",
|
|
435
|
+
"order_id": "order_001",
|
|
436
|
+
"duration_ms": 150,
|
|
437
|
+
"status": "success"
|
|
438
|
+
}
|
|
439
|
+
```
|
|
440
|
+
|
|
441
|
+
### Log Level Guidelines
|
|
442
|
+
| Level | Usage | Example |
|
|
443
|
+
|-------|-------|---------|
|
|
444
|
+
| ERROR | System failures requiring action | DB connection lost |
|
|
445
|
+
| WARN | Potential issues, degraded service | Retry succeeded |
|
|
446
|
+
| INFO | Business events, transactions | Order created |
|
|
447
|
+
| DEBUG | Development/troubleshooting | Function entry/exit |
|
|
448
|
+
```
|
|
449
|
+
|
|
450
|
+
### Metrics & Tracing
|
|
451
|
+
|
|
452
|
+
```markdown
|
|
453
|
+
## Metrics Review
|
|
454
|
+
|
|
455
|
+
### Required Metrics (RED Method)
|
|
456
|
+
| Metric Type | Description | Implementation |
|
|
457
|
+
|-------------|-------------|----------------|
|
|
458
|
+
| Rate | Requests per second | Counter |
|
|
459
|
+
| Errors | Error rate | Counter + Labels |
|
|
460
|
+
| Duration | Response time distribution | Histogram |
|
|
461
|
+
|
|
462
|
+
### Distributed Tracing Checklist
|
|
463
|
+
- [ ] Trace ID propagated across services
|
|
464
|
+
- [ ] Span context preserved in async calls
|
|
465
|
+
- [ ] External calls instrumented
|
|
466
|
+
- [ ] Database queries traced
|
|
467
|
+
- [ ] Queue messages traced
|
|
468
|
+
```
|
|
469
|
+
|
|
470
|
+
---
|
|
471
|
+
|
|
472
|
+
## 🔧 Configuration Management
|
|
473
|
+
|
|
474
|
+
### Environment Variable Handling
|
|
475
|
+
|
|
476
|
+
```python
|
|
477
|
+
# ❌ No fallback, crashes on missing env
|
|
478
|
+
import os
|
|
479
|
+
API_KEY = os.environ["API_KEY"]
|
|
480
|
+
|
|
481
|
+
# ❌ Silent failure, uses None
|
|
482
|
+
API_KEY = os.environ.get("API_KEY")
|
|
483
|
+
|
|
484
|
+
# ✅ Fail fast with clear message
|
|
485
|
+
API_KEY = os.environ.get("API_KEY")
|
|
486
|
+
if not API_KEY:
|
|
487
|
+
raise ValueError("API_KEY environment variable is required")
|
|
488
|
+
|
|
489
|
+
# ✅ Use pydantic-settings for validation
|
|
490
|
+
from pydantic_settings import BaseSettings
|
|
491
|
+
|
|
492
|
+
class Settings(BaseSettings):
|
|
493
|
+
api_key: str
|
|
494
|
+
database_url: str
|
|
495
|
+
debug: bool = False
|
|
496
|
+
|
|
497
|
+
class Config:
|
|
498
|
+
env_file = ".env"
|
|
499
|
+
|
|
500
|
+
settings = Settings() # Fails fast with validation errors
|
|
501
|
+
```
|
|
502
|
+
|
|
503
|
+
### Graceful Shutdown
|
|
504
|
+
|
|
505
|
+
```python
|
|
506
|
+
# ❌ No graceful shutdown
|
|
507
|
+
if __name__ == "__main__":
|
|
508
|
+
uvicorn.run(app, host="0.0.0.0", port=8000)
|
|
509
|
+
|
|
510
|
+
# ✅ Graceful shutdown handler
|
|
511
|
+
import signal
|
|
512
|
+
import asyncio
|
|
513
|
+
|
|
514
|
+
shutdown_event = asyncio.Event()
|
|
515
|
+
|
|
516
|
+
def signal_handler(signum, frame):
|
|
517
|
+
shutdown_event.set()
|
|
518
|
+
|
|
519
|
+
signal.signal(signal.SIGTERM, signal_handler)
|
|
520
|
+
signal.signal(signal.SIGINT, signal_handler)
|
|
521
|
+
|
|
522
|
+
@app.on_event("shutdown")
|
|
523
|
+
async def shutdown():
|
|
524
|
+
# Complete in-flight requests
|
|
525
|
+
await shutdown_event.wait()
|
|
526
|
+
# Close connections
|
|
527
|
+
await db.disconnect()
|
|
528
|
+
await redis.close()
|
|
529
|
+
```
|
|
530
|
+
|
|
531
|
+
---
|
|
532
|
+
|
|
533
|
+
## 🔄 Retry Mechanism Review
|
|
534
|
+
|
|
535
|
+
### Exponential Backoff Pattern
|
|
536
|
+
|
|
537
|
+
```python
|
|
538
|
+
# ❌ Infinite retry without backoff
|
|
539
|
+
def fetch_data(url):
|
|
540
|
+
while True:
|
|
541
|
+
try:
|
|
542
|
+
return requests.get(url).json()
|
|
543
|
+
except Exception:
|
|
544
|
+
continue # Hammers the service!
|
|
545
|
+
|
|
546
|
+
# ❌ Fixed delay retry
|
|
547
|
+
def fetch_data(url):
|
|
548
|
+
for _ in range(3):
|
|
549
|
+
try:
|
|
550
|
+
return requests.get(url).json()
|
|
551
|
+
except Exception:
|
|
552
|
+
time.sleep(1) # All retries hit at same time
|
|
553
|
+
|
|
554
|
+
# ✅ Exponential backoff with jitter
|
|
555
|
+
from tenacity import retry, stop_after_attempt, wait_exponential_jitter
|
|
556
|
+
|
|
557
|
+
@retry(
|
|
558
|
+
stop=stop_after_attempt(5),
|
|
559
|
+
wait=wait_exponential_jitter(initial=1, max=30, jitter=5)
|
|
560
|
+
)
|
|
561
|
+
def fetch_data(url):
|
|
562
|
+
response = requests.get(url, timeout=10)
|
|
563
|
+
response.raise_for_status()
|
|
564
|
+
return response.json()
|
|
565
|
+
```
|
|
566
|
+
|
|
567
|
+
### Circuit Breaker Pattern
|
|
568
|
+
|
|
569
|
+
```python
|
|
570
|
+
from circuitbreaker import circuit
|
|
571
|
+
|
|
572
|
+
@circuit(
|
|
573
|
+
failure_threshold=5,
|
|
574
|
+
recovery_timeout=60,
|
|
575
|
+
expected_exception=requests.RequestException
|
|
576
|
+
)
|
|
577
|
+
def call_external_service(url):
|
|
578
|
+
response = requests.get(url, timeout=10)
|
|
579
|
+
response.raise_for_status()
|
|
580
|
+
return response.json()
|
|
581
|
+
```
|
|
582
|
+
|
|
583
|
+
---
|
|
584
|
+
|
|
585
|
+
## 🗄️ Database & Migration Review
|
|
586
|
+
|
|
587
|
+
### Migration Safety Checklist
|
|
588
|
+
|
|
589
|
+
```markdown
|
|
590
|
+
## Migration Review
|
|
591
|
+
|
|
592
|
+
### Pre-Deployment Checks
|
|
593
|
+
- [ ] Migration tested on copy of production data
|
|
594
|
+
- [ ] Rollback script exists and tested
|
|
595
|
+
- [ ] Estimated execution time acceptable
|
|
596
|
+
- [ ] No table locks on high-traffic tables
|
|
597
|
+
- [ ] Backward compatible with current code
|
|
598
|
+
|
|
599
|
+
### Schema Change Risk Matrix
|
|
600
|
+
| Change Type | Risk Level | Strategy |
|
|
601
|
+
|-------------|------------|----------|
|
|
602
|
+
| Add nullable column | ✅ Low | Deploy migration, then code |
|
|
603
|
+
| Add non-nullable column | 🟡 Medium | Add nullable → backfill → add constraint |
|
|
604
|
+
| Drop column | 🟡 Medium | Remove code → deploy → drop column |
|
|
605
|
+
| Rename column | 🔴 High | Add new → copy data → dual write → remove old |
|
|
606
|
+
| Change column type | 🔴 High | Add new → copy → switch → remove |
|
|
607
|
+
| Add index | 🟡 Medium | CONCURRENTLY if supported |
|
|
608
|
+
| Drop table | 🔴 High | Verify no references → soft delete period |
|
|
609
|
+
|
|
610
|
+
### Index Impact Analysis
|
|
611
|
+
| Index | Table Size | Write Impact | Build Time |
|
|
612
|
+
|-------|------------|--------------|------------|
|
|
613
|
+
| idx_users_email | 1M rows | +5% | ~30s |
|
|
614
|
+
| idx_orders_user_date | 10M rows | +15% | ~5min |
|
|
615
|
+
```
|
|
616
|
+
|
|
617
|
+
---
|
|
618
|
+
|
|
619
|
+
## 🧪 Backend Test Review
|
|
620
|
+
|
|
621
|
+
### Test Categories Checklist
|
|
622
|
+
|
|
623
|
+
```markdown
|
|
624
|
+
## Test Coverage Review
|
|
625
|
+
|
|
626
|
+
### Unit Tests
|
|
627
|
+
| Component | Coverage | Missing |
|
|
628
|
+
|-----------|----------|---------|
|
|
629
|
+
| Services | 85% | Error paths |
|
|
630
|
+
| Repositories | 70% | Edge cases |
|
|
631
|
+
| Utils | 95% | ✅ |
|
|
632
|
+
|
|
633
|
+
### Integration Tests
|
|
634
|
+
| Integration Point | Tested | Missing |
|
|
635
|
+
|-------------------|--------|---------|
|
|
636
|
+
| Database CRUD | ✅ | Transaction rollback |
|
|
637
|
+
| Redis cache | ✅ | Cache invalidation |
|
|
638
|
+
| External API | ⚠️ | Timeout handling |
|
|
639
|
+
| Message queue | ❌ | All scenarios |
|
|
640
|
+
|
|
641
|
+
### Contract Tests
|
|
642
|
+
| API | Consumer | Provider | Status |
|
|
643
|
+
|-----|----------|----------|--------|
|
|
644
|
+
| /users | Frontend | Backend | ✅ |
|
|
645
|
+
| /orders | Mobile | Backend | ⚠️ Drift |
|
|
646
|
+
```
|
|
647
|
+
|
|
648
|
+
### Mock Quality Review
|
|
649
|
+
|
|
650
|
+
```python
|
|
651
|
+
# ❌ Over-mocking - testing implementation not behavior
|
|
652
|
+
@patch('myapp.services.user.repository.db.session.query')
|
|
653
|
+
@patch('myapp.services.user.repository.db.session.add')
|
|
654
|
+
@patch('myapp.services.user.repository.db.session.commit')
|
|
655
|
+
def test_create_user(mock_commit, mock_add, mock_query):
|
|
656
|
+
# Testing implementation details, not behavior
|
|
657
|
+
|
|
658
|
+
# ✅ Mock at boundaries only
|
|
659
|
+
@patch('myapp.services.external_api.verify_email')
|
|
660
|
+
def test_create_user(mock_verify):
|
|
661
|
+
mock_verify.return_value = True
|
|
662
|
+
result = UserService.create(valid_user_data)
|
|
663
|
+
assert result.email_verified is True
|
|
664
|
+
mock_verify.assert_called_once_with(valid_user_data.email)
|
|
665
|
+
```
|
|
666
|
+
|
|
667
|
+
---
|
|
668
|
+
|
|
669
|
+
## 📋 Backend Review Summary Template
|
|
670
|
+
|
|
671
|
+
```markdown
|
|
672
|
+
# Backend Review Report
|
|
673
|
+
|
|
674
|
+
## Coverage Summary
|
|
675
|
+
| Category | Files | Reviewed | Issues |
|
|
676
|
+
|----------|-------|----------|--------|
|
|
677
|
+
| Controllers/Routes | X | X | N |
|
|
678
|
+
| Services | X | X | N |
|
|
679
|
+
| Repositories | X | X | N |
|
|
680
|
+
| Models | X | X | N |
|
|
681
|
+
| Utils | X | X | N |
|
|
682
|
+
| Config | X | X | N |
|
|
683
|
+
| Migrations | X | X | N |
|
|
684
|
+
| Tests | X | X | N |
|
|
685
|
+
|
|
686
|
+
## Tool Scan Results
|
|
687
|
+
| Tool | Status | Critical | Warning |
|
|
688
|
+
|------|--------|----------|---------|
|
|
689
|
+
| Linter | ✅ | 0 | 5 |
|
|
690
|
+
| Type Check | ✅ | 0 | 2 |
|
|
691
|
+
| Security Scan | ⚠️ | 1 | 3 |
|
|
692
|
+
| Coverage | ❌ | 75% (<80%) | - |
|
|
693
|
+
|
|
694
|
+
## Architecture Issues
|
|
695
|
+
| Issue | Severity | Location | Recommendation |
|
|
696
|
+
|-------|----------|----------|----------------|
|
|
697
|
+
| Circular import | 🟡 | service A ↔ B | Extract shared interface |
|
|
698
|
+
| N+1 query | 🔴 | repo.py:45 | Use select_related |
|
|
699
|
+
|
|
700
|
+
## Runtime Concerns
|
|
701
|
+
| Concern | Status | Action Required |
|
|
702
|
+
|---------|--------|-----------------|
|
|
703
|
+
| Connection pool | ⚠️ | Increase max connections |
|
|
704
|
+
| Cache strategy | ❌ | Add cache invalidation |
|
|
705
|
+
| Error handling | ⚠️ | Add retry with backoff |
|
|
706
|
+
|
|
707
|
+
## Security Findings
|
|
708
|
+
| Finding | Severity | Location | Fix |
|
|
709
|
+
|---------|----------|----------|-----|
|
|
710
|
+
| SQL injection risk | 🔴 Critical | query.py:23 | Use parameterized query |
|
|
711
|
+
| Hardcoded secret | 🔴 Critical | config.py:5 | Move to env var |
|
|
712
|
+
|
|
713
|
+
## Recommendations
|
|
714
|
+
1. **[P0]** Fix SQL injection vulnerability before merge
|
|
715
|
+
2. **[P1]** Add missing integration tests
|
|
716
|
+
3. **[P2]** Implement circuit breaker for external calls
|
|
717
|
+
4. **[P3]** Consider adding request tracing
|
|
718
|
+
```
|
|
719
|
+
|
|
720
|
+
---
|
|
721
|
+
|
|
722
|
+
## 🔐 Comprehensive Security Review Checklist
|
|
723
|
+
|
|
724
|
+
Detailed security checks beyond OWASP basics. Use this for any code touching auth, data, or external input.
|
|
725
|
+
|
|
726
|
+
### Authentication & Authorization
|
|
727
|
+
|
|
728
|
+
```markdown
|
|
729
|
+
## Auth Security Checklist
|
|
730
|
+
|
|
731
|
+
### Authentication
|
|
732
|
+
- [ ] JWT validation includes BOTH signature AND expiry check
|
|
733
|
+
- [ ] Password hashing uses bcrypt (cost >= 10) or argon2
|
|
734
|
+
- [ ] API keys are not hardcoded in source
|
|
735
|
+
- [ ] Session tokens have appropriate expiry
|
|
736
|
+
- [ ] Failed login attempts are rate-limited
|
|
737
|
+
- [ ] Password reset tokens are single-use and time-limited
|
|
738
|
+
|
|
739
|
+
### Authorization
|
|
740
|
+
- [ ] Every state-changing endpoint has authorization check
|
|
741
|
+
- [ ] Authorization happens BEFORE business logic
|
|
742
|
+
- [ ] Resource ownership verified (user can only access their data)
|
|
743
|
+
- [ ] Role/permission checks use allowlist, not denylist
|
|
744
|
+
- [ ] Admin endpoints have additional authentication factor
|
|
745
|
+
|
|
746
|
+
### Session Management
|
|
747
|
+
- [ ] Sessions invalidated on password change
|
|
748
|
+
- [ ] Sessions invalidated on logout
|
|
749
|
+
- [ ] Session tokens regenerated after privilege escalation
|
|
750
|
+
- [ ] Concurrent session limit enforced (if applicable)
|
|
751
|
+
```
|
|
752
|
+
|
|
753
|
+
### Input Validation & Sanitization
|
|
754
|
+
|
|
755
|
+
```markdown
|
|
756
|
+
## Input Security Checklist
|
|
757
|
+
|
|
758
|
+
### Request Validation
|
|
759
|
+
- [ ] All user inputs validated on server side
|
|
760
|
+
- [ ] Input length limits enforced
|
|
761
|
+
- [ ] Input type validation (string, number, email, etc.)
|
|
762
|
+
- [ ] Whitelist allowed characters where applicable
|
|
763
|
+
- [ ] File uploads restricted by size AND type
|
|
764
|
+
- [ ] File upload names sanitized
|
|
765
|
+
|
|
766
|
+
### Injection Prevention
|
|
767
|
+
- [ ] SQL queries use parameterized statements (NEVER string concat)
|
|
768
|
+
- [ ] NoSQL queries use typed queries (not $where)
|
|
769
|
+
- [ ] Shell commands use subprocess with list args (not shell=True)
|
|
770
|
+
- [ ] LDAP queries use proper escaping
|
|
771
|
+
- [ ] XML parsing disables external entities (XXE prevention)
|
|
772
|
+
|
|
773
|
+
### Output Encoding
|
|
774
|
+
- [ ] HTML output escaped (XSS prevention)
|
|
775
|
+
- [ ] JSON responses use proper Content-Type
|
|
776
|
+
- [ ] Error messages don't leak internal details
|
|
777
|
+
- [ ] Stack traces not exposed to users
|
|
778
|
+
```
|
|
779
|
+
|
|
780
|
+
### Data Protection
|
|
781
|
+
|
|
782
|
+
```markdown
|
|
783
|
+
## Data Security Checklist
|
|
784
|
+
|
|
785
|
+
### Storage Security
|
|
786
|
+
- [ ] Passwords NEVER stored in plaintext
|
|
787
|
+
- [ ] Sensitive data encrypted at rest
|
|
788
|
+
- [ ] Encryption keys stored separately from data
|
|
789
|
+
- [ ] PII handled per compliance requirements (GDPR, etc.)
|
|
790
|
+
- [ ] Credit card data follows PCI-DSS
|
|
791
|
+
|
|
792
|
+
### Transport Security
|
|
793
|
+
- [ ] HTTPS enforced for all sensitive endpoints
|
|
794
|
+
- [ ] HSTS header enabled
|
|
795
|
+
- [ ] Secure cookies (Secure, HttpOnly, SameSite)
|
|
796
|
+
- [ ] Certificate validation not disabled
|
|
797
|
+
|
|
798
|
+
### Logging Security
|
|
799
|
+
- [ ] Passwords/tokens NEVER logged
|
|
800
|
+
- [ ] PII redacted from logs
|
|
801
|
+
- [ ] Request bodies sanitized before logging
|
|
802
|
+
- [ ] Log injection prevented (newline characters)
|
|
803
|
+
```
|
|
804
|
+
|
|
805
|
+
### Common Vulnerability Patterns
|
|
806
|
+
|
|
807
|
+
```python
|
|
808
|
+
# 🚫 SQL Injection
|
|
809
|
+
query = f"SELECT * FROM users WHERE id = {user_id}" # 💀
|
|
810
|
+
|
|
811
|
+
# ✅ Parameterized query
|
|
812
|
+
cursor.execute("SELECT * FROM users WHERE id = %s", (user_id,))
|
|
813
|
+
|
|
814
|
+
# 🚫 Command Injection
|
|
815
|
+
os.system(f"convert {user_filename} output.png") # 💀
|
|
816
|
+
|
|
817
|
+
# ✅ Safe subprocess
|
|
818
|
+
subprocess.run(["convert", user_filename, "output.png"])
|
|
819
|
+
|
|
820
|
+
# 🚫 Path Traversal
|
|
821
|
+
file_path = f"/uploads/{user_filename}" # 💀 User can pass ../../../etc/passwd
|
|
822
|
+
|
|
823
|
+
# ✅ Path validation
|
|
824
|
+
safe_path = Path("/uploads") / user_filename
|
|
825
|
+
if not safe_path.resolve().is_relative_to(Path("/uploads").resolve()):
|
|
826
|
+
raise ValueError("Invalid path")
|
|
827
|
+
|
|
828
|
+
# 🚫 Hardcoded secret
|
|
829
|
+
API_KEY = "sk-prod-abc123xyz" # 💀 Visible in git history forever
|
|
830
|
+
|
|
831
|
+
# ✅ Environment variable
|
|
832
|
+
API_KEY = os.environ["API_KEY"] # With validation
|
|
833
|
+
|
|
834
|
+
# 🚫 Insecure random
|
|
835
|
+
token = str(random.randint(0, 999999)) # 💀 Predictable
|
|
836
|
+
|
|
837
|
+
# ✅ Cryptographic random
|
|
838
|
+
token = secrets.token_urlsafe(32)
|
|
839
|
+
|
|
840
|
+
# 🚫 Missing rate limit
|
|
841
|
+
@app.post("/login") # 💀 Brute force possible
|
|
842
|
+
def login(credentials): ...
|
|
843
|
+
|
|
844
|
+
# ✅ Rate limited
|
|
845
|
+
@app.post("/login")
|
|
846
|
+
@limiter.limit("5/minute")
|
|
847
|
+
def login(credentials): ...
|
|
848
|
+
```
|
|
849
|
+
|
|
850
|
+
### Security Detection Commands
|
|
851
|
+
|
|
852
|
+
```bash
|
|
853
|
+
# Find hardcoded secrets
|
|
854
|
+
grep -rn "password\s*=\|api_key\s*=\|secret\s*=" --include="*.py" --include="*.ts" | grep -v "os.environ\|process.env\|config\."
|
|
855
|
+
|
|
856
|
+
# Find SQL string concatenation
|
|
857
|
+
grep -rn "SELECT.*+.*user\|INSERT.*+.*user\|UPDATE.*+.*user" --include="*.py" --include="*.ts"
|
|
858
|
+
|
|
859
|
+
# Find shell=True usage (Python)
|
|
860
|
+
grep -rn "shell=True" --include="*.py"
|
|
861
|
+
|
|
862
|
+
# Find eval/exec usage
|
|
863
|
+
grep -rn "\beval(\|exec(" --include="*.py" --include="*.ts" --include="*.js"
|
|
864
|
+
|
|
865
|
+
# Find disabled SSL verification
|
|
866
|
+
grep -rn "verify=False\|rejectUnauthorized.*false" --include="*.py" --include="*.ts"
|
|
867
|
+
```
|
|
868
|
+
|