start-vibing 3.0.8 → 3.0.9

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.
Files changed (96) hide show
  1. package/package.json +1 -1
  2. package/template/.claude/CLAUDE.md +18 -3
  3. package/template/.claude/skills/api-docs/SKILL.md +206 -0
  4. package/template/.claude/skills/claude-seo/SKILL.md +84 -0
  5. package/template/.claude/skills/mongoose-patterns/SKILL.md +188 -0
  6. package/template/.claude/skills/playwright-testing/SKILL.md +251 -0
  7. package/template/.claude/skills/skill-creator/SKILL.md +106 -0
  8. package/template/.claude/skills/test-infrastructure/SKILL.md +242 -0
  9. package/template/.claude/agents/_archive/01-orchestration/agent-selector.md +0 -130
  10. package/template/.claude/agents/_archive/01-orchestration/checkpoint-manager.md +0 -142
  11. package/template/.claude/agents/_archive/01-orchestration/context-manager.md +0 -138
  12. package/template/.claude/agents/_archive/01-orchestration/error-recovery.md +0 -182
  13. package/template/.claude/agents/_archive/01-orchestration/orchestrator.md +0 -114
  14. package/template/.claude/agents/_archive/01-orchestration/parallel-coordinator.md +0 -141
  15. package/template/.claude/agents/_archive/01-orchestration/task-decomposer.md +0 -121
  16. package/template/.claude/agents/_archive/01-orchestration/workflow-router.md +0 -119
  17. package/template/.claude/agents/_archive/02-typescript/bun-runtime-expert.md +0 -197
  18. package/template/.claude/agents/_archive/02-typescript/esm-resolver.md +0 -193
  19. package/template/.claude/agents/_archive/02-typescript/import-alias-enforcer.md +0 -158
  20. package/template/.claude/agents/_archive/02-typescript/ts-generics-helper.md +0 -183
  21. package/template/.claude/agents/_archive/02-typescript/ts-migration-helper.md +0 -238
  22. package/template/.claude/agents/_archive/02-typescript/ts-strict-checker.md +0 -180
  23. package/template/.claude/agents/_archive/02-typescript/ts-types-analyzer.md +0 -199
  24. package/template/.claude/agents/_archive/02-typescript/type-definition-writer.md +0 -187
  25. package/template/.claude/agents/_archive/02-typescript/zod-schema-designer.md +0 -212
  26. package/template/.claude/agents/_archive/02-typescript/zod-validator.md +0 -158
  27. package/template/.claude/agents/_archive/03-testing/playwright-assertions.md +0 -265
  28. package/template/.claude/agents/_archive/03-testing/playwright-e2e.md +0 -247
  29. package/template/.claude/agents/_archive/03-testing/playwright-fixtures.md +0 -234
  30. package/template/.claude/agents/_archive/03-testing/playwright-multi-viewport.md +0 -256
  31. package/template/.claude/agents/_archive/03-testing/playwright-page-objects.md +0 -247
  32. package/template/.claude/agents/_archive/03-testing/test-cleanup-manager.md +0 -248
  33. package/template/.claude/agents/_archive/03-testing/test-data-generator.md +0 -254
  34. package/template/.claude/agents/_archive/03-testing/tester-integration.md +0 -278
  35. package/template/.claude/agents/_archive/03-testing/tester-unit.md +0 -207
  36. package/template/.claude/agents/_archive/03-testing/vitest-config.md +0 -287
  37. package/template/.claude/agents/_archive/04-docker/container-health.md +0 -255
  38. package/template/.claude/agents/_archive/04-docker/deployment-validator.md +0 -225
  39. package/template/.claude/agents/_archive/04-docker/docker-compose-designer.md +0 -281
  40. package/template/.claude/agents/_archive/04-docker/docker-env-manager.md +0 -235
  41. package/template/.claude/agents/_archive/04-docker/docker-multi-stage.md +0 -241
  42. package/template/.claude/agents/_archive/04-docker/dockerfile-optimizer.md +0 -208
  43. package/template/.claude/agents/_archive/05-database/database-seeder.md +0 -273
  44. package/template/.claude/agents/_archive/05-database/mongodb-query-optimizer.md +0 -230
  45. package/template/.claude/agents/_archive/05-database/mongoose-aggregation.md +0 -306
  46. package/template/.claude/agents/_archive/05-database/mongoose-index-optimizer.md +0 -182
  47. package/template/.claude/agents/_archive/05-database/mongoose-schema-designer.md +0 -267
  48. package/template/.claude/agents/_archive/06-security/auth-session-validator.md +0 -68
  49. package/template/.claude/agents/_archive/06-security/input-sanitizer.md +0 -80
  50. package/template/.claude/agents/_archive/06-security/owasp-checker.md +0 -97
  51. package/template/.claude/agents/_archive/06-security/permission-auditor.md +0 -100
  52. package/template/.claude/agents/_archive/06-security/security-auditor.md +0 -84
  53. package/template/.claude/agents/_archive/06-security/sensitive-data-scanner.md +0 -83
  54. package/template/.claude/agents/_archive/07-documentation/api-documenter.md +0 -136
  55. package/template/.claude/agents/_archive/07-documentation/changelog-manager.md +0 -105
  56. package/template/.claude/agents/_archive/07-documentation/claude-md-compactor.md +0 -214
  57. package/template/.claude/agents/_archive/07-documentation/documenter.md +0 -184
  58. package/template/.claude/agents/_archive/07-documentation/domain-updater.md +0 -138
  59. package/template/.claude/agents/_archive/07-documentation/jsdoc-generator.md +0 -114
  60. package/template/.claude/agents/_archive/07-documentation/readme-generator.md +0 -135
  61. package/template/.claude/agents/_archive/08-git/branch-manager.md +0 -58
  62. package/template/.claude/agents/_archive/08-git/commit-manager.md +0 -78
  63. package/template/.claude/agents/_archive/09-quality/code-reviewer.md +0 -71
  64. package/template/.claude/agents/_archive/09-quality/quality-checker.md +0 -67
  65. package/template/.claude/agents/_archive/10-research/best-practices-finder.md +0 -89
  66. package/template/.claude/agents/_archive/10-research/competitor-analyzer.md +0 -106
  67. package/template/.claude/agents/_archive/10-research/pattern-researcher.md +0 -93
  68. package/template/.claude/agents/_archive/10-research/research-cache-manager.md +0 -76
  69. package/template/.claude/agents/_archive/10-research/research-web.md +0 -98
  70. package/template/.claude/agents/_archive/10-research/tech-evaluator.md +0 -101
  71. package/template/.claude/agents/_archive/11-ui-ux/accessibility-auditor.md +0 -136
  72. package/template/.claude/agents/_archive/11-ui-ux/design-system-enforcer.md +0 -125
  73. package/template/.claude/agents/_archive/11-ui-ux/skeleton-generator.md +0 -118
  74. package/template/.claude/agents/_archive/11-ui-ux/ui-desktop.md +0 -132
  75. package/template/.claude/agents/_archive/11-ui-ux/ui-mobile.md +0 -125
  76. package/template/.claude/agents/_archive/11-ui-ux/ui-tablet.md +0 -110
  77. package/template/.claude/agents/_archive/12-performance/api-latency-analyzer.md +0 -156
  78. package/template/.claude/agents/_archive/12-performance/bundle-analyzer.md +0 -113
  79. package/template/.claude/agents/_archive/12-performance/memory-leak-detector.md +0 -137
  80. package/template/.claude/agents/_archive/12-performance/performance-profiler.md +0 -115
  81. package/template/.claude/agents/_archive/12-performance/query-optimizer.md +0 -124
  82. package/template/.claude/agents/_archive/12-performance/render-optimizer.md +0 -154
  83. package/template/.claude/agents/_archive/_backup/analyzer.md +0 -134
  84. package/template/.claude/agents/_archive/_backup/code-reviewer.md +0 -279
  85. package/template/.claude/agents/_archive/_backup/commit-manager.md +0 -219
  86. package/template/.claude/agents/_archive/_backup/debugger.md +0 -280
  87. package/template/.claude/agents/_archive/_backup/documenter.md +0 -237
  88. package/template/.claude/agents/_archive/_backup/domain-updater.md +0 -197
  89. package/template/.claude/agents/_archive/_backup/final-validator.md +0 -169
  90. package/template/.claude/agents/_archive/_backup/orchestrator.md +0 -149
  91. package/template/.claude/agents/_archive/_backup/performance.md +0 -232
  92. package/template/.claude/agents/_archive/_backup/quality-checker.md +0 -240
  93. package/template/.claude/agents/_archive/_backup/research.md +0 -315
  94. package/template/.claude/agents/_archive/_backup/security-auditor.md +0 -192
  95. package/template/.claude/agents/_archive/_backup/tester.md +0 -566
  96. package/template/.claude/agents/_archive/_backup/ui-ux-reviewer.md +0 -247
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "start-vibing",
3
- "version": "3.0.8",
3
+ "version": "3.0.9",
4
4
  "description": "Setup Claude Code agents, skills, and hooks in your project. Smart copy that preserves your custom domains and configurations.",
5
5
  "type": "module",
6
6
  "bin": {
@@ -9,8 +9,7 @@ This file provides detailed context for the development system. For user-facing
9
9
  ```
10
10
  .claude/
11
11
  ├── agents/ # 6 active subagents (flat structure)
12
- │ └── _archive/ # 82+ archived agents (unused, kept for reference)
13
- ├── skills/ # 20 skill systems with cache
12
+ ├── skills/ # 26 skill systems with cache
14
13
  ├── scripts/ # Utility scripts (validate-skills.sh)
15
14
  ├── config/ # Project-specific configuration
16
15
  └── commands/ # Slash commands (feature, fix, research, validate)
@@ -48,7 +47,7 @@ implement -> quality gates -> domain-updater -> commit-manager -> complete
48
47
 
49
48
  ---
50
49
 
51
- ## Skills (20 Active)
50
+ ## Skills (26 Active)
52
51
 
53
52
  Skills are auto-injected into context when the task matches their description. All use the imperative pattern for 95%+ auto-invocation.
54
53
 
@@ -73,6 +72,14 @@ Skills are auto-injected into context when the task matches their description. A
73
72
  | **security-scan** | API, auth, user data code | OWASP Top 10, Zod validation (HAS VETO POWER) |
74
73
  | **test-coverage** | After implementing features | Creates Vitest unit + Playwright E2E tests |
75
74
  | **final-check** | Before completing any task | Validates skills used, docs updated (HAS VETO POWER) |
75
+ | **playwright-testing** | Playwright E2E tests | Page Objects, fixtures, multi-viewport patterns |
76
+ | **test-infrastructure** | Test configs, data factories | Vitest config, MongoMemoryServer, cleanup |
77
+
78
+ ### Database Skills
79
+
80
+ | Skill | Trigger | Description |
81
+ |-------|---------|-------------|
82
+ | **mongoose-patterns** | Mongoose models, queries, DB ops | Schema template, ESR indexes, aggregation, seeders |
76
83
 
77
84
  ### Infrastructure & DevOps Skills
78
85
 
@@ -91,6 +98,14 @@ Skills are auto-injected into context when the task matches their description. A
91
98
  | **docs-tracker** | After implementation | Detects modified files, creates/updates docs |
92
99
  | **research-cache** | Before web research | Checks cached findings to avoid redundant searches |
93
100
  | **ui-ux-audit** | Before UI features | Competitors, WCAG 2.1, responsiveness |
101
+ | **api-docs** | After API/function changes | API docs, JSDoc, changelog management |
102
+
103
+ ### Meta & SEO Skills
104
+
105
+ | Skill | Trigger | Description |
106
+ |-------|---------|-------------|
107
+ | **skill-creator** | Creating/editing skills | Interview, draft, test, iterate loop (from anthropics/skills) |
108
+ | **claude-seo** | SEO analysis, audits, sitemaps | Full SEO suite with health scoring (from AgriciDaniel/claude-seo) |
94
109
 
95
110
  ---
96
111
 
@@ -0,0 +1,206 @@
1
+ ---
2
+ name: api-docs
3
+ description: "ALWAYS invoke after creating or modifying API endpoints, exported functions, or releasing features. Do NOT skip API documentation, JSDoc comments, or changelog entries."
4
+ allowed-tools: Read, Write, Edit, Bash, Grep, Glob
5
+ ---
6
+
7
+ # API Documentation
8
+
9
+ Patterns for API endpoint docs, JSDoc comments, and changelog management.
10
+
11
+ ## API Documentation Template
12
+
13
+ ````markdown
14
+ ## POST /api/users
15
+
16
+ Create a new user.
17
+
18
+ ### Request
19
+
20
+ **Headers:**
21
+ | Header | Required | Description |
22
+ |--------|----------|-------------|
23
+ | Authorization | Yes | Bearer token |
24
+ | Content-Type | Yes | application/json |
25
+
26
+ **Body:**
27
+ ```json
28
+ {
29
+ "email": "user@example.com",
30
+ "password": "Password123!",
31
+ "name": "John Doe"
32
+ }
33
+ ```
34
+
35
+ **Validation:**
36
+ - email: Required, valid email format
37
+ - password: Required, min 8 chars, 1 uppercase, 1 number
38
+ - name: Required, 1-100 chars
39
+
40
+ ### Response
41
+
42
+ **Success (201):**
43
+ ```json
44
+ {
45
+ "id": "abc123",
46
+ "email": "user@example.com",
47
+ "name": "John Doe",
48
+ "createdAt": "2025-01-03T12:00:00Z"
49
+ }
50
+ ```
51
+
52
+ **Error (400):**
53
+ ```json
54
+ {
55
+ "error": "Validation failed",
56
+ "details": [{ "field": "email", "message": "Invalid email format" }]
57
+ }
58
+ ```
59
+ ````
60
+
61
+ ### Documentation Location
62
+
63
+ ```
64
+ docs/api/
65
+ ├── README.md # API overview
66
+ ├── auth.md # Auth endpoints
67
+ ├── users.md # User endpoints
68
+ └── openapi.yaml # OpenAPI spec (optional)
69
+ ```
70
+
71
+ ## OpenAPI Quick Reference
72
+
73
+ ```yaml
74
+ openapi: 3.0.3
75
+ info:
76
+ title: My API
77
+ version: 1.0.0
78
+ paths:
79
+ /api/users:
80
+ post:
81
+ summary: Create user
82
+ requestBody:
83
+ required: true
84
+ content:
85
+ application/json:
86
+ schema:
87
+ $ref: '#/components/schemas/CreateUser'
88
+ responses:
89
+ '201':
90
+ description: User created
91
+ components:
92
+ schemas:
93
+ CreateUser:
94
+ type: object
95
+ required: [email, password, name]
96
+ properties:
97
+ email:
98
+ type: string
99
+ format: email
100
+ password:
101
+ type: string
102
+ minLength: 8
103
+ ```
104
+
105
+ ## JSDoc Patterns
106
+
107
+ ```typescript
108
+ /**
109
+ * Creates a new user in the database.
110
+ *
111
+ * @param data - The user creation data
112
+ * @returns The created user document
113
+ * @throws {ValidationError} If data is invalid
114
+ * @throws {ConflictError} If email already exists
115
+ *
116
+ * @example
117
+ * ```typescript
118
+ * const user = await createUser({
119
+ * email: 'user@example.com',
120
+ * password: 'Password123!',
121
+ * name: 'John Doe'
122
+ * });
123
+ * ```
124
+ */
125
+ async function createUser(data: CreateUserInput): Promise<User> {
126
+ // Implementation
127
+ }
128
+
129
+ /** User creation input data. */
130
+ interface CreateUserInput {
131
+ /** User email address (must be unique) */
132
+ email: string;
133
+ /** User password (min 8 chars, 1 uppercase, 1 number) */
134
+ password: string;
135
+ /** User display name */
136
+ name: string;
137
+ }
138
+ ```
139
+
140
+ | Tag | Usage |
141
+ |-----|-------|
142
+ | `@param` | Function parameter |
143
+ | `@returns` | Return value |
144
+ | `@throws` | Possible errors |
145
+ | `@example` | Usage example |
146
+ | `@deprecated` | Deprecated feature |
147
+ | `@see` | Related docs |
148
+
149
+ ### When to Document
150
+
151
+ - Public API functions
152
+ - Complex algorithms
153
+ - Non-obvious behavior
154
+ - Exported types/interfaces
155
+
156
+ ## Changelog Management
157
+
158
+ ```markdown
159
+ # Changelog
160
+
161
+ Format: [Keep a Changelog](https://keepachangelog.com/en/1.1.0/)
162
+
163
+ ## [Unreleased]
164
+
165
+ ### Added
166
+ - New feature description
167
+
168
+ ### Changed
169
+ - Changed behavior description
170
+
171
+ ### Fixed
172
+ - Bug fix description
173
+
174
+ ### Security
175
+ - Security improvement
176
+
177
+ ## [1.0.0] - 2025-01-01
178
+
179
+ ### Added
180
+ - Initial release features
181
+ ```
182
+
183
+ | Category | Use When |
184
+ |----------|----------|
185
+ | Added | New features |
186
+ | Changed | Existing functionality changes |
187
+ | Deprecated | Soon-to-be-removed features |
188
+ | Removed | Removed features |
189
+ | Fixed | Bug fixes |
190
+ | Security | Security fixes |
191
+
192
+ ### Versioning
193
+
194
+ - **MAJOR** (1.0.0): Breaking changes
195
+ - **MINOR** (0.1.0): New features, backwards compatible
196
+ - **PATCH** (0.0.1): Bug fixes
197
+
198
+ ## Critical Rules
199
+
200
+ 1. **Include examples** — Request and response for every endpoint
201
+ 2. **List all errors** — Every possible error response code
202
+ 3. **Document validation** — Field requirements and constraints
203
+ 4. **Keep current** — Update docs when endpoints change
204
+ 5. **Explain why** — Not just what, in JSDoc comments
205
+ 6. **User perspective** — Write changelog for users, not devs
206
+ 7. **Always [Unreleased]** — Keep this section at top of changelog
@@ -0,0 +1,84 @@
1
+ ---
2
+ name: claude-seo
3
+ description: "ALWAYS invoke when doing SEO analysis, audits, schema markup, sitemaps, or content optimization. Do NOT skip SEO checks when building public-facing pages or marketing content."
4
+ allowed-tools: Read, Write, Edit, Bash, Grep, Glob
5
+ ---
6
+
7
+ # SEO Analysis
8
+
9
+ Comprehensive SEO analysis for any website or business type.
10
+
11
+ > Source: `AgriciDaniel/claude-seo` (adapted for project conventions)
12
+
13
+ ## Commands
14
+
15
+ | Command | What it does |
16
+ |---------|-------------|
17
+ | `/seo audit <url>` | Full website audit with parallel analysis |
18
+ | `/seo page <url>` | Deep single-page analysis |
19
+ | `/seo sitemap <url>` | Analyze or generate XML sitemaps |
20
+ | `/seo schema <url>` | Detect, validate, and generate Schema.org markup |
21
+ | `/seo images <url>` | Image optimization analysis |
22
+ | `/seo technical <url>` | Technical SEO audit (crawlability, indexability, CWV) |
23
+ | `/seo content <url>` | E-E-A-T and content quality analysis |
24
+ | `/seo geo <url>` | AI Overviews / Generative Engine Optimization |
25
+ | `/seo plan <type>` | Strategic SEO planning by business type |
26
+
27
+ ## SEO Health Score (0-100)
28
+
29
+ | Category | Weight |
30
+ |----------|--------|
31
+ | Technical SEO | 25% |
32
+ | Content Quality (E-E-A-T) | 25% |
33
+ | On-Page SEO | 20% |
34
+ | Schema / Structured Data | 10% |
35
+ | Performance (Core Web Vitals) | 10% |
36
+ | Images | 5% |
37
+ | AI Search Readiness | 5% |
38
+
39
+ ## Industry Detection
40
+
41
+ - **SaaS**: pricing page, /features, /docs, "free trial"
42
+ - **Local Service**: phone, address, service area, Google Maps
43
+ - **E-commerce**: /products, /cart, "add to cart", product schema
44
+ - **Publisher**: /blog, /articles, article schema, author pages
45
+ - **Agency**: /case-studies, /portfolio, client logos
46
+
47
+ ## Audit Workflow
48
+
49
+ 1. Detect business type from homepage signals
50
+ 2. Run parallel analysis: technical, content, schema, sitemap, performance
51
+ 3. Generate unified report with SEO Health Score
52
+ 4. Create prioritized action plan (Critical → High → Medium → Low)
53
+
54
+ ## Priority Levels
55
+
56
+ - **Critical**: Blocks indexing or causes penalties (immediate fix)
57
+ - **High**: Significantly impacts rankings (fix within 1 week)
58
+ - **Medium**: Optimization opportunity (fix within 1 month)
59
+ - **Low**: Nice to have (backlog)
60
+
61
+ ## Quality Gates
62
+
63
+ - Never recommend HowTo schema (deprecated Sept 2023)
64
+ - FAQ schema only for government and healthcare sites
65
+ - All Core Web Vitals references use INP, never FID
66
+ - Warn at 30+ location pages (enforce 60%+ unique content)
67
+ - Hard stop at 50+ location pages (require user justification)
68
+
69
+ ## AI Search Readiness (GEO)
70
+
71
+ Check accessibility for AI crawlers:
72
+ - GPTBot, ClaudeBot, PerplexityBot in robots.txt
73
+ - llms.txt compliance
74
+ - Brand mention signals
75
+ - Passage-level citability
76
+
77
+ ## Critical Rules
78
+
79
+ 1. **INP not FID** — FID is deprecated, always use INP for Core Web Vitals
80
+ 2. **No HowTo schema** — Deprecated since Sept 2023
81
+ 3. **E-E-A-T framework** — Experience, Expertise, Authoritativeness, Trustworthiness
82
+ 4. **Parallel analysis** — Run all audit categories simultaneously
83
+ 5. **Business-type aware** — Tailor recommendations to industry
84
+ 6. **GEO included** — Always check AI search readiness alongside traditional SEO
@@ -0,0 +1,188 @@
1
+ ---
2
+ name: mongoose-patterns
3
+ description: "ALWAYS invoke when creating or editing Mongoose models, queries, or database operations. Do NOT write MongoDB code without checking schema, index, and query patterns first."
4
+ allowed-tools: Read, Write, Edit, Bash, Grep, Glob
5
+ ---
6
+
7
+ # Mongoose Patterns
8
+
9
+ Comprehensive patterns for Mongoose schemas, indexes, queries, aggregations, and seeders.
10
+
11
+ ## Schema Template
12
+
13
+ ```typescript
14
+ // types/[entity].ts — ALL interfaces in types/ folder
15
+ export interface I[Entity] {
16
+ field1: string;
17
+ field2: number;
18
+ createdAt: Date;
19
+ updatedAt: Date;
20
+ }
21
+
22
+ export interface I[Entity]Document extends I[Entity], Document {
23
+ comparePassword(password: string): Promise<boolean>;
24
+ }
25
+
26
+ export interface I[Entity]Model extends Model<I[Entity]Document> {
27
+ findByEmail(email: string): Promise<I[Entity]Document | null>;
28
+ }
29
+ ```
30
+
31
+ ```typescript
32
+ // src/models/[entity].model.ts
33
+ import type { I[Entity]Document, I[Entity]Model } from '$types/[entity]';
34
+
35
+ const [Entity]Schema = new Schema<I[Entity]Document, I[Entity]Model>(
36
+ {
37
+ field1: {
38
+ type: String,
39
+ required: [true, 'Field1 is required'],
40
+ trim: true,
41
+ maxlength: [100, 'Max 100 characters'],
42
+ },
43
+ },
44
+ {
45
+ timestamps: true,
46
+ collection: '[entities]',
47
+ toJSON: {
48
+ transform: (_, ret) => {
49
+ delete ret.password;
50
+ delete ret.__v;
51
+ return ret;
52
+ },
53
+ },
54
+ }
55
+ );
56
+ ```
57
+
58
+ ## Index Strategy (ESR Rule)
59
+
60
+ Order compound indexes by: **Equality → Sort → Range**
61
+
62
+ ```typescript
63
+ // Query: { status: "active", createdAt: { $gt: date } }.sort({ score: -1 })
64
+ // Index: { status: 1, score: -1, createdAt: 1 }
65
+ // [Equality] [Sort] [Range]
66
+
67
+ UserSchema.index({ email: 1 }, { unique: true });
68
+ UserSchema.index({ role: 1, isActive: 1 }); // Compound
69
+ UserSchema.index({ createdAt: 1 }, { expireAfterSeconds: 86400 }); // TTL
70
+ UserSchema.index({ name: 'text', bio: 'text' }); // Text search
71
+ UserSchema.index({ nickname: 1 }, { sparse: true }); // Only non-null
72
+ ```
73
+
74
+ | Type | Syntax | Use Case |
75
+ |------|--------|----------|
76
+ | Single | `{ field: 1 }` | Frequent queries |
77
+ | Compound | `{ a: 1, b: -1 }` | Multi-field queries |
78
+ | Unique | `{ unique: true }` | No duplicates |
79
+ | Text | `{ field: 'text' }` | Full-text search |
80
+ | TTL | `{ expireAfterSeconds: N }` | Auto-expire |
81
+ | Sparse | `{ sparse: true }` | Only index non-null |
82
+ | Partial | `{ partialFilterExpression: {} }` | Conditional index |
83
+
84
+ ## Query Optimization
85
+
86
+ ```typescript
87
+ // Use .lean() for read-only (2-5x faster)
88
+ const users = await User.find({}).select('name email').lean();
89
+
90
+ // Use .exists() instead of findOne for checks
91
+ const exists = await User.exists({ email });
92
+
93
+ // Selective population
94
+ await Order.find({}).populate('user', 'name email');
95
+
96
+ // Cursor for large datasets
97
+ const cursor = User.find({}).cursor();
98
+ for await (const user of cursor) { /* ... */ }
99
+
100
+ // Batch operations
101
+ await Model.insertMany(items);
102
+ await Model.bulkWrite([
103
+ { insertOne: { document: { ... } } },
104
+ { updateOne: { filter: { ... }, update: { ... } } },
105
+ ]);
106
+
107
+ // Use $in over $or
108
+ await User.find({ status: { $in: ['active', 'pending'] } });
109
+
110
+ // Pagination with count (parallel)
111
+ const [items, total] = await Promise.all([
112
+ Model.find(query).skip((page - 1) * limit).limit(limit).lean(),
113
+ Model.countDocuments(query),
114
+ ]);
115
+ ```
116
+
117
+ ## Aggregation Patterns
118
+
119
+ ```typescript
120
+ // Paginated search with $facet
121
+ const [result] = await Product.aggregate([
122
+ { $match: { $text: { $search: query } } },
123
+ {
124
+ $facet: {
125
+ data: [
126
+ { $sort: { score: { $meta: 'textScore' } } },
127
+ { $skip: (page - 1) * limit },
128
+ { $limit: limit },
129
+ ],
130
+ total: [{ $count: 'count' }],
131
+ },
132
+ },
133
+ {
134
+ $project: {
135
+ items: '$data',
136
+ total: { $arrayElemAt: ['$total.count', 0] },
137
+ },
138
+ },
139
+ ]);
140
+
141
+ // Sales report grouped by day
142
+ await Order.aggregate([
143
+ { $match: { createdAt: { $gte: start, $lte: end }, status: 'completed' } },
144
+ {
145
+ $group: {
146
+ _id: { $dateToString: { format: '%Y-%m-%d', date: '$createdAt' } },
147
+ totalSales: { $sum: '$total' },
148
+ orderCount: { $sum: 1 },
149
+ avgOrderValue: { $avg: '$total' },
150
+ },
151
+ },
152
+ { $sort: { _id: 1 } },
153
+ ]);
154
+ ```
155
+
156
+ **Performance**: $match first, use indexes, $project early, $facet for parallel ops, allowDiskUse for large datasets.
157
+
158
+ ## Seeder Pattern
159
+
160
+ ```typescript
161
+ // scripts/seed/index.ts
162
+ async function seed() {
163
+ await mongoose.connect(process.env['MONGODB_URI']!);
164
+ // Clear children before parents
165
+ await Promise.all([
166
+ mongoose.connection.collection('orders').deleteMany({}),
167
+ mongoose.connection.collection('products').deleteMany({}),
168
+ mongoose.connection.collection('users').deleteMany({}),
169
+ ]);
170
+ const users = await seedUsers();
171
+ const products = await seedProducts();
172
+ await seedOrders(users, products);
173
+ await mongoose.disconnect();
174
+ }
175
+ ```
176
+
177
+ ## Critical Rules
178
+
179
+ 1. **Types in `types/`** — Interfaces separate from schema (I[Entity], I[Entity]Document, I[Entity]Model)
180
+ 2. **`select: false`** for passwords — Hide sensitive fields by default
181
+ 3. **`toJSON.transform`** — Remove password, __v from API responses
182
+ 4. **`Bun.password.hash`** — Use Bun's native hashing (not bcrypt)
183
+ 5. **ESR ordering** — Equality, Sort, Range for compound indexes
184
+ 6. **`.lean()`** — Always for read-only queries
185
+ 7. **`$facet`** — For paginated search (data + count in one query)
186
+ 8. **Explain first** — Always analyze with `.explain('executionStats')` before optimizing
187
+ 9. **COLLSCAN = bad** — Every frequent query needs an IXSCAN
188
+ 10. **Clear children first** — Delete dependent collections before parents in seeders