@iamnishankhan/opencode-kit-grok 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/bin/cli.js +46 -0
- package/kit/.opencode/AGENTS.md +392 -0
- package/kit/.opencode/README.md +71 -0
- package/kit/.opencode/USAGE.md +405 -0
- package/kit/.opencode/agents/backend-specialist.md +278 -0
- package/kit/.opencode/agents/code-archaeologist.md +114 -0
- package/kit/.opencode/agents/database-architect.md +233 -0
- package/kit/.opencode/agents/debugger.md +234 -0
- package/kit/.opencode/agents/devops-engineer.md +252 -0
- package/kit/.opencode/agents/documentation-writer.md +111 -0
- package/kit/.opencode/agents/explorer-agent.md +83 -0
- package/kit/.opencode/agents/frontend-specialist.md +606 -0
- package/kit/.opencode/agents/game-developer.md +169 -0
- package/kit/.opencode/agents/mobile-developer.md +385 -0
- package/kit/.opencode/agents/orchestrator.md +213 -0
- package/kit/.opencode/agents/penetration-tester.md +197 -0
- package/kit/.opencode/agents/performance-optimizer.md +194 -0
- package/kit/.opencode/agents/product-manager.md +120 -0
- package/kit/.opencode/agents/product-owner.md +103 -0
- package/kit/.opencode/agents/project-planner.md +418 -0
- package/kit/.opencode/agents/qa-automation-engineer.md +113 -0
- package/kit/.opencode/agents/security-auditor.md +179 -0
- package/kit/.opencode/agents/seo-specialist.md +119 -0
- package/kit/.opencode/agents/test-engineer.md +169 -0
- package/kit/.opencode/commands/brainstorm.md +113 -0
- package/kit/.opencode/commands/coordinate.md +72 -0
- package/kit/.opencode/commands/create.md +63 -0
- package/kit/.opencode/commands/debug.md +102 -0
- package/kit/.opencode/commands/deploy.md +175 -0
- package/kit/.opencode/commands/enhance.md +62 -0
- package/kit/.opencode/commands/orchestrate.md +241 -0
- package/kit/.opencode/commands/plan.md +89 -0
- package/kit/.opencode/commands/preview.md +80 -0
- package/kit/.opencode/commands/remember.md +67 -0
- package/kit/.opencode/commands/status.md +86 -0
- package/kit/.opencode/commands/test.md +143 -0
- package/kit/.opencode/commands/verify.md +71 -0
- package/kit/.opencode/memory/MEMORY.md +6 -0
- package/kit/.opencode/memory/feedback-history.md +9 -0
- package/kit/.opencode/memory/project-conventions.md +16 -0
- package/kit/.opencode/memory/tech-decisions.md +10 -0
- package/kit/.opencode/memory/user-preferences.md +9 -0
- package/kit/.opencode/opencode.json +15 -0
- package/kit/.opencode/scripts/README.md +95 -0
- package/kit/.opencode/scripts/auto_preview.py +149 -0
- package/kit/.opencode/scripts/checklist.py +75 -0
- package/kit/.opencode/scripts/component_registry.py +238 -0
- package/kit/.opencode/scripts/dependency_graph.py +73 -0
- package/kit/.opencode/scripts/generate_manifest.py +44 -0
- package/kit/.opencode/scripts/session_manager.py +120 -0
- package/kit/.opencode/scripts/tests/test_toolkit.py +238 -0
- package/kit/.opencode/scripts/validate_kit.py +397 -0
- package/kit/.opencode/scripts/validation_runner.py +216 -0
- package/kit/.opencode/scripts/verify_all.py +85 -0
- package/kit/.opencode/skills/api-patterns/SKILL.md +83 -0
- package/kit/.opencode/skills/api-patterns/api-style.md +42 -0
- package/kit/.opencode/skills/api-patterns/auth.md +24 -0
- package/kit/.opencode/skills/api-patterns/documentation.md +26 -0
- package/kit/.opencode/skills/api-patterns/graphql.md +41 -0
- package/kit/.opencode/skills/api-patterns/rate-limiting.md +31 -0
- package/kit/.opencode/skills/api-patterns/response.md +37 -0
- package/kit/.opencode/skills/api-patterns/rest.md +40 -0
- package/kit/.opencode/skills/api-patterns/scripts/api_validator.py +211 -0
- package/kit/.opencode/skills/api-patterns/security-testing.md +122 -0
- package/kit/.opencode/skills/api-patterns/trpc.md +41 -0
- package/kit/.opencode/skills/api-patterns/versioning.md +22 -0
- package/kit/.opencode/skills/app-builder/SKILL.md +78 -0
- package/kit/.opencode/skills/app-builder/agent-coordination.md +71 -0
- package/kit/.opencode/skills/app-builder/feature-building.md +53 -0
- package/kit/.opencode/skills/app-builder/project-detection.md +45 -0
- package/kit/.opencode/skills/app-builder/scaffolding.md +110 -0
- package/kit/.opencode/skills/app-builder/tech-stack.md +41 -0
- package/kit/.opencode/skills/app-builder/templates/SKILL.md +39 -0
- package/kit/.opencode/skills/app-builder/templates/astro-static/TEMPLATE.md +78 -0
- package/kit/.opencode/skills/app-builder/templates/chrome-extension/TEMPLATE.md +96 -0
- package/kit/.opencode/skills/app-builder/templates/cli-tool/TEMPLATE.md +88 -0
- package/kit/.opencode/skills/app-builder/templates/electron-desktop/TEMPLATE.md +97 -0
- package/kit/.opencode/skills/app-builder/templates/express-api/TEMPLATE.md +89 -0
- package/kit/.opencode/skills/app-builder/templates/flutter-app/TEMPLATE.md +93 -0
- package/kit/.opencode/skills/app-builder/templates/monorepo-turborepo/TEMPLATE.md +97 -0
- package/kit/.opencode/skills/app-builder/templates/nextjs-fullstack/TEMPLATE.md +126 -0
- package/kit/.opencode/skills/app-builder/templates/nextjs-saas/TEMPLATE.md +125 -0
- package/kit/.opencode/skills/app-builder/templates/nextjs-static/TEMPLATE.md +174 -0
- package/kit/.opencode/skills/app-builder/templates/nuxt-app/TEMPLATE.md +127 -0
- package/kit/.opencode/skills/app-builder/templates/python-fastapi/TEMPLATE.md +94 -0
- package/kit/.opencode/skills/app-builder/templates/react-native-app/TEMPLATE.md +121 -0
- package/kit/.opencode/skills/architecture/SKILL.md +57 -0
- package/kit/.opencode/skills/architecture/context-discovery.md +43 -0
- package/kit/.opencode/skills/architecture/examples.md +94 -0
- package/kit/.opencode/skills/architecture/pattern-selection.md +68 -0
- package/kit/.opencode/skills/architecture/patterns-reference.md +50 -0
- package/kit/.opencode/skills/architecture/trade-off-analysis.md +77 -0
- package/kit/.opencode/skills/bash-linux/SKILL.md +201 -0
- package/kit/.opencode/skills/batch-operations/SKILL.md +105 -0
- package/kit/.opencode/skills/behavioral-modes/SKILL.md +253 -0
- package/kit/.opencode/skills/brainstorming/SKILL.md +178 -0
- package/kit/.opencode/skills/brainstorming/dynamic-questioning.md +350 -0
- package/kit/.opencode/skills/clean-code/SKILL.md +201 -0
- package/kit/.opencode/skills/code-review-checklist/SKILL.md +111 -0
- package/kit/.opencode/skills/code-review-graph/SKILL.md +305 -0
- package/kit/.opencode/skills/context-compression/SKILL.md +145 -0
- package/kit/.opencode/skills/coordinator-mode/SKILL.md +208 -0
- package/kit/.opencode/skills/database-design/SKILL.md +54 -0
- package/kit/.opencode/skills/database-design/database-selection.md +43 -0
- package/kit/.opencode/skills/database-design/indexing.md +39 -0
- package/kit/.opencode/skills/database-design/migrations.md +48 -0
- package/kit/.opencode/skills/database-design/optimization.md +36 -0
- package/kit/.opencode/skills/database-design/orm-selection.md +30 -0
- package/kit/.opencode/skills/database-design/schema-design.md +56 -0
- package/kit/.opencode/skills/database-design/scripts/schema_validator.py +172 -0
- package/kit/.opencode/skills/deployment-procedures/SKILL.md +243 -0
- package/kit/.opencode/skills/design-spec/SKILL.md +185 -0
- package/kit/.opencode/skills/design-spec/collection.md +106 -0
- package/kit/.opencode/skills/documentation-templates/SKILL.md +196 -0
- package/kit/.opencode/skills/frontend-architecture/SKILL.md +245 -0
- package/kit/.opencode/skills/frontend-design/SKILL.md +1222 -0
- package/kit/.opencode/skills/frontend-design/redesign.md +178 -0
- package/kit/.opencode/skills/frontend-design/scripts/accessibility_checker.py +145 -0
- package/kit/.opencode/skills/frontend-design/scripts/ux_audit.py +722 -0
- package/kit/.opencode/skills/frontend-design/style-brutalist.md +92 -0
- package/kit/.opencode/skills/frontend-design/style-minimalist.md +85 -0
- package/kit/.opencode/skills/game-development/2d-games/SKILL.md +118 -0
- package/kit/.opencode/skills/game-development/3d-games/SKILL.md +134 -0
- package/kit/.opencode/skills/game-development/SKILL.md +169 -0
- package/kit/.opencode/skills/game-development/game-art/SKILL.md +184 -0
- package/kit/.opencode/skills/game-development/game-audio/SKILL.md +189 -0
- package/kit/.opencode/skills/game-development/game-design/SKILL.md +128 -0
- package/kit/.opencode/skills/game-development/mobile-games/SKILL.md +107 -0
- package/kit/.opencode/skills/game-development/multiplayer/SKILL.md +131 -0
- package/kit/.opencode/skills/game-development/pc-games/SKILL.md +143 -0
- package/kit/.opencode/skills/game-development/vr-ar/SKILL.md +122 -0
- package/kit/.opencode/skills/game-development/web-games/SKILL.md +149 -0
- package/kit/.opencode/skills/geo-fundamentals/SKILL.md +158 -0
- package/kit/.opencode/skills/geo-fundamentals/scripts/geo_checker.py +273 -0
- package/kit/.opencode/skills/i18n-localization/SKILL.md +156 -0
- package/kit/.opencode/skills/i18n-localization/scripts/i18n_checker.py +223 -0
- package/kit/.opencode/skills/intelligent-routing/SKILL.md +337 -0
- package/kit/.opencode/skills/lint-and-validate/SKILL.md +47 -0
- package/kit/.opencode/skills/lint-and-validate/scripts/lint_runner.py +184 -0
- package/kit/.opencode/skills/lint-and-validate/scripts/type_coverage.py +245 -0
- package/kit/.opencode/skills/mcp-builder/SKILL.md +205 -0
- package/kit/.opencode/skills/memory-system/SKILL.md +181 -0
- package/kit/.opencode/skills/mobile-design/SKILL.md +396 -0
- package/kit/.opencode/skills/mobile-design/decision-trees.md +516 -0
- package/kit/.opencode/skills/mobile-design/mobile-backend.md +491 -0
- package/kit/.opencode/skills/mobile-design/mobile-color-system.md +420 -0
- package/kit/.opencode/skills/mobile-design/mobile-debugging.md +122 -0
- package/kit/.opencode/skills/mobile-design/mobile-design-thinking.md +357 -0
- package/kit/.opencode/skills/mobile-design/mobile-navigation.md +458 -0
- package/kit/.opencode/skills/mobile-design/mobile-performance.md +767 -0
- package/kit/.opencode/skills/mobile-design/mobile-testing.md +356 -0
- package/kit/.opencode/skills/mobile-design/mobile-typography.md +433 -0
- package/kit/.opencode/skills/mobile-design/platform-android.md +666 -0
- package/kit/.opencode/skills/mobile-design/platform-ios.md +561 -0
- package/kit/.opencode/skills/mobile-design/scripts/mobile_audit.py +670 -0
- package/kit/.opencode/skills/mobile-design/touch-psychology.md +537 -0
- package/kit/.opencode/skills/nextjs-react-expert/1-async-eliminating-waterfalls.md +351 -0
- package/kit/.opencode/skills/nextjs-react-expert/2-bundle-bundle-size-optimization.md +240 -0
- package/kit/.opencode/skills/nextjs-react-expert/3-server-server-side-performance.md +490 -0
- package/kit/.opencode/skills/nextjs-react-expert/4-client-client-side-data-fetching.md +264 -0
- package/kit/.opencode/skills/nextjs-react-expert/5-rerender-re-render-optimization.md +581 -0
- package/kit/.opencode/skills/nextjs-react-expert/6-rendering-rendering-performance.md +432 -0
- package/kit/.opencode/skills/nextjs-react-expert/7-js-javascript-performance.md +684 -0
- package/kit/.opencode/skills/nextjs-react-expert/8-advanced-advanced-patterns.md +150 -0
- package/kit/.opencode/skills/nextjs-react-expert/9-cache-components.md +103 -0
- package/kit/.opencode/skills/nextjs-react-expert/SKILL.md +293 -0
- package/kit/.opencode/skills/nextjs-react-expert/scripts/convert_rules.py +222 -0
- package/kit/.opencode/skills/nextjs-react-expert/scripts/react_performance_checker.py +281 -0
- package/kit/.opencode/skills/nodejs-best-practices/SKILL.md +336 -0
- package/kit/.opencode/skills/parallel-agents/SKILL.md +192 -0
- package/kit/.opencode/skills/performance-profiling/SKILL.md +145 -0
- package/kit/.opencode/skills/performance-profiling/scripts/bundle_analyzer.py +120 -0
- package/kit/.opencode/skills/performance-profiling/scripts/lighthouse_audit.py +108 -0
- package/kit/.opencode/skills/plan-writing/SKILL.md +153 -0
- package/kit/.opencode/skills/powershell-windows/SKILL.md +169 -0
- package/kit/.opencode/skills/python-patterns/SKILL.md +443 -0
- package/kit/.opencode/skills/red-team-tactics/SKILL.md +201 -0
- package/kit/.opencode/skills/rust-pro/SKILL.md +177 -0
- package/kit/.opencode/skills/seo-fundamentals/SKILL.md +131 -0
- package/kit/.opencode/skills/seo-fundamentals/scripts/seo_checker.py +219 -0
- package/kit/.opencode/skills/server-management/SKILL.md +163 -0
- package/kit/.opencode/skills/simplify-code/SKILL.md +131 -0
- package/kit/.opencode/skills/skillify/SKILL.md +115 -0
- package/kit/.opencode/skills/systematic-debugging/SKILL.md +111 -0
- package/kit/.opencode/skills/tailwind-patterns/SKILL.md +271 -0
- package/kit/.opencode/skills/tdd-workflow/SKILL.md +151 -0
- package/kit/.opencode/skills/testing-patterns/SKILL.md +180 -0
- package/kit/.opencode/skills/testing-patterns/scripts/test_runner.py +219 -0
- package/kit/.opencode/skills/verify-changes/SKILL.md +127 -0
- package/kit/.opencode/skills/vulnerability-scanner/SKILL.md +278 -0
- package/kit/.opencode/skills/vulnerability-scanner/checklists.md +124 -0
- package/kit/.opencode/skills/vulnerability-scanner/scripts/dependency_analyzer.py +144 -0
- package/kit/.opencode/skills/vulnerability-scanner/scripts/security_scan.py +410 -0
- package/kit/.opencode/skills/web-design-guidelines/SKILL.md +56 -0
- package/kit/.opencode/skills/webapp-testing/SKILL.md +189 -0
- package/kit/.opencode/skills/webapp-testing/scripts/playwright_runner.py +123 -0
- package/lib/init.js +61 -0
- package/package.json +21 -0
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: context-compression
|
|
3
|
+
description: Manage and compress conversation context in long sessions. Detect when context is growing large, summarize completed work phases, archive old findings while preserving key decisions. Prevents context degradation.
|
|
4
|
+
compatibility: opencode
|
|
5
|
+
metadata:
|
|
6
|
+
when_to_use: "\"When a session has 20+ turns, when context feels repetitive, when the agent is losing track of earlier work, or when the user says 'summarize what we've done'. NOT for short sessions.\""
|
|
7
|
+
version: "1.0.0"
|
|
8
|
+
---
|
|
9
|
+
# Context Compression — Long Session Management
|
|
10
|
+
|
|
11
|
+
> Keep sessions productive by compressing completed work while preserving key decisions.
|
|
12
|
+
|
|
13
|
+
## Overview
|
|
14
|
+
|
|
15
|
+
Long sessions (30+ turns) cause context degradation — the AI loses track of earlier work, repeats itself, or forgets decisions. Context compression proactively summarizes completed phases so the context window stays focused on active work.
|
|
16
|
+
|
|
17
|
+
**Token Impact:** Recovers 5,000-15,000 tokens in long sessions by replacing verbose tool outputs with semantic summaries.
|
|
18
|
+
|
|
19
|
+
---
|
|
20
|
+
|
|
21
|
+
## When to Compress
|
|
22
|
+
|
|
23
|
+
| Signal | Action |
|
|
24
|
+
|---|---|
|
|
25
|
+
| Session has 20+ turns | Consider proactive compression |
|
|
26
|
+
| Agent repeats earlier suggestions | Context is saturated — compress now |
|
|
27
|
+
| User says "we already discussed this" | Compress immediately |
|
|
28
|
+
| Switching to a new phase of work | Compress the completed phase |
|
|
29
|
+
| Large tool output (500+ lines) | Micro-compact the output |
|
|
30
|
+
|
|
31
|
+
---
|
|
32
|
+
|
|
33
|
+
## Compression Levels
|
|
34
|
+
|
|
35
|
+
### Level 1: Micro-Compact (Tool Output)
|
|
36
|
+
|
|
37
|
+
Compress individual tool outputs while retaining semantic content:
|
|
38
|
+
|
|
39
|
+
```
|
|
40
|
+
❌ Before (raw grep output — 200 lines, ~4,000 tokens):
|
|
41
|
+
src/auth/jwt.ts:15: import { verify } from 'jsonwebtoken'
|
|
42
|
+
src/auth/jwt.ts:23: export function validateToken(token: string) {
|
|
43
|
+
src/auth/jwt.ts:24: try {
|
|
44
|
+
src/auth/jwt.ts:25: const decoded = verify(token, SECRET)
|
|
45
|
+
... (195 more lines)
|
|
46
|
+
|
|
47
|
+
✅ After (micro-compact — 5 lines, ~100 tokens):
|
|
48
|
+
Grep results for "jwt": Found 8 files, 42 matches.
|
|
49
|
+
Key files: src/auth/jwt.ts (main JWT logic), src/middleware/auth.ts (middleware),
|
|
50
|
+
src/api/login.ts (token creation). Token validation at jwt.ts:23-40.
|
|
51
|
+
Error handling at jwt.ts:42-55. Secret loaded from env at jwt.ts:8.
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
### Level 2: Phase Summary
|
|
55
|
+
|
|
56
|
+
Replace a completed work phase with a summary:
|
|
57
|
+
|
|
58
|
+
```
|
|
59
|
+
❌ Before (full research transcript — ~3,000 tokens):
|
|
60
|
+
[turn 1] Read package.json...
|
|
61
|
+
[turn 2] Read src/index.ts...
|
|
62
|
+
[turn 3] Grep for "auth"...
|
|
63
|
+
[turn 4] Found 8 files related to auth...
|
|
64
|
+
[turn 5] Read src/auth/jwt.ts...
|
|
65
|
+
... (10 more turns of exploration)
|
|
66
|
+
|
|
67
|
+
✅ After (phase summary — ~200 tokens):
|
|
68
|
+
## Research Phase Complete
|
|
69
|
+
- Project: Next.js 15 app with JWT auth
|
|
70
|
+
- Auth files: 8 files in src/auth/, src/middleware/, src/api/
|
|
71
|
+
- Token flow: login → create JWT → store in httpOnly cookie → validate in middleware
|
|
72
|
+
- Bug location: src/auth/jwt.ts:45 — expiry check uses `<` instead of `<=`
|
|
73
|
+
- Decision: Fix the comparison operator, add edge case test
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
### Level 3: Session Checkpoint
|
|
77
|
+
|
|
78
|
+
Full session summary for long-running work:
|
|
79
|
+
|
|
80
|
+
```markdown
|
|
81
|
+
## Session Checkpoint (Turn 35)
|
|
82
|
+
|
|
83
|
+
### Completed
|
|
84
|
+
- [x] Researched auth system (8 files, JWT flow mapped)
|
|
85
|
+
- [x] Fixed token expiry bug in jwt.ts:45
|
|
86
|
+
- [x] Added edge case test in jwt.test.ts
|
|
87
|
+
- [x] Verified: all 42 tests passing
|
|
88
|
+
|
|
89
|
+
### In Progress
|
|
90
|
+
- [ ] Update API documentation
|
|
91
|
+
- [ ] Review related middleware
|
|
92
|
+
|
|
93
|
+
### Key Decisions
|
|
94
|
+
1. Keep httpOnly cookies (not localStorage) for token storage
|
|
95
|
+
2. Use `<=` for expiry check to include exact-moment expiry
|
|
96
|
+
3. Add 5-minute grace period for clock skew
|
|
97
|
+
|
|
98
|
+
### Files Modified
|
|
99
|
+
- src/auth/jwt.ts (line 45: comparison fix)
|
|
100
|
+
- tests/auth/jwt.test.ts (added 3 edge case tests)
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
---
|
|
104
|
+
|
|
105
|
+
## Compression Protocol
|
|
106
|
+
|
|
107
|
+
### Step 1: Identify Completed Phases
|
|
108
|
+
```
|
|
109
|
+
What work is DONE and won't be revisited?
|
|
110
|
+
→ Research findings already synthesized
|
|
111
|
+
→ Implementation already verified
|
|
112
|
+
→ Decisions already made and applied
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
### Step 2: Extract Key Information
|
|
116
|
+
```
|
|
117
|
+
From the completed phase, preserve:
|
|
118
|
+
✅ Decisions made and WHY
|
|
119
|
+
✅ File paths and line numbers of changes
|
|
120
|
+
✅ Key findings that inform ongoing work
|
|
121
|
+
✅ Error messages or test results (summarized)
|
|
122
|
+
|
|
123
|
+
Discard:
|
|
124
|
+
❌ Step-by-step tool invocation details
|
|
125
|
+
❌ Full file contents that were read
|
|
126
|
+
❌ Exploratory dead-ends that didn't lead anywhere
|
|
127
|
+
❌ Verbose error stack traces (keep the message only)
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
### Step 3: Write Summary
|
|
131
|
+
```
|
|
132
|
+
Use the Phase Summary format above.
|
|
133
|
+
Keep to 100-300 tokens per completed phase.
|
|
134
|
+
Include enough detail to resume work without re-reading.
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
---
|
|
138
|
+
|
|
139
|
+
## Best Practices
|
|
140
|
+
|
|
141
|
+
1. **Compress phases, not facts** — Individual decisions should stay, full transcripts should go
|
|
142
|
+
2. **Preserve "why" over "what"** — Why a decision was made matters more than the exact commands run
|
|
143
|
+
3. **Never auto-compress** — Always tell the user "I'm summarizing the completed research phase to keep context focused"
|
|
144
|
+
4. **Keep file references** — Always preserve file paths and line numbers in summaries
|
|
145
|
+
5. **Checkpoint on phase transitions** — Natural compression point when switching from research to implementation
|
|
@@ -0,0 +1,208 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: coordinator-mode
|
|
3
|
+
description: Advanced multi-agent orchestration with parallel workers, synthesis protocols, and coordinator lifecycle. Use when complex tasks require multiple agents working in parallel with intelligent result synthesis.
|
|
4
|
+
compatibility: opencode
|
|
5
|
+
metadata:
|
|
6
|
+
when_to_use: "\"When the user needs multi-agent coordination, parallel task execution, complex multi-domain work, or when /coordinate or /orchestrate is invoked. NOT for single-domain tasks.\""
|
|
7
|
+
version: "1.0.0"
|
|
8
|
+
---
|
|
9
|
+
# Coordinator Mode — Multi-Agent Orchestration
|
|
10
|
+
|
|
11
|
+
> Distilled from production-proven coordinator patterns. Transforms sequential agent chains into intelligent parallel orchestration.
|
|
12
|
+
|
|
13
|
+
## Overview
|
|
14
|
+
|
|
15
|
+
The Coordinator is a specialized orchestration mode where **you become the conductor** — decomposing complex tasks into worker subtasks, dispatching them in parallel where safe, and synthesizing results into cohesive output.
|
|
16
|
+
|
|
17
|
+
**You are NOT a worker. You are the coordinator.** Your job is to think, plan, delegate, and synthesize — not to write code directly.
|
|
18
|
+
|
|
19
|
+
---
|
|
20
|
+
|
|
21
|
+
## Coordinator Lifecycle
|
|
22
|
+
|
|
23
|
+
```
|
|
24
|
+
User Request
|
|
25
|
+
↓
|
|
26
|
+
1. DECOMPOSE — Break task into worker subtasks
|
|
27
|
+
↓
|
|
28
|
+
2. CLASSIFY — Mark each subtask: Research | Implementation | Verification
|
|
29
|
+
↓
|
|
30
|
+
3. DISPATCH — Launch workers (parallel for reads, sequential for writes)
|
|
31
|
+
↓
|
|
32
|
+
4. MONITOR — Track worker completion notifications
|
|
33
|
+
↓
|
|
34
|
+
5. SYNTHESIZE — Combine results into unified response
|
|
35
|
+
↓
|
|
36
|
+
6. VERIFY — Ensure completeness before reporting to user
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
---
|
|
40
|
+
|
|
41
|
+
## Phase-Based Workflow
|
|
42
|
+
|
|
43
|
+
| Phase | Purpose | Concurrency | Worker Type |
|
|
44
|
+
|-------|---------|-------------|-------------|
|
|
45
|
+
| **Research** | Gather information, explore codebase | ✅ Fully parallel | Read-only agents |
|
|
46
|
+
| **Synthesis** | Analyze findings, plan approach | ❌ Coordinator only | No workers |
|
|
47
|
+
| **Implementation** | Make changes to code/files | ⚠️ Sequential per file set | Write-capable agents |
|
|
48
|
+
| **Verification** | Test, lint, validate changes | ✅ Parallel (independent) | Test/security agents |
|
|
49
|
+
|
|
50
|
+
> 🔴 **Rule:** NEVER skip the Synthesis phase. Research → direct Implementation = poor results.
|
|
51
|
+
|
|
52
|
+
---
|
|
53
|
+
|
|
54
|
+
## Concurrency Rules
|
|
55
|
+
|
|
56
|
+
### Safe to Parallelize
|
|
57
|
+
- ✅ Multiple agents reading different files
|
|
58
|
+
- ✅ Security audit + performance audit (read-only)
|
|
59
|
+
- ✅ Test runner + linter (independent)
|
|
60
|
+
- ✅ Exploring different directories
|
|
61
|
+
|
|
62
|
+
### Must Be Sequential
|
|
63
|
+
- ❌ Two agents writing to the same file
|
|
64
|
+
- ❌ Implementation that depends on another agent's output
|
|
65
|
+
- ❌ Database migration + code that uses the new schema
|
|
66
|
+
- ❌ API change + frontend that consumes the API
|
|
67
|
+
|
|
68
|
+
---
|
|
69
|
+
|
|
70
|
+
## Worker Prompt Writing Guide
|
|
71
|
+
|
|
72
|
+
### 🔴 The Golden Rule: Never Delegate Understanding
|
|
73
|
+
|
|
74
|
+
```
|
|
75
|
+
❌ WRONG: "Based on your findings, fix the bug"
|
|
76
|
+
❌ WRONG: "Based on the research, implement it"
|
|
77
|
+
❌ WRONG: "Look at the code and do what's needed"
|
|
78
|
+
|
|
79
|
+
✅ RIGHT: "The bug is in src/auth/jwt.ts line 45 — the token expiry
|
|
80
|
+
check uses `<` instead of `<=`, causing off-by-one failures
|
|
81
|
+
at exactly the expiry time. Change line 45 from
|
|
82
|
+
`if (now < expiry)` to `if (now <= expiry)`"
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
> **Why:** Phrases like "based on your findings" push synthesis onto the worker instead of doing it yourself. Write prompts that prove YOU understood — include file paths, line numbers, what specifically to change.
|
|
86
|
+
|
|
87
|
+
### Writing Effective Worker Prompts
|
|
88
|
+
|
|
89
|
+
Brief the worker like a **smart colleague who just walked into the room**:
|
|
90
|
+
|
|
91
|
+
1. **Explain what** you're trying to accomplish and why
|
|
92
|
+
2. **Describe what** you've already learned or ruled out
|
|
93
|
+
3. **Give enough context** about the surrounding problem for judgment calls
|
|
94
|
+
4. **Be specific** about scope: what's in, what's out, what another agent handles
|
|
95
|
+
5. **State the output format** you expect ("report in under 200 words")
|
|
96
|
+
|
|
97
|
+
### Prompt Templates
|
|
98
|
+
|
|
99
|
+
#### Research Worker
|
|
100
|
+
```
|
|
101
|
+
Investigate [specific question] in [file/directory scope].
|
|
102
|
+
Context: We're trying to [goal] because [reason].
|
|
103
|
+
I've already checked [what you checked] and found [what you found].
|
|
104
|
+
Report: List [specific deliverable]. Under 200 words.
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
#### Implementation Worker
|
|
108
|
+
```
|
|
109
|
+
Modify [specific file(s)] to [specific change].
|
|
110
|
+
Context: [Why this change is needed].
|
|
111
|
+
The current code at [file:line] does [X], change it to [Y].
|
|
112
|
+
Constraints: Don't touch [out-of-scope files]. Another agent handles [related area].
|
|
113
|
+
Verify: [How the worker should confirm success].
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
#### Verification Worker
|
|
117
|
+
```
|
|
118
|
+
Verify that [specific change] works correctly.
|
|
119
|
+
Run: [specific commands].
|
|
120
|
+
Check: [what success looks like].
|
|
121
|
+
Report: Pass/fail with details on any failures.
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
---
|
|
125
|
+
|
|
126
|
+
## Fork Semantics
|
|
127
|
+
|
|
128
|
+
### When to Fork (vs. Spawn Fresh Agent)
|
|
129
|
+
|
|
130
|
+
| Scenario | Action | Why |
|
|
131
|
+
|----------|--------|-----|
|
|
132
|
+
| Open-ended research question | **Fork** (omit agent type) | Fork inherits context, shorter prompt |
|
|
133
|
+
| Independent parallel research | **Fork** multiple in one message | Each fork shares cache |
|
|
134
|
+
| Specialized domain work | **Spawn** (specify agent type) | Fresh specialist starts clean |
|
|
135
|
+
| Second opinion on your work | **Spawn** | Independent perspective |
|
|
136
|
+
|
|
137
|
+
### Fork Rules
|
|
138
|
+
|
|
139
|
+
1. **Don't peek.** Don't read the fork's output file mid-flight. You'll get a completion notification. Reading the transcript pulls tool noise into your context.
|
|
140
|
+
|
|
141
|
+
2. **Don't race.** After launching, you know nothing about what the fork found. Never fabricate or predict fork results. If the user asks before notification lands, say "the fork is still running."
|
|
142
|
+
|
|
143
|
+
3. **Keep prompts short.** Forks inherit your full context — write a *directive* (what to do), not a *briefing* (what the situation is).
|
|
144
|
+
|
|
145
|
+
---
|
|
146
|
+
|
|
147
|
+
## Anti-Patterns
|
|
148
|
+
|
|
149
|
+
| Anti-Pattern | Why It's Bad | Fix |
|
|
150
|
+
|---|---|---|
|
|
151
|
+
| "Look at the code and fix it" | Zero context = workers make wrong assumptions | Provide specific file paths, line numbers, and what to change |
|
|
152
|
+
| Skipping Research phase | Implementation without understanding = rework | Always research first, even briefly |
|
|
153
|
+
| Launching 10+ workers at once | Overwhelms synthesis, diminishing returns | 2-5 workers per round, synthesize, then more if needed |
|
|
154
|
+
| Fabricating worker results | User gets wrong information | Wait for actual notification, say "still running" if asked |
|
|
155
|
+
| Coordinator writes code directly | Loses orchestration benefits | Always delegate to appropriate specialist |
|
|
156
|
+
|
|
157
|
+
---
|
|
158
|
+
|
|
159
|
+
## Synthesis Protocol
|
|
160
|
+
|
|
161
|
+
After all workers complete:
|
|
162
|
+
|
|
163
|
+
```markdown
|
|
164
|
+
## Coordinator Synthesis
|
|
165
|
+
|
|
166
|
+
### Task: [Original Request]
|
|
167
|
+
|
|
168
|
+
### Workers Dispatched
|
|
169
|
+
| Worker | Type | Status | Key Finding |
|
|
170
|
+
|--------|------|--------|-------------|
|
|
171
|
+
| agent-1 | Research | ✅ | Found X in file Y |
|
|
172
|
+
| agent-2 | Research | ✅ | Identified Y pattern |
|
|
173
|
+
|
|
174
|
+
### Consolidated Analysis
|
|
175
|
+
[Your synthesis — not a copy-paste of worker output]
|
|
176
|
+
|
|
177
|
+
### Decision & Rationale
|
|
178
|
+
[What you decided based on ALL worker findings and why]
|
|
179
|
+
|
|
180
|
+
### Implementation Plan
|
|
181
|
+
1. [Specific change with file path]
|
|
182
|
+
2. [Specific change with file path]
|
|
183
|
+
|
|
184
|
+
### Remaining Risk
|
|
185
|
+
- [Anything workers flagged but couldn't resolve]
|
|
186
|
+
```
|
|
187
|
+
|
|
188
|
+
---
|
|
189
|
+
|
|
190
|
+
## Continue vs. Spawn Decision
|
|
191
|
+
|
|
192
|
+
| Situation | Action |
|
|
193
|
+
|-----------|--------|
|
|
194
|
+
| Worker completed, need follow-up on same topic | **Continue** (send message to worker ID) |
|
|
195
|
+
| Worker completed, need different domain work | **Spawn new** specialist |
|
|
196
|
+
| Worker failed, need retry with same context | **Continue** with corrected instructions |
|
|
197
|
+
| Worker failed, need fundamentally different approach | **Spawn new** |
|
|
198
|
+
|
|
199
|
+
---
|
|
200
|
+
|
|
201
|
+
## Best Practices
|
|
202
|
+
|
|
203
|
+
1. **Start with 2-3 workers** — add more after synthesis if needed
|
|
204
|
+
2. **Research before implementation** — always, even for "simple" tasks
|
|
205
|
+
3. **Synthesize, don't copy** — your summary should add insight, not repeat
|
|
206
|
+
4. **Verify independently** — verification workers shouldn't trust implementation workers
|
|
207
|
+
5. **Track state** — note which workers are pending/completed/failed
|
|
208
|
+
6. **Share scratchpad** — use a known directory for cross-worker artifacts
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: database-design
|
|
3
|
+
description: Database design principles and decision-making. Schema design, indexing strategy, ORM selection, serverless databases.
|
|
4
|
+
compatibility: opencode
|
|
5
|
+
metadata:
|
|
6
|
+
when_to_use: "\"When designing database schemas, choosing ORMs, planning migrations, or optimizing queries. When working with Prisma, Drizzle, or SQL files.\""
|
|
7
|
+
version: "1.0.0"
|
|
8
|
+
---
|
|
9
|
+
# Database Design
|
|
10
|
+
|
|
11
|
+
> **Learn to THINK, not copy SQL patterns.**
|
|
12
|
+
|
|
13
|
+
## 🎯 Selective Reading Rule
|
|
14
|
+
|
|
15
|
+
**Read ONLY files relevant to the request!** Check the content map, find what you need.
|
|
16
|
+
|
|
17
|
+
| File | Description | When to Read |
|
|
18
|
+
|------|-------------|--------------|
|
|
19
|
+
| `database-selection.md` | PostgreSQL vs Neon vs Turso vs SQLite | Choosing database |
|
|
20
|
+
| `orm-selection.md` | Drizzle vs Prisma vs Kysely | Choosing ORM |
|
|
21
|
+
| `schema-design.md` | Normalization, PKs, relationships | Designing schema |
|
|
22
|
+
| `indexing.md` | Index types, composite indexes | Performance tuning |
|
|
23
|
+
| `optimization.md` | N+1, EXPLAIN ANALYZE | Query optimization |
|
|
24
|
+
| `migrations.md` | Safe migrations, serverless DBs | Schema changes |
|
|
25
|
+
|
|
26
|
+
---
|
|
27
|
+
|
|
28
|
+
## ⚠️ Core Principle
|
|
29
|
+
|
|
30
|
+
- ASK user for database preferences when unclear
|
|
31
|
+
- Choose database/ORM based on CONTEXT
|
|
32
|
+
- Don't default to PostgreSQL for everything
|
|
33
|
+
|
|
34
|
+
---
|
|
35
|
+
|
|
36
|
+
## Decision Checklist
|
|
37
|
+
|
|
38
|
+
Before designing schema:
|
|
39
|
+
|
|
40
|
+
- [ ] Asked user about database preference?
|
|
41
|
+
- [ ] Chosen database for THIS context?
|
|
42
|
+
- [ ] Considered deployment environment?
|
|
43
|
+
- [ ] Planned index strategy?
|
|
44
|
+
- [ ] Defined relationship types?
|
|
45
|
+
|
|
46
|
+
---
|
|
47
|
+
|
|
48
|
+
## Anti-Patterns
|
|
49
|
+
|
|
50
|
+
❌ Default to PostgreSQL for simple apps (SQLite may suffice)
|
|
51
|
+
❌ Skip indexing
|
|
52
|
+
❌ Use SELECT * in production
|
|
53
|
+
❌ Store JSON when structured data is better
|
|
54
|
+
❌ Ignore N+1 queries
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
# Database Selection
|
|
2
|
+
|
|
3
|
+
> Choose database based on context, not default.
|
|
4
|
+
|
|
5
|
+
## Decision Tree
|
|
6
|
+
|
|
7
|
+
```
|
|
8
|
+
What are your requirements?
|
|
9
|
+
│
|
|
10
|
+
├── Full relational features needed
|
|
11
|
+
│ ├── Self-hosted → PostgreSQL
|
|
12
|
+
│ └── Serverless → Neon, Supabase
|
|
13
|
+
│
|
|
14
|
+
├── Edge deployment / Ultra-low latency
|
|
15
|
+
│ └── Turso (edge SQLite)
|
|
16
|
+
│
|
|
17
|
+
├── AI / Vector search
|
|
18
|
+
│ └── PostgreSQL + pgvector
|
|
19
|
+
│
|
|
20
|
+
├── Simple / Embedded / Local
|
|
21
|
+
│ └── SQLite
|
|
22
|
+
│
|
|
23
|
+
└── Global distribution
|
|
24
|
+
└── PlanetScale, CockroachDB, Turso
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
## Comparison
|
|
28
|
+
|
|
29
|
+
| Database | Best For | Trade-offs |
|
|
30
|
+
|----------|----------|------------|
|
|
31
|
+
| **PostgreSQL** | Full features, complex queries | Needs hosting |
|
|
32
|
+
| **Neon** | Serverless PG, branching | PG complexity |
|
|
33
|
+
| **Turso** | Edge, low latency | SQLite limitations |
|
|
34
|
+
| **SQLite** | Simple, embedded, local | Single-writer |
|
|
35
|
+
| **PlanetScale** | MySQL, global scale | FK support enabled per-database |
|
|
36
|
+
|
|
37
|
+
## Questions to Ask
|
|
38
|
+
|
|
39
|
+
1. What's the deployment environment?
|
|
40
|
+
2. How complex are the queries?
|
|
41
|
+
3. Is edge/serverless important?
|
|
42
|
+
4. Vector search needed?
|
|
43
|
+
5. Global distribution required?
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
# Indexing Principles
|
|
2
|
+
|
|
3
|
+
> When and how to create indexes effectively.
|
|
4
|
+
|
|
5
|
+
## When to Create Indexes
|
|
6
|
+
|
|
7
|
+
```
|
|
8
|
+
Index these:
|
|
9
|
+
├── Columns in WHERE clauses
|
|
10
|
+
├── Columns in JOIN conditions
|
|
11
|
+
├── Columns in ORDER BY
|
|
12
|
+
├── Foreign key columns
|
|
13
|
+
└── Unique constraints
|
|
14
|
+
|
|
15
|
+
Don't over-index:
|
|
16
|
+
├── Write-heavy tables (slower inserts)
|
|
17
|
+
├── Low-cardinality columns
|
|
18
|
+
├── Columns rarely queried
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
## Index Type Selection
|
|
22
|
+
|
|
23
|
+
| Type | Use For |
|
|
24
|
+
|------|---------|
|
|
25
|
+
| **B-tree** | General purpose, equality & range |
|
|
26
|
+
| **Hash** | Equality only, faster |
|
|
27
|
+
| **GIN** | JSONB, arrays, full-text |
|
|
28
|
+
| **GiST** | Geometric, range types |
|
|
29
|
+
| **HNSW/IVFFlat** | Vector similarity (pgvector) |
|
|
30
|
+
|
|
31
|
+
## Composite Index Principles
|
|
32
|
+
|
|
33
|
+
```
|
|
34
|
+
Order matters for composite indexes:
|
|
35
|
+
├── Equality columns first
|
|
36
|
+
├── Range columns last
|
|
37
|
+
├── Most selective first
|
|
38
|
+
└── Match query pattern
|
|
39
|
+
```
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
# Migration Principles
|
|
2
|
+
|
|
3
|
+
> Safe migration strategy for zero-downtime changes.
|
|
4
|
+
|
|
5
|
+
## Safe Migration Strategy
|
|
6
|
+
|
|
7
|
+
```
|
|
8
|
+
For zero-downtime changes:
|
|
9
|
+
│
|
|
10
|
+
├── Adding column
|
|
11
|
+
│ └── Add as nullable → backfill → add NOT NULL
|
|
12
|
+
│
|
|
13
|
+
├── Removing column
|
|
14
|
+
│ └── Stop using → deploy → remove column
|
|
15
|
+
│
|
|
16
|
+
├── Adding index
|
|
17
|
+
│ └── CREATE INDEX CONCURRENTLY (non-blocking)
|
|
18
|
+
│
|
|
19
|
+
└── Renaming column
|
|
20
|
+
└── Add new → migrate data → deploy → drop old
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
## Migration Philosophy
|
|
24
|
+
|
|
25
|
+
- Never make breaking changes in one step
|
|
26
|
+
- Test migrations on data copy first
|
|
27
|
+
- Have rollback plan
|
|
28
|
+
- Run in transaction when possible
|
|
29
|
+
|
|
30
|
+
## Serverless Databases
|
|
31
|
+
|
|
32
|
+
### Neon (Serverless PostgreSQL)
|
|
33
|
+
|
|
34
|
+
| Feature | Benefit |
|
|
35
|
+
|---------|---------|
|
|
36
|
+
| Scale to zero | Cost savings |
|
|
37
|
+
| Instant branching | Dev/preview |
|
|
38
|
+
| Full PostgreSQL | Compatibility |
|
|
39
|
+
| Autoscaling | Traffic handling |
|
|
40
|
+
|
|
41
|
+
### Turso (Edge SQLite)
|
|
42
|
+
|
|
43
|
+
| Feature | Benefit |
|
|
44
|
+
|---------|---------|
|
|
45
|
+
| Edge locations | Ultra-low latency |
|
|
46
|
+
| SQLite compatible | Simple |
|
|
47
|
+
| Generous free tier | Cost |
|
|
48
|
+
| Global distribution | Performance |
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
# Query Optimization
|
|
2
|
+
|
|
3
|
+
> N+1 problem, EXPLAIN ANALYZE, optimization priorities.
|
|
4
|
+
|
|
5
|
+
## N+1 Problem
|
|
6
|
+
|
|
7
|
+
```
|
|
8
|
+
What is N+1?
|
|
9
|
+
├── 1 query to get parent records
|
|
10
|
+
├── N queries to get related records
|
|
11
|
+
└── Very slow!
|
|
12
|
+
|
|
13
|
+
Solutions:
|
|
14
|
+
├── JOIN → Single query with all data
|
|
15
|
+
├── Eager loading → ORM handles JOIN
|
|
16
|
+
├── DataLoader → Batch and cache (GraphQL)
|
|
17
|
+
└── Subquery → Fetch related in one query
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
## Query Analysis Mindset
|
|
21
|
+
|
|
22
|
+
```
|
|
23
|
+
Before optimizing:
|
|
24
|
+
├── EXPLAIN ANALYZE the query
|
|
25
|
+
├── Look for Seq Scan (full table scan)
|
|
26
|
+
├── Check actual vs estimated rows
|
|
27
|
+
└── Identify missing indexes
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
## Optimization Priorities
|
|
31
|
+
|
|
32
|
+
1. **Add missing indexes** (most common issue)
|
|
33
|
+
2. **Select only needed columns** (not SELECT *)
|
|
34
|
+
3. **Use proper JOINs** (avoid subqueries when possible)
|
|
35
|
+
4. **Limit early** (pagination at database level)
|
|
36
|
+
5. **Cache** (when appropriate)
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
# ORM Selection
|
|
2
|
+
|
|
3
|
+
> Choose ORM based on deployment and DX needs.
|
|
4
|
+
|
|
5
|
+
## Decision Tree
|
|
6
|
+
|
|
7
|
+
```
|
|
8
|
+
What's the context?
|
|
9
|
+
│
|
|
10
|
+
├── Edge deployment / Bundle size matters
|
|
11
|
+
│ └── Drizzle (smallest, SQL-like)
|
|
12
|
+
│
|
|
13
|
+
├── Best DX / Schema-first
|
|
14
|
+
│ └── Prisma (migrations, studio)
|
|
15
|
+
│
|
|
16
|
+
├── Maximum control
|
|
17
|
+
│ └── Raw SQL with query builder
|
|
18
|
+
│
|
|
19
|
+
└── Python ecosystem
|
|
20
|
+
└── SQLAlchemy 2.0 (async support)
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
## Comparison
|
|
24
|
+
|
|
25
|
+
| ORM | Best For | Trade-offs |
|
|
26
|
+
|-----|----------|------------|
|
|
27
|
+
| **Drizzle** | Edge, TypeScript | Newer, less examples |
|
|
28
|
+
| **Prisma** | DX, schema management | Heavier, not edge-ready |
|
|
29
|
+
| **Kysely** | Type-safe SQL builder | Manual migrations |
|
|
30
|
+
| **Raw SQL** | Complex queries, control | Manual type safety |
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
# Schema Design Principles
|
|
2
|
+
|
|
3
|
+
> Normalization, primary keys, timestamps, relationships.
|
|
4
|
+
|
|
5
|
+
## Normalization Decision
|
|
6
|
+
|
|
7
|
+
```
|
|
8
|
+
When to normalize (separate tables):
|
|
9
|
+
├── Data is repeated across rows
|
|
10
|
+
├── Updates would need multiple changes
|
|
11
|
+
├── Relationships are clear
|
|
12
|
+
└── Query patterns benefit
|
|
13
|
+
|
|
14
|
+
When to denormalize (embed/duplicate):
|
|
15
|
+
├── Read performance critical
|
|
16
|
+
├── Data rarely changes
|
|
17
|
+
├── Always fetched together
|
|
18
|
+
└── Simpler queries needed
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
## Primary Key Selection
|
|
22
|
+
|
|
23
|
+
| Type | Use When |
|
|
24
|
+
|------|----------|
|
|
25
|
+
| **UUID** | Distributed systems, security |
|
|
26
|
+
| **ULID** | UUID + sortable by time |
|
|
27
|
+
| **Auto-increment** | Simple apps, single database |
|
|
28
|
+
| **Natural key** | Rarely (business meaning) |
|
|
29
|
+
|
|
30
|
+
## Timestamp Strategy
|
|
31
|
+
|
|
32
|
+
```
|
|
33
|
+
For every table:
|
|
34
|
+
├── created_at → When created
|
|
35
|
+
├── updated_at → Last modified
|
|
36
|
+
└── deleted_at → Soft delete (if needed)
|
|
37
|
+
|
|
38
|
+
Use TIMESTAMPTZ (with timezone) not TIMESTAMP
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
## Relationship Types
|
|
42
|
+
|
|
43
|
+
| Type | When | Implementation |
|
|
44
|
+
|------|------|----------------|
|
|
45
|
+
| **One-to-One** | Extension data | Separate table with FK |
|
|
46
|
+
| **One-to-Many** | Parent-children | FK on child table |
|
|
47
|
+
| **Many-to-Many** | Both sides have many | Junction table |
|
|
48
|
+
|
|
49
|
+
## Foreign Key ON DELETE
|
|
50
|
+
|
|
51
|
+
```
|
|
52
|
+
├── CASCADE → Delete children with parent
|
|
53
|
+
├── SET NULL → Children become orphans
|
|
54
|
+
├── RESTRICT → Prevent delete if children exist
|
|
55
|
+
└── SET DEFAULT → Children get default value
|
|
56
|
+
```
|