ai-playbook 1.0.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/README.md +146 -0
- package/agents/README.md +168 -0
- package/agents/SKILL.md +633 -0
- package/agents/architect/AGENT.md +44 -0
- package/agents/architect/README.md +5 -0
- package/agents/coder/AGENT.md +43 -0
- package/agents/coder/README.md +5 -0
- package/agents/debugger/AGENT.md +42 -0
- package/agents/debugger/README.md +6 -0
- package/agents/devops/AGENT.md +43 -0
- package/agents/devops/README.md +5 -0
- package/agents/documentation/AGENT.md +45 -0
- package/agents/documentation/README.md +5 -0
- package/agents/examples.md +550 -0
- package/agents/performance/AGENT.md +45 -0
- package/agents/performance/README.md +6 -0
- package/agents/planner/AGENT.md +44 -0
- package/agents/planner/README.md +6 -0
- package/agents/product-owner/AGENT.md +46 -0
- package/agents/product-owner/README.md +6 -0
- package/agents/refactorer/AGENT.md +44 -0
- package/agents/refactorer/README.md +6 -0
- package/agents/release-manager/AGENT.md +45 -0
- package/agents/release-manager/README.md +6 -0
- package/agents/researcher/AGENT.md +44 -0
- package/agents/researcher/README.md +6 -0
- package/agents/reviewer/AGENT.md +43 -0
- package/agents/reviewer/README.md +6 -0
- package/agents/security/AGENT.md +46 -0
- package/agents/security/README.md +6 -0
- package/agents/support/AGENT.md +45 -0
- package/agents/support/README.md +6 -0
- package/agents/tester/AGENT.md +46 -0
- package/agents/tester/README.md +5 -0
- package/bin/cli.js +186 -0
- package/commands/README.md +266 -0
- package/commands/build.md +135 -0
- package/commands/clean.md +126 -0
- package/commands/deploy-prod.md +171 -0
- package/commands/deploy-staging.md +147 -0
- package/commands/deps.md +169 -0
- package/commands/dev.md +132 -0
- package/commands/format.md +142 -0
- package/commands/lint.md +125 -0
- package/commands/migrate.md +159 -0
- package/commands/release.md +183 -0
- package/commands/rollback.md +152 -0
- package/commands/seed.md +178 -0
- package/commands/setup.md +109 -0
- package/commands/test.md +134 -0
- package/commands/validate.md +147 -0
- package/context/README.md +7 -0
- package/context/aem.md +47 -0
- package/context/architecture.md +51 -0
- package/context/bullminder.md +57 -0
- package/context/coding-style.md +42 -0
- package/context/communication.md +53 -0
- package/context/company.md +46 -0
- package/context/engineering.md +63 -0
- package/context/project-template.md +71 -0
- package/context/trading.md +52 -0
- package/hooks/README.md +326 -0
- package/hooks/code-review/README.md +6 -0
- package/hooks/code-review/check-coverage.md +101 -0
- package/hooks/custom/README.md +6 -0
- package/hooks/custom/project-specific-hooks.md +273 -0
- package/hooks/deployment/README.md +6 -0
- package/hooks/deployment/health-check.md +102 -0
- package/hooks/deployment/pre-deploy-check.md +84 -0
- package/hooks/documentation/README.md +6 -0
- package/hooks/documentation/update-changelog.md +146 -0
- package/hooks/post-task/README.md +5 -0
- package/hooks/post-task/run-tests.md +61 -0
- package/hooks/pre-commit/README.md +6 -0
- package/hooks/pre-commit/format.md +63 -0
- package/hooks/pre-commit/lint.md +62 -0
- package/hooks/pre-commit/type-check.md +78 -0
- package/hooks/pre-task/README.md +6 -0
- package/hooks/pre-task/check-branch.md +48 -0
- package/hooks/pre-task/validate-environment.md +48 -0
- package/hooks/security-check/README.md +6 -0
- package/hooks/security-check/dependency-audit.md +85 -0
- package/hooks/security-check/secrets-scan.md +77 -0
- package/hooks/test-before-finish/README.md +6 -0
- package/hooks/test-before-finish/run-all-tests.md +128 -0
- package/index.js +69 -0
- package/knowledge/README.md +33 -0
- package/knowledge/ai-agents.md +74 -0
- package/knowledge/decision-making.md +73 -0
- package/knowledge/documentation.md +67 -0
- package/knowledge/engineering-principles.md +65 -0
- package/knowledge/product-discovery.md +68 -0
- package/knowledge/security-privacy.md +54 -0
- package/knowledge/testing-quality.md +63 -0
- package/package.json +63 -0
- package/patterns/README.md +7 -0
- package/prompts/README.md +208 -0
- package/prompts/architect/README.md +96 -0
- package/prompts/architect/design-system.md +140 -0
- package/prompts/debugger/README.md +96 -0
- package/prompts/debugger/diagnose-issue.md +141 -0
- package/prompts/developer/README.md +129 -0
- package/prompts/developer/fix-bug.md +136 -0
- package/prompts/developer/implement-feature.md +133 -0
- package/prompts/product-owner/README.md +116 -0
- package/prompts/product-owner/define-feature.md +145 -0
- package/prompts/reviewer/README.md +91 -0
- package/prompts/reviewer/code-review.md +129 -0
- package/prompts/support/README.md +154 -0
- package/prompts/support/resolve-issue.md +124 -0
- package/roles/README.md +6 -0
- package/roles/design-architect/README.md +98 -0
- package/roles/design-architect/accessibility/README.md +33 -0
- package/roles/design-architect/accessibility/checklists.md +29 -0
- package/roles/design-architect/accessibility/examples.md +35 -0
- package/roles/design-architect/checklists.md +76 -0
- package/roles/design-architect/component-library/README.md +35 -0
- package/roles/design-architect/component-library/checklists.md +29 -0
- package/roles/design-architect/component-library/examples.md +35 -0
- package/roles/design-architect/design-system/README.md +35 -0
- package/roles/design-architect/design-system/checklists.md +27 -0
- package/roles/design-architect/design-system/examples.md +41 -0
- package/roles/design-architect/examples/README.md +31 -0
- package/roles/design-architect/examples/checklists.md +26 -0
- package/roles/design-architect/examples/examples.md +46 -0
- package/roles/design-architect/examples.md +90 -0
- package/roles/design-architect/figma/README.md +33 -0
- package/roles/design-architect/figma/checklists.md +27 -0
- package/roles/design-architect/figma/examples.md +38 -0
- package/roles/design-architect/responsibilities.md +73 -0
- package/roles/design-architect/responsive/README.md +34 -0
- package/roles/design-architect/responsive/checklists.md +26 -0
- package/roles/design-architect/responsive/examples.md +39 -0
- package/roles/design-architect/role.md +129 -0
- package/roles/design-architect/skill-map.md +42 -0
- package/roles/design-architect/triggers.md +110 -0
- package/roles/design-architect/ui/README.md +36 -0
- package/roles/design-architect/ui/checklists.md +29 -0
- package/roles/design-architect/ui/examples.md +28 -0
- package/roles/design-architect/usability/README.md +34 -0
- package/roles/design-architect/usability/checklists.md +28 -0
- package/roles/design-architect/usability/examples.md +31 -0
- package/roles/design-architect/ux/README.md +36 -0
- package/roles/design-architect/ux/checklists.md +28 -0
- package/roles/design-architect/ux/examples.md +37 -0
- package/roles/design-architect/wireframes/README.md +34 -0
- package/roles/design-architect/wireframes/checklists.md +25 -0
- package/roles/design-architect/wireframes/examples.md +32 -0
- package/roles/design-architect/workflow.md +80 -0
- package/roles/devops/README.md +101 -0
- package/roles/devops/ansible/README.md +6 -0
- package/roles/devops/checklists.md +413 -0
- package/roles/devops/ci-cd/README.md +169 -0
- package/roles/devops/ci-cd/checklists.md +289 -0
- package/roles/devops/ci-cd/examples.md +429 -0
- package/roles/devops/cloud-platforms/README.md +109 -0
- package/roles/devops/cost-optimization/README.md +131 -0
- package/roles/devops/disaster-recovery/README.md +118 -0
- package/roles/devops/docker/README.md +6 -0
- package/roles/devops/examples/README.md +6 -0
- package/roles/devops/examples.md +775 -0
- package/roles/devops/github-actions/README.md +6 -0
- package/roles/devops/helm/README.md +6 -0
- package/roles/devops/infrastructure-as-code/README.md +160 -0
- package/roles/devops/infrastructure-as-code/checklists.md +124 -0
- package/roles/devops/jenkins/README.md +6 -0
- package/roles/devops/kubernetes/README.md +150 -0
- package/roles/devops/kubernetes/checklists.md +192 -0
- package/roles/devops/kubernetes/examples.md +189 -0
- package/roles/devops/monitoring/README.md +93 -0
- package/roles/devops/networking/README.md +83 -0
- package/roles/devops/performance/README.md +104 -0
- package/roles/devops/responsibilities.md +95 -0
- package/roles/devops/role.md +130 -0
- package/roles/devops/security/README.md +126 -0
- package/roles/devops/skill-map.md +162 -0
- package/roles/devops/terraform/README.md +6 -0
- package/roles/devops/triggers.md +241 -0
- package/roles/devops/workflow.md +197 -0
- package/roles/qa/README.md +16 -0
- package/roles/qa/api-testing/README.md +6 -0
- package/roles/qa/automation/README.md +6 -0
- package/roles/qa/checklists.md +24 -0
- package/roles/qa/examples/README.md +6 -0
- package/roles/qa/examples.md +27 -0
- package/roles/qa/performance/README.md +6 -0
- package/roles/qa/playwright/README.md +6 -0
- package/roles/qa/responsibilities.md +16 -0
- package/roles/qa/role.md +47 -0
- package/roles/qa/selenium/README.md +6 -0
- package/roles/qa/skill-map.md +14 -0
- package/roles/qa/triggers.md +10 -0
- package/roles/qa/workflow.md +9 -0
- package/roles/software-architect/README.md +16 -0
- package/roles/software-architect/agents/README.md +6 -0
- package/roles/software-architect/ai-architecture/README.md +6 -0
- package/roles/software-architect/aws/README.md +6 -0
- package/roles/software-architect/azure/README.md +6 -0
- package/roles/software-architect/caching/README.md +6 -0
- package/roles/software-architect/checklists.md +25 -0
- package/roles/software-architect/cloud/README.md +6 -0
- package/roles/software-architect/database-design/README.md +6 -0
- package/roles/software-architect/diagrams/README.md +6 -0
- package/roles/software-architect/distributed-systems/README.md +7 -0
- package/roles/software-architect/docker/README.md +6 -0
- package/roles/software-architect/event-driven/README.md +7 -0
- package/roles/software-architect/examples/README.md +6 -0
- package/roles/software-architect/examples.md +22 -0
- package/roles/software-architect/gcp/README.md +6 -0
- package/roles/software-architect/kubernetes/README.md +6 -0
- package/roles/software-architect/messaging/README.md +6 -0
- package/roles/software-architect/rag/README.md +7 -0
- package/roles/software-architect/responsibilities.md +17 -0
- package/roles/software-architect/role.md +46 -0
- package/roles/software-architect/scalability/README.md +6 -0
- package/roles/software-architect/security/README.md +6 -0
- package/roles/software-architect/skill-map.md +15 -0
- package/roles/software-architect/system-design/README.md +6 -0
- package/roles/software-architect/triggers.md +10 -0
- package/roles/software-architect/vector-db/README.md +6 -0
- package/roles/software-architect/workflow.md +9 -0
- package/roles/software-developer/README.md +116 -0
- package/roles/software-developer/api/README.md +365 -0
- package/roles/software-developer/api/checklist.md +131 -0
- package/roles/software-developer/api/examples.md +459 -0
- package/roles/software-developer/authentication/README.md +26 -0
- package/roles/software-developer/authentication/checklists.md +22 -0
- package/roles/software-developer/authentication/examples.md +32 -0
- package/roles/software-developer/authorization/README.md +26 -0
- package/roles/software-developer/authorization/checklists.md +21 -0
- package/roles/software-developer/authorization/examples.md +27 -0
- package/roles/software-developer/backend/README.md +26 -0
- package/roles/software-developer/backend/checklists.md +21 -0
- package/roles/software-developer/backend/examples.md +21 -0
- package/roles/software-developer/cache/README.md +25 -0
- package/roles/software-developer/cache/checklists.md +21 -0
- package/roles/software-developer/cache/examples.md +22 -0
- package/roles/software-developer/checklists.md +122 -0
- package/roles/software-developer/code-review/README.md +23 -0
- package/roles/software-developer/code-review/checklists.md +22 -0
- package/roles/software-developer/code-review/examples.md +20 -0
- package/roles/software-developer/database/README.md +27 -0
- package/roles/software-developer/database/checklists.md +21 -0
- package/roles/software-developer/database/examples.md +27 -0
- package/roles/software-developer/debugging/README.md +24 -0
- package/roles/software-developer/debugging/checklists.md +20 -0
- package/roles/software-developer/debugging/examples.md +28 -0
- package/roles/software-developer/examples/README.md +22 -0
- package/roles/software-developer/examples/checklists.md +8 -0
- package/roles/software-developer/examples/examples.md +25 -0
- package/roles/software-developer/examples.md +378 -0
- package/roles/software-developer/frontend/README.md +76 -0
- package/roles/software-developer/frontend/accessibility/README.md +136 -0
- package/roles/software-developer/frontend/accessibility/best-practices.md +368 -0
- package/roles/software-developer/frontend/code-quality/README.md +136 -0
- package/roles/software-developer/frontend/code-quality/best-practices.md +309 -0
- package/roles/software-developer/frontend/components/README.md +65 -0
- package/roles/software-developer/frontend/components/best-practices.md +273 -0
- package/roles/software-developer/frontend/debugging/README.md +149 -0
- package/roles/software-developer/frontend/debugging/best-practices.md +329 -0
- package/roles/software-developer/frontend/examples/README.md +19 -0
- package/roles/software-developer/frontend/examples/checklists.md +8 -0
- package/roles/software-developer/frontend/examples/examples.md +17 -0
- package/roles/software-developer/frontend/logging-observability/README.md +196 -0
- package/roles/software-developer/frontend/logging-observability/best-practices.md +430 -0
- package/roles/software-developer/frontend/performance/README.md +99 -0
- package/roles/software-developer/frontend/performance/best-practices.md +350 -0
- package/roles/software-developer/frontend/state-management/README.md +85 -0
- package/roles/software-developer/frontend/state-management/best-practices.md +344 -0
- package/roles/software-developer/frontend/testing/README.md +114 -0
- package/roles/software-developer/frontend/testing/best-practices.md +272 -0
- package/roles/software-developer/fullstack/README.md +25 -0
- package/roles/software-developer/fullstack/checklists.md +19 -0
- package/roles/software-developer/fullstack/examples.md +14 -0
- package/roles/software-developer/graphql/README.md +24 -0
- package/roles/software-developer/graphql/checklists.md +20 -0
- package/roles/software-developer/graphql/examples.md +24 -0
- package/roles/software-developer/integration-tests/README.md +25 -0
- package/roles/software-developer/integration-tests/checklists.md +20 -0
- package/roles/software-developer/integration-tests/examples.md +18 -0
- package/roles/software-developer/java/README.md +24 -0
- package/roles/software-developer/java/checklists.md +16 -0
- package/roles/software-developer/java/examples.md +22 -0
- package/roles/software-developer/javascript/README.md +24 -0
- package/roles/software-developer/javascript/checklists.md +15 -0
- package/roles/software-developer/javascript/examples.md +18 -0
- package/roles/software-developer/logging/README.md +105 -0
- package/roles/software-developer/logging/checklists.md +48 -0
- package/roles/software-developer/logging/examples.md +135 -0
- package/roles/software-developer/messaging/README.md +24 -0
- package/roles/software-developer/messaging/checklists.md +21 -0
- package/roles/software-developer/messaging/examples.md +26 -0
- package/roles/software-developer/microservices/README.md +25 -0
- package/roles/software-developer/microservices/checklists.md +21 -0
- package/roles/software-developer/microservices/examples.md +21 -0
- package/roles/software-developer/node/README.md +25 -0
- package/roles/software-developer/node/checklists.md +15 -0
- package/roles/software-developer/node/examples.md +15 -0
- package/roles/software-developer/nosql/README.md +24 -0
- package/roles/software-developer/nosql/checklists.md +21 -0
- package/roles/software-developer/nosql/examples.md +20 -0
- package/roles/software-developer/observability/README.md +25 -0
- package/roles/software-developer/observability/checklists.md +21 -0
- package/roles/software-developer/observability/examples.md +22 -0
- package/roles/software-developer/performance/README.md +26 -0
- package/roles/software-developer/performance/checklists.md +20 -0
- package/roles/software-developer/performance/examples.md +20 -0
- package/roles/software-developer/python/README.md +25 -0
- package/roles/software-developer/python/checklists.md +15 -0
- package/roles/software-developer/python/examples.md +17 -0
- package/roles/software-developer/react/README.md +24 -0
- package/roles/software-developer/react/checklists.md +15 -0
- package/roles/software-developer/react/examples.md +22 -0
- package/roles/software-developer/refactoring/README.md +23 -0
- package/roles/software-developer/refactoring/checklists.md +21 -0
- package/roles/software-developer/refactoring/examples.md +11 -0
- package/roles/software-developer/responsibilities.md +58 -0
- package/roles/software-developer/role.md +127 -0
- package/roles/software-developer/skill-map.md +88 -0
- package/roles/software-developer/springboot/README.md +25 -0
- package/roles/software-developer/springboot/checklists.md +15 -0
- package/roles/software-developer/springboot/examples.md +21 -0
- package/roles/software-developer/sql/README.md +24 -0
- package/roles/software-developer/sql/checklists.md +22 -0
- package/roles/software-developer/sql/examples.md +20 -0
- package/roles/software-developer/testing/README.md +25 -0
- package/roles/software-developer/testing/checklists.md +21 -0
- package/roles/software-developer/testing/examples.md +19 -0
- package/roles/software-developer/triggers.md +550 -0
- package/roles/software-developer/typescript/README.md +25 -0
- package/roles/software-developer/typescript/checklists.md +15 -0
- package/roles/software-developer/typescript/examples.md +18 -0
- package/roles/software-developer/unit-tests/README.md +24 -0
- package/roles/software-developer/unit-tests/checklists.md +19 -0
- package/roles/software-developer/unit-tests/examples.md +22 -0
- package/roles/software-developer/workflow.md +196 -0
- package/roles/sre/README.md +16 -0
- package/roles/sre/alerts/README.md +6 -0
- package/roles/sre/availability/README.md +6 -0
- package/roles/sre/chaos/README.md +6 -0
- package/roles/sre/checklists.md +24 -0
- package/roles/sre/examples/README.md +6 -0
- package/roles/sre/examples.md +19 -0
- package/roles/sre/observability/README.md +6 -0
- package/roles/sre/reliability/README.md +6 -0
- package/roles/sre/responsibilities.md +16 -0
- package/roles/sre/role.md +46 -0
- package/roles/sre/skill-map.md +14 -0
- package/roles/sre/slos/README.md +6 -0
- package/roles/sre/triggers.md +10 -0
- package/roles/sre/workflow.md +9 -0
- package/roles/support-engineer/README.md +16 -0
- package/roles/support-engineer/checklists.md +24 -0
- package/roles/support-engineer/datadog/README.md +6 -0
- package/roles/support-engineer/examples/README.md +6 -0
- package/roles/support-engineer/examples.md +17 -0
- package/roles/support-engineer/incident-response/README.md +6 -0
- package/roles/support-engineer/kubernetes/README.md +6 -0
- package/roles/support-engineer/linux/README.md +6 -0
- package/roles/support-engineer/logs/README.md +6 -0
- package/roles/support-engineer/monitoring/README.md +6 -0
- package/roles/support-engineer/networking/README.md +6 -0
- package/roles/support-engineer/newrelic/README.md +6 -0
- package/roles/support-engineer/postmortem/README.md +6 -0
- package/roles/support-engineer/production/README.md +6 -0
- package/roles/support-engineer/responsibilities.md +16 -0
- package/roles/support-engineer/role.md +47 -0
- package/roles/support-engineer/root-cause-analysis/README.md +6 -0
- package/roles/support-engineer/runbooks/README.md +6 -0
- package/roles/support-engineer/skill-map.md +14 -0
- package/roles/support-engineer/splunk/README.md +6 -0
- package/roles/support-engineer/triggers.md +10 -0
- package/roles/support-engineer/troubleshooting/README.md +6 -0
- package/roles/support-engineer/workflow.md +9 -0
- package/setup.sh +204 -0
- package/skills/.claude/README.md +7 -0
- package/skills/README.md +21 -0
- package/skills/ai-agents/README.md +207 -0
- package/skills/ai-agents/examples.md +335 -0
- package/skills/ai-agents/skill.md +392 -0
- package/skills/architecture/README.md +198 -0
- package/skills/architecture/examples.md +316 -0
- package/skills/architecture/skill.md +189 -0
- package/skills/design-architecture/README.md +107 -0
- package/skills/design-architecture/examples.md +84 -0
- package/skills/design-architecture/skill.md +192 -0
- package/skills/devops/README.md +177 -0
- package/skills/devops/examples.md +376 -0
- package/skills/devops/skill.md +210 -0
- package/skills/documentation/README.md +182 -0
- package/skills/documentation/examples.md +364 -0
- package/skills/documentation/skill.md +200 -0
- package/skills/performance/README.md +177 -0
- package/skills/performance/examples.md +376 -0
- package/skills/performance/skill.md +199 -0
- package/skills/qa/README.md +106 -0
- package/skills/qa/examples.md +84 -0
- package/skills/qa/skill.md +384 -0
- package/skills/security/README.md +108 -0
- package/skills/security/examples.md +85 -0
- package/skills/security/skill.md +223 -0
- package/skills/software-development/README.md +239 -0
- package/skills/software-development/assessment.md +0 -0
- package/skills/software-development/checklists.md +0 -0
- package/skills/software-development/examples.md +375 -0
- package/skills/software-development/prompts.md +0 -0
- package/skills/software-development/skill.md +390 -0
- package/skills/software-development/templates/README.md +7 -0
- package/skills/software-development/templates/api-development.md +0 -0
- package/skills/software-development/templates/bug-fix.md +0 -0
- package/skills/software-development/templates/code-review.md +0 -0
- package/skills/software-development/templates/feature-implementation.md +0 -0
- package/skills/software-development/templates/llm-integration.md +0 -0
- package/skills/software-development/templates/performance-review.md +0 -0
- package/skills/software-development/templates/security-review.md +0 -0
- package/skills/software-development/templates/test-generation.md +0 -0
- package/skills/software-development/tools.md +0 -0
- package/skills/software-development/workflows.md +0 -0
- package/skills/sre/README.md +107 -0
- package/skills/sre/examples.md +379 -0
- package/skills/sre/skill.md +256 -0
- package/skills/support-engineering/README.md +107 -0
- package/skills/support-engineering/examples.md +85 -0
- package/skills/support-engineering/skill.md +103 -0
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
# Debugging
|
|
2
|
+
|
|
3
|
+
Senior frontend developers debug systematically. Don't guess — observe, hypothesize, test.
|
|
4
|
+
|
|
5
|
+
## Debugging Process
|
|
6
|
+
|
|
7
|
+
1. **Reproduce** — isolate when bug occurs
|
|
8
|
+
2. **Observe** — what's different from expected?
|
|
9
|
+
3. **Hypothesis** — what could cause this?
|
|
10
|
+
4. **Test** — verify hypothesis
|
|
11
|
+
5. **Fix** — make minimal change
|
|
12
|
+
6. **Verify** — bug gone, no regressions
|
|
13
|
+
|
|
14
|
+
Rushing skips steps, wastes time.
|
|
15
|
+
|
|
16
|
+
## Browser DevTools
|
|
17
|
+
|
|
18
|
+
### Console
|
|
19
|
+
- View errors/warnings
|
|
20
|
+
- Log data with `console.log()`
|
|
21
|
+
- Use `console.table()` for structured data
|
|
22
|
+
- Group logs with `console.group()`
|
|
23
|
+
- Measure with `console.time()`
|
|
24
|
+
|
|
25
|
+
### Sources/Debugger
|
|
26
|
+
- Set breakpoints (click line number)
|
|
27
|
+
- Step through code (step over/in/out)
|
|
28
|
+
- Inspect variable values
|
|
29
|
+
- Conditional breakpoints
|
|
30
|
+
- Watch expressions
|
|
31
|
+
|
|
32
|
+
### Elements/Inspector
|
|
33
|
+
- Inspect DOM structure
|
|
34
|
+
- Change CSS temporarily
|
|
35
|
+
- View computed styles
|
|
36
|
+
- Check classes/attributes
|
|
37
|
+
- Debug layout issues
|
|
38
|
+
|
|
39
|
+
### Network Tab
|
|
40
|
+
- View API requests/responses
|
|
41
|
+
- Check status codes
|
|
42
|
+
- View response data
|
|
43
|
+
- Monitor timing
|
|
44
|
+
- Throttle network (slow 3G simulation)
|
|
45
|
+
|
|
46
|
+
### Performance Tab
|
|
47
|
+
- Record and analyze runtime performance
|
|
48
|
+
- Identify slow operations
|
|
49
|
+
- Check for jank
|
|
50
|
+
- Analyze flame charts
|
|
51
|
+
|
|
52
|
+
### React DevTools
|
|
53
|
+
- Inspect component tree
|
|
54
|
+
- View props and state
|
|
55
|
+
- Track re-renders
|
|
56
|
+
- Highlight updates
|
|
57
|
+
- Profile performance
|
|
58
|
+
|
|
59
|
+
## Common Bugs & Solutions
|
|
60
|
+
|
|
61
|
+
### Component Not Rendering
|
|
62
|
+
- Check console for errors
|
|
63
|
+
- Verify JSX syntax (components PascalCase)
|
|
64
|
+
- Check props passed correctly
|
|
65
|
+
- Verify conditional render logic
|
|
66
|
+
- Check CSS display/visibility
|
|
67
|
+
|
|
68
|
+
### State Not Updating
|
|
69
|
+
- Mutating state directly (use setState)
|
|
70
|
+
- Not triggering re-render (wrong hook)
|
|
71
|
+
- Race conditions (async state)
|
|
72
|
+
- Stale closure (old props in handler)
|
|
73
|
+
- Not returning new object (mutations)
|
|
74
|
+
|
|
75
|
+
### API Calls Not Firing
|
|
76
|
+
- Check Network tab for request
|
|
77
|
+
- Verify endpoint URL
|
|
78
|
+
- Check request headers/body
|
|
79
|
+
- Verify loading/error handling
|
|
80
|
+
- Check CORS settings
|
|
81
|
+
- Verify API key/auth
|
|
82
|
+
|
|
83
|
+
### Memory Leaks
|
|
84
|
+
- Event listeners not removed
|
|
85
|
+
- Timers (setTimeout, setInterval) not cleared
|
|
86
|
+
- Subscriptions not unsubscribed
|
|
87
|
+
- Stale component references
|
|
88
|
+
- Circular references
|
|
89
|
+
|
|
90
|
+
### Performance Issues
|
|
91
|
+
- Check DevTools Performance tab
|
|
92
|
+
- Identify slow operations
|
|
93
|
+
- Unnecessary re-renders
|
|
94
|
+
- Large bundle size
|
|
95
|
+
- Slow network requests
|
|
96
|
+
|
|
97
|
+
## Debugging Techniques
|
|
98
|
+
|
|
99
|
+
### Strategic Logging
|
|
100
|
+
- Log at decision points
|
|
101
|
+
- Log data structures with context
|
|
102
|
+
- Use descriptive log messages
|
|
103
|
+
- Remove logs before commit (or use debug flag)
|
|
104
|
+
|
|
105
|
+
### Rubber Duck Debugging
|
|
106
|
+
- Explain code to someone (or rubber duck)
|
|
107
|
+
- Explaining forces clarity
|
|
108
|
+
- Often find bug while explaining
|
|
109
|
+
|
|
110
|
+
### Narrowing Scope
|
|
111
|
+
- Comment out code to isolate issue
|
|
112
|
+
- Temporarily remove features
|
|
113
|
+
- Use git bisect to find bad commit
|
|
114
|
+
- Create minimal reproduction case
|
|
115
|
+
|
|
116
|
+
### Reproducing Bugs
|
|
117
|
+
- Get exact steps to reproduce
|
|
118
|
+
- Isolate inputs that trigger bug
|
|
119
|
+
- Create minimal test case
|
|
120
|
+
- Debug in controlled environment
|
|
121
|
+
|
|
122
|
+
## Debugging Checklist
|
|
123
|
+
|
|
124
|
+
When bug occurs:
|
|
125
|
+
- [ ] Console errors/warnings checked
|
|
126
|
+
- [ ] Reproduction steps documented
|
|
127
|
+
- [ ] Hypothesis written down
|
|
128
|
+
- [ ] DevTools used (console, debugger, network)
|
|
129
|
+
- [ ] Data at each step verified
|
|
130
|
+
- [ ] Code changes minimal
|
|
131
|
+
- [ ] Tests added for bug
|
|
132
|
+
- [ ] No new issues introduced
|
|
133
|
+
|
|
134
|
+
## Anti-Patterns
|
|
135
|
+
|
|
136
|
+
- Guessing instead of investigating
|
|
137
|
+
- Adding lots of `console.log()` without removing
|
|
138
|
+
- Not using debugger (just relying on logs)
|
|
139
|
+
- Ignoring error messages
|
|
140
|
+
- Changing multiple things at once
|
|
141
|
+
- Not reproducing bug reliably
|
|
142
|
+
- Band-aid fixes without fixing root cause
|
|
143
|
+
- Not testing fix thoroughly
|
|
144
|
+
|
|
145
|
+
## Related Guidance
|
|
146
|
+
|
|
147
|
+
- `/logging-observability` — logging for debugging
|
|
148
|
+
- `/testing` — preventing bugs with tests
|
|
149
|
+
- `/code-quality` — clean code is easier to debug
|
|
@@ -0,0 +1,329 @@
|
|
|
1
|
+
# Debugging: Best Practices
|
|
2
|
+
|
|
3
|
+
Debugging is a systematic skill. The faster you find bugs, the more productive you are. This guide covers proven techniques for tracking down problems efficiently.
|
|
4
|
+
|
|
5
|
+
## Reproduction is Half the Battle
|
|
6
|
+
|
|
7
|
+
The hardest part of debugging is reproducing the problem consistently. Once you can reliably reproduce it, the fix is often obvious.
|
|
8
|
+
|
|
9
|
+
```javascript
|
|
10
|
+
// GOOD: Document reproduction steps clearly
|
|
11
|
+
/*
|
|
12
|
+
Bug: User avatar not loading on profile page
|
|
13
|
+
|
|
14
|
+
Steps to reproduce:
|
|
15
|
+
1. Log in as user
|
|
16
|
+
2. Navigate to profile page
|
|
17
|
+
3. Avatar does not appear (broken image icon shown)
|
|
18
|
+
4. Network tab shows 404 for avatar URL
|
|
19
|
+
|
|
20
|
+
Expected: Profile picture loads from /avatars/{userId}.jpg
|
|
21
|
+
Actual: Returns 404
|
|
22
|
+
|
|
23
|
+
Environment: Chrome 120, macOS Sonoma
|
|
24
|
+
Last worked: Version 2.1.0
|
|
25
|
+
First noticed: Version 2.3.1
|
|
26
|
+
*/
|
|
27
|
+
|
|
28
|
+
// During debugging, keep detailed notes:
|
|
29
|
+
// What works vs doesn't work
|
|
30
|
+
// What changed between working and broken
|
|
31
|
+
// Any error messages (exact text matters!)
|
|
32
|
+
// Browser/device/OS combination
|
|
33
|
+
// Network conditions if relevant
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
## Use DevTools Effectively
|
|
37
|
+
|
|
38
|
+
Browser DevTools are powerful when used correctly.
|
|
39
|
+
|
|
40
|
+
```javascript
|
|
41
|
+
// Debugging React components:
|
|
42
|
+
// 1. Install React DevTools extension
|
|
43
|
+
// 2. Open DevTools → Components tab
|
|
44
|
+
// 3. Inspect component tree, view current props/state
|
|
45
|
+
// 4. Simulate prop changes to test behavior
|
|
46
|
+
// 5. Check if component re-renders when expected
|
|
47
|
+
|
|
48
|
+
// Common DevTools tricks:
|
|
49
|
+
|
|
50
|
+
// View element styles and specificity
|
|
51
|
+
// Inspect → Styles tab
|
|
52
|
+
// Hover over CSS rules to see which file they come from
|
|
53
|
+
|
|
54
|
+
// Watch variables change in real-time
|
|
55
|
+
// Inspect → Console
|
|
56
|
+
function debugValue(name, value) {
|
|
57
|
+
console.log(`${name}:`, value);
|
|
58
|
+
window[`debug_${name}`] = value; // Access in console as window.debug_value
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
// Network debugging:
|
|
62
|
+
// Network tab → filter by type
|
|
63
|
+
// Check response headers (Content-Type, Cache-Control)
|
|
64
|
+
// Check request headers (Authorization, User-Agent)
|
|
65
|
+
// Watch for failed requests (red) vs slow requests (yellow)
|
|
66
|
+
|
|
67
|
+
// Performance profiling:
|
|
68
|
+
// Performance tab → record
|
|
69
|
+
// Perform action
|
|
70
|
+
// Analyze flame chart to find slow operations
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
## Isolate the Problem
|
|
74
|
+
|
|
75
|
+
Narrow down where the bug is by removing variables.
|
|
76
|
+
|
|
77
|
+
```javascript
|
|
78
|
+
// BAD: Vague debugging
|
|
79
|
+
// Component not working, let me add console.log everywhere
|
|
80
|
+
|
|
81
|
+
// GOOD: Systematic isolation
|
|
82
|
+
function UserProfile({ userId }) {
|
|
83
|
+
const [user, setUser] = useState(null);
|
|
84
|
+
|
|
85
|
+
useEffect(() => {
|
|
86
|
+
// Is the API called?
|
|
87
|
+
console.log('Fetching user:', userId);
|
|
88
|
+
|
|
89
|
+
fetchUser(userId)
|
|
90
|
+
.then(data => {
|
|
91
|
+
// Does API return data?
|
|
92
|
+
console.log('API returned:', data);
|
|
93
|
+
setUser(data);
|
|
94
|
+
})
|
|
95
|
+
.catch(err => {
|
|
96
|
+
// Does API fail?
|
|
97
|
+
console.error('API error:', err);
|
|
98
|
+
});
|
|
99
|
+
}, [userId]);
|
|
100
|
+
|
|
101
|
+
// Is state set correctly?
|
|
102
|
+
console.log('Current state:', user);
|
|
103
|
+
|
|
104
|
+
if (!user) return <div>Loading...</div>;
|
|
105
|
+
|
|
106
|
+
return <div>{user.name}</div>;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
// Isolate steps:
|
|
110
|
+
// 1. Does API get called with correct userId?
|
|
111
|
+
// 2. Does API return expected data?
|
|
112
|
+
// 3. Is state set correctly after API returns?
|
|
113
|
+
// 4. Does component render using that state?
|
|
114
|
+
|
|
115
|
+
// Once you find which step fails, focus there
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
## React-Specific Debugging
|
|
119
|
+
|
|
120
|
+
React has specific patterns and tools for debugging.
|
|
121
|
+
|
|
122
|
+
```javascript
|
|
123
|
+
// Common React bugs:
|
|
124
|
+
|
|
125
|
+
// 1. Stale closure in useEffect
|
|
126
|
+
// BAD: useEffect uses value that might be stale
|
|
127
|
+
function Timer() {
|
|
128
|
+
const [count, setCount] = useState(0);
|
|
129
|
+
|
|
130
|
+
useEffect(() => {
|
|
131
|
+
const interval = setInterval(() => {
|
|
132
|
+
setCount(count + 1); // Always increments by 1, even if count changed
|
|
133
|
+
}, 1000);
|
|
134
|
+
|
|
135
|
+
return () => clearInterval(interval);
|
|
136
|
+
}, []); // Missing count dependency
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
// GOOD: Include count in dependencies
|
|
140
|
+
useEffect(() => {
|
|
141
|
+
const interval = setInterval(() => {
|
|
142
|
+
setCount(count + 1);
|
|
143
|
+
}, 1000);
|
|
144
|
+
|
|
145
|
+
return () => clearInterval(interval);
|
|
146
|
+
}, [count]);
|
|
147
|
+
|
|
148
|
+
// OR use functional setState
|
|
149
|
+
useEffect(() => {
|
|
150
|
+
const interval = setInterval(() => {
|
|
151
|
+
setCount(c => c + 1); // Always has current value
|
|
152
|
+
}, 1000);
|
|
153
|
+
|
|
154
|
+
return () => clearInterval(interval);
|
|
155
|
+
}, []);
|
|
156
|
+
|
|
157
|
+
// 2. Infinite loops from missing dependencies
|
|
158
|
+
// Every render calls effect, effect triggers re-render
|
|
159
|
+
useEffect(() => {
|
|
160
|
+
setData(someValue); // If someValue is from props/state, add to dependency array
|
|
161
|
+
}, []); // Bug: someValue changes but effect doesn't re-run
|
|
162
|
+
|
|
163
|
+
// 3. Memory leaks from uncleared timers/listeners
|
|
164
|
+
// BAD: Listener added but never removed
|
|
165
|
+
useEffect(() => {
|
|
166
|
+
window.addEventListener('resize', handleResize);
|
|
167
|
+
// No cleanup - listener accumulates
|
|
168
|
+
}, []);
|
|
169
|
+
|
|
170
|
+
// GOOD: Always cleanup
|
|
171
|
+
useEffect(() => {
|
|
172
|
+
window.addEventListener('resize', handleResize);
|
|
173
|
+
return () => {
|
|
174
|
+
window.removeEventListener('resize', handleResize);
|
|
175
|
+
};
|
|
176
|
+
}, []);
|
|
177
|
+
|
|
178
|
+
// Use React DevTools Profiler:
|
|
179
|
+
// 1. Open DevTools → Profiler tab
|
|
180
|
+
// 2. Record interactions
|
|
181
|
+
// 3. See which components rendered
|
|
182
|
+
// 4. Identify unnecessary re-renders
|
|
183
|
+
```
|
|
184
|
+
|
|
185
|
+
## Network Debugging
|
|
186
|
+
|
|
187
|
+
Many bugs are actually network issues.
|
|
188
|
+
|
|
189
|
+
```javascript
|
|
190
|
+
// Network tab shows:
|
|
191
|
+
// - Failed requests (red = 4xx/5xx, gray = blocked)
|
|
192
|
+
// - Slow requests (larger bars = slower)
|
|
193
|
+
// - Response sizes (watch for large payloads)
|
|
194
|
+
// - Caching (check Cache-Control headers)
|
|
195
|
+
|
|
196
|
+
// Common network bugs:
|
|
197
|
+
|
|
198
|
+
// 1. CORS errors
|
|
199
|
+
// Error: Access to XMLHttpRequest blocked by CORS policy
|
|
200
|
+
// Fix: Server must allow Origin in Access-Control-Allow-Origin
|
|
201
|
+
|
|
202
|
+
// 2. Timeout issues
|
|
203
|
+
// Request takes > 30s and browser cancels
|
|
204
|
+
// Fix: Implement timeout handling, show loading state
|
|
205
|
+
|
|
206
|
+
// 3. Authentication missing
|
|
207
|
+
// 401 responses mean missing/expired token
|
|
208
|
+
// Fix: Check authorization header, refresh token logic
|
|
209
|
+
|
|
210
|
+
// 4. Wrong endpoint
|
|
211
|
+
// 404 means URL doesn't exist
|
|
212
|
+
// Fix: Check API documentation, verify URL construction
|
|
213
|
+
|
|
214
|
+
function debugNetworkRequest(url) {
|
|
215
|
+
const start = performance.now();
|
|
216
|
+
|
|
217
|
+
fetch(url)
|
|
218
|
+
.then(r => {
|
|
219
|
+
const duration = performance.now() - start;
|
|
220
|
+
console.log(`${url} - ${r.status} - ${duration}ms`);
|
|
221
|
+
return r.json();
|
|
222
|
+
})
|
|
223
|
+
.catch(err => {
|
|
224
|
+
const duration = performance.now() - start;
|
|
225
|
+
console.error(`${url} - Failed after ${duration}ms:`, err.message);
|
|
226
|
+
});
|
|
227
|
+
}
|
|
228
|
+
```
|
|
229
|
+
|
|
230
|
+
## Rubber Duck Debugging
|
|
231
|
+
|
|
232
|
+
Explaining your code to someone (or something) often reveals the bug.
|
|
233
|
+
|
|
234
|
+
```javascript
|
|
235
|
+
// Talk through your code step by step:
|
|
236
|
+
// "This function takes userId"
|
|
237
|
+
// "Fetches user from API"
|
|
238
|
+
// "Sets user state"
|
|
239
|
+
// "...wait, what if userId is undefined? We don't check that"
|
|
240
|
+
// "Oh! When userId is null, fetch URL becomes /api/users/null"
|
|
241
|
+
// "That's why we get 404"
|
|
242
|
+
|
|
243
|
+
// You found the bug by explaining it
|
|
244
|
+
|
|
245
|
+
// Benefits of rubber duck debugging:
|
|
246
|
+
// - Forces you to think through logic carefully
|
|
247
|
+
// - Slows you down (good for thinking)
|
|
248
|
+
// - Works even with non-technical duck
|
|
249
|
+
// - Free and always available
|
|
250
|
+
```
|
|
251
|
+
|
|
252
|
+
## Version Control Debugging
|
|
253
|
+
|
|
254
|
+
Use git to find when bugs were introduced.
|
|
255
|
+
|
|
256
|
+
```javascript
|
|
257
|
+
// git bisect: binary search for the commit that broke things
|
|
258
|
+
git bisect start
|
|
259
|
+
git bisect bad # Current version is broken
|
|
260
|
+
git bisect good v1.0.0 # Last known good version
|
|
261
|
+
|
|
262
|
+
// Git tests commits between good and bad
|
|
263
|
+
// You test each one: works or broken
|
|
264
|
+
// Eventually finds exact commit that introduced bug
|
|
265
|
+
|
|
266
|
+
git bisect log # See history of bisect
|
|
267
|
+
git bisect reset # Return to original branch
|
|
268
|
+
|
|
269
|
+
// Once you find the bad commit:
|
|
270
|
+
git show <commit> # See what changed
|
|
271
|
+
git log -p <commit>~1..<commit> # See the diff
|
|
272
|
+
git blame path/to/file # See who changed each line
|
|
273
|
+
|
|
274
|
+
// Example workflow:
|
|
275
|
+
// "Bug appeared in version 2.3.0"
|
|
276
|
+
// "Last known good: 2.2.0"
|
|
277
|
+
git bisect start
|
|
278
|
+
git bisect bad v2.3.0
|
|
279
|
+
git bisect good v2.2.0
|
|
280
|
+
# Git checks out commit halfway between
|
|
281
|
+
# Test: does bug exist?
|
|
282
|
+
# Tell git: git bisect bad (or git bisect good)
|
|
283
|
+
# Repeat until found exact commit
|
|
284
|
+
```
|
|
285
|
+
|
|
286
|
+
## Debugging Checklist
|
|
287
|
+
|
|
288
|
+
```
|
|
289
|
+
Before starting:
|
|
290
|
+
- [ ] Reproduced the bug consistently
|
|
291
|
+
- [ ] Read the error message carefully (exact text)
|
|
292
|
+
- [ ] Checked browser console (DevTools)
|
|
293
|
+
- [ ] Checked network tab (failed requests?)
|
|
294
|
+
- [ ] Cleared cache/hard refresh
|
|
295
|
+
|
|
296
|
+
During debugging:
|
|
297
|
+
- [ ] Used console logging to track values
|
|
298
|
+
- [ ] Used debugger breakpoints
|
|
299
|
+
- [ ] Isolated the problem area
|
|
300
|
+
- [ ] Checked assumptions
|
|
301
|
+
- [ ] Verified dependencies (useEffect, imports)
|
|
302
|
+
|
|
303
|
+
React-specific:
|
|
304
|
+
- [ ] Checked React DevTools component tree
|
|
305
|
+
- [ ] Verified state and props values
|
|
306
|
+
- [ ] Checked for missing useEffect dependencies
|
|
307
|
+
- [ ] Verified cleanup functions run
|
|
308
|
+
- [ ] Checked for stale closures
|
|
309
|
+
|
|
310
|
+
Network:
|
|
311
|
+
- [ ] Verified request goes to correct URL
|
|
312
|
+
- [ ] Verified response status (200, 404, 500?)
|
|
313
|
+
- [ ] Checked response headers
|
|
314
|
+
- [ ] Verified authentication header sent
|
|
315
|
+
- [ ] Checked for CORS errors
|
|
316
|
+
|
|
317
|
+
After finding bug:
|
|
318
|
+
- [ ] Understand root cause
|
|
319
|
+
- [ ] Write test to prevent regression
|
|
320
|
+
- [ ] Check for similar bugs elsewhere
|
|
321
|
+
- [ ] Update documentation if needed
|
|
322
|
+
```
|
|
323
|
+
|
|
324
|
+
## Related Guidance
|
|
325
|
+
|
|
326
|
+
- `/testing` — writing tests to prevent bugs
|
|
327
|
+
- `/code-quality` — clean code is easier to debug
|
|
328
|
+
- `/logging-observability` — comprehensive logging helps debugging
|
|
329
|
+
- `/tools-setup` — debugging tools configuration
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
# Frontend Examples
|
|
2
|
+
|
|
3
|
+
This folder is reserved for larger frontend examples that complement the topic
|
|
4
|
+
guides under `components/`, `state-management/`, `testing/`, and related folders.
|
|
5
|
+
|
|
6
|
+
## Use Cases
|
|
7
|
+
|
|
8
|
+
- Complete form implementation examples.
|
|
9
|
+
- Component decomposition before-and-after examples.
|
|
10
|
+
- Accessibility remediation walkthroughs.
|
|
11
|
+
- Performance profiling and optimization narratives.
|
|
12
|
+
|
|
13
|
+
## Related Files
|
|
14
|
+
|
|
15
|
+
- `../components/`
|
|
16
|
+
- `../state-management/`
|
|
17
|
+
- `../testing/`
|
|
18
|
+
- `../accessibility/`
|
|
19
|
+
- `../performance/`
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
# Frontend Example Checklist
|
|
2
|
+
|
|
3
|
+
- [ ] State the user workflow or UI behavior.
|
|
4
|
+
- [ ] Include component structure and state ownership.
|
|
5
|
+
- [ ] Cover loading, empty, error, and success states.
|
|
6
|
+
- [ ] Include accessibility expectations.
|
|
7
|
+
- [ ] Include tests that verify user-observable behavior.
|
|
8
|
+
- [ ] Include performance or observability notes when relevant.
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
# Frontend Example Template
|
|
2
|
+
|
|
3
|
+
```markdown
|
|
4
|
+
# Frontend Scenario
|
|
5
|
+
|
|
6
|
+
## User Flow
|
|
7
|
+
|
|
8
|
+
Describe the interaction from the user's perspective.
|
|
9
|
+
|
|
10
|
+
## Component Shape
|
|
11
|
+
|
|
12
|
+
List the main components and state ownership.
|
|
13
|
+
|
|
14
|
+
## Verification
|
|
15
|
+
|
|
16
|
+
List unit, integration, accessibility, and browser checks.
|
|
17
|
+
```
|
|
@@ -0,0 +1,196 @@
|
|
|
1
|
+
# Logging & Observability
|
|
2
|
+
|
|
3
|
+
Senior frontend developers instrument code with proper logging and monitoring. What you can't measure, you can't improve.
|
|
4
|
+
|
|
5
|
+
## Logging Principles
|
|
6
|
+
|
|
7
|
+
- **Structured Logging** — machine-readable format (JSON)
|
|
8
|
+
- **Log Levels** — debug, info, warn, error
|
|
9
|
+
- **Context** — include relevant data with logs
|
|
10
|
+
- **No Secrets** — never log API keys, tokens, passwords
|
|
11
|
+
- **Cleanup** — remove debug logs before production
|
|
12
|
+
|
|
13
|
+
## Log Levels
|
|
14
|
+
|
|
15
|
+
### DEBUG
|
|
16
|
+
- Development only
|
|
17
|
+
- Detailed diagnostic information
|
|
18
|
+
- Variable values, function calls
|
|
19
|
+
- Remove before committing
|
|
20
|
+
|
|
21
|
+
### INFO
|
|
22
|
+
- General informational messages
|
|
23
|
+
- User actions (login, form submit)
|
|
24
|
+
- State changes
|
|
25
|
+
- API calls
|
|
26
|
+
|
|
27
|
+
### WARN
|
|
28
|
+
- Unexpected but recoverable
|
|
29
|
+
- Deprecated API usage
|
|
30
|
+
- Performance concerns
|
|
31
|
+
- Fallbacks being used
|
|
32
|
+
|
|
33
|
+
### ERROR
|
|
34
|
+
- Errors that impact functionality
|
|
35
|
+
- Exceptions/crashes
|
|
36
|
+
- Failed API calls
|
|
37
|
+
- Missing resources
|
|
38
|
+
|
|
39
|
+
## Structured Logging Example
|
|
40
|
+
|
|
41
|
+
```javascript
|
|
42
|
+
// Bad: unstructured
|
|
43
|
+
console.log('User logged in')
|
|
44
|
+
|
|
45
|
+
// Good: structured with context
|
|
46
|
+
console.log({
|
|
47
|
+
level: 'INFO',
|
|
48
|
+
timestamp: new Date().toISOString(),
|
|
49
|
+
event: 'user_login',
|
|
50
|
+
userId: user.id,
|
|
51
|
+
email: user.email,
|
|
52
|
+
duration_ms: 234
|
|
53
|
+
})
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
## Common Things to Log
|
|
57
|
+
|
|
58
|
+
### User Actions
|
|
59
|
+
- Login/logout
|
|
60
|
+
- Form submissions
|
|
61
|
+
- Navigation changes
|
|
62
|
+
- Button clicks (important ones)
|
|
63
|
+
- Modal open/close
|
|
64
|
+
|
|
65
|
+
### Data Flow
|
|
66
|
+
- API requests (URL, method, status)
|
|
67
|
+
- API responses (status, response time)
|
|
68
|
+
- Data fetches and updates
|
|
69
|
+
- State changes
|
|
70
|
+
- Cache hits/misses
|
|
71
|
+
|
|
72
|
+
### Errors
|
|
73
|
+
- Uncaught exceptions
|
|
74
|
+
- API failures
|
|
75
|
+
- Network errors
|
|
76
|
+
- Validation failures
|
|
77
|
+
- Timeouts
|
|
78
|
+
|
|
79
|
+
### Performance
|
|
80
|
+
- Page load time
|
|
81
|
+
- API response times
|
|
82
|
+
- Slow renders
|
|
83
|
+
- Memory usage
|
|
84
|
+
- Bundle size
|
|
85
|
+
|
|
86
|
+
## What NOT to Log
|
|
87
|
+
|
|
88
|
+
- Passwords, tokens, API keys
|
|
89
|
+
- Personal information (SSN, credit cards)
|
|
90
|
+
- Large objects (log relevant fields only)
|
|
91
|
+
- Frequent noisy events (every keystroke)
|
|
92
|
+
- Stack traces for expected errors
|
|
93
|
+
|
|
94
|
+
## Logging Best Practices
|
|
95
|
+
|
|
96
|
+
### Use Logging Library
|
|
97
|
+
- winston
|
|
98
|
+
- bunyan
|
|
99
|
+
- pino
|
|
100
|
+
- loglevel
|
|
101
|
+
|
|
102
|
+
```javascript
|
|
103
|
+
import { createLogger } from 'winston'
|
|
104
|
+
|
|
105
|
+
const logger = createLogger({
|
|
106
|
+
format: 'json',
|
|
107
|
+
level: process.env.LOG_LEVEL || 'info'
|
|
108
|
+
})
|
|
109
|
+
|
|
110
|
+
logger.info('User action', { userId, action: 'login' })
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
### Log Early, Log Often
|
|
114
|
+
- Log at function entry (especially for errors)
|
|
115
|
+
- Log at decision points
|
|
116
|
+
- Log state transitions
|
|
117
|
+
- Log async operations start/end
|
|
118
|
+
|
|
119
|
+
### Use Request IDs
|
|
120
|
+
- Trace across multiple functions
|
|
121
|
+
- Correlate frontend + backend logs
|
|
122
|
+
- Helps in debugging distributed issues
|
|
123
|
+
|
|
124
|
+
```javascript
|
|
125
|
+
const requestId = generateId()
|
|
126
|
+
logger.info('Request started', { requestId, endpoint: '/api/users' })
|
|
127
|
+
// ... do stuff ...
|
|
128
|
+
logger.info('Request completed', { requestId, status: 200 })
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
## Monitoring & Observability
|
|
132
|
+
|
|
133
|
+
### Metrics to Track
|
|
134
|
+
- **Errors** — error rates, crash rates
|
|
135
|
+
- **Performance** — page load, API latency
|
|
136
|
+
- **Usage** — active users, feature usage
|
|
137
|
+
- **Business** — conversions, revenue
|
|
138
|
+
|
|
139
|
+
### Tools
|
|
140
|
+
- Google Analytics (usage)
|
|
141
|
+
- Sentry (error tracking)
|
|
142
|
+
- DataDog (APM/monitoring)
|
|
143
|
+
- Rollbar (error monitoring)
|
|
144
|
+
- Custom dashboards
|
|
145
|
+
|
|
146
|
+
### Error Reporting
|
|
147
|
+
- Catch unhandled errors
|
|
148
|
+
- Send to error service
|
|
149
|
+
- Include context (user, page, timestamp)
|
|
150
|
+
- Don't send sensitive data
|
|
151
|
+
|
|
152
|
+
```javascript
|
|
153
|
+
window.addEventListener('error', (event) => {
|
|
154
|
+
logError({
|
|
155
|
+
message: event.message,
|
|
156
|
+
stack: event.error.stack,
|
|
157
|
+
url: window.location.href,
|
|
158
|
+
timestamp: new Date()
|
|
159
|
+
})
|
|
160
|
+
})
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
### Real User Monitoring
|
|
164
|
+
- Track real user experience
|
|
165
|
+
- Monitor Core Web Vitals
|
|
166
|
+
- Correlate with errors
|
|
167
|
+
- Identify performance issues
|
|
168
|
+
|
|
169
|
+
## Logging Anti-Patterns
|
|
170
|
+
|
|
171
|
+
- Logging everything (noise)
|
|
172
|
+
- Not logging failures
|
|
173
|
+
- Logging without context
|
|
174
|
+
- Logging sensitive data
|
|
175
|
+
- Using console.log in production code
|
|
176
|
+
- Inconsistent format
|
|
177
|
+
- Logs too verbose or too sparse
|
|
178
|
+
- Not rotating/cleaning logs
|
|
179
|
+
|
|
180
|
+
## Logging Checklist
|
|
181
|
+
|
|
182
|
+
Before pushing:
|
|
183
|
+
- [ ] Debug logs removed
|
|
184
|
+
- [ ] Info/warn/error logs meaningful
|
|
185
|
+
- [ ] No sensitive data logged
|
|
186
|
+
- [ ] Context included with logs
|
|
187
|
+
- [ ] Errors properly caught and logged
|
|
188
|
+
- [ ] Performance metrics logged
|
|
189
|
+
- [ ] Log statements have appropriate levels
|
|
190
|
+
- [ ] Monitoring tools configured
|
|
191
|
+
|
|
192
|
+
## Related Guidance
|
|
193
|
+
|
|
194
|
+
- `/debugging` — using logs to debug
|
|
195
|
+
- `/testing` — testing logging behavior
|
|
196
|
+
- `/code-quality` — consistent log formatting
|