@hivehub/rulebook 2.0.0 → 3.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.
Files changed (188) hide show
  1. package/README.md +779 -654
  2. package/dist/cli/commands.d.ts +22 -0
  3. package/dist/cli/commands.d.ts.map +1 -1
  4. package/dist/cli/commands.js +291 -8
  5. package/dist/cli/commands.js.map +1 -1
  6. package/dist/core/claude-mcp.d.ts +32 -0
  7. package/dist/core/claude-mcp.d.ts.map +1 -0
  8. package/dist/core/claude-mcp.js +92 -0
  9. package/dist/core/claude-mcp.js.map +1 -0
  10. package/dist/core/config-manager.d.ts.map +1 -1
  11. package/dist/core/config-manager.js +27 -6
  12. package/dist/core/config-manager.js.map +1 -1
  13. package/dist/core/generator.d.ts.map +1 -1
  14. package/dist/core/generator.js +98 -49
  15. package/dist/core/generator.js.map +1 -1
  16. package/dist/core/migrator.d.ts +13 -0
  17. package/dist/core/migrator.d.ts.map +1 -1
  18. package/dist/core/migrator.js +76 -9
  19. package/dist/core/migrator.js.map +1 -1
  20. package/dist/core/openspec-migrator.d.ts +1 -1
  21. package/dist/core/openspec-migrator.d.ts.map +1 -1
  22. package/dist/core/openspec-migrator.js +14 -7
  23. package/dist/core/openspec-migrator.js.map +1 -1
  24. package/dist/core/workflow-generator.js +297 -176
  25. package/dist/core/workflow-generator.js.map +1 -1
  26. package/dist/index.js +40 -1
  27. package/dist/index.js.map +1 -1
  28. package/dist/mcp/rulebook-server.d.ts.map +1 -1
  29. package/dist/mcp/rulebook-server.js +255 -74
  30. package/dist/mcp/rulebook-server.js.map +1 -1
  31. package/dist/memory/hnsw-index.d.ts +63 -0
  32. package/dist/memory/hnsw-index.d.ts.map +1 -0
  33. package/dist/memory/hnsw-index.js +421 -0
  34. package/dist/memory/hnsw-index.js.map +1 -0
  35. package/dist/memory/memory-cache.d.ts +33 -0
  36. package/dist/memory/memory-cache.d.ts.map +1 -0
  37. package/dist/memory/memory-cache.js +85 -0
  38. package/dist/memory/memory-cache.js.map +1 -0
  39. package/dist/memory/memory-hooks.d.ts +42 -0
  40. package/dist/memory/memory-hooks.d.ts.map +1 -0
  41. package/dist/memory/memory-hooks.js +193 -0
  42. package/dist/memory/memory-hooks.js.map +1 -0
  43. package/dist/memory/memory-manager.d.ts +55 -0
  44. package/dist/memory/memory-manager.d.ts.map +1 -0
  45. package/dist/memory/memory-manager.js +209 -0
  46. package/dist/memory/memory-manager.js.map +1 -0
  47. package/dist/memory/memory-search.d.ts +42 -0
  48. package/dist/memory/memory-search.d.ts.map +1 -0
  49. package/dist/memory/memory-search.js +166 -0
  50. package/dist/memory/memory-search.js.map +1 -0
  51. package/dist/memory/memory-store.d.ts +59 -0
  52. package/dist/memory/memory-store.d.ts.map +1 -0
  53. package/dist/memory/memory-store.js +394 -0
  54. package/dist/memory/memory-store.js.map +1 -0
  55. package/dist/memory/memory-types.d.ts +69 -0
  56. package/dist/memory/memory-types.d.ts.map +1 -0
  57. package/dist/memory/memory-types.js +7 -0
  58. package/dist/memory/memory-types.js.map +1 -0
  59. package/dist/memory/memory-vectorizer.d.ts +29 -0
  60. package/dist/memory/memory-vectorizer.d.ts.map +1 -0
  61. package/dist/memory/memory-vectorizer.js +104 -0
  62. package/dist/memory/memory-vectorizer.js.map +1 -0
  63. package/dist/types.d.ts +7 -0
  64. package/dist/types.d.ts.map +1 -1
  65. package/package.json +107 -106
  66. package/templates/cli/CLAUDE_CODE.md +114 -13
  67. package/templates/commands/rulebook-memory-save.md +48 -0
  68. package/templates/commands/rulebook-memory-search.md +47 -0
  69. package/templates/commands/rulebook-task-apply.md +2 -2
  70. package/templates/commands/rulebook-task-archive.md +2 -2
  71. package/templates/commands/rulebook-task-create.md +2 -2
  72. package/templates/commands/rulebook-task-list.md +2 -2
  73. package/templates/commands/rulebook-task-show.md +2 -2
  74. package/templates/commands/rulebook-task-validate.md +2 -2
  75. package/templates/git/CI_CD_PATTERNS.md +4 -4
  76. package/templates/git/GITHUB_ACTIONS.md +3 -3
  77. package/templates/git/GITLAB_CI.md +4 -4
  78. package/templates/git/SECRETS_MANAGEMENT.md +4 -4
  79. package/templates/hooks/COMMIT_MSG.md +4 -4
  80. package/templates/hooks/POST_CHECKOUT.md +3 -3
  81. package/templates/hooks/PREPARE_COMMIT_MSG.md +3 -3
  82. package/templates/hooks/PRE_COMMIT.md +4 -4
  83. package/templates/hooks/PRE_PUSH.md +4 -4
  84. package/templates/modules/MEMORY.md +63 -0
  85. package/templates/skills/cli/aider/SKILL.md +59 -0
  86. package/templates/skills/cli/amazon-q/SKILL.md +35 -0
  87. package/templates/skills/cli/auggie/SKILL.md +42 -0
  88. package/templates/skills/cli/claude/SKILL.md +42 -0
  89. package/templates/skills/cli/claude-code/SKILL.md +146 -0
  90. package/templates/skills/cli/cline/SKILL.md +42 -0
  91. package/templates/skills/cli/codebuddy/SKILL.md +30 -0
  92. package/templates/skills/cli/codeium/SKILL.md +30 -0
  93. package/templates/skills/cli/codex/SKILL.md +31 -0
  94. package/templates/skills/cli/continue/SKILL.md +44 -0
  95. package/templates/skills/cli/cursor-cli/SKILL.md +38 -0
  96. package/templates/skills/cli/factory/SKILL.md +28 -0
  97. package/templates/skills/cli/gemini/SKILL.md +45 -0
  98. package/templates/skills/cli/kilocode/SKILL.md +28 -0
  99. package/templates/skills/cli/opencode/SKILL.md +28 -0
  100. package/templates/skills/core/agent-automation/SKILL.md +194 -0
  101. package/templates/skills/core/dag/SKILL.md +314 -0
  102. package/templates/skills/core/documentation-rules/SKILL.md +47 -0
  103. package/templates/skills/core/quality-enforcement/SKILL.md +78 -0
  104. package/templates/skills/frameworks/angular/SKILL.md +46 -0
  105. package/templates/skills/frameworks/django/SKILL.md +93 -0
  106. package/templates/skills/frameworks/electron/SKILL.md +157 -0
  107. package/templates/skills/frameworks/flask/SKILL.md +48 -0
  108. package/templates/skills/frameworks/flutter/SKILL.md +65 -0
  109. package/templates/skills/frameworks/jquery/SKILL.md +42 -0
  110. package/templates/skills/frameworks/laravel/SKILL.md +48 -0
  111. package/templates/skills/frameworks/nestjs/SKILL.md +53 -0
  112. package/templates/skills/frameworks/nextjs/SKILL.md +137 -0
  113. package/templates/skills/frameworks/nuxt/SKILL.md +50 -0
  114. package/templates/skills/frameworks/rails/SKILL.md +76 -0
  115. package/templates/skills/frameworks/react/SKILL.md +48 -0
  116. package/templates/skills/frameworks/react-native/SKILL.md +57 -0
  117. package/templates/skills/frameworks/spring/SKILL.md +49 -0
  118. package/templates/skills/frameworks/symfony/SKILL.md +46 -0
  119. package/templates/skills/frameworks/vue/SKILL.md +46 -0
  120. package/templates/skills/frameworks/zend/SKILL.md +45 -0
  121. package/templates/skills/ides/copilot/SKILL.md +47 -0
  122. package/templates/skills/ides/cursor/SKILL.md +53 -0
  123. package/templates/skills/ides/jetbrains-ai/SKILL.md +45 -0
  124. package/templates/skills/ides/replit/SKILL.md +46 -0
  125. package/templates/skills/ides/tabnine/SKILL.md +39 -0
  126. package/templates/skills/ides/vscode/SKILL.md +50 -0
  127. package/templates/skills/ides/windsurf/SKILL.md +46 -0
  128. package/templates/skills/ides/zed/SKILL.md +42 -0
  129. package/templates/skills/languages/ada/SKILL.md +68 -0
  130. package/templates/skills/languages/c/SKILL.md +343 -0
  131. package/templates/skills/languages/cpp/SKILL.md +753 -0
  132. package/templates/skills/languages/csharp/SKILL.md +427 -0
  133. package/templates/skills/languages/dart/SKILL.md +342 -0
  134. package/templates/skills/languages/elixir/SKILL.md +464 -0
  135. package/templates/skills/languages/erlang/SKILL.md +371 -0
  136. package/templates/skills/languages/go/SKILL.md +655 -0
  137. package/templates/skills/languages/haskell/SKILL.md +187 -0
  138. package/templates/skills/languages/java/SKILL.md +617 -0
  139. package/templates/skills/languages/javascript/SKILL.md +641 -0
  140. package/templates/skills/languages/julia/SKILL.md +107 -0
  141. package/templates/skills/languages/kotlin/SKILL.md +521 -0
  142. package/templates/skills/languages/lisp/SKILL.md +110 -0
  143. package/templates/skills/languages/lua/SKILL.md +84 -0
  144. package/templates/skills/languages/objectivec/SKILL.md +100 -0
  145. package/templates/skills/languages/php/SKILL.md +426 -0
  146. package/templates/skills/languages/python/SKILL.md +692 -0
  147. package/templates/skills/languages/r/SKILL.md +360 -0
  148. package/templates/skills/languages/ruby/SKILL.md +431 -0
  149. package/templates/skills/languages/rust/SKILL.md +487 -0
  150. package/templates/skills/languages/sas/SKILL.md +83 -0
  151. package/templates/skills/languages/scala/SKILL.md +358 -0
  152. package/templates/skills/languages/solidity/SKILL.md +590 -0
  153. package/templates/skills/languages/sql/SKILL.md +147 -0
  154. package/templates/skills/languages/swift/SKILL.md +476 -0
  155. package/templates/skills/languages/zig/SKILL.md +275 -0
  156. package/templates/skills/modules/atlassian/SKILL.md +265 -0
  157. package/templates/skills/modules/context7/SKILL.md +64 -0
  158. package/templates/skills/modules/figma/SKILL.md +277 -0
  159. package/templates/skills/modules/github-mcp/SKILL.md +74 -0
  160. package/templates/skills/modules/grafana/SKILL.md +338 -0
  161. package/templates/skills/modules/memory/SKILL.md +73 -0
  162. package/templates/skills/modules/notion/SKILL.md +257 -0
  163. package/templates/skills/modules/playwright/SKILL.md +100 -0
  164. package/templates/skills/modules/rulebook-mcp/SKILL.md +166 -0
  165. package/templates/skills/modules/serena/SKILL.md +347 -0
  166. package/templates/skills/modules/supabase/SKILL.md +233 -0
  167. package/templates/skills/modules/synap/SKILL.md +79 -0
  168. package/templates/skills/modules/vectorizer/SKILL.md +73 -0
  169. package/templates/skills/services/azure-blob/SKILL.md +194 -0
  170. package/templates/skills/services/cassandra/SKILL.md +249 -0
  171. package/templates/skills/services/dynamodb/SKILL.md +318 -0
  172. package/templates/skills/services/elasticsearch/SKILL.md +357 -0
  173. package/templates/skills/services/gcs/SKILL.md +188 -0
  174. package/templates/skills/services/influxdb/SKILL.md +275 -0
  175. package/templates/skills/services/kafka/SKILL.md +351 -0
  176. package/templates/skills/services/mariadb/SKILL.md +193 -0
  177. package/templates/skills/services/memcached/SKILL.md +252 -0
  178. package/templates/skills/services/minio/SKILL.md +211 -0
  179. package/templates/skills/services/mongodb/SKILL.md +278 -0
  180. package/templates/skills/services/mysql/SKILL.md +368 -0
  181. package/templates/skills/services/neo4j/SKILL.md +257 -0
  182. package/templates/skills/services/oracle/SKILL.md +300 -0
  183. package/templates/skills/services/postgresql/SKILL.md +336 -0
  184. package/templates/skills/services/rabbitmq/SKILL.md +296 -0
  185. package/templates/skills/services/redis/SKILL.md +302 -0
  186. package/templates/skills/services/s3/SKILL.md +308 -0
  187. package/templates/skills/services/sqlite/SKILL.md +304 -0
  188. package/templates/skills/services/sqlserver/SKILL.md +304 -0
@@ -0,0 +1,73 @@
1
+ ---
2
+ name: "Vectorizer"
3
+ description: "Use MCP Vectorizer as primary data source for project information instead of file reading."
4
+ version: "1.0.0"
5
+ category: "modules"
6
+ author: "Rulebook"
7
+ tags: ["modules", "mcp"]
8
+ dependencies: []
9
+ conflicts: []
10
+ ---
11
+ <!-- VECTORIZER:START -->
12
+ # Vectorizer Instructions
13
+
14
+ **CRITICAL**: Use MCP Vectorizer as primary data source for project information instead of file reading.
15
+
16
+ ## Core Functions
17
+
18
+ ### Search
19
+ ```
20
+ mcp_vectorizer_search - Multiple strategies:
21
+ - intelligent: AI-powered with query expansion
22
+ - semantic: Advanced with reranking
23
+ - contextual: Context-aware with filtering
24
+ - multi_collection: Cross-project search
25
+ - batch: Parallel queries
26
+ - by_file_type: Filter by extension (.rs, .ts, .py)
27
+ ```
28
+
29
+ ### File Operations
30
+ ```
31
+ get_content - Retrieve file without disk I/O
32
+ list_files - List indexed files with metadata
33
+ get_summary - File summaries (extractive/structural)
34
+ get_chunks - Progressive reading of large files
35
+ get_outline - Project structure overview
36
+ get_related - Find semantically related files
37
+ ```
38
+
39
+ ### Discovery
40
+ ```
41
+ full_pipeline - Complete discovery with scoring
42
+ broad_discovery - Multi-query with deduplication
43
+ semantic_focus - Deep semantic search
44
+ expand_queries - Generate query variations
45
+ ```
46
+
47
+ ## When to Use
48
+
49
+ | Task | Tool |
50
+ |------|------|
51
+ | Explore unfamiliar code | intelligent search |
52
+ | Read file | get_content |
53
+ | Understand structure | get_outline |
54
+ | Find related files | get_related |
55
+ | Read large file | get_chunks |
56
+ | Complex question | full_pipeline |
57
+
58
+ ## Best Practices
59
+
60
+ ✅ **DO:**
61
+ - Start with intelligent search for exploration
62
+ - Use file_operations to avoid disk I/O
63
+ - Batch queries for related items
64
+ - Set similarity thresholds (0.6-0.8)
65
+ - Use specific collections when known
66
+
67
+ ❌ **DON'T:**
68
+ - Read files from disk when available in vectorizer
69
+ - Use sequential searches (batch instead)
70
+ - Skip similarity thresholds
71
+ - Search entire codebase when collection is known
72
+
73
+ <!-- VECTORIZER:END -->
@@ -0,0 +1,194 @@
1
+ ---
2
+ name: "Azure Blob Storage"
3
+ description: "Use Azure Blob Storage for object storage, file uploads, static assets, and backup storage in Azure cloud."
4
+ version: "1.0.0"
5
+ category: "services"
6
+ author: "Rulebook"
7
+ tags: ["services", "storage"]
8
+ dependencies: []
9
+ conflicts: []
10
+ ---
11
+ <!-- AZURE_BLOB:START -->
12
+ # Azure Blob Storage Instructions
13
+
14
+ **CRITICAL**: Use Azure Blob Storage for object storage, file uploads, static assets, and backup storage in Azure cloud.
15
+
16
+ ## Core Features
17
+
18
+ ### Connection
19
+ ```typescript
20
+ // Using @azure/storage-blob
21
+ import { BlobServiceClient, StorageSharedKeyCredential } from '@azure/storage-blob'
22
+
23
+ const accountName = process.env.AZURE_STORAGE_ACCOUNT_NAME || ''
24
+ const accountKey = process.env.AZURE_STORAGE_ACCOUNT_KEY || ''
25
+
26
+ const sharedKeyCredential = new StorageSharedKeyCredential(accountName, accountKey)
27
+ const blobServiceClient = new BlobServiceClient(
28
+ `https://${accountName}.blob.core.windows.net`,
29
+ sharedKeyCredential
30
+ )
31
+
32
+ const containerClient = blobServiceClient.getContainerClient(
33
+ process.env.AZURE_CONTAINER_NAME || 'mycontainer'
34
+ )
35
+ ```
36
+
37
+ ### Basic Operations
38
+ ```typescript
39
+ // Create container
40
+ await containerClient.createIfNotExists({
41
+ access: 'blob', // 'blob', 'container', or 'private'
42
+ })
43
+
44
+ // Upload blob
45
+ const blockBlobClient = containerClient.getBlockBlobClient('path/to/file.jpg')
46
+ await blockBlobClient.upload(fileBuffer, fileBuffer.length, {
47
+ blobHTTPHeaders: {
48
+ blobContentType: 'image/jpeg',
49
+ },
50
+ metadata: {
51
+ userId: '123',
52
+ originalName: 'photo.jpg',
53
+ },
54
+ })
55
+
56
+ // Download blob
57
+ const downloadResponse = await blockBlobClient.download()
58
+ const fileContent = await streamToBuffer(downloadResponse.readableStreamBody)
59
+
60
+ // Delete blob
61
+ await blockBlobClient.delete()
62
+
63
+ // List blobs
64
+ for await (const blob of containerClient.listBlobsFlat()) {
65
+ console.log(blob.name, blob.properties.contentLength)
66
+ }
67
+ ```
68
+
69
+ ### Advanced Features
70
+ ```typescript
71
+ // Generate SAS URL
72
+ import { generateBlobSASQueryParameters, BlobSASPermissions, StorageSharedKeyCredential } from '@azure/storage-blob'
73
+
74
+ const sasToken = generateBlobSASQueryParameters(
75
+ {
76
+ containerName: 'mycontainer',
77
+ blobName: 'path/to/file.jpg',
78
+ permissions: BlobSASPermissions.parse('r'), // read
79
+ startsOn: new Date(),
80
+ expiresOn: new Date(new Date().valueOf() + 3600 * 1000), // 1 hour
81
+ },
82
+ sharedKeyCredential
83
+ ).toString()
84
+
85
+ const sasUrl = `https://${accountName}.blob.core.windows.net/mycontainer/path/to/file.jpg?${sasToken}`
86
+
87
+ // Copy blob
88
+ const sourceBlobClient = containerClient.getBlockBlobClient('source/file.jpg')
89
+ const destBlobClient = containerClient.getBlockBlobClient('dest/file.jpg')
90
+ await destBlobClient.beginCopyFromURL(sourceBlobClient.url)
91
+
92
+ // Set blob metadata
93
+ await blockBlobClient.setMetadata({
94
+ category: 'profile',
95
+ uploadedBy: 'user-123',
96
+ })
97
+
98
+ // Get blob properties
99
+ const properties = await blockBlobClient.getProperties()
100
+ console.log(properties.contentType, properties.contentLength, properties.metadata)
101
+ ```
102
+
103
+ ## Common Patterns
104
+
105
+ ### File Upload Handler
106
+ ```typescript
107
+ async function uploadFile(file: Buffer, filename: string, userId: string) {
108
+ const blobName = `users/${userId}/${Date.now()}-${filename}`
109
+ const blobClient = containerClient.getBlockBlobClient(blobName)
110
+
111
+ await blobClient.upload(file, file.length, {
112
+ blobHTTPHeaders: {
113
+ blobContentType: getContentType(filename),
114
+ },
115
+ metadata: {
116
+ userId,
117
+ originalName: filename,
118
+ uploadedAt: new Date().toISOString(),
119
+ },
120
+ })
121
+
122
+ return {
123
+ blobName,
124
+ url: blobClient.url,
125
+ }
126
+ }
127
+ ```
128
+
129
+ ### Temporary Access URL
130
+ ```typescript
131
+ async function generateTemporaryUrl(blobName: string, expiresInMinutes: number = 60) {
132
+ const blobClient = containerClient.getBlockBlobClient(blobName)
133
+ const sasToken = generateBlobSASQueryParameters(
134
+ {
135
+ containerName: containerClient.containerName,
136
+ blobName,
137
+ permissions: BlobSASPermissions.parse('r'),
138
+ expiresOn: new Date(Date.now() + expiresInMinutes * 60 * 1000),
139
+ },
140
+ sharedKeyCredential
141
+ ).toString()
142
+
143
+ return `${blobClient.url}?${sasToken}`
144
+ }
145
+ ```
146
+
147
+ ## Best Practices
148
+
149
+ ✅ **DO:**
150
+ - Use appropriate access tiers (Hot, Cool, Archive)
151
+ - Set blob metadata for organization
152
+ - Use SAS tokens for temporary access
153
+ - Implement proper error handling
154
+ - Use appropriate content types
155
+ - Enable soft delete for important data
156
+ - Monitor storage usage and costs
157
+ - Use lifecycle management policies
158
+ - Implement retry logic
159
+ - Use connection strings or managed identity
160
+
161
+ ❌ **DON'T:**
162
+ - Store sensitive data without encryption
163
+ - Use public access unnecessarily
164
+ - Hardcode credentials
165
+ - Ignore error handling
166
+ - Skip content-type validation
167
+ - Ignore lifecycle policies
168
+ - Skip access logging
169
+ - Use default access levels
170
+ - Ignore cost optimization
171
+ - Store large files without chunking
172
+
173
+ ## Configuration
174
+
175
+ ### Environment Variables
176
+ ```bash
177
+ AZURE_STORAGE_ACCOUNT_NAME=myaccount
178
+ AZURE_STORAGE_ACCOUNT_KEY=your-account-key
179
+ AZURE_CONTAINER_NAME=mycontainer
180
+ AZURE_STORAGE_CONNECTION_STRING=DefaultEndpointsProtocol=https;AccountName=...
181
+ ```
182
+
183
+ ### Managed Identity (Recommended)
184
+ ```typescript
185
+ import { DefaultAzureCredential } from '@azure/identity'
186
+
187
+ const blobServiceClient = new BlobServiceClient(
188
+ `https://${accountName}.blob.core.windows.net`,
189
+ new DefaultAzureCredential()
190
+ )
191
+ ```
192
+
193
+ <!-- AZURE_BLOB:END -->
194
+
@@ -0,0 +1,249 @@
1
+ ---
2
+ name: "Cassandra"
3
+ description: "Use Cassandra for distributed NoSQL database with high availability, linear scalability, and eventual consistency."
4
+ version: "1.0.0"
5
+ category: "services"
6
+ author: "Rulebook"
7
+ tags: ["services", "database"]
8
+ dependencies: []
9
+ conflicts: []
10
+ ---
11
+ <!-- CASSANDRA:START -->
12
+ # Apache Cassandra Database Instructions
13
+
14
+ **CRITICAL**: Use Cassandra for distributed NoSQL database with high availability, linear scalability, and eventual consistency.
15
+
16
+ ## Core Features
17
+
18
+ ### Connection
19
+ ```typescript
20
+ // Using cassandra-driver
21
+ import { Client } from 'cassandra-driver'
22
+
23
+ const client = new Client({
24
+ contactPoints: (process.env.CASSANDRA_HOSTS || 'localhost').split(','),
25
+ localDataCenter: process.env.CASSANDRA_DATACENTER || 'datacenter1',
26
+ keyspace: process.env.CASSANDRA_KEYSPACE || 'myapp',
27
+ credentials: {
28
+ username: process.env.CASSANDRA_USER || 'cassandra',
29
+ password: process.env.CASSANDRA_PASSWORD || 'cassandra',
30
+ },
31
+ queryOptions: {
32
+ consistency: 1, // ONE, QUORUM, ALL
33
+ prepare: true,
34
+ },
35
+ })
36
+ ```
37
+
38
+ ### Basic Operations
39
+ ```typescript
40
+ // Create keyspace
41
+ await client.execute(`
42
+ CREATE KEYSPACE IF NOT EXISTS myapp
43
+ WITH REPLICATION = {
44
+ 'class': 'SimpleStrategy',
45
+ 'replication_factor': 1
46
+ }
47
+ `)
48
+
49
+ // Use keyspace
50
+ await client.execute('USE myapp')
51
+
52
+ // Create table
53
+ await client.execute(`
54
+ CREATE TABLE IF NOT EXISTS users (
55
+ id UUID PRIMARY KEY,
56
+ email TEXT,
57
+ name TEXT,
58
+ created_at TIMESTAMP
59
+ )
60
+ `)
61
+
62
+ // Create index
63
+ await client.execute('CREATE INDEX IF NOT EXISTS ON users (email)')
64
+
65
+ // Insert
66
+ await client.execute(
67
+ 'INSERT INTO users (id, email, name, created_at) VALUES (?, ?, ?, ?)',
68
+ [cassandra.types.Uuid.random(), 'john@example.com', 'John Doe', new Date()],
69
+ { prepare: true }
70
+ )
71
+
72
+ // Select
73
+ const result = await client.execute(
74
+ 'SELECT * FROM users WHERE id = ?',
75
+ [userId],
76
+ { prepare: true }
77
+ )
78
+ const user = result.first()
79
+
80
+ // Update
81
+ await client.execute(
82
+ 'UPDATE users SET name = ? WHERE id = ?',
83
+ ['Jane Doe', userId],
84
+ { prepare: true }
85
+ )
86
+
87
+ // Delete
88
+ await client.execute(
89
+ 'DELETE FROM users WHERE id = ?',
90
+ [userId],
91
+ { prepare: true }
92
+ )
93
+ ```
94
+
95
+ ### Advanced Features
96
+ ```typescript
97
+ // Batch operations
98
+ const queries = [
99
+ {
100
+ query: 'INSERT INTO users (id, email, name) VALUES (?, ?, ?)',
101
+ params: [id1, 'user1@example.com', 'User 1'],
102
+ },
103
+ {
104
+ query: 'INSERT INTO users (id, email, name) VALUES (?, ?, ?)',
105
+ params: [id2, 'user2@example.com', 'User 2'],
106
+ },
107
+ ]
108
+
109
+ await client.batch(queries, { prepare: true })
110
+
111
+ // Collections
112
+ await client.execute(`
113
+ CREATE TABLE IF NOT EXISTS products (
114
+ id UUID PRIMARY KEY,
115
+ name TEXT,
116
+ tags SET<TEXT>,
117
+ metadata MAP<TEXT, TEXT>
118
+ )
119
+ `)
120
+
121
+ await client.execute(
122
+ 'UPDATE products SET tags = tags + ? WHERE id = ?',
123
+ [['electronics', 'gadgets'], productId],
124
+ { prepare: true }
125
+ )
126
+
127
+ // Time-to-Live (TTL)
128
+ await client.execute(
129
+ 'INSERT INTO sessions (id, data) VALUES (?, ?) USING TTL 3600',
130
+ [sessionId, sessionData],
131
+ { prepare: true }
132
+ )
133
+ ```
134
+
135
+ ## Common Patterns
136
+
137
+ ### Data Modeling
138
+ ```typescript
139
+ // Design tables for query patterns
140
+ // Query: Get users by email
141
+ await client.execute(`
142
+ CREATE TABLE users_by_email (
143
+ email TEXT PRIMARY KEY,
144
+ id UUID,
145
+ name TEXT,
146
+ created_at TIMESTAMP
147
+ )
148
+ `)
149
+
150
+ // Query: Get posts by user and date
151
+ await client.execute(`
152
+ CREATE TABLE posts_by_user (
153
+ user_id UUID,
154
+ created_at TIMESTAMP,
155
+ post_id UUID,
156
+ title TEXT,
157
+ content TEXT,
158
+ PRIMARY KEY (user_id, created_at, post_id)
159
+ ) WITH CLUSTERING ORDER BY (created_at DESC)
160
+ `)
161
+ ```
162
+
163
+ ### Consistency Levels
164
+ ```typescript
165
+ // Read with QUORUM consistency
166
+ const result = await client.execute(
167
+ 'SELECT * FROM users WHERE id = ?',
168
+ [userId],
169
+ {
170
+ consistency: 2, // QUORUM
171
+ prepare: true,
172
+ }
173
+ )
174
+
175
+ // Write with ALL consistency (strongest)
176
+ await client.execute(
177
+ 'INSERT INTO users (id, email, name) VALUES (?, ?, ?)',
178
+ [id, email, name],
179
+ {
180
+ consistency: 3, // ALL
181
+ prepare: true,
182
+ }
183
+ )
184
+ ```
185
+
186
+ ## Best Practices
187
+
188
+ ✅ **DO:**
189
+ - Design tables for query patterns (denormalize)
190
+ - Use appropriate partition keys
191
+ - Use clustering keys for sorting
192
+ - Create secondary indexes sparingly
193
+ - Use prepared statements
194
+ - Set appropriate consistency levels
195
+ - Use TTL for time-based data
196
+ - Monitor cluster health
197
+ - Use batch operations carefully
198
+ - Implement retry logic
199
+
200
+ ❌ **DON'T:**
201
+ - Use secondary indexes on high-cardinality columns
202
+ - Create too many secondary indexes
203
+ - Use ALL consistency for all operations
204
+ - Store large values (> 1MB)
205
+ - Skip error handling
206
+ - Ignore cluster topology
207
+ - Hardcode contact points
208
+ - Use SELECT * in production
209
+ - Ignore data modeling best practices
210
+ - Skip monitoring
211
+
212
+ ## Configuration
213
+
214
+ ### Environment Variables
215
+ ```bash
216
+ CASSANDRA_HOSTS=localhost
217
+ CASSANDRA_HOSTS=node1:9042,node2:9042,node3:9042
218
+ CASSANDRA_DATACENTER=datacenter1
219
+ CASSANDRA_KEYSPACE=myapp
220
+ CASSANDRA_USER=cassandra
221
+ CASSANDRA_PASSWORD=securepassword
222
+ ```
223
+
224
+ ### Docker Compose
225
+ ```yaml
226
+ services:
227
+ cassandra:
228
+ image: cassandra:4
229
+ ports:
230
+ - "9042:9042"
231
+ environment:
232
+ CASSANDRA_CLUSTER_NAME: my-cluster
233
+ CASSANDRA_DC: datacenter1
234
+ CASSANDRA_RACK: rack1
235
+ CASSANDRA_ENDPOINT_SNITCH: GossipingPropertyFileSnitch
236
+ volumes:
237
+ - cassandra_data:/var/lib/cassandra
238
+ healthcheck:
239
+ test: ["CMD-SHELL", "nodetool status | grep -E '^UN' || exit 1"]
240
+ interval: 30s
241
+ timeout: 10s
242
+ retries: 5
243
+
244
+ volumes:
245
+ cassandra_data:
246
+ ```
247
+
248
+ <!-- CASSANDRA:END -->
249
+