@neyugn/agent-kits 0.1.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 +514 -0
- package/README.vi.md +410 -0
- package/README.zh.md +410 -0
- package/dist/cli.d.ts +1 -0
- package/dist/cli.js +422 -0
- package/kits/coder/ARCHITECTURE.md +289 -0
- package/kits/coder/agents/ai-engineer.md +344 -0
- package/kits/coder/agents/backend-specialist.md +270 -0
- package/kits/coder/agents/cloud-architect.md +363 -0
- package/kits/coder/agents/code-reviewer.md +284 -0
- package/kits/coder/agents/data-engineer.md +401 -0
- package/kits/coder/agents/database-specialist.md +251 -0
- package/kits/coder/agents/debugger.md +209 -0
- package/kits/coder/agents/devops-engineer.md +281 -0
- package/kits/coder/agents/documentation-writer.md +296 -0
- package/kits/coder/agents/frontend-specialist.md +298 -0
- package/kits/coder/agents/i18n-specialist.md +348 -0
- package/kits/coder/agents/integration-specialist.md +314 -0
- package/kits/coder/agents/mobile-developer.md +271 -0
- package/kits/coder/agents/multi-tenant-architect.md +281 -0
- package/kits/coder/agents/orchestrator.md +263 -0
- package/kits/coder/agents/performance-analyst.md +327 -0
- package/kits/coder/agents/project-planner.md +277 -0
- package/kits/coder/agents/queue-specialist.md +282 -0
- package/kits/coder/agents/realtime-specialist.md +267 -0
- package/kits/coder/agents/security-auditor.md +253 -0
- package/kits/coder/agents/test-engineer.md +315 -0
- package/kits/coder/agents/ux-researcher.md +388 -0
- package/kits/coder/rules/.cursorrules +287 -0
- package/kits/coder/rules/CLAUDE.md +287 -0
- package/kits/coder/rules/CODEX.md +287 -0
- package/kits/coder/rules/GEMINI.md +287 -0
- package/kits/coder/scripts/checklist.py +318 -0
- package/kits/coder/scripts/kit_status.py +292 -0
- package/kits/coder/scripts/skills_manager.py +243 -0
- package/kits/coder/scripts/verify_all.py +391 -0
- package/kits/coder/skills/accessibility-patterns/SKILL.md +372 -0
- package/kits/coder/skills/accessibility-patterns/scripts/a11y_checker.py +211 -0
- package/kits/coder/skills/ai-rag-patterns/SKILL.md +444 -0
- package/kits/coder/skills/api-patterns/SKILL.md +316 -0
- package/kits/coder/skills/api-patterns/assets/.gitkeep +1 -0
- package/kits/coder/skills/api-patterns/references/deep-dive.md +21 -0
- package/kits/coder/skills/api-patterns/scripts/api_validator.py +253 -0
- package/kits/coder/skills/api-patterns/scripts/validate.py +56 -0
- package/kits/coder/skills/auth-patterns/SKILL.md +267 -0
- package/kits/coder/skills/aws-patterns/SKILL.md +576 -0
- package/kits/coder/skills/brainstorming/SKILL.md +370 -0
- package/kits/coder/skills/brainstorming/assets/.gitkeep +1 -0
- package/kits/coder/skills/brainstorming/references/deep-dive.md +21 -0
- package/kits/coder/skills/brainstorming/scripts/validate.py +56 -0
- package/kits/coder/skills/clean-code/SKILL.md +240 -0
- package/kits/coder/skills/clean-code/assets/.gitkeep +1 -0
- package/kits/coder/skills/clean-code/references/deep-dive.md +21 -0
- package/kits/coder/skills/clean-code/scripts/lint_runner.py +186 -0
- package/kits/coder/skills/clean-code/scripts/validate.py +56 -0
- package/kits/coder/skills/database-design/SKILL.md +255 -0
- package/kits/coder/skills/database-design/assets/.gitkeep +1 -0
- package/kits/coder/skills/database-design/references/deep-dive.md +21 -0
- package/kits/coder/skills/database-design/scripts/schema_validator.py +272 -0
- package/kits/coder/skills/database-design/scripts/validate.py +56 -0
- package/kits/coder/skills/docker-patterns/SKILL.md +240 -0
- package/kits/coder/skills/documentation-templates/SKILL.md +441 -0
- package/kits/coder/skills/e2e-testing/SKILL.md +457 -0
- package/kits/coder/skills/flutter-patterns/SKILL.md +330 -0
- package/kits/coder/skills/frontend-design/SKILL.md +127 -0
- package/kits/coder/skills/github-actions/SKILL.md +349 -0
- package/kits/coder/skills/gitlab-ci-patterns/SKILL.md +466 -0
- package/kits/coder/skills/graphql-patterns/SKILL.md +558 -0
- package/kits/coder/skills/i18n-localization/SKILL.md +345 -0
- package/kits/coder/skills/i18n-localization/scripts/i18n_checker.py +267 -0
- package/kits/coder/skills/kubernetes-patterns/SKILL.md +357 -0
- package/kits/coder/skills/mermaid-diagrams/SKILL.md +351 -0
- package/kits/coder/skills/mobile-design/SKILL.md +305 -0
- package/kits/coder/skills/monitoring-observability/SKILL.md +458 -0
- package/kits/coder/skills/multi-tenancy/SKILL.md +317 -0
- package/kits/coder/skills/multi-tenancy/assets/.gitkeep +1 -0
- package/kits/coder/skills/multi-tenancy/references/deep-dive.md +21 -0
- package/kits/coder/skills/multi-tenancy/scripts/validate.py +56 -0
- package/kits/coder/skills/nodejs-best-practices/SKILL.md +220 -0
- package/kits/coder/skills/performance-profiling/SKILL.md +333 -0
- package/kits/coder/skills/performance-profiling/assets/.gitkeep +1 -0
- package/kits/coder/skills/performance-profiling/references/deep-dive.md +21 -0
- package/kits/coder/skills/performance-profiling/scripts/validate.py +56 -0
- package/kits/coder/skills/plan-writing/SKILL.md +360 -0
- package/kits/coder/skills/plan-writing/assets/.gitkeep +1 -0
- package/kits/coder/skills/plan-writing/references/deep-dive.md +21 -0
- package/kits/coder/skills/plan-writing/scripts/validate.py +56 -0
- package/kits/coder/skills/postgres-patterns/SKILL.md +361 -0
- package/kits/coder/skills/prompt-engineering/SKILL.md +277 -0
- package/kits/coder/skills/queue-patterns/SKILL.md +359 -0
- package/kits/coder/skills/queue-patterns/assets/.gitkeep +1 -0
- package/kits/coder/skills/queue-patterns/references/deep-dive.md +21 -0
- package/kits/coder/skills/queue-patterns/scripts/validate.py +56 -0
- package/kits/coder/skills/react-native-patterns/SKILL.md +393 -0
- package/kits/coder/skills/react-patterns/SKILL.md +319 -0
- package/kits/coder/skills/realtime-patterns/SKILL.md +506 -0
- package/kits/coder/skills/realtime-patterns/assets/.gitkeep +1 -0
- package/kits/coder/skills/realtime-patterns/references/deep-dive.md +21 -0
- package/kits/coder/skills/realtime-patterns/scripts/validate.py +56 -0
- package/kits/coder/skills/redis-patterns/SKILL.md +484 -0
- package/kits/coder/skills/security-fundamentals/SKILL.md +363 -0
- package/kits/coder/skills/security-fundamentals/assets/.gitkeep +1 -0
- package/kits/coder/skills/security-fundamentals/references/deep-dive.md +21 -0
- package/kits/coder/skills/security-fundamentals/scripts/security_scan.py +326 -0
- package/kits/coder/skills/security-fundamentals/scripts/validate.py +56 -0
- package/kits/coder/skills/seo-patterns/SKILL.md +262 -0
- package/kits/coder/skills/seo-patterns/scripts/seo_checker.py +211 -0
- package/kits/coder/skills/systematic-debugging/SKILL.md +478 -0
- package/kits/coder/skills/systematic-debugging/assets/.gitkeep +1 -0
- package/kits/coder/skills/systematic-debugging/references/deep-dive.md +21 -0
- package/kits/coder/skills/systematic-debugging/scripts/validate.py +56 -0
- package/kits/coder/skills/tailwind-patterns/SKILL.md +395 -0
- package/kits/coder/skills/terraform-patterns/SKILL.md +470 -0
- package/kits/coder/skills/testing-patterns/SKILL.md +285 -0
- package/kits/coder/skills/testing-patterns/assets/.gitkeep +1 -0
- package/kits/coder/skills/testing-patterns/references/deep-dive.md +21 -0
- package/kits/coder/skills/testing-patterns/scripts/test_runner.py +219 -0
- package/kits/coder/skills/testing-patterns/scripts/validate.py +56 -0
- package/kits/coder/skills/typescript-patterns/SKILL.md +417 -0
- package/kits/coder/skills/ui-ux-pro-max/SKILL.md +364 -0
- package/kits/coder/skills/ui-ux-pro-max/data/charts.csv +26 -0
- package/kits/coder/skills/ui-ux-pro-max/data/colors.csv +97 -0
- package/kits/coder/skills/ui-ux-pro-max/data/icons.csv +101 -0
- package/kits/coder/skills/ui-ux-pro-max/data/landing.csv +31 -0
- package/kits/coder/skills/ui-ux-pro-max/data/products.csv +97 -0
- package/kits/coder/skills/ui-ux-pro-max/data/prompts.csv +24 -0
- package/kits/coder/skills/ui-ux-pro-max/data/react-performance.csv +45 -0
- package/kits/coder/skills/ui-ux-pro-max/data/stacks/flutter.csv +53 -0
- package/kits/coder/skills/ui-ux-pro-max/data/stacks/html-tailwind.csv +56 -0
- package/kits/coder/skills/ui-ux-pro-max/data/stacks/nextjs.csv +53 -0
- package/kits/coder/skills/ui-ux-pro-max/data/stacks/nuxt-ui.csv +51 -0
- package/kits/coder/skills/ui-ux-pro-max/data/stacks/nuxtjs.csv +59 -0
- package/kits/coder/skills/ui-ux-pro-max/data/stacks/react-native.csv +52 -0
- package/kits/coder/skills/ui-ux-pro-max/data/stacks/react.csv +54 -0
- package/kits/coder/skills/ui-ux-pro-max/data/stacks/shadcn.csv +61 -0
- package/kits/coder/skills/ui-ux-pro-max/data/stacks/svelte.csv +54 -0
- package/kits/coder/skills/ui-ux-pro-max/data/stacks/swiftui.csv +51 -0
- package/kits/coder/skills/ui-ux-pro-max/data/stacks/vue.csv +50 -0
- package/kits/coder/skills/ui-ux-pro-max/data/styles.csv +59 -0
- package/kits/coder/skills/ui-ux-pro-max/data/typography.csv +58 -0
- package/kits/coder/skills/ui-ux-pro-max/data/ui-reasoning.csv +101 -0
- package/kits/coder/skills/ui-ux-pro-max/data/ux-guidelines.csv +100 -0
- package/kits/coder/skills/ui-ux-pro-max/data/web-interface.csv +31 -0
- package/kits/coder/skills/ui-ux-pro-max/scripts/__pycache__/core.cpython-314.pyc +0 -0
- package/kits/coder/skills/ui-ux-pro-max/scripts/__pycache__/design_system.cpython-314.pyc +0 -0
- package/kits/coder/skills/ui-ux-pro-max/scripts/core.py +257 -0
- package/kits/coder/skills/ui-ux-pro-max/scripts/design_system.py +488 -0
- package/kits/coder/skills/ui-ux-pro-max/scripts/search.py +76 -0
- package/kits/coder/workflows/.gitkeep +20 -0
- package/kits/coder/workflows/create.md +152 -0
- package/kits/coder/workflows/debug.md +223 -0
- package/kits/coder/workflows/deploy.md +283 -0
- package/kits/coder/workflows/orchestrate.md +243 -0
- package/kits/coder/workflows/plan.md +134 -0
- package/kits/coder/workflows/test.md +237 -0
- package/kits/coder/workflows/ui-ux-pro-max.md +109 -0
- package/package.json +49 -0
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""
|
|
3
|
+
Lint Runner - Unified linting and type checking
|
|
4
|
+
=================================================
|
|
5
|
+
|
|
6
|
+
Auto-detects project type and runs appropriate linters.
|
|
7
|
+
|
|
8
|
+
Usage:
|
|
9
|
+
python .agent/skills/clean-code/scripts/lint_runner.py <project_path>
|
|
10
|
+
python .agent/skills/clean-code/scripts/lint_runner.py . --fix
|
|
11
|
+
|
|
12
|
+
Supports:
|
|
13
|
+
- Node.js: npm run lint, eslint, prettier, tsc --noEmit
|
|
14
|
+
- Python: ruff check, black --check, mypy
|
|
15
|
+
"""
|
|
16
|
+
|
|
17
|
+
import subprocess
|
|
18
|
+
import sys
|
|
19
|
+
import json
|
|
20
|
+
import platform
|
|
21
|
+
from pathlib import Path
|
|
22
|
+
from datetime import datetime
|
|
23
|
+
|
|
24
|
+
# Fix console encoding
|
|
25
|
+
try:
|
|
26
|
+
sys.stdout.reconfigure(encoding='utf-8', errors='replace')
|
|
27
|
+
except:
|
|
28
|
+
pass
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
def detect_project_type(project_path: Path) -> dict:
|
|
32
|
+
"""Detect project type and available linters."""
|
|
33
|
+
result = {"type": "unknown", "linters": []}
|
|
34
|
+
|
|
35
|
+
# Node.js project
|
|
36
|
+
package_json = project_path / "package.json"
|
|
37
|
+
if package_json.exists():
|
|
38
|
+
result["type"] = "node"
|
|
39
|
+
try:
|
|
40
|
+
pkg = json.loads(package_json.read_text(encoding='utf-8'))
|
|
41
|
+
scripts = pkg.get("scripts", {})
|
|
42
|
+
deps = {**pkg.get("dependencies", {}), **pkg.get("devDependencies", {})}
|
|
43
|
+
|
|
44
|
+
# Check for lint script
|
|
45
|
+
if "lint" in scripts:
|
|
46
|
+
result["linters"].append({"name": "npm lint", "cmd": ["npm", "run", "lint"]})
|
|
47
|
+
elif "eslint" in deps:
|
|
48
|
+
result["linters"].append({"name": "eslint", "cmd": ["npx", "eslint", "."]})
|
|
49
|
+
|
|
50
|
+
# Check for TypeScript
|
|
51
|
+
if "typescript" in deps or (project_path / "tsconfig.json").exists():
|
|
52
|
+
result["linters"].append({"name": "tsc", "cmd": ["npx", "tsc", "--noEmit"]})
|
|
53
|
+
|
|
54
|
+
# Check for Prettier
|
|
55
|
+
if "prettier" in deps or (project_path / ".prettierrc").exists():
|
|
56
|
+
result["linters"].append({"name": "prettier", "cmd": ["npx", "prettier", "--check", "."]})
|
|
57
|
+
|
|
58
|
+
except:
|
|
59
|
+
pass
|
|
60
|
+
|
|
61
|
+
# Python project
|
|
62
|
+
if (project_path / "pyproject.toml").exists() or (project_path / "requirements.txt").exists():
|
|
63
|
+
result["type"] = "python"
|
|
64
|
+
result["linters"].append({"name": "ruff", "cmd": ["ruff", "check", "."]})
|
|
65
|
+
|
|
66
|
+
if (project_path / "mypy.ini").exists() or (project_path / "pyproject.toml").exists():
|
|
67
|
+
result["linters"].append({"name": "mypy", "cmd": ["mypy", "."]})
|
|
68
|
+
|
|
69
|
+
return result
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
def run_linter(linter: dict, cwd: Path) -> dict:
|
|
73
|
+
"""Run a single linter and return results."""
|
|
74
|
+
result = {
|
|
75
|
+
"name": linter["name"],
|
|
76
|
+
"passed": False,
|
|
77
|
+
"output": "",
|
|
78
|
+
"error": ""
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
try:
|
|
82
|
+
cmd = linter["cmd"]
|
|
83
|
+
|
|
84
|
+
# Windows compatibility
|
|
85
|
+
if platform.system() == "Windows":
|
|
86
|
+
if cmd[0] in ["npm", "npx"]:
|
|
87
|
+
cmd[0] = f"{cmd[0]}.cmd"
|
|
88
|
+
|
|
89
|
+
proc = subprocess.run(
|
|
90
|
+
cmd,
|
|
91
|
+
cwd=str(cwd),
|
|
92
|
+
capture_output=True,
|
|
93
|
+
text=True,
|
|
94
|
+
encoding='utf-8',
|
|
95
|
+
errors='replace',
|
|
96
|
+
timeout=120,
|
|
97
|
+
shell=platform.system() == "Windows"
|
|
98
|
+
)
|
|
99
|
+
|
|
100
|
+
result["output"] = proc.stdout[:2000] if proc.stdout else ""
|
|
101
|
+
result["error"] = proc.stderr[:500] if proc.stderr else ""
|
|
102
|
+
result["passed"] = proc.returncode == 0
|
|
103
|
+
|
|
104
|
+
except FileNotFoundError:
|
|
105
|
+
result["error"] = f"Command not found: {linter['cmd'][0]}"
|
|
106
|
+
except subprocess.TimeoutExpired:
|
|
107
|
+
result["error"] = "Timeout after 120s"
|
|
108
|
+
except Exception as e:
|
|
109
|
+
result["error"] = str(e)
|
|
110
|
+
|
|
111
|
+
return result
|
|
112
|
+
|
|
113
|
+
|
|
114
|
+
def main():
|
|
115
|
+
project_path = Path(sys.argv[1] if len(sys.argv) > 1 else ".").resolve()
|
|
116
|
+
fix_mode = "--fix" in sys.argv
|
|
117
|
+
|
|
118
|
+
print(f"\n{'='*60}")
|
|
119
|
+
print(f"[AGT-KIT LINT RUNNER] Code Quality Check")
|
|
120
|
+
print(f"{'='*60}")
|
|
121
|
+
print(f"Project: {project_path}")
|
|
122
|
+
print(f"Time: {datetime.now().strftime('%Y-%m-%d %H:%M:%S')}")
|
|
123
|
+
print(f"Fix Mode: {fix_mode}")
|
|
124
|
+
|
|
125
|
+
# Detect project type
|
|
126
|
+
project_info = detect_project_type(project_path)
|
|
127
|
+
print(f"Type: {project_info['type']}")
|
|
128
|
+
print(f"Linters: {len(project_info['linters'])}")
|
|
129
|
+
print("-"*60)
|
|
130
|
+
|
|
131
|
+
if not project_info["linters"]:
|
|
132
|
+
print("No linters found for this project type.")
|
|
133
|
+
output = {
|
|
134
|
+
"script": "lint_runner",
|
|
135
|
+
"skill": "clean-code",
|
|
136
|
+
"project": str(project_path),
|
|
137
|
+
"type": project_info["type"],
|
|
138
|
+
"checks": [],
|
|
139
|
+
"passed": True,
|
|
140
|
+
"message": "No linters configured"
|
|
141
|
+
}
|
|
142
|
+
print(json.dumps(output, indent=2))
|
|
143
|
+
sys.exit(0)
|
|
144
|
+
|
|
145
|
+
# Run each linter
|
|
146
|
+
results = []
|
|
147
|
+
all_passed = True
|
|
148
|
+
|
|
149
|
+
for linter in project_info["linters"]:
|
|
150
|
+
print(f"\nRunning: {linter['name']}...")
|
|
151
|
+
result = run_linter(linter, project_path)
|
|
152
|
+
results.append(result)
|
|
153
|
+
|
|
154
|
+
if result["passed"]:
|
|
155
|
+
print(f" ✅ {linter['name']}: PASSED")
|
|
156
|
+
else:
|
|
157
|
+
print(f" ❌ {linter['name']}: FAILED")
|
|
158
|
+
if result["error"]:
|
|
159
|
+
print(f" Error: {result['error'][:200]}")
|
|
160
|
+
all_passed = False
|
|
161
|
+
|
|
162
|
+
# Summary
|
|
163
|
+
print("\n" + "="*60)
|
|
164
|
+
print("SUMMARY")
|
|
165
|
+
print("="*60)
|
|
166
|
+
|
|
167
|
+
for r in results:
|
|
168
|
+
icon = "✅" if r["passed"] else "❌"
|
|
169
|
+
print(f"{icon} {r['name']}")
|
|
170
|
+
|
|
171
|
+
output = {
|
|
172
|
+
"script": "lint_runner",
|
|
173
|
+
"skill": "clean-code",
|
|
174
|
+
"project": str(project_path),
|
|
175
|
+
"type": project_info["type"],
|
|
176
|
+
"checks": results,
|
|
177
|
+
"passed": all_passed
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
print("\n" + json.dumps(output, indent=2))
|
|
181
|
+
|
|
182
|
+
sys.exit(0 if all_passed else 1)
|
|
183
|
+
|
|
184
|
+
|
|
185
|
+
if __name__ == "__main__":
|
|
186
|
+
main()
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""
|
|
3
|
+
Example validator for clean-code
|
|
4
|
+
|
|
5
|
+
Usage:
|
|
6
|
+
python validate.py <project_path>
|
|
7
|
+
"""
|
|
8
|
+
|
|
9
|
+
import sys
|
|
10
|
+
from pathlib import Path
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
def validate(project_path: str) -> dict:
|
|
14
|
+
"""Main validation logic"""
|
|
15
|
+
results = {
|
|
16
|
+
'errors': [],
|
|
17
|
+
'warnings': [],
|
|
18
|
+
'passed': []
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
# TODO: Add validation logic
|
|
22
|
+
results['passed'].append('Placeholder validation passed')
|
|
23
|
+
|
|
24
|
+
return results
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
def print_results(results: dict):
|
|
28
|
+
"""Pretty print results"""
|
|
29
|
+
print("\n🔍 Validation Results\n")
|
|
30
|
+
|
|
31
|
+
if results['errors']:
|
|
32
|
+
print(f"❌ Errors ({len(results['errors'])})")
|
|
33
|
+
for error in results['errors']:
|
|
34
|
+
print(f" - {error}")
|
|
35
|
+
|
|
36
|
+
if results['warnings']:
|
|
37
|
+
print(f"\n⚠️ Warnings ({len(results['warnings'])})")
|
|
38
|
+
for warning in results['warnings']:
|
|
39
|
+
print(f" - {warning}")
|
|
40
|
+
|
|
41
|
+
if results['passed']:
|
|
42
|
+
print(f"\n✅ Passed ({len(results['passed'])})")
|
|
43
|
+
for passed in results['passed']:
|
|
44
|
+
print(f" - {passed}")
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
if __name__ == "__main__":
|
|
48
|
+
if len(sys.argv) < 2:
|
|
49
|
+
print("Usage: python validate.py <project_path>")
|
|
50
|
+
sys.exit(1)
|
|
51
|
+
|
|
52
|
+
project_path = sys.argv[1]
|
|
53
|
+
results = validate(project_path)
|
|
54
|
+
print_results(results)
|
|
55
|
+
|
|
56
|
+
sys.exit(1 if results['errors'] else 0)
|
|
@@ -0,0 +1,255 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: database-design
|
|
3
|
+
description: Database design principles and decision-making. Use when designing schemas, choosing databases, selecting ORMs, or optimizing queries. Covers schema design, indexing strategy, ORM selection, migrations.
|
|
4
|
+
allowed-tools: Read, Write, Edit, Glob, Grep
|
|
5
|
+
version: 2.0
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
# Database Design - Principles & Decision Making
|
|
9
|
+
|
|
10
|
+
> **Philosophy:** Choose the right database and design for the context. Learn to THINK, not copy SQL patterns.
|
|
11
|
+
|
|
12
|
+
---
|
|
13
|
+
|
|
14
|
+
## Database Selection Decision Tree
|
|
15
|
+
|
|
16
|
+
```
|
|
17
|
+
What are your requirements?
|
|
18
|
+
│
|
|
19
|
+
├─ Simple app / Embedded / Edge?
|
|
20
|
+
│ └─ → SQLite / Turso / LibSQL
|
|
21
|
+
│
|
|
22
|
+
├─ Full relational / Complex queries?
|
|
23
|
+
│ └─ → PostgreSQL (self-hosted or managed)
|
|
24
|
+
│
|
|
25
|
+
├─ Serverless / Edge-first?
|
|
26
|
+
│ └─ → Neon / PlanetScale / Turso
|
|
27
|
+
│
|
|
28
|
+
├─ Document-oriented / Flexible schema?
|
|
29
|
+
│ └─ → MongoDB / Firestore
|
|
30
|
+
│
|
|
31
|
+
├─ Real-time updates required?
|
|
32
|
+
│ └─ → Firebase / Supabase Realtime
|
|
33
|
+
│
|
|
34
|
+
├─ Time-series data?
|
|
35
|
+
│ └─ → TimescaleDB / InfluxDB
|
|
36
|
+
│
|
|
37
|
+
└─ Graph relationships?
|
|
38
|
+
└─ → Neo4j / ArangoDB
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
---
|
|
42
|
+
|
|
43
|
+
## Schema Design Principles
|
|
44
|
+
|
|
45
|
+
### Normalization Levels
|
|
46
|
+
|
|
47
|
+
| Level | Description | Use Case |
|
|
48
|
+
| ---------------- | ---------------------------------- | --------------------- |
|
|
49
|
+
| **1NF** | Atomic values, no repeating groups | Always |
|
|
50
|
+
| **2NF** | 1NF + no partial dependencies | Standard apps |
|
|
51
|
+
| **3NF** | 2NF + no transitive dependencies | Most applications |
|
|
52
|
+
| **BCNF** | Stronger 3NF | Complex schemas |
|
|
53
|
+
| **Denormalized** | Intentional redundancy | Read-heavy, analytics |
|
|
54
|
+
|
|
55
|
+
### When to Denormalize
|
|
56
|
+
|
|
57
|
+
| Scenario | Consider Denormalization |
|
|
58
|
+
| ----------------------------- | ------------------------ |
|
|
59
|
+
| Frequent JOINs on same tables | ✅ Yes |
|
|
60
|
+
| Read-heavy workload | ✅ Yes |
|
|
61
|
+
| Real-time analytics | ✅ Yes |
|
|
62
|
+
| Write-heavy workload | ❌ No |
|
|
63
|
+
| Data integrity critical | ❌ No |
|
|
64
|
+
|
|
65
|
+
---
|
|
66
|
+
|
|
67
|
+
## Primary Key Selection
|
|
68
|
+
|
|
69
|
+
| Strategy | Pros | Cons | Best For |
|
|
70
|
+
| ------------------ | ------------------ | ---------------- | --------------- |
|
|
71
|
+
| **Auto-increment** | Simple, sequential | Not distributed | Single DB |
|
|
72
|
+
| **UUID v4** | Globally unique | Random, 36 chars | Distributed |
|
|
73
|
+
| **ULID** | Sortable, unique | 26 chars | Time-ordered |
|
|
74
|
+
| **UUID v7** | Sortable, unique | Newer standard | Modern apps |
|
|
75
|
+
| **Composite** | Natural keys | Complex JOINs | Junction tables |
|
|
76
|
+
|
|
77
|
+
**Recommendation:** Use UUID v7 or ULID for new projects (time-sortable + unique).
|
|
78
|
+
|
|
79
|
+
---
|
|
80
|
+
|
|
81
|
+
## Indexing Strategy
|
|
82
|
+
|
|
83
|
+
### Index Types
|
|
84
|
+
|
|
85
|
+
| Type | Use Case | Example |
|
|
86
|
+
| ------------- | -------------------------- | -------------------------- |
|
|
87
|
+
| **B-Tree** | Equality, range queries | `WHERE status = 'active'` |
|
|
88
|
+
| **Hash** | Exact match only | `WHERE id = 123` |
|
|
89
|
+
| **GIN** | Full-text, arrays, JSONB | `WHERE tags @> ARRAY['a']` |
|
|
90
|
+
| **GiST** | Geometric, range types | `WHERE location <@ box` |
|
|
91
|
+
| **Composite** | Multi-column queries | `WHERE a = 1 AND b = 2` |
|
|
92
|
+
| **Partial** | Subset of rows | `WHERE deleted_at IS NULL` |
|
|
93
|
+
| **Covering** | Include all SELECT columns | Avoid table lookup |
|
|
94
|
+
|
|
95
|
+
### Indexing Rules
|
|
96
|
+
|
|
97
|
+
| ✅ Index | ❌ Don't Index |
|
|
98
|
+
| ------------------------ | ---------------------------- |
|
|
99
|
+
| WHERE clause columns | Low cardinality (bool, enum) |
|
|
100
|
+
| JOIN condition columns | Frequently updated columns |
|
|
101
|
+
| ORDER BY columns | Small tables (<1000 rows) |
|
|
102
|
+
| Foreign keys | Columns rarely queried |
|
|
103
|
+
| High cardinality columns | Already indexed via PK |
|
|
104
|
+
|
|
105
|
+
### Composite Index Order
|
|
106
|
+
|
|
107
|
+
```sql
|
|
108
|
+
-- Query: WHERE a = 1 AND b = 2 ORDER BY c
|
|
109
|
+
-- Index should be: (a, b, c)
|
|
110
|
+
|
|
111
|
+
-- Rule: Equality → Range → Sort
|
|
112
|
+
CREATE INDEX idx_example ON table (a, b, c);
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
---
|
|
116
|
+
|
|
117
|
+
## ORM Selection
|
|
118
|
+
|
|
119
|
+
| ORM | Language | Type Safety | Best For |
|
|
120
|
+
| -------------- | ---------- | ----------- | ----------------------- |
|
|
121
|
+
| **Drizzle** | TypeScript | ⭐⭐⭐ | Type-first, lightweight |
|
|
122
|
+
| **Prisma** | TypeScript | ⭐⭐⭐ | Full-featured, DX focus |
|
|
123
|
+
| **Kysely** | TypeScript | ⭐⭐⭐ | SQL-first, type-safe |
|
|
124
|
+
| **TypeORM** | TypeScript | ⭐⭐ | Enterprise, decorators |
|
|
125
|
+
| **SQLAlchemy** | Python | ⭐⭐⭐ | Full-featured, flexible |
|
|
126
|
+
| **GORM** | Go | ⭐⭐ | Go standard |
|
|
127
|
+
| **Eloquent** | PHP | ⭐⭐ | Laravel ecosystem |
|
|
128
|
+
|
|
129
|
+
### ORM Decision Tree
|
|
130
|
+
|
|
131
|
+
```
|
|
132
|
+
TypeScript project?
|
|
133
|
+
├─ Yes → Need raw SQL control?
|
|
134
|
+
│ ├─ Yes → Kysely or Drizzle
|
|
135
|
+
│ └─ No → Prisma
|
|
136
|
+
│
|
|
137
|
+
└─ No → Use language-native ORM
|
|
138
|
+
├─ Python → SQLAlchemy
|
|
139
|
+
├─ Go → GORM
|
|
140
|
+
└─ PHP → Eloquent
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
---
|
|
144
|
+
|
|
145
|
+
## Query Optimization
|
|
146
|
+
|
|
147
|
+
### N+1 Problem
|
|
148
|
+
|
|
149
|
+
```typescript
|
|
150
|
+
// ❌ N+1 Problem
|
|
151
|
+
const users = await db.query("SELECT * FROM users");
|
|
152
|
+
for (const user of users) {
|
|
153
|
+
user.posts = await db.query("SELECT * FROM posts WHERE user_id = ?", user.id);
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
// ✅ Eager Loading
|
|
157
|
+
const users = await db.query(`
|
|
158
|
+
SELECT users.*, posts.*
|
|
159
|
+
FROM users
|
|
160
|
+
LEFT JOIN posts ON posts.user_id = users.id
|
|
161
|
+
`);
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
### EXPLAIN ANALYZE
|
|
165
|
+
|
|
166
|
+
```sql
|
|
167
|
+
EXPLAIN ANALYZE SELECT * FROM users WHERE email = 'test@example.com';
|
|
168
|
+
|
|
169
|
+
-- Look for:
|
|
170
|
+
-- ❌ Seq Scan (full table scan)
|
|
171
|
+
-- ✅ Index Scan (using index)
|
|
172
|
+
-- ❌ High "actual time"
|
|
173
|
+
-- ✅ Low "actual time"
|
|
174
|
+
```
|
|
175
|
+
|
|
176
|
+
---
|
|
177
|
+
|
|
178
|
+
## Migration Best Practices
|
|
179
|
+
|
|
180
|
+
### Safe Migrations
|
|
181
|
+
|
|
182
|
+
| Operation | Risk | Safe Approach |
|
|
183
|
+
| ------------- | ------ | ----------------------------------------------- |
|
|
184
|
+
| Add column | Low | Add nullable first, backfill, then set NOT NULL |
|
|
185
|
+
| Drop column | High | Stop reading first, deploy, then drop |
|
|
186
|
+
| Rename column | High | Add new, sync, drop old (multi-step) |
|
|
187
|
+
| Add index | Medium | CREATE INDEX CONCURRENTLY |
|
|
188
|
+
| Change type | High | Add new column, migrate, swap |
|
|
189
|
+
|
|
190
|
+
### Migration Checklist
|
|
191
|
+
|
|
192
|
+
- [ ] Tested on production-like data?
|
|
193
|
+
- [ ] Backward compatible?
|
|
194
|
+
- [ ] Rollback plan exists?
|
|
195
|
+
- [ ] No locks on large tables?
|
|
196
|
+
- [ ] Index created concurrently?
|
|
197
|
+
|
|
198
|
+
---
|
|
199
|
+
|
|
200
|
+
## Data Types Best Practices
|
|
201
|
+
|
|
202
|
+
| Data | ✅ Use | ❌ Avoid |
|
|
203
|
+
| ---------- | --------------- | ----------------------- |
|
|
204
|
+
| Money | `DECIMAL(19,4)` | `FLOAT`, `DOUBLE` |
|
|
205
|
+
| Timestamps | `TIMESTAMPTZ` | `TIMESTAMP` (no TZ) |
|
|
206
|
+
| Short text | `VARCHAR(n)` | `TEXT` for small fields |
|
|
207
|
+
| Long text | `TEXT` | `VARCHAR(10000)` |
|
|
208
|
+
| Boolean | `BOOLEAN` | `INT`, `CHAR(1)` |
|
|
209
|
+
| UUID | `UUID` type | `VARCHAR(36)` |
|
|
210
|
+
| JSON | `JSONB` | `JSON` (no indexing) |
|
|
211
|
+
|
|
212
|
+
---
|
|
213
|
+
|
|
214
|
+
## Anti-Patterns
|
|
215
|
+
|
|
216
|
+
| ❌ Don't | ✅ Do |
|
|
217
|
+
| ------------------------------------ | ------------------------ |
|
|
218
|
+
| Default to PostgreSQL for everything | Choose based on needs |
|
|
219
|
+
| Use `SELECT *` in production | Select specific columns |
|
|
220
|
+
| Skip indexing | Index WHERE/JOIN columns |
|
|
221
|
+
| Store structured data as JSON | Use proper columns |
|
|
222
|
+
| Ignore N+1 queries | Use eager loading |
|
|
223
|
+
| Run migrations without testing | Test on prod-like data |
|
|
224
|
+
| Store dates as strings | Use proper DATE types |
|
|
225
|
+
| No foreign key constraints | Define relationships |
|
|
226
|
+
|
|
227
|
+
---
|
|
228
|
+
|
|
229
|
+
## Database Design Checklist
|
|
230
|
+
|
|
231
|
+
Before implementation:
|
|
232
|
+
|
|
233
|
+
- [ ] Identified write vs read patterns?
|
|
234
|
+
- [ ] Chosen appropriate database type?
|
|
235
|
+
- [ ] Designed normalized schema (3NF)?
|
|
236
|
+
- [ ] Identified denormalization needs?
|
|
237
|
+
- [ ] Selected primary key strategy?
|
|
238
|
+
- [ ] Planned indexing strategy?
|
|
239
|
+
- [ ] Chosen ORM for project?
|
|
240
|
+
- [ ] Defined migration strategy?
|
|
241
|
+
|
|
242
|
+
---
|
|
243
|
+
|
|
244
|
+
## Related Skills
|
|
245
|
+
|
|
246
|
+
| Need | Skill |
|
|
247
|
+
| ----------------- | ----------------------- |
|
|
248
|
+
| API design | `api-patterns` |
|
|
249
|
+
| Backend patterns | `nodejs-best-practices` |
|
|
250
|
+
| Query performance | `performance-profiling` |
|
|
251
|
+
| Security | `security-fundamentals` |
|
|
252
|
+
|
|
253
|
+
---
|
|
254
|
+
|
|
255
|
+
> **Remember:** The best database design is one that matches your access patterns. Design for how data is used, not just how it's stored.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
# Assets directory - add templates, images, etc.
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
# Reference Documentation for Database Design
|
|
2
|
+
|
|
3
|
+
[TODO: Add detailed reference content here]
|
|
4
|
+
|
|
5
|
+
## Overview
|
|
6
|
+
|
|
7
|
+
[Detailed explanation of concepts]
|
|
8
|
+
|
|
9
|
+
## Deep Dive Topics
|
|
10
|
+
|
|
11
|
+
### Topic 1
|
|
12
|
+
|
|
13
|
+
[Content]
|
|
14
|
+
|
|
15
|
+
### Topic 2
|
|
16
|
+
|
|
17
|
+
[Content]
|
|
18
|
+
|
|
19
|
+
## Examples
|
|
20
|
+
|
|
21
|
+
[Real-world examples]
|