@trieungoctam/vibekit 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/LICENSE +21 -0
- package/README.md +85 -0
- package/agents/debugger.md +158 -0
- package/agents/docs-manager.md +220 -0
- package/agents/planner.md +129 -0
- package/agents/researcher.md +58 -0
- package/agents/reviewer.md +152 -0
- package/agents/tester.md +126 -0
- package/bin/vibekit.js +18 -0
- package/hooks/lib/ck-config-utils.cjs +831 -0
- package/hooks/lib/colors.cjs +95 -0
- package/hooks/lib/config-counter.cjs +103 -0
- package/hooks/lib/context-builder.cjs +616 -0
- package/hooks/lib/git-info-cache.cjs +143 -0
- package/hooks/lib/hook-logger.cjs +92 -0
- package/hooks/lib/privacy-checker.cjs +297 -0
- package/hooks/lib/project-detector.cjs +474 -0
- package/hooks/lib/scout-checker.cjs +263 -0
- package/hooks/lib/transcript-parser.cjs +181 -0
- package/hooks/post-edit-simplify-reminder.cjs +156 -0
- package/hooks/privacy-block.cjs +166 -0
- package/hooks/scout-block.cjs +147 -0
- package/hooks/session-init.cjs +360 -0
- package/package.json +41 -0
- package/rules/development-rules.md +52 -0
- package/rules/documentation-management.md +121 -0
- package/rules/orchestration-protocol.md +43 -0
- package/rules/primary-workflow.md +57 -0
- package/rules/team-coordination-rules.md +90 -0
- package/skills/ai/agent-browser/SKILL.md +294 -0
- package/skills/ai/agent-browser/references/.gitkeep +0 -0
- package/skills/ai/agent-browser/references/agent-browser-vs-chrome-devtools.md +112 -0
- package/skills/ai/agent-browser/references/browserbase-cloud-setup.md +161 -0
- package/skills/ai/ai-artist/SKILL.md +122 -0
- package/skills/ai/ai-artist/data/awesome-prompts.csv +3592 -0
- package/skills/ai/ai-artist/data/lighting.csv +19 -0
- package/skills/ai/ai-artist/data/nano-banana-templates.csv +17 -0
- package/skills/ai/ai-artist/data/platforms.csv +11 -0
- package/skills/ai/ai-artist/data/styles.csv +26 -0
- package/skills/ai/ai-artist/data/techniques.csv +19 -0
- package/skills/ai/ai-artist/data/use-cases.csv +16 -0
- package/skills/ai/ai-artist/references/advanced-techniques.md +184 -0
- package/skills/ai/ai-artist/references/awesome-nano-banana-pro-prompts.md +8575 -0
- package/skills/ai/ai-artist/references/domain-code.md +66 -0
- package/skills/ai/ai-artist/references/domain-data.md +72 -0
- package/skills/ai/ai-artist/references/domain-marketing.md +66 -0
- package/skills/ai/ai-artist/references/domain-patterns.md +33 -0
- package/skills/ai/ai-artist/references/domain-writing.md +68 -0
- package/skills/ai/ai-artist/references/image-prompting.md +141 -0
- package/skills/ai/ai-artist/references/llm-prompting.md +165 -0
- package/skills/ai/ai-artist/references/nano-banana.md +136 -0
- package/skills/ai/ai-artist/references/reasoning-techniques.md +201 -0
- package/skills/ai/ai-artist/references/validation-workflow.md +117 -0
- package/skills/ai/ai-artist/scripts/core.py +197 -0
- package/skills/ai/ai-artist/scripts/extract_prompts.py +102 -0
- package/skills/ai/ai-artist/scripts/generate.py +370 -0
- package/skills/ai/ai-artist/scripts/search.py +147 -0
- package/skills/ai/ai-multimodal/.env.example +204 -0
- package/skills/ai/ai-multimodal/SKILL.md +110 -0
- package/skills/ai/ai-multimodal/references/audio-processing.md +387 -0
- package/skills/ai/ai-multimodal/references/image-generation.md +939 -0
- package/skills/ai/ai-multimodal/references/music-generation.md +311 -0
- package/skills/ai/ai-multimodal/references/video-analysis.md +515 -0
- package/skills/ai/ai-multimodal/references/video-generation.md +457 -0
- package/skills/ai/ai-multimodal/references/vision-understanding.md +492 -0
- package/skills/ai/ai-multimodal/scripts/.coverage +0 -0
- package/skills/ai/ai-multimodal/scripts/check_setup.py +315 -0
- package/skills/ai/ai-multimodal/scripts/document_converter.py +395 -0
- package/skills/ai/ai-multimodal/scripts/gemini_batch_process.py +1185 -0
- package/skills/ai/ai-multimodal/scripts/media_optimizer.py +506 -0
- package/skills/ai/ai-multimodal/scripts/requirements.txt +26 -0
- package/skills/ai/ai-multimodal/scripts/tests/.coverage +0 -0
- package/skills/ai/ai-multimodal/scripts/tests/requirements.txt +20 -0
- package/skills/ai/ai-multimodal/scripts/tests/test_document_converter.py +74 -0
- package/skills/ai/ai-multimodal/scripts/tests/test_gemini_batch_process.py +362 -0
- package/skills/ai/ai-multimodal/scripts/tests/test_media_optimizer.py +373 -0
- package/skills/ai/mcp-management/README.md +219 -0
- package/skills/ai/mcp-management/SKILL.md +210 -0
- package/skills/ai/mcp-management/assets/tools.json +3146 -0
- package/skills/ai/mcp-management/references/configuration.md +114 -0
- package/skills/ai/mcp-management/references/gemini-cli-integration.md +221 -0
- package/skills/ai/mcp-management/references/mcp-protocol.md +116 -0
- package/skills/ai/mcp-management/scripts/.env.example +10 -0
- package/skills/ai/mcp-management/scripts/cli.ts +195 -0
- package/skills/ai/mcp-management/scripts/dist/analyze-tools.js +70 -0
- package/skills/ai/mcp-management/scripts/dist/cli.js +160 -0
- package/skills/ai/mcp-management/scripts/dist/mcp-client.js +183 -0
- package/skills/ai/mcp-management/scripts/mcp-client.ts +230 -0
- package/skills/ai/mcp-management/scripts/package.json +20 -0
- package/skills/ai/mcp-management/scripts/tsconfig.json +15 -0
- package/skills/core/brainstorm/SKILL.md +164 -0
- package/skills/core/brainstorm/scripts/frame-template.html +214 -0
- package/skills/core/brainstorm/scripts/helper.js +88 -0
- package/skills/core/brainstorm/scripts/server.cjs +338 -0
- package/skills/core/brainstorm/scripts/start-server.sh +153 -0
- package/skills/core/brainstorm/scripts/stop-server.sh +55 -0
- package/skills/core/brainstorm/spec-document-reviewer-prompt.md +49 -0
- package/skills/core/brainstorm/visual-companion.md +286 -0
- package/skills/core/code-review/SKILL.md +147 -0
- package/skills/core/code-review/references/code-review-reception.md +113 -0
- package/skills/core/code-review/references/codebase-scan-workflow.md +29 -0
- package/skills/core/code-review/references/edge-case-scouting.md +119 -0
- package/skills/core/code-review/references/parallel-review-workflow.md +69 -0
- package/skills/core/code-review/references/requesting-code-review.md +116 -0
- package/skills/core/code-review/references/task-management-reviews.md +140 -0
- package/skills/core/code-review/references/verification-before-completion.md +139 -0
- package/skills/core/cook/README.md +86 -0
- package/skills/core/cook/SKILL.md +113 -0
- package/skills/core/cook/references/intent-detection.md +101 -0
- package/skills/core/cook/references/review-cycle.md +75 -0
- package/skills/core/cook/references/subagent-patterns.md +75 -0
- package/skills/core/cook/references/workflow-steps.md +172 -0
- package/skills/core/debug/SKILL.md +121 -0
- package/skills/core/debug/references/defense-in-depth.md +124 -0
- package/skills/core/debug/references/frontend-verification.md +103 -0
- package/skills/core/debug/references/investigation-methodology.md +101 -0
- package/skills/core/debug/references/log-and-ci-analysis.md +97 -0
- package/skills/core/debug/references/performance-diagnostics.md +113 -0
- package/skills/core/debug/references/reporting-standards.md +122 -0
- package/skills/core/debug/references/root-cause-tracing.md +122 -0
- package/skills/core/debug/references/systematic-debugging.md +102 -0
- package/skills/core/debug/references/task-management-debugging.md +155 -0
- package/skills/core/debug/references/verification.md +123 -0
- package/skills/core/debug/scripts/find-polluter.sh +63 -0
- package/skills/core/debug/scripts/find-polluter.test.md +102 -0
- package/skills/core/execute/SKILL.md +70 -0
- package/skills/core/fix/SKILL.md +111 -0
- package/skills/core/fix/references/complexity-assessment.md +72 -0
- package/skills/core/fix/references/mode-selection.md +46 -0
- package/skills/core/fix/references/parallel-exploration.md +100 -0
- package/skills/core/fix/references/review-cycle.md +77 -0
- package/skills/core/fix/references/skill-activation-matrix.md +78 -0
- package/skills/core/fix/references/task-orchestration.md +103 -0
- package/skills/core/fix/references/workflow-ci.md +28 -0
- package/skills/core/fix/references/workflow-deep.md +122 -0
- package/skills/core/fix/references/workflow-logs.md +72 -0
- package/skills/core/fix/references/workflow-quick.md +59 -0
- package/skills/core/fix/references/workflow-standard.md +111 -0
- package/skills/core/fix/references/workflow-test.md +75 -0
- package/skills/core/fix/references/workflow-types.md +33 -0
- package/skills/core/fix/references/workflow-ui.md +75 -0
- package/skills/core/plan/SKILL.md +145 -0
- package/skills/core/plan/plan-document-reviewer-prompt.md +49 -0
- package/skills/core/subagent-dev/SKILL.md +277 -0
- package/skills/core/subagent-dev/code-quality-reviewer-prompt.md +26 -0
- package/skills/core/subagent-dev/implementer-prompt.md +113 -0
- package/skills/core/subagent-dev/spec-reviewer-prompt.md +61 -0
- package/skills/core/tdd/SKILL.md +371 -0
- package/skills/core/tdd/testing-anti-patterns.md +299 -0
- package/skills/core/test/SKILL.md +109 -0
- package/skills/core/test/references/report-format.md +58 -0
- package/skills/core/test/references/test-execution-workflow.md +103 -0
- package/skills/core/test/references/ui-testing-workflow.md +65 -0
- package/skills/core/verify/SKILL.md +139 -0
- package/skills/dev/backend-dev/SKILL.md +96 -0
- package/skills/dev/backend-dev/references/backend-api-design.md +495 -0
- package/skills/dev/backend-dev/references/backend-architecture.md +454 -0
- package/skills/dev/backend-dev/references/backend-authentication.md +338 -0
- package/skills/dev/backend-dev/references/backend-code-quality.md +659 -0
- package/skills/dev/backend-dev/references/backend-debugging.md +904 -0
- package/skills/dev/backend-dev/references/backend-devops.md +494 -0
- package/skills/dev/backend-dev/references/backend-mindset.md +387 -0
- package/skills/dev/backend-dev/references/backend-performance.md +397 -0
- package/skills/dev/backend-dev/references/backend-security.md +290 -0
- package/skills/dev/backend-dev/references/backend-technologies.md +256 -0
- package/skills/dev/backend-dev/references/backend-testing.md +429 -0
- package/skills/dev/context-engineering/SKILL.md +108 -0
- package/skills/dev/context-engineering/references/context-compression.md +84 -0
- package/skills/dev/context-engineering/references/context-degradation.md +93 -0
- package/skills/dev/context-engineering/references/context-fundamentals.md +75 -0
- package/skills/dev/context-engineering/references/context-optimization.md +82 -0
- package/skills/dev/context-engineering/references/evaluation.md +89 -0
- package/skills/dev/context-engineering/references/memory-systems.md +88 -0
- package/skills/dev/context-engineering/references/multi-agent-patterns.md +90 -0
- package/skills/dev/context-engineering/references/project-development.md +97 -0
- package/skills/dev/context-engineering/references/runtime-awareness.md +202 -0
- package/skills/dev/context-engineering/references/tool-design.md +86 -0
- package/skills/dev/context-engineering/scripts/compression_evaluator.py +349 -0
- package/skills/dev/context-engineering/scripts/context_analyzer.py +317 -0
- package/skills/dev/context-engineering/scripts/tests/test_edge_cases.py +246 -0
- package/skills/dev/databases/SKILL.md +84 -0
- package/skills/dev/databases/analytics.md +198 -0
- package/skills/dev/databases/db-design.md +188 -0
- package/skills/dev/databases/incremental-etl.md +213 -0
- package/skills/dev/databases/references/mongodb-aggregation.md +447 -0
- package/skills/dev/databases/references/mongodb-atlas.md +465 -0
- package/skills/dev/databases/references/mongodb-crud.md +408 -0
- package/skills/dev/databases/references/mongodb-indexing.md +442 -0
- package/skills/dev/databases/references/postgresql-administration.md +594 -0
- package/skills/dev/databases/references/postgresql-performance.md +527 -0
- package/skills/dev/databases/references/postgresql-psql-cli.md +467 -0
- package/skills/dev/databases/references/postgresql-queries.md +475 -0
- package/skills/dev/databases/scripts/.coverage +0 -0
- package/skills/dev/databases/scripts/db_backup.py +502 -0
- package/skills/dev/databases/scripts/db_migrate.py +426 -0
- package/skills/dev/databases/scripts/db_performance_check.py +457 -0
- package/skills/dev/databases/scripts/requirements.txt +20 -0
- package/skills/dev/databases/scripts/tests/coverage-db.json +1 -0
- package/skills/dev/databases/scripts/tests/requirements.txt +4 -0
- package/skills/dev/databases/scripts/tests/test_db_backup.py +340 -0
- package/skills/dev/databases/scripts/tests/test_db_migrate.py +277 -0
- package/skills/dev/databases/scripts/tests/test_db_performance_check.py +370 -0
- package/skills/dev/databases/stacks/bigquery.md +231 -0
- package/skills/dev/databases/stacks/d1_cloudflare.md +137 -0
- package/skills/dev/databases/stacks/mysql.md +216 -0
- package/skills/dev/databases/stacks/postgres.md +235 -0
- package/skills/dev/databases/stacks/sqlite.md +244 -0
- package/skills/dev/databases/transactional.md +176 -0
- package/skills/dev/devops/.env.example +76 -0
- package/skills/dev/devops/SKILL.md +97 -0
- package/skills/dev/devops/references/browser-rendering.md +305 -0
- package/skills/dev/devops/references/cloudflare-d1-kv.md +123 -0
- package/skills/dev/devops/references/cloudflare-platform.md +271 -0
- package/skills/dev/devops/references/cloudflare-r2-storage.md +280 -0
- package/skills/dev/devops/references/cloudflare-workers-advanced.md +312 -0
- package/skills/dev/devops/references/cloudflare-workers-apis.md +309 -0
- package/skills/dev/devops/references/cloudflare-workers-basics.md +418 -0
- package/skills/dev/devops/references/docker-basics.md +297 -0
- package/skills/dev/devops/references/docker-compose.md +292 -0
- package/skills/dev/devops/references/gcloud-platform.md +297 -0
- package/skills/dev/devops/references/gcloud-services.md +304 -0
- package/skills/dev/devops/references/kubernetes-basics.md +99 -0
- package/skills/dev/devops/references/kubernetes-helm-advanced.md +75 -0
- package/skills/dev/devops/references/kubernetes-helm.md +81 -0
- package/skills/dev/devops/references/kubernetes-kubectl.md +74 -0
- package/skills/dev/devops/references/kubernetes-security-advanced.md +98 -0
- package/skills/dev/devops/references/kubernetes-security.md +95 -0
- package/skills/dev/devops/references/kubernetes-troubleshooting-advanced.md +74 -0
- package/skills/dev/devops/references/kubernetes-troubleshooting.md +49 -0
- package/skills/dev/devops/references/kubernetes-workflows-advanced.md +75 -0
- package/skills/dev/devops/references/kubernetes-workflows.md +78 -0
- package/skills/dev/devops/scripts/cloudflare_deploy.py +269 -0
- package/skills/dev/devops/scripts/docker_optimize.py +332 -0
- package/skills/dev/devops/scripts/requirements.txt +20 -0
- package/skills/dev/devops/scripts/tests/requirements.txt +3 -0
- package/skills/dev/devops/scripts/tests/test_cloudflare_deploy.py +285 -0
- package/skills/dev/devops/scripts/tests/test_docker_optimize.py +436 -0
- package/skills/dev/frontend-design/SKILL.md +78 -0
- package/skills/dev/frontend-design/references/ai-multimodal-overview.md +165 -0
- package/skills/dev/frontend-design/references/analysis-best-practices.md +80 -0
- package/skills/dev/frontend-design/references/analysis-prompts.md +141 -0
- package/skills/dev/frontend-design/references/analysis-techniques.md +118 -0
- package/skills/dev/frontend-design/references/animejs.md +396 -0
- package/skills/dev/frontend-design/references/asset-generation.md +337 -0
- package/skills/dev/frontend-design/references/design-extraction-overview.md +71 -0
- package/skills/dev/frontend-design/references/extraction-best-practices.md +141 -0
- package/skills/dev/frontend-design/references/extraction-output-templates.md +162 -0
- package/skills/dev/frontend-design/references/extraction-prompts.md +127 -0
- package/skills/dev/frontend-design/references/technical-accessibility.md +119 -0
- package/skills/dev/frontend-design/references/technical-best-practices.md +97 -0
- package/skills/dev/frontend-design/references/technical-optimization.md +44 -0
- package/skills/dev/frontend-design/references/technical-overview.md +90 -0
- package/skills/dev/frontend-design/references/technical-workflows.md +150 -0
- package/skills/dev/frontend-design/references/visual-analysis-overview.md +95 -0
- package/skills/dev/frontend-design/references/workflow-3d.md +102 -0
- package/skills/dev/frontend-design/references/workflow-describe.md +87 -0
- package/skills/dev/frontend-design/references/workflow-immersive.md +87 -0
- package/skills/dev/frontend-design/references/workflow-quick.md +57 -0
- package/skills/dev/frontend-design/references/workflow-screenshot.md +63 -0
- package/skills/dev/frontend-design/references/workflow-video.md +74 -0
- package/skills/dev/frontend-dev/SKILL.md +400 -0
- package/skills/dev/frontend-dev/resources/common-patterns.md +331 -0
- package/skills/dev/frontend-dev/resources/complete-examples.md +872 -0
- package/skills/dev/frontend-dev/resources/component-patterns.md +502 -0
- package/skills/dev/frontend-dev/resources/data-fetching.md +767 -0
- package/skills/dev/frontend-dev/resources/file-organization.md +502 -0
- package/skills/dev/frontend-dev/resources/loading-and-error-states.md +501 -0
- package/skills/dev/frontend-dev/resources/performance.md +406 -0
- package/skills/dev/frontend-dev/resources/routing-guide.md +364 -0
- package/skills/dev/frontend-dev/resources/styling-guide.md +428 -0
- package/skills/dev/frontend-dev/resources/typescript-standards.md +418 -0
- package/skills/dev/git/SKILL.md +114 -0
- package/skills/dev/git/references/branch-management.md +88 -0
- package/skills/dev/git/references/commit-standards.md +46 -0
- package/skills/dev/git/references/gh-cli-guide.md +109 -0
- package/skills/dev/git/references/safety-protocols.md +69 -0
- package/skills/dev/git/references/workflow-commit.md +58 -0
- package/skills/dev/git/references/workflow-merge.md +48 -0
- package/skills/dev/git/references/workflow-pr.md +58 -0
- package/skills/dev/git/references/workflow-push.md +52 -0
- package/skills/dev/git-worktree/SKILL.md +218 -0
- package/skills/utils/ask/SKILL.md +58 -0
- package/skills/utils/bootstrap/SKILL.md +101 -0
- package/skills/utils/bootstrap/references/shared-phases.md +59 -0
- package/skills/utils/bootstrap/references/workflow-auto.md +52 -0
- package/skills/utils/bootstrap/references/workflow-fast.md +50 -0
- package/skills/utils/bootstrap/references/workflow-full.md +60 -0
- package/skills/utils/bootstrap/references/workflow-parallel.md +59 -0
- package/skills/utils/ck-help/SKILL.md +102 -0
- package/skills/utils/ck-help/scripts/ck-help.py +1321 -0
- package/skills/utils/ck-help/scripts/commands_data.yaml +3 -0
- package/skills/utils/ck-help/scripts/skills_data.yaml +593 -0
- package/skills/utils/copywriting/SKILL.md +94 -0
- package/skills/utils/copywriting/references/copy-formulas.md +150 -0
- package/skills/utils/copywriting/references/cta-patterns.md +168 -0
- package/skills/utils/copywriting/references/email-copy.md +193 -0
- package/skills/utils/copywriting/references/headline-templates.md +140 -0
- package/skills/utils/copywriting/references/landing-page-copy.md +175 -0
- package/skills/utils/copywriting/references/power-words.md +189 -0
- package/skills/utils/copywriting/references/social-media-copy.md +222 -0
- package/skills/utils/copywriting/references/workflow-cro.md +83 -0
- package/skills/utils/copywriting/references/workflow-enhance.md +32 -0
- package/skills/utils/copywriting/references/workflow-fast.md +29 -0
- package/skills/utils/copywriting/references/workflow-good.md +39 -0
- package/skills/utils/copywriting/references/writing-styles.md +247 -0
- package/skills/utils/copywriting/scripts/extract-writing-styles.py +308 -0
- package/skills/utils/copywriting/templates/copy-brief.md +49 -0
- package/skills/utils/docs/SKILL.md +55 -0
- package/skills/utils/docs/references/init-workflow.md +32 -0
- package/skills/utils/docs/references/summarize-workflow.md +18 -0
- package/skills/utils/docs/references/update-workflow.md +59 -0
- package/skills/utils/journal/SKILL.md +11 -0
- package/skills/utils/kanban/SKILL.md +99 -0
- package/skills/utils/preview/SKILL.md +75 -0
- package/skills/utils/preview/references/generation-modes.md +95 -0
- package/skills/utils/preview/references/view-mode.md +42 -0
- package/skills/utils/repomix/SKILL.md +248 -0
- package/skills/utils/repomix/references/configuration.md +211 -0
- package/skills/utils/repomix/references/usage-patterns.md +232 -0
- package/skills/utils/repomix/scripts/.coverage +0 -0
- package/skills/utils/repomix/scripts/README.md +179 -0
- package/skills/utils/repomix/scripts/repomix_batch.py +455 -0
- package/skills/utils/repomix/scripts/repos.example.json +15 -0
- package/skills/utils/repomix/scripts/requirements.txt +15 -0
- package/skills/utils/repomix/scripts/tests/test_repomix_batch.py +531 -0
- package/skills/utils/research/SKILL.md +171 -0
- package/skills/utils/scout/SKILL.md +89 -0
- package/skills/utils/scout/references/external-scouting.md +140 -0
- package/skills/utils/scout/references/internal-scouting.md +119 -0
- package/skills/utils/scout/references/task-management-scouting.md +125 -0
- package/skills/utils/sequential-thinking/.env.example +8 -0
- package/skills/utils/sequential-thinking/README.md +183 -0
- package/skills/utils/sequential-thinking/SKILL.md +95 -0
- package/skills/utils/sequential-thinking/package.json +31 -0
- package/skills/utils/sequential-thinking/references/advanced-strategies.md +79 -0
- package/skills/utils/sequential-thinking/references/advanced-techniques.md +76 -0
- package/skills/utils/sequential-thinking/references/core-patterns.md +95 -0
- package/skills/utils/sequential-thinking/references/examples-api.md +88 -0
- package/skills/utils/sequential-thinking/references/examples-architecture.md +94 -0
- package/skills/utils/sequential-thinking/references/examples-debug.md +90 -0
- package/skills/utils/sequential-thinking/scripts/format-thought.js +159 -0
- package/skills/utils/sequential-thinking/scripts/process-thought.js +236 -0
- package/skills/utils/sequential-thinking/tests/format-thought.test.js +133 -0
- package/skills/utils/sequential-thinking/tests/process-thought.test.js +215 -0
- package/skills/utils/write-skill/SKILL.md +655 -0
- package/skills/utils/write-skill/anthropic-best-practices.md +1150 -0
- package/skills/utils/write-skill/examples/CLAUDE_MD_TESTING.md +189 -0
- package/skills/utils/write-skill/graphviz-conventions.dot +172 -0
- package/skills/utils/write-skill/persuasion-principles.md +187 -0
- package/skills/utils/write-skill/render-graphs.js +168 -0
- package/skills/utils/write-skill/testing-skills-with-subagents.md +384 -0
- package/src/commands/init.js +238 -0
|
@@ -0,0 +1,246 @@
|
|
|
1
|
+
"""Tests for context-engineering edge case handling.
|
|
2
|
+
|
|
3
|
+
Tests the error handling improvements in compression_evaluator.py and context_analyzer.py:
|
|
4
|
+
- File not found
|
|
5
|
+
- Permission denied
|
|
6
|
+
- Invalid JSON
|
|
7
|
+
- File too large
|
|
8
|
+
- UTF-8 encoding
|
|
9
|
+
"""
|
|
10
|
+
|
|
11
|
+
import json
|
|
12
|
+
import os
|
|
13
|
+
import stat
|
|
14
|
+
import subprocess
|
|
15
|
+
import sys
|
|
16
|
+
import tempfile
|
|
17
|
+
from pathlib import Path
|
|
18
|
+
|
|
19
|
+
import pytest
|
|
20
|
+
|
|
21
|
+
SCRIPTS_DIR = Path(__file__).parent.parent
|
|
22
|
+
PYTHON = sys.executable
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
class TestCompressionEvaluatorEdgeCases:
|
|
26
|
+
"""Test edge cases in compression_evaluator.py"""
|
|
27
|
+
|
|
28
|
+
@pytest.fixture
|
|
29
|
+
def valid_json_file(self, tmp_path):
|
|
30
|
+
"""Create valid JSON file."""
|
|
31
|
+
f = tmp_path / "valid.json"
|
|
32
|
+
f.write_text('{"messages": [{"role": "user", "content": "hello"}]}', encoding='utf-8')
|
|
33
|
+
return str(f)
|
|
34
|
+
|
|
35
|
+
@pytest.fixture
|
|
36
|
+
def valid_text_file(self, tmp_path):
|
|
37
|
+
"""Create valid text file."""
|
|
38
|
+
f = tmp_path / "compressed.txt"
|
|
39
|
+
f.write_text("Summary of conversation", encoding='utf-8')
|
|
40
|
+
return str(f)
|
|
41
|
+
|
|
42
|
+
def run_script(self, *args, timeout=30):
|
|
43
|
+
"""Run compression_evaluator.py with args."""
|
|
44
|
+
cmd = [PYTHON, str(SCRIPTS_DIR / "compression_evaluator.py")] + list(args)
|
|
45
|
+
result = subprocess.run(cmd, capture_output=True, text=True, timeout=timeout)
|
|
46
|
+
return result
|
|
47
|
+
|
|
48
|
+
def test_missing_file_exits_1(self, tmp_path):
|
|
49
|
+
"""Test exit code 1 when file not found."""
|
|
50
|
+
result = self.run_script("evaluate", "/nonexistent/file.json", str(tmp_path / "c.txt"))
|
|
51
|
+
assert result.returncode == 1
|
|
52
|
+
assert "File not found" in result.stderr
|
|
53
|
+
|
|
54
|
+
def test_missing_file_error_message(self, tmp_path):
|
|
55
|
+
"""Test error message format for missing file."""
|
|
56
|
+
missing = "/this/path/does/not/exist/file.json"
|
|
57
|
+
result = self.run_script("evaluate", missing, str(tmp_path / "c.txt"))
|
|
58
|
+
assert result.returncode == 1
|
|
59
|
+
assert missing in result.stderr or "not found" in result.stderr.lower()
|
|
60
|
+
|
|
61
|
+
def test_invalid_json_exits_1(self, tmp_path, valid_text_file):
|
|
62
|
+
"""Test exit code 1 when JSON is invalid."""
|
|
63
|
+
bad_json = tmp_path / "bad.json"
|
|
64
|
+
bad_json.write_text("{invalid json content", encoding='utf-8')
|
|
65
|
+
|
|
66
|
+
result = self.run_script("evaluate", str(bad_json), valid_text_file)
|
|
67
|
+
assert result.returncode == 1
|
|
68
|
+
assert "Invalid JSON" in result.stderr or "JSON" in result.stderr
|
|
69
|
+
|
|
70
|
+
def test_valid_files_succeed(self, valid_json_file, valid_text_file):
|
|
71
|
+
"""Test success with valid inputs."""
|
|
72
|
+
result = self.run_script("evaluate", valid_json_file, valid_text_file)
|
|
73
|
+
assert result.returncode == 0
|
|
74
|
+
output = json.loads(result.stdout)
|
|
75
|
+
assert "compression_ratio" in output
|
|
76
|
+
assert "quality_score" in output
|
|
77
|
+
|
|
78
|
+
def test_generate_probes_missing_file(self):
|
|
79
|
+
"""Test generate-probes with missing file."""
|
|
80
|
+
result = self.run_script("generate-probes", "/nonexistent/context.json")
|
|
81
|
+
assert result.returncode == 1
|
|
82
|
+
assert "File not found" in result.stderr
|
|
83
|
+
|
|
84
|
+
def test_generate_probes_invalid_json(self, tmp_path):
|
|
85
|
+
"""Test generate-probes with invalid JSON."""
|
|
86
|
+
bad = tmp_path / "bad.json"
|
|
87
|
+
bad.write_text("not valid json {{{", encoding='utf-8')
|
|
88
|
+
|
|
89
|
+
result = self.run_script("generate-probes", str(bad))
|
|
90
|
+
assert result.returncode == 1
|
|
91
|
+
assert "Invalid JSON" in result.stderr or "JSON" in result.stderr
|
|
92
|
+
|
|
93
|
+
def test_generate_probes_success(self, valid_json_file):
|
|
94
|
+
"""Test generate-probes with valid file."""
|
|
95
|
+
result = self.run_script("generate-probes", valid_json_file)
|
|
96
|
+
assert result.returncode == 0
|
|
97
|
+
output = json.loads(result.stdout)
|
|
98
|
+
assert isinstance(output, list)
|
|
99
|
+
|
|
100
|
+
def test_utf8_content(self, tmp_path):
|
|
101
|
+
"""Test UTF-8 encoding with special characters."""
|
|
102
|
+
utf8_file = tmp_path / "utf8.json"
|
|
103
|
+
content = {"messages": [{"role": "user", "content": "日本語テスト émojis 🎉"}]}
|
|
104
|
+
utf8_file.write_text(json.dumps(content), encoding='utf-8')
|
|
105
|
+
|
|
106
|
+
compressed = tmp_path / "compressed.txt"
|
|
107
|
+
compressed.write_text("Summary with 日本語 and émojis 🎉", encoding='utf-8')
|
|
108
|
+
|
|
109
|
+
result = self.run_script("evaluate", str(utf8_file), str(compressed))
|
|
110
|
+
assert result.returncode == 0
|
|
111
|
+
|
|
112
|
+
@pytest.mark.skipif(os.name == 'nt', reason="Permission test not reliable on Windows")
|
|
113
|
+
def test_permission_denied(self, tmp_path):
|
|
114
|
+
"""Test permission denied error."""
|
|
115
|
+
protected = tmp_path / "protected.json"
|
|
116
|
+
protected.write_text('{"messages": []}', encoding='utf-8')
|
|
117
|
+
os.chmod(protected, 0o000)
|
|
118
|
+
|
|
119
|
+
try:
|
|
120
|
+
result = self.run_script("generate-probes", str(protected))
|
|
121
|
+
assert result.returncode == 1
|
|
122
|
+
assert "Permission denied" in result.stderr or "permission" in result.stderr.lower()
|
|
123
|
+
finally:
|
|
124
|
+
os.chmod(protected, stat.S_IRUSR | stat.S_IWUSR)
|
|
125
|
+
|
|
126
|
+
|
|
127
|
+
class TestContextAnalyzerEdgeCases:
|
|
128
|
+
"""Test edge cases in context_analyzer.py"""
|
|
129
|
+
|
|
130
|
+
@pytest.fixture
|
|
131
|
+
def valid_context_file(self, tmp_path):
|
|
132
|
+
"""Create valid context file."""
|
|
133
|
+
f = tmp_path / "context.json"
|
|
134
|
+
content = {
|
|
135
|
+
"messages": [
|
|
136
|
+
{"role": "user", "content": "implement feature X"},
|
|
137
|
+
{"role": "assistant", "content": "I'll help with that"}
|
|
138
|
+
]
|
|
139
|
+
}
|
|
140
|
+
f.write_text(json.dumps(content), encoding='utf-8')
|
|
141
|
+
return str(f)
|
|
142
|
+
|
|
143
|
+
def run_script(self, *args, timeout=30):
|
|
144
|
+
"""Run context_analyzer.py with args."""
|
|
145
|
+
cmd = [PYTHON, str(SCRIPTS_DIR / "context_analyzer.py")] + list(args)
|
|
146
|
+
result = subprocess.run(cmd, capture_output=True, text=True, timeout=timeout)
|
|
147
|
+
return result
|
|
148
|
+
|
|
149
|
+
def test_missing_file_exits_1(self):
|
|
150
|
+
"""Test exit code 1 when file not found."""
|
|
151
|
+
result = self.run_script("analyze", "/nonexistent/context.json")
|
|
152
|
+
assert result.returncode == 1
|
|
153
|
+
assert "File not found" in result.stderr
|
|
154
|
+
|
|
155
|
+
def test_invalid_json_exits_1(self, tmp_path):
|
|
156
|
+
"""Test exit code 1 when JSON is invalid."""
|
|
157
|
+
bad = tmp_path / "bad.json"
|
|
158
|
+
bad.write_text("not json", encoding='utf-8')
|
|
159
|
+
|
|
160
|
+
result = self.run_script("analyze", str(bad))
|
|
161
|
+
assert result.returncode == 1
|
|
162
|
+
assert "Invalid JSON" in result.stderr or "JSON" in result.stderr
|
|
163
|
+
|
|
164
|
+
def test_valid_file_succeeds(self, valid_context_file):
|
|
165
|
+
"""Test success with valid input."""
|
|
166
|
+
result = self.run_script("analyze", valid_context_file)
|
|
167
|
+
assert result.returncode == 0
|
|
168
|
+
output = json.loads(result.stdout)
|
|
169
|
+
assert "health_status" in output or "health_score" in output
|
|
170
|
+
|
|
171
|
+
def test_utf8_content(self, tmp_path):
|
|
172
|
+
"""Test UTF-8 encoding with international characters."""
|
|
173
|
+
utf8_file = tmp_path / "utf8.json"
|
|
174
|
+
content = {
|
|
175
|
+
"messages": [
|
|
176
|
+
{"role": "user", "content": "日本語で説明してください"},
|
|
177
|
+
{"role": "assistant", "content": "はい、説明します。émojis: 🎉🚀"}
|
|
178
|
+
]
|
|
179
|
+
}
|
|
180
|
+
utf8_file.write_text(json.dumps(content, ensure_ascii=False), encoding='utf-8')
|
|
181
|
+
|
|
182
|
+
result = self.run_script("analyze", str(utf8_file))
|
|
183
|
+
assert result.returncode == 0
|
|
184
|
+
|
|
185
|
+
def test_empty_messages_array(self, tmp_path):
|
|
186
|
+
"""Test handling of empty messages array."""
|
|
187
|
+
f = tmp_path / "empty.json"
|
|
188
|
+
f.write_text('{"messages": []}', encoding='utf-8')
|
|
189
|
+
|
|
190
|
+
result = self.run_script("analyze", str(f))
|
|
191
|
+
assert result.returncode == 0
|
|
192
|
+
|
|
193
|
+
def test_direct_messages_list(self, tmp_path):
|
|
194
|
+
"""Test handling of direct messages list (no wrapper)."""
|
|
195
|
+
f = tmp_path / "direct.json"
|
|
196
|
+
content = [
|
|
197
|
+
{"role": "user", "content": "hello"},
|
|
198
|
+
{"role": "assistant", "content": "hi"}
|
|
199
|
+
]
|
|
200
|
+
f.write_text(json.dumps(content), encoding='utf-8')
|
|
201
|
+
|
|
202
|
+
result = self.run_script("analyze", str(f))
|
|
203
|
+
assert result.returncode == 0
|
|
204
|
+
|
|
205
|
+
@pytest.mark.skipif(os.name == 'nt', reason="Permission test not reliable on Windows")
|
|
206
|
+
def test_permission_denied(self, tmp_path):
|
|
207
|
+
"""Test permission denied error."""
|
|
208
|
+
protected = tmp_path / "protected.json"
|
|
209
|
+
protected.write_text('{"messages": []}', encoding='utf-8')
|
|
210
|
+
os.chmod(protected, 0o000)
|
|
211
|
+
|
|
212
|
+
try:
|
|
213
|
+
result = self.run_script("analyze", str(protected))
|
|
214
|
+
assert result.returncode == 1
|
|
215
|
+
assert "Permission denied" in result.stderr or "permission" in result.stderr.lower()
|
|
216
|
+
finally:
|
|
217
|
+
os.chmod(protected, stat.S_IRUSR | stat.S_IWUSR)
|
|
218
|
+
|
|
219
|
+
def test_with_keywords_filter(self, valid_context_file):
|
|
220
|
+
"""Test analyze with keywords filter."""
|
|
221
|
+
result = self.run_script("analyze", valid_context_file, "--keywords", "feature,implement")
|
|
222
|
+
assert result.returncode == 0
|
|
223
|
+
|
|
224
|
+
def test_with_limit(self, valid_context_file):
|
|
225
|
+
"""Test analyze with limit parameter."""
|
|
226
|
+
result = self.run_script("analyze", valid_context_file, "--limit", "10")
|
|
227
|
+
assert result.returncode == 0
|
|
228
|
+
|
|
229
|
+
|
|
230
|
+
class TestFileSizeValidation:
|
|
231
|
+
"""Test file size validation (100MB limit)."""
|
|
232
|
+
|
|
233
|
+
def test_large_file_warning_in_code(self):
|
|
234
|
+
"""Verify MAX_FILE_SIZE_MB constant exists in scripts."""
|
|
235
|
+
evaluator = SCRIPTS_DIR / "compression_evaluator.py"
|
|
236
|
+
analyzer = SCRIPTS_DIR / "context_analyzer.py"
|
|
237
|
+
|
|
238
|
+
eval_content = evaluator.read_text()
|
|
239
|
+
analyzer_content = analyzer.read_text()
|
|
240
|
+
|
|
241
|
+
assert "MAX_FILE_SIZE_MB = 100" in eval_content
|
|
242
|
+
assert "MAX_FILE_SIZE_MB = 100" in analyzer_content
|
|
243
|
+
|
|
244
|
+
|
|
245
|
+
if __name__ == "__main__":
|
|
246
|
+
pytest.main([__file__, "-v"])
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: databases
|
|
3
|
+
description: Design schemas, write queries for MongoDB and PostgreSQL. Use for database design, SQL/NoSQL queries, aggregation pipelines, indexes, migrations, replication, performance optimization, psql CLI.
|
|
4
|
+
license: MIT
|
|
5
|
+
argument-hint: "[query or schema task]"
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
# Databases Skill
|
|
9
|
+
|
|
10
|
+
Unified guide for working with MongoDB (document-oriented) and PostgreSQL (relational) databases. Choose the right database for your use case and master both systems.
|
|
11
|
+
|
|
12
|
+
## When to Use This Skill
|
|
13
|
+
|
|
14
|
+
Use when:
|
|
15
|
+
- Designing database schemas and data models
|
|
16
|
+
- Writing queries (SQL or MongoDB query language)
|
|
17
|
+
- Building aggregation pipelines or complex joins
|
|
18
|
+
- Optimizing indexes and query performance
|
|
19
|
+
- Implementing database migrations
|
|
20
|
+
- Setting up replication, sharding, or clustering
|
|
21
|
+
- Configuring backups and disaster recovery
|
|
22
|
+
- Managing database users and permissions
|
|
23
|
+
- Analyzing slow queries and performance issues
|
|
24
|
+
- Administering production database deployments
|
|
25
|
+
|
|
26
|
+
## Reference Navigation
|
|
27
|
+
|
|
28
|
+
### Database Design
|
|
29
|
+
- **[db-design.md](references/db-design.md)** - Activate when user requests: Database/table design for transactional (OLTP), analytics (OLAP), create or extend schema, design fact/dimension tables, analyze/review CSV/JSON/SQL files to create tables, or need advice on data storage structure.
|
|
30
|
+
|
|
31
|
+
### MongoDB References
|
|
32
|
+
- **[mongodb-crud.md](references/mongodb-crud.md)** - CRUD operations, query operators, atomic updates
|
|
33
|
+
- **[mongodb-aggregation.md](references/mongodb-aggregation.md)** - Aggregation pipeline, stages, operators, patterns
|
|
34
|
+
- **[mongodb-indexing.md](references/mongodb-indexing.md)** - Index types, compound indexes, performance optimization
|
|
35
|
+
- **[mongodb-atlas.md](references/mongodb-atlas.md)** - Atlas cloud setup, clusters, monitoring, search
|
|
36
|
+
|
|
37
|
+
### PostgreSQL References
|
|
38
|
+
- **[postgresql-queries.md](references/postgresql-queries.md)** - SELECT, JOINs, subqueries, CTEs, window functions
|
|
39
|
+
- **[postgresql-psql-cli.md](references/postgresql-psql-cli.md)** - psql commands, meta-commands, scripting
|
|
40
|
+
- **[postgresql-performance.md](references/postgresql-performance.md)** - EXPLAIN, query optimization, vacuum, indexes
|
|
41
|
+
- **[postgresql-administration.md](references/postgresql-administration.md)** - User management, backups, replication, maintenance
|
|
42
|
+
|
|
43
|
+
## Python Utilities
|
|
44
|
+
|
|
45
|
+
Database utility scripts in `scripts/`:
|
|
46
|
+
- **db_migrate.py** - Generate and apply migrations for both databases (MongoDB and PostgreSQL)
|
|
47
|
+
- **db_backup.py** - Backup and restore MongoDB and PostgreSQL
|
|
48
|
+
- **db_performance_check.py** - Analyze slow queries and recommend indexes
|
|
49
|
+
|
|
50
|
+
```bash
|
|
51
|
+
# Generate migration
|
|
52
|
+
python scripts/db_migrate.py --db mongodb --generate "add_user_index"
|
|
53
|
+
|
|
54
|
+
# Run backup
|
|
55
|
+
python scripts/db_backup.py --db postgres --output /backups/
|
|
56
|
+
|
|
57
|
+
# Check performance
|
|
58
|
+
python scripts/db_performance_check.py --db mongodb --threshold 100ms
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
## Best Practices
|
|
62
|
+
|
|
63
|
+
**MongoDB:**
|
|
64
|
+
- Use embedded documents for 1-to-few relationships
|
|
65
|
+
- Reference documents for 1-to-many or many-to-many
|
|
66
|
+
- Index frequently queried fields
|
|
67
|
+
- Use aggregation pipeline for complex transformations
|
|
68
|
+
- Enable authentication and TLS in production
|
|
69
|
+
- Use Atlas for managed hosting
|
|
70
|
+
|
|
71
|
+
**PostgreSQL:**
|
|
72
|
+
- Normalize schema to 3NF, denormalize for performance
|
|
73
|
+
- Use foreign keys for referential integrity
|
|
74
|
+
- Index foreign keys and frequently filtered columns
|
|
75
|
+
- Use EXPLAIN ANALYZE to optimize queries
|
|
76
|
+
- Regular VACUUM and ANALYZE maintenance
|
|
77
|
+
- Connection pooling (pgBouncer) for web apps
|
|
78
|
+
|
|
79
|
+
## Resources
|
|
80
|
+
|
|
81
|
+
- MongoDB: https://www.mongodb.com/docs/
|
|
82
|
+
- PostgreSQL: https://www.postgresql.org/docs/
|
|
83
|
+
- MongoDB University: https://learn.mongodb.com/
|
|
84
|
+
- PostgreSQL Tutorial: https://www.postgresqltutorial.com/
|
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
# Analytics (OLAP) Rules
|
|
2
|
+
|
|
3
|
+
> **Note:** Core naming conventions, workflow, and checklist are in `SKILL.md` or `db-design.md` (always loaded).
|
|
4
|
+
|
|
5
|
+
Guidelines for designing schemas for statistics and reporting tables.
|
|
6
|
+
|
|
7
|
+
---
|
|
8
|
+
|
|
9
|
+
## General Principles
|
|
10
|
+
|
|
11
|
+
- **Separate** from transactional tables - don't mix analytics logic into business tables
|
|
12
|
+
- When heavy analytics queries/aggregations repeat → create separate tables
|
|
13
|
+
- Use **Star Schema**: Fact tables at center, Dimension tables around
|
|
14
|
+
|
|
15
|
+
---
|
|
16
|
+
|
|
17
|
+
## Design Process
|
|
18
|
+
|
|
19
|
+
### 1. Analyze Statistics Requirements
|
|
20
|
+
|
|
21
|
+
Ask user to clarify:
|
|
22
|
+
- **Analysis dimensions**: by date, by customer, by product, by channel, by region?
|
|
23
|
+
- **Granularity**: per order, per item, per day, per month?
|
|
24
|
+
- **Metrics**: order_count, revenue, margin, conversion_rate, avg_order_value?
|
|
25
|
+
|
|
26
|
+
### 2. Define Fact Granularity
|
|
27
|
+
|
|
28
|
+
**Important**: What does 1 row in fact table represent?
|
|
29
|
+
|
|
30
|
+
| Fact Table | Granularity | Use case |
|
|
31
|
+
|------------|-------------|----------|
|
|
32
|
+
| `fact_orders` | 1 row = 1 order | Statistics by order |
|
|
33
|
+
| `fact_order_items` | 1 row = 1 order item | Statistics by product |
|
|
34
|
+
| `fact_daily_sales` | 1 row = 1 day + store | Daily summary |
|
|
35
|
+
|
|
36
|
+
### 3. Identify Required Dimensions
|
|
37
|
+
|
|
38
|
+
Create separate dim table when:
|
|
39
|
+
- Reused in multiple places
|
|
40
|
+
- Has many descriptive attributes
|
|
41
|
+
- Subject to slow changes (Slowly Changing Dimension)
|
|
42
|
+
|
|
43
|
+
---
|
|
44
|
+
|
|
45
|
+
## Fact Tables
|
|
46
|
+
|
|
47
|
+
### Fact table structure
|
|
48
|
+
|
|
49
|
+
```sql
|
|
50
|
+
CREATE TABLE fact_orders (
|
|
51
|
+
fact_id BIGINT PRIMARY KEY AUTO_INCREMENT,
|
|
52
|
+
-- Dimension keys
|
|
53
|
+
date_key INT NOT NULL, -- FK to dim_date
|
|
54
|
+
customer_key BIGINT NOT NULL, -- FK to dim_customer
|
|
55
|
+
store_key INT,
|
|
56
|
+
channel_key INT,
|
|
57
|
+
-- Degenerate dimensions (no separate dim needed)
|
|
58
|
+
order_id BIGINT NOT NULL,
|
|
59
|
+
order_number VARCHAR(50),
|
|
60
|
+
-- Measures
|
|
61
|
+
item_count INT NOT NULL,
|
|
62
|
+
gross_amount DECIMAL(18,2) NOT NULL,
|
|
63
|
+
discount_amount DECIMAL(18,2) DEFAULT 0,
|
|
64
|
+
net_amount DECIMAL(18,2) NOT NULL,
|
|
65
|
+
|
|
66
|
+
INDEX idx_fact_orders_date (date_key),
|
|
67
|
+
INDEX idx_fact_orders_customer (customer_key),
|
|
68
|
+
INDEX idx_fact_orders_date_store (date_key, store_key)
|
|
69
|
+
);
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
---
|
|
73
|
+
|
|
74
|
+
## Dimension Tables
|
|
75
|
+
|
|
76
|
+
### dim_date (required for every analytics schema)
|
|
77
|
+
|
|
78
|
+
```sql
|
|
79
|
+
CREATE TABLE dim_date (
|
|
80
|
+
date_key INT PRIMARY KEY, -- Format: YYYYMMDD (20241215)
|
|
81
|
+
full_date DATE NOT NULL,
|
|
82
|
+
year INT NOT NULL,
|
|
83
|
+
quarter INT NOT NULL, -- 1-4
|
|
84
|
+
month INT NOT NULL, -- 1-12
|
|
85
|
+
month_name VARCHAR(20), -- 'January', 'February'
|
|
86
|
+
week_of_year INT NOT NULL,
|
|
87
|
+
day_of_month INT NOT NULL,
|
|
88
|
+
day_of_week INT NOT NULL, -- 1=Monday, 7=Sunday
|
|
89
|
+
day_name VARCHAR(20),
|
|
90
|
+
is_weekend BOOLEAN NOT NULL,
|
|
91
|
+
is_holiday BOOLEAN DEFAULT FALSE,
|
|
92
|
+
|
|
93
|
+
UNIQUE (full_date)
|
|
94
|
+
);
|
|
95
|
+
-- Pre-populate for multiple years (2020-2030)
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
### dim_customer
|
|
99
|
+
|
|
100
|
+
```sql
|
|
101
|
+
CREATE TABLE dim_customer (
|
|
102
|
+
customer_key BIGINT PRIMARY KEY AUTO_INCREMENT, -- Surrogate key
|
|
103
|
+
customer_id BIGINT NOT NULL, -- Natural key from users
|
|
104
|
+
customer_name VARCHAR(255),
|
|
105
|
+
email VARCHAR(255),
|
|
106
|
+
segment VARCHAR(50), -- 'VIP', 'Regular', 'New'
|
|
107
|
+
city VARCHAR(100),
|
|
108
|
+
region VARCHAR(100),
|
|
109
|
+
first_order_date DATE,
|
|
110
|
+
-- SCD Type 2 columns (if history needed)
|
|
111
|
+
effective_from DATE NOT NULL,
|
|
112
|
+
effective_to DATE,
|
|
113
|
+
is_current BOOLEAN DEFAULT TRUE,
|
|
114
|
+
|
|
115
|
+
INDEX idx_dim_customer_id (customer_id),
|
|
116
|
+
INDEX idx_dim_customer_current (is_current, customer_id)
|
|
117
|
+
);
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
---
|
|
121
|
+
|
|
122
|
+
## Summary Tables (Pre-aggregated)
|
|
123
|
+
|
|
124
|
+
When pre-aggregation needed for dashboard performance:
|
|
125
|
+
|
|
126
|
+
```sql
|
|
127
|
+
CREATE TABLE summary_daily_sales (
|
|
128
|
+
id BIGINT PRIMARY KEY AUTO_INCREMENT,
|
|
129
|
+
date_key INT NOT NULL,
|
|
130
|
+
store_key INT,
|
|
131
|
+
channel_key INT,
|
|
132
|
+
-- Pre-aggregated measures
|
|
133
|
+
order_count INT NOT NULL,
|
|
134
|
+
item_count INT NOT NULL,
|
|
135
|
+
gross_revenue DECIMAL(18,2) NOT NULL,
|
|
136
|
+
net_revenue DECIMAL(18,2) NOT NULL,
|
|
137
|
+
unique_customers INT NOT NULL,
|
|
138
|
+
avg_order_value DECIMAL(18,2),
|
|
139
|
+
|
|
140
|
+
UNIQUE (date_key, store_key, channel_key),
|
|
141
|
+
INDEX idx_summary_date (date_key)
|
|
142
|
+
);
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
---
|
|
146
|
+
|
|
147
|
+
## Slowly Changing Dimensions (SCD)
|
|
148
|
+
|
|
149
|
+
### Type 1 - Overwrite
|
|
150
|
+
Overwrite old value, no history kept:
|
|
151
|
+
```sql
|
|
152
|
+
UPDATE dim_customer SET segment = 'VIP' WHERE customer_id = 123;
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
### Type 2 - Add new row (Recommended when history needed)
|
|
156
|
+
```sql
|
|
157
|
+
-- 1. Close old row
|
|
158
|
+
UPDATE dim_customer
|
|
159
|
+
SET effective_to = CURRENT_DATE - 1, is_current = FALSE
|
|
160
|
+
WHERE customer_id = 123 AND is_current = TRUE;
|
|
161
|
+
|
|
162
|
+
-- 2. Add new row
|
|
163
|
+
INSERT INTO dim_customer (customer_id, segment, effective_from, is_current)
|
|
164
|
+
VALUES (123, 'VIP', CURRENT_DATE, TRUE);
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
---
|
|
168
|
+
|
|
169
|
+
## Indexing for Analytics
|
|
170
|
+
|
|
171
|
+
### Fact tables
|
|
172
|
+
- Index FKs to dimensions: `date_key`, `customer_key`, `product_key`
|
|
173
|
+
- Composite index based on query patterns: `INDEX (date_key, store_key)`
|
|
174
|
+
|
|
175
|
+
### Dimension tables
|
|
176
|
+
- PK: surrogate key
|
|
177
|
+
- Index natural key: `customer_id`, `product_id`
|
|
178
|
+
- Index for SCD: `(is_current, customer_id)`
|
|
179
|
+
|
|
180
|
+
---
|
|
181
|
+
|
|
182
|
+
## Naming Convention
|
|
183
|
+
|
|
184
|
+
- Fact tables: `fact_*` or `fct_*`
|
|
185
|
+
- Dimension tables: `dim_*`
|
|
186
|
+
- Summary tables: `summary_*` or `agg_*`
|
|
187
|
+
|
|
188
|
+
---
|
|
189
|
+
|
|
190
|
+
## Checklist
|
|
191
|
+
|
|
192
|
+
- [ ] Granularity defined for each fact table
|
|
193
|
+
- [ ] dim_date exists or created (pre-populate multiple years)
|
|
194
|
+
- [ ] Surrogate keys for dimensions
|
|
195
|
+
- [ ] Index FKs in fact tables
|
|
196
|
+
- [ ] SCD strategy for changing dimensions (Type 1 or Type 2)
|
|
197
|
+
- [ ] Naming: `fact_*`, `dim_*`, `summary_*`
|
|
198
|
+
- [ ] Refresh strategy: see [incremental-etl.md](incremental-etl.md)
|