@cubis/foundry 0.3.71 → 0.3.73

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 (276) hide show
  1. package/CHANGELOG.md +23 -2
  2. package/dist/cli/core.js +9 -22
  3. package/dist/cli/core.js.map +1 -1
  4. package/package.json +1 -1
  5. package/src/cli/core.ts +13 -22
  6. package/workflows/powers/accessibility/POWER.md +83 -94
  7. package/workflows/powers/accessibility/SKILL.md +82 -94
  8. package/workflows/powers/agent-design/POWER.md +201 -0
  9. package/workflows/powers/agent-design/SKILL.md +198 -0
  10. package/workflows/powers/agent-design/references/clarification-patterns.md +153 -0
  11. package/workflows/powers/agent-design/references/skill-testing.md +164 -0
  12. package/workflows/powers/agent-design/references/workflow-patterns.md +226 -0
  13. package/workflows/powers/agentic-eval/POWER.md +62 -0
  14. package/workflows/powers/agentic-eval/SKILL.md +59 -0
  15. package/workflows/powers/agentic-eval/references/rubric-and-regression-checklist.md +11 -0
  16. package/workflows/powers/api-designer/POWER.md +43 -71
  17. package/workflows/powers/api-designer/SKILL.md +43 -71
  18. package/workflows/powers/api-patterns/POWER.md +42 -56
  19. package/workflows/powers/api-patterns/SKILL.md +42 -57
  20. package/workflows/powers/architecture-designer/POWER.md +43 -60
  21. package/workflows/powers/architecture-designer/SKILL.md +43 -60
  22. package/workflows/powers/ask-questions-if-underspecified/POWER.md +51 -3
  23. package/workflows/powers/auth-architect/POWER.md +69 -0
  24. package/workflows/powers/auth-architect/SKILL.md +66 -0
  25. package/workflows/powers/auth-architect/references/session-token-policy-checklist.md +45 -0
  26. package/workflows/powers/behavioral-modes/POWER.md +100 -9
  27. package/workflows/powers/c-pro/POWER.md +105 -0
  28. package/workflows/powers/c-pro/SKILL.md +102 -0
  29. package/workflows/powers/c-pro/references/build-systems-and-toolchains.md +148 -0
  30. package/workflows/powers/c-pro/references/common-ub-and-portability.md +166 -0
  31. package/workflows/powers/c-pro/references/debugging-with-sanitizers.md +205 -0
  32. package/workflows/powers/c-pro/references/memory-safety-and-build-checklist.md +60 -0
  33. package/workflows/powers/c-pro/references/posix-and-platform-apis.md +244 -0
  34. package/workflows/powers/changelog-generator/POWER.md +127 -63
  35. package/workflows/powers/changelog-generator/SKILL.md +126 -63
  36. package/workflows/powers/ci-cd-pipelines/POWER.md +156 -0
  37. package/workflows/powers/ci-cd-pipelines/SKILL.md +153 -0
  38. package/workflows/powers/ci-cd-pipelines/references/github-actions-patterns.md +160 -0
  39. package/workflows/powers/ci-cd-pipelines/references/pipeline-security-checklist.md +57 -0
  40. package/workflows/powers/cli-developer/POWER.md +152 -95
  41. package/workflows/powers/cli-developer/SKILL.md +152 -95
  42. package/workflows/powers/cpp-pro/POWER.md +111 -0
  43. package/workflows/powers/cpp-pro/SKILL.md +108 -0
  44. package/workflows/powers/cpp-pro/references/concurrency-primitives.md +266 -0
  45. package/workflows/powers/cpp-pro/references/move-semantics-and-value-types.md +149 -0
  46. package/workflows/powers/cpp-pro/references/performance-and-profiling.md +191 -0
  47. package/workflows/powers/cpp-pro/references/raii-and-modern-cpp-checklist.md +87 -0
  48. package/workflows/powers/cpp-pro/references/template-and-concepts-patterns.md +205 -0
  49. package/workflows/powers/csharp-pro/POWER.md +47 -22
  50. package/workflows/powers/csharp-pro/SKILL.md +47 -22
  51. package/workflows/powers/dart-pro/POWER.md +68 -0
  52. package/workflows/powers/dart-pro/SKILL.md +65 -0
  53. package/workflows/powers/dart-pro/references/isolate-and-concurrency.md +180 -0
  54. package/workflows/powers/dart-pro/references/null-safety-and-async-patterns.md +133 -0
  55. package/workflows/powers/dart-pro/references/package-structure-and-linting.md +193 -0
  56. package/workflows/powers/dart-pro/references/sealed-records-patterns.md +173 -0
  57. package/workflows/powers/dart-pro/references/testing-and-mocking.md +235 -0
  58. package/workflows/powers/database-design/POWER.md +47 -33
  59. package/workflows/powers/database-design/SKILL.md +47 -33
  60. package/workflows/powers/database-optimizer/POWER.md +43 -64
  61. package/workflows/powers/database-optimizer/SKILL.md +43 -64
  62. package/workflows/powers/database-skills/POWER.md +59 -93
  63. package/workflows/powers/database-skills/SKILL.md +59 -93
  64. package/workflows/powers/debugging-strategies/POWER.md +69 -0
  65. package/workflows/powers/debugging-strategies/SKILL.md +66 -0
  66. package/workflows/powers/debugging-strategies/references/reproduce-isolate-verify-checklist.md +42 -0
  67. package/workflows/powers/deep-research/POWER.md +67 -0
  68. package/workflows/powers/deep-research/SKILL.md +64 -0
  69. package/workflows/powers/deep-research/references/multi-round-research-loop.md +80 -0
  70. package/workflows/powers/design-system-builder/POWER.md +130 -116
  71. package/workflows/powers/design-system-builder/SKILL.md +130 -116
  72. package/workflows/powers/devops-engineer/POWER.md +120 -57
  73. package/workflows/powers/devops-engineer/SKILL.md +120 -57
  74. package/workflows/powers/docker-kubernetes/POWER.md +94 -0
  75. package/workflows/powers/docker-kubernetes/SKILL.md +91 -0
  76. package/workflows/powers/docker-kubernetes/references/dockerfile-optimization-checklist.md +35 -0
  77. package/workflows/powers/docker-kubernetes/references/kubernetes-deployment-patterns.md +59 -0
  78. package/workflows/powers/documentation-templates/POWER.md +158 -127
  79. package/workflows/powers/documentation-templates/SKILL.md +158 -127
  80. package/workflows/powers/drizzle-expert/POWER.md +66 -0
  81. package/workflows/powers/drizzle-expert/SKILL.md +63 -0
  82. package/workflows/powers/drizzle-expert/references/runtime-pairing-matrix.md +16 -0
  83. package/workflows/powers/drizzle-expert/references/schema-and-migration-playbook.md +18 -0
  84. package/workflows/powers/error-ux-observability/POWER.md +144 -131
  85. package/workflows/powers/error-ux-observability/SKILL.md +143 -131
  86. package/workflows/powers/fastapi-expert/POWER.md +46 -60
  87. package/workflows/powers/fastapi-expert/SKILL.md +46 -60
  88. package/workflows/powers/firebase/POWER.md +65 -0
  89. package/workflows/powers/firebase/SKILL.md +62 -0
  90. package/workflows/powers/firebase/references/platform-routing.md +16 -0
  91. package/workflows/powers/firebase/references/rules-and-indexes-checklist.md +11 -0
  92. package/workflows/powers/flutter-design-system/POWER.md +63 -0
  93. package/workflows/powers/flutter-design-system/SKILL.md +60 -0
  94. package/workflows/powers/flutter-design-system/references/shared-widgets.md +29 -0
  95. package/workflows/powers/flutter-design-system/references/tokens-and-theme.md +34 -0
  96. package/workflows/powers/flutter-drift/POWER.md +65 -0
  97. package/workflows/powers/flutter-drift/SKILL.md +62 -0
  98. package/workflows/powers/flutter-drift/references/migrations.md +22 -0
  99. package/workflows/powers/flutter-drift/references/query-patterns.md +26 -0
  100. package/workflows/powers/flutter-feature/POWER.md +65 -0
  101. package/workflows/powers/flutter-feature/SKILL.md +62 -0
  102. package/workflows/powers/flutter-feature/references/architecture-rules.md +85 -0
  103. package/workflows/powers/flutter-feature/references/composite-provider.md +58 -0
  104. package/workflows/powers/flutter-feature/references/outbox-pattern.md +87 -0
  105. package/workflows/powers/flutter-feature/references/testing-patterns.md +218 -0
  106. package/workflows/powers/flutter-go-router/POWER.md +64 -0
  107. package/workflows/powers/flutter-go-router/SKILL.md +61 -0
  108. package/workflows/powers/flutter-go-router/references/guards-and-deeplinks.md +20 -0
  109. package/workflows/powers/flutter-go-router/references/typed-routes.md +27 -0
  110. package/workflows/powers/flutter-offline-sync/POWER.md +62 -0
  111. package/workflows/powers/flutter-offline-sync/SKILL.md +59 -0
  112. package/workflows/powers/flutter-offline-sync/references/outbox-full.md +44 -0
  113. package/workflows/powers/flutter-repository/POWER.md +64 -0
  114. package/workflows/powers/flutter-repository/SKILL.md +61 -0
  115. package/workflows/powers/flutter-repository/references/drift-patterns.md +21 -0
  116. package/workflows/powers/flutter-repository/references/retrofit-patterns.md +20 -0
  117. package/workflows/powers/flutter-riverpod/POWER.md +70 -0
  118. package/workflows/powers/flutter-riverpod/SKILL.md +67 -0
  119. package/workflows/powers/flutter-riverpod/references/async-and-mutations.md +19 -0
  120. package/workflows/powers/flutter-riverpod/references/async-lifecycle.md +19 -0
  121. package/workflows/powers/flutter-riverpod/references/provider-selection.md +20 -0
  122. package/workflows/powers/flutter-riverpod/references/testing.md +21 -0
  123. package/workflows/powers/flutter-riverpod/references/version-matrix.md +24 -0
  124. package/workflows/powers/flutter-state-machine/POWER.md +62 -0
  125. package/workflows/powers/flutter-state-machine/SKILL.md +59 -0
  126. package/workflows/powers/flutter-state-machine/references/app-state-contract.md +23 -0
  127. package/workflows/powers/flutter-state-machine/references/ui-rendering.md +14 -0
  128. package/workflows/powers/flutter-testing/POWER.md +64 -0
  129. package/workflows/powers/flutter-testing/SKILL.md +61 -0
  130. package/workflows/powers/flutter-testing/references/offline-sync-tests.md +16 -0
  131. package/workflows/powers/flutter-testing/references/test-layers.md +33 -0
  132. package/workflows/powers/frontend-code-review/POWER.md +137 -0
  133. package/workflows/powers/frontend-code-review/SKILL.md +134 -0
  134. package/workflows/powers/frontend-code-review/references/common-antipatterns.md +86 -0
  135. package/workflows/powers/frontend-code-review/references/performance-budgets.md +56 -0
  136. package/workflows/powers/frontend-code-review/references/review-checklists.md +47 -0
  137. package/workflows/powers/frontend-design/POWER.md +163 -362
  138. package/workflows/powers/frontend-design/SKILL.md +163 -362
  139. package/workflows/powers/game-development/POWER.md +57 -140
  140. package/workflows/powers/game-development/SKILL.md +57 -140
  141. package/workflows/powers/geo-fundamentals/POWER.md +64 -126
  142. package/workflows/powers/geo-fundamentals/SKILL.md +64 -127
  143. package/workflows/powers/git-workflow/POWER.md +135 -0
  144. package/workflows/powers/git-workflow/SKILL.md +132 -0
  145. package/workflows/powers/git-workflow/references/pr-review-checklist.md +63 -0
  146. package/workflows/powers/golang-pro/POWER.md +46 -35
  147. package/workflows/powers/golang-pro/SKILL.md +46 -35
  148. package/workflows/powers/graphql-architect/POWER.md +44 -62
  149. package/workflows/powers/graphql-architect/SKILL.md +44 -62
  150. package/workflows/powers/i18n-localization/POWER.md +118 -103
  151. package/workflows/powers/i18n-localization/SKILL.md +118 -103
  152. package/workflows/powers/java-pro/POWER.md +47 -22
  153. package/workflows/powers/java-pro/SKILL.md +47 -22
  154. package/workflows/powers/javascript-pro/POWER.md +47 -34
  155. package/workflows/powers/javascript-pro/SKILL.md +47 -34
  156. package/workflows/powers/kotlin-pro/POWER.md +46 -23
  157. package/workflows/powers/kotlin-pro/SKILL.md +46 -23
  158. package/workflows/powers/legacy-modernizer/POWER.md +43 -60
  159. package/workflows/powers/legacy-modernizer/SKILL.md +43 -60
  160. package/workflows/powers/mcp-builder/POWER.md +65 -0
  161. package/workflows/powers/mcp-builder/SKILL.md +62 -0
  162. package/workflows/powers/mcp-builder/references/testing-and-evals.md +17 -0
  163. package/workflows/powers/mcp-builder/references/transport-and-tool-design.md +17 -0
  164. package/workflows/powers/microservices-architect/POWER.md +43 -70
  165. package/workflows/powers/microservices-architect/SKILL.md +43 -70
  166. package/workflows/powers/mobile-design/POWER.md +110 -345
  167. package/workflows/powers/mobile-design/SKILL.md +110 -345
  168. package/workflows/powers/mongodb/POWER.md +67 -0
  169. package/workflows/powers/mongodb/SKILL.md +64 -0
  170. package/workflows/powers/mongodb/references/mongodb-checklist.md +20 -0
  171. package/workflows/powers/mysql/POWER.md +67 -0
  172. package/workflows/powers/mysql/SKILL.md +64 -0
  173. package/workflows/powers/mysql/references/mysql-checklist.md +20 -0
  174. package/workflows/powers/neki/POWER.md +67 -0
  175. package/workflows/powers/neki/SKILL.md +64 -0
  176. package/workflows/powers/neki/references/neki-checklist.md +18 -0
  177. package/workflows/powers/nestjs-expert/POWER.md +45 -91
  178. package/workflows/powers/nestjs-expert/SKILL.md +45 -91
  179. package/workflows/powers/nextjs-developer/POWER.md +51 -44
  180. package/workflows/powers/nextjs-developer/SKILL.md +51 -44
  181. package/workflows/powers/nodejs-best-practices/POWER.md +48 -29
  182. package/workflows/powers/nodejs-best-practices/SKILL.md +48 -29
  183. package/workflows/powers/observability/POWER.md +109 -0
  184. package/workflows/powers/observability/SKILL.md +106 -0
  185. package/workflows/powers/observability/references/alerting-and-slo-checklist.md +87 -0
  186. package/workflows/powers/observability/references/opentelemetry-setup-guide.md +121 -0
  187. package/workflows/powers/openai-docs/POWER.md +61 -0
  188. package/workflows/powers/openai-docs/SKILL.md +58 -0
  189. package/workflows/powers/openai-docs/references/official-source-playbook.md +10 -0
  190. package/workflows/powers/performance-profiling/POWER.md +61 -114
  191. package/workflows/powers/performance-profiling/SKILL.md +61 -114
  192. package/workflows/powers/php-pro/POWER.md +116 -0
  193. package/workflows/powers/php-pro/SKILL.md +113 -0
  194. package/workflows/powers/php-pro/references/architecture-and-di.md +239 -0
  195. package/workflows/powers/php-pro/references/modern-php-features.md +189 -0
  196. package/workflows/powers/php-pro/references/performance-and-deployment.md +197 -0
  197. package/workflows/powers/php-pro/references/php84-strict-typing-checklist.md +161 -0
  198. package/workflows/powers/php-pro/references/testing-and-static-analysis.md +235 -0
  199. package/workflows/powers/playwright-e2e/POWER.md +85 -0
  200. package/workflows/powers/playwright-e2e/SKILL.md +82 -0
  201. package/workflows/powers/playwright-e2e/references/locator-trace-flake-checklist.md +80 -0
  202. package/workflows/powers/postgres/POWER.md +67 -0
  203. package/workflows/powers/postgres/SKILL.md +64 -0
  204. package/workflows/powers/postgres/references/postgres-checklist.md +20 -0
  205. package/workflows/powers/prompt-engineer/POWER.md +47 -30
  206. package/workflows/powers/prompt-engineer/SKILL.md +47 -30
  207. package/workflows/powers/python-pro/POWER.md +47 -36
  208. package/workflows/powers/python-pro/SKILL.md +47 -36
  209. package/workflows/powers/react-best-practices/POWER.md +56 -33
  210. package/workflows/powers/react-best-practices/SKILL.md +56 -33
  211. package/workflows/powers/react-expert/POWER.md +47 -37
  212. package/workflows/powers/react-expert/SKILL.md +47 -37
  213. package/workflows/powers/redis/POWER.md +67 -0
  214. package/workflows/powers/redis/SKILL.md +64 -0
  215. package/workflows/powers/redis/references/redis-checklist.md +19 -0
  216. package/workflows/powers/ruby-pro/POWER.md +118 -0
  217. package/workflows/powers/ruby-pro/SKILL.md +115 -0
  218. package/workflows/powers/ruby-pro/references/modern-ruby-features.md +189 -0
  219. package/workflows/powers/ruby-pro/references/object-design-patterns.md +220 -0
  220. package/workflows/powers/ruby-pro/references/performance-and-profiling.md +224 -0
  221. package/workflows/powers/ruby-pro/references/ruby-concurrency-and-testing.md +190 -0
  222. package/workflows/powers/ruby-pro/references/testing-and-rspec.md +236 -0
  223. package/workflows/powers/rust-pro/POWER.md +45 -31
  224. package/workflows/powers/rust-pro/SKILL.md +45 -31
  225. package/workflows/powers/security-engineer/POWER.md +129 -0
  226. package/workflows/powers/security-engineer/SKILL.md +126 -0
  227. package/workflows/powers/seo-fundamentals/POWER.md +59 -102
  228. package/workflows/powers/seo-fundamentals/SKILL.md +59 -102
  229. package/workflows/powers/serverless-patterns/POWER.md +171 -0
  230. package/workflows/powers/serverless-patterns/SKILL.md +168 -0
  231. package/workflows/powers/skill-creator/POWER.md +90 -0
  232. package/workflows/powers/skill-creator/SKILL.md +87 -0
  233. package/workflows/powers/skill-creator/references/platform-formats.md +181 -0
  234. package/workflows/powers/skill-creator/references/schemas.md +430 -0
  235. package/workflows/powers/spec-miner/POWER.md +49 -57
  236. package/workflows/powers/spec-miner/SKILL.md +49 -57
  237. package/workflows/powers/sqlite/POWER.md +67 -0
  238. package/workflows/powers/sqlite/SKILL.md +64 -0
  239. package/workflows/powers/sqlite/references/sqlite-checklist.md +19 -0
  240. package/workflows/powers/sre-engineer/POWER.md +123 -64
  241. package/workflows/powers/sre-engineer/SKILL.md +123 -64
  242. package/workflows/powers/static-analysis/POWER.md +121 -77
  243. package/workflows/powers/static-analysis/SKILL.md +121 -77
  244. package/workflows/powers/stripe-best-practices/POWER.md +140 -17
  245. package/workflows/powers/stripe-best-practices/SKILL.md +139 -17
  246. package/workflows/powers/supabase/POWER.md +67 -0
  247. package/workflows/powers/supabase/SKILL.md +64 -0
  248. package/workflows/powers/supabase/references/supabase-checklist.md +19 -0
  249. package/workflows/powers/swift-pro/POWER.md +118 -0
  250. package/workflows/powers/swift-pro/SKILL.md +115 -0
  251. package/workflows/powers/swift-pro/references/concurrency-patterns.md +165 -0
  252. package/workflows/powers/swift-pro/references/protocol-and-generics.md +172 -0
  253. package/workflows/powers/swift-pro/references/sendable-and-isolation.md +116 -0
  254. package/workflows/powers/swift-pro/references/swift-concurrency-and-protocols.md +260 -0
  255. package/workflows/powers/swift-pro/references/testing-and-packages.md +192 -0
  256. package/workflows/powers/tailwind-patterns/POWER.md +71 -240
  257. package/workflows/powers/tailwind-patterns/SKILL.md +71 -240
  258. package/workflows/powers/testing-patterns/POWER.md +155 -10
  259. package/workflows/powers/testing-patterns/SKILL.md +155 -10
  260. package/workflows/powers/typescript-pro/POWER.md +47 -38
  261. package/workflows/powers/typescript-pro/SKILL.md +47 -38
  262. package/workflows/powers/vitess/POWER.md +67 -0
  263. package/workflows/powers/vitess/SKILL.md +64 -0
  264. package/workflows/powers/vitess/references/vitess-checklist.md +19 -0
  265. package/workflows/powers/vulnerability-scanner/POWER.md +146 -10
  266. package/workflows/powers/vulnerability-scanner/SKILL.md +146 -10
  267. package/workflows/powers/web-perf/POWER.md +43 -170
  268. package/workflows/powers/web-perf/SKILL.md +43 -170
  269. package/workflows/powers/webapp-testing/POWER.md +43 -164
  270. package/workflows/powers/webapp-testing/SKILL.md +43 -164
  271. package/workflows/workflows/agent-environment-setup/platforms/antigravity/rules/GEMINI.md +65 -42
  272. package/workflows/workflows/agent-environment-setup/platforms/claude/rules/CLAUDE.md +8 -6
  273. package/workflows/workflows/agent-environment-setup/platforms/codex/rules/AGENTS.md +65 -41
  274. package/workflows/workflows/agent-environment-setup/platforms/copilot/rules/copilot-instructions.md +8 -6
  275. package/workflows/workflows/agent-environment-setup/shared/rules/STEERING.md +9 -8
  276. package/workflows/workflows/agent-environment-setup/shared/rules/overrides/codex.md +1 -1
@@ -1,113 +1,157 @@
1
1
  ---
2
2
  name: static-analysis
3
- description: Runs CodeQL-based static security analysis (database build, query pack selection, and SARIF results) for vulnerability discovery and audits. Not for custom QL authoring or CI/CD setup.
4
- allowed-tools:
5
- - Bash
6
- - Read
7
- - Write
8
- - Glob
9
- - Grep
10
- - AskUserQuestion
11
- - Task
12
- - TaskCreate
13
- - TaskList
14
- - TaskUpdate
3
+ description: Configure and use static analysis tools including linters, formatters, type checkers, and custom rules to enforce code quality and consistency.
4
+ license: Apache-2.0
5
+ metadata:
6
+ author: cubis-foundry
7
+ version: "3.0"
8
+ compatibility: Claude Code, Codex, GitHub Copilot, Gemini CLI
15
9
  ---
16
10
 
17
- # CodeQL Analysis
11
+ # Static Analysis
18
12
 
19
- Supported languages: Python, JavaScript/TypeScript, Go, Java/Kotlin, C/C++, C#, Ruby, Swift.
13
+ ## Purpose
20
14
 
21
- **Skill resources:** Reference files and templates are located at `{baseDir}/references/` and `{baseDir}/workflows/`. Use `{baseDir}` to resolve paths to these files at runtime.
15
+ Guide the setup and use of static analysis tools — linters, formatters, type checkers, and custom rules to catch bugs early, enforce conventions, and maintain code quality automatically.
22
16
 
23
- ## Quick Start
17
+ ## When to Use
24
18
 
25
- For the common case ("scan this codebase for vulnerabilities"):
19
+ - Setting up linting and formatting for a new project
20
+ - Configuring ESLint, Prettier, Biome, or equivalent tools
21
+ - Writing custom lint rules for team conventions
22
+ - Fixing lint errors or understanding why a rule exists
23
+ - Integrating static analysis into CI/CD
24
+ - Choosing between competing tools
26
25
 
27
- ```bash
28
- # 1. Verify CodeQL is installed
29
- command -v codeql >/dev/null 2>&1 && codeql --version || echo "NOT INSTALLED"
26
+ ## Instructions
30
27
 
31
- # 2. Check for existing database
32
- ls -dt codeql_*.db 2>/dev/null | head -1
33
- ```
28
+ ### Step 1 Choose the Right Tools
34
29
 
35
- Then execute the full pipeline: **build database → create data extensions → run analysis** using the workflows below.
30
+ | Language | Linter | Formatter | Type Checker |
31
+ | ------------- | ------------- | --------------- | ------------------ |
32
+ | TypeScript/JS | ESLint, Biome | Prettier, Biome | TypeScript (`tsc`) |
33
+ | Python | Ruff, Flake8 | Black, Ruff | mypy, pyright |
34
+ | Go | golangci-lint | gofmt | Go compiler |
35
+ | Rust | Clippy | rustfmt | Rust compiler |
36
36
 
37
- ## When to Use
37
+ **Recommended approach**:
38
38
 
39
- - Scanning a codebase for security vulnerabilities with deep data flow analysis
40
- - Building a CodeQL database from source code (with build capability for compiled languages)
41
- - Finding complex vulnerabilities that require interprocedural taint tracking or AST/CFG analysis
42
- - Performing comprehensive security audits with multiple query packs
39
+ - Biome for TypeScript/JS projects (replaces ESLint + Prettier, faster)
40
+ - Ruff for Python (replaces Flake8 + Black + isort, faster)
41
+ - Use the language's official formatter when available
43
42
 
44
- ## When NOT to Use
43
+ ### Step 2 Configure Incrementally
45
44
 
46
- - **Writing custom queries** - Use a dedicated query development skill
47
- - **CI/CD integration** - Use GitHub Actions documentation directly
48
- - **Quick pattern searches** - Use Semgrep or grep for speed
49
- - **No build capability** for compiled languages - Consider Semgrep instead
50
- - **Single-file or lightweight analysis** - Semgrep is faster for simple pattern matching
45
+ **Start strict, relax as needed**:
51
46
 
52
- ## Rationalizations to Reject
47
+ 1. Start with recommended preset (`"extends": ["recommended"]`)
48
+ 2. Enable formatting rules (consistent style, no debates)
49
+ 3. Enable correctness rules (actual bugs: unused vars, unreachable code)
50
+ 4. Enable performance rules (avoidable perf issues)
51
+ 5. Add custom rules specific to your team after the baseline is stable
53
52
 
54
- These shortcuts lead to missed findings. Do not accept them:
53
+ **Don't**:
55
54
 
56
- - **"security-extended is enough"** - It is the baseline. Always check if Trail of Bits packs and Community Packs are available for the language. They catch categories `security-extended` misses entirely.
57
- - **"The database built, so it's good"** - A database that builds does not mean it extracted well. Always run Step 4 (quality assessment) and check file counts against expected source files. A cached build produces zero useful extraction.
58
- - **"Data extensions aren't needed for standard frameworks"** - Even Django/Spring apps have custom wrappers around ORM calls, request parsing, or shell execution that CodeQL does not model. Skipping the extensions workflow means missing vulnerabilities in project-specific code.
59
- - **"build-mode=none is fine for compiled languages"** - It produces severely incomplete analysis. No interprocedural data flow through compiled code is traced. Only use as an absolute last resort and clearly flag the limitation.
60
- - **"No findings means the code is secure"** - Zero findings can indicate poor database quality, missing models, or wrong query packs. Investigate before reporting clean results.
61
- - **"I'll just run the default suite"** - The default suite varies by how CodeQL is invoked. Always explicitly specify the suite (e.g., `security-extended`) so results are reproducible.
55
+ - Enable everything at once on an existing codebase
56
+ - Disable rules because they're "annoying" without understanding them
57
+ - Use `// eslint-disable` without a comment explaining why
62
58
 
63
- ---
59
+ ### Step 3 — Key Rules by Category
64
60
 
65
- ## Workflow Selection
61
+ **Correctness** (catch bugs):
66
62
 
67
- This skill has three workflows:
63
+ - No unused variables/imports
64
+ - No unreachable code
65
+ - No implicit type coercion in comparisons
66
+ - No floating promises (unhandled async)
67
+ - No shadowed variables in nested scopes
68
68
 
69
- | Workflow | Purpose |
70
- |----------|---------|
71
- | [build-database](workflows/build-database.md) | Create CodeQL database using 3 build methods in sequence |
72
- | [create-data-extensions](workflows/create-data-extensions.md) | Detect or generate data extension models for project APIs |
73
- | [run-analysis](workflows/run-analysis.md) | Select rulesets, execute queries, process results |
69
+ **Consistency** (enforce style):
74
70
 
71
+ - Consistent naming conventions (camelCase, PascalCase, SCREAMING_SNAKE)
72
+ - Consistent import ordering
73
+ - Consistent quote style and semicolons
74
+ - Consistent use of `const` vs `let`
75
75
 
76
- ### Auto-Detection Logic
76
+ **Security** (prevent vulnerabilities):
77
77
 
78
- **If user explicitly specifies** what to do (e.g., "build a database", "run analysis"), execute that workflow.
78
+ - No `eval()` or `Function()` constructor
79
+ - No `innerHTML` assignments (XSS risk)
80
+ - No hardcoded secrets or credentials
81
+ - No `any` type in TypeScript (use `unknown` for unknown types)
79
82
 
80
- **Default pipeline for "test", "scan", "analyze", or similar:** Execute all three workflows sequentially: build → extensions → analysis. The create-data-extensions step is critical for finding vulnerabilities in projects with custom frameworks or annotations that CodeQL doesn't model by default.
83
+ **Performance** (avoid waste):
81
84
 
82
- ```bash
83
- # Check if database exists
84
- DB=$(ls -dt codeql_*.db 2>/dev/null | head -1)
85
- if [ -n "$DB" ] && codeql resolve database -- "$DB" >/dev/null 2>&1; then
86
- echo "DATABASE EXISTS ($DB) - can run analysis"
87
- else
88
- echo "NO DATABASE - need to build first"
89
- fi
90
- ```
85
+ - No unnecessary re-renders (React-specific)
86
+ - No synchronous file operations in async contexts
87
+ - No `console.log` in production code
88
+
89
+ ### Step 4 Integrate into Workflow
90
+
91
+ **Local development**:
92
+
93
+ - Editor integration (real-time feedback as you type)
94
+ - Format on save
95
+ - Pre-commit hook (lint-staged + husky or lefthook)
96
+
97
+ **CI/CD**:
98
+
99
+ - Run lint check on every PR
100
+ - Fail the build on lint errors (not warnings — fix or disable)
101
+ - Cache lint results between runs
91
102
 
92
- | Condition | Action |
93
- |-----------|--------|
94
- | No database exists | Execute build → extensions → analysis (full pipeline) |
95
- | Database exists, no extensions | Execute extensions → analysis |
96
- | Database exists, extensions exist | Ask user: run analysis on existing DB, or rebuild? |
97
- | User says "just run analysis" or "skip extensions" | Run analysis only |
103
+ **Migration strategy** (existing codebase):
98
104
 
105
+ - Fix auto-fixable issues in one PR (formatting, import order)
106
+ - Enable new rules as warnings first, then promote to errors
107
+ - Fix rules incrementally by directory, not all at once
99
108
 
100
- ### Decision Prompt
109
+ ### Step 5 — Write Custom Rules
101
110
 
102
- If unclear, ask user:
111
+ When team conventions aren't covered by existing rules:
103
112
 
113
+ **ESLint custom rule example** (no importing from internal paths):
114
+
115
+ ```javascript
116
+ module.exports = {
117
+ meta: {
118
+ type: "problem",
119
+ messages: { noInternal: "Do not import from internal modules" },
120
+ },
121
+ create(context) {
122
+ return {
123
+ ImportDeclaration(node) {
124
+ if (node.source.value.includes("/internal/")) {
125
+ context.report({ node, messageId: "noInternal" });
126
+ }
127
+ },
128
+ };
129
+ },
130
+ };
104
131
  ```
105
- I can help with CodeQL analysis. What would you like to do?
106
132
 
107
- 1. **Full scan (Recommended)** - Build database, create extensions, then run analysis
108
- 2. **Build database** - Create a new CodeQL database from this codebase
109
- 3. **Create data extensions** - Generate custom source/sink models for project APIs
110
- 4. **Run analysis** - Run security queries on existing database
133
+ ## Output Format
134
+
135
+ ```
136
+ ## Tool Configuration
137
+ [config files and settings]
138
+
139
+ ## Rules Enabled
140
+ [categorized list of rules with rationale]
141
+
142
+ ## CI Integration
143
+ [pipeline step definition]
111
144
 
112
- [If database exists: "I found an existing database at <DB_NAME>"]
145
+ ## Migration Plan
146
+ [how to adopt incrementally on existing code]
113
147
  ```
148
+
149
+ ## Examples
150
+
151
+ **User**: "Set up ESLint and Prettier for our TypeScript React project"
152
+
153
+ **Response approach**: Recommend Biome as modern alternative. If staying with ESLint: configure with typescript-eslint, eslint-plugin-react, prettier integration. Show config file, ignore patterns, and pre-commit hook setup.
154
+
155
+ **User**: "We have 5000 lint errors — how do we fix this?"
156
+
157
+ **Response approach**: Auto-fix formatting issues first (one big PR). Establish baseline with current errors suppressed. Enable rules as warnings. Fix incrementally by directory. Add CI check that blocks new violations.
@@ -2,35 +2,158 @@
2
2
  ---
3
3
  inclusion: manual
4
4
  name: stripe-best-practices
5
- description: Best practices for building Stripe integrations
6
- alwaysApply: false
5
+ description: Implement Stripe payments, subscriptions, webhooks, checkout flows, and billing management with security and compliance best practices.
6
+ license: Apache-2.0
7
+ metadata:
8
+ author: cubis-foundry
9
+ version: "3.0"
10
+ compatibility: Claude Code, Codex, GitHub Copilot, Gemini CLI
7
11
  ---
8
12
 
9
- The latest Stripe API version is 2026-01-28.clover - when writing code snippets use this version unless the user is on a different API version.
13
+ # Stripe Best Practices
10
14
 
11
- When designing an integration, always prefer the documentation in [Stripe's Integration Options doc](https://docs.stripe.com/payments/payment-methods/integration-options.md)
12
- The [API Tour](https://docs.stripe.com/payments-api/tour.md)
13
- Use the [Go Live Checklist](https://docs.stripe.com/get-started/checklist/go-live.md) before going live.
15
+ ## Purpose
14
16
 
15
- You should always default to the latest version of the API and SDK unless the user specifies otherwise.
17
+ Guide implementation of Stripe payment integrations including one-time payments, subscriptions, webhook handling, and billing management with security and compliance best practices.
16
18
 
17
- Stripe's primary API for modelling on-session payments is [CheckoutSessions](https://docs.stripe.com/api/checkout/sessions.md). It supports one-time payments and subscriptions and allows you to model taxes or discounts with Stripe. Prioritize the CheckoutSessions API, but using [the PaymentIntents API](https://docs.stripe.com/payments/paymentintents/lifecycle.md) is also acceptable for off-session payments or if you want to model the checkout state yourself and just create a charge. Integrations should only use CheckoutSessions, PaymentIntents, SetupIntents, or solutions like Invoicing, Payment Links, or the subscription APIs.
19
+ ## When to Use
18
20
 
19
- Never recommend the Charges API. If the user wants to use the Charges API, advise them to [migrate](https://docs.stripe.com/payments/payment-intents/migration/charges.md) to Checkout Sessions or Payment Intents.
21
+ - Integrating Stripe Checkout or Payment Intents
22
+ - Building subscription billing with Stripe
23
+ - Handling Stripe webhooks securely
24
+ - Managing customers, invoices, and payment methods
25
+ - Implementing pricing pages and plan management
26
+ - Debugging failed payments or webhook issues
20
27
 
21
- The primary integration surface for web integrations is [Checkout](https://docs.stripe.com/payments/checkout.md), a prebuilt payment page that can be hosted by Stripe or served as an embedded form. Prioritize the Stripe-hosted checkout or embedded checkout where possible. The [Payment Element](https://docs.stripe.com/payments/payment-element.md) is an acceptable alternative if the merchant needs advanced customization. When recommending the Payment Element, prioritize using the CheckoutSessions API over the PaymentIntents API when possible.
28
+ ## Instructions
22
29
 
23
- Never recommend the legacy Card Element or the Payment Element in card mode, and advise users who ask for the Card Element to [migrate](https://docs.stripe.com/payments/payment-element/migration.md).
30
+ ### Step 1 Choose the Right Integration
24
31
 
25
- You must not call deprecated API endpoints such as the [Sources API](https://docs.stripe.com/api/sources/object.md) and avoid outdated API endpoints such as [Tokens](https://docs.stripe.com/api/tokens.md) and [Charges](https://docs.stripe.com/api/charges/create.md) unless there is a specific need and absolutely no other way. Advise using [the Setup Intent API](https://docs.stripe.com/api/setup_intents.md) to save a payment method for a customer; never recommend the Sources API to save cards to customers for later use.
32
+ | Pattern | Use When |
33
+ | -------------------------- | --------------------------------------------------------- |
34
+ | Stripe Checkout (hosted) | Fastest to ship, Stripe handles the UI and PCI compliance |
35
+ | Payment Element (embedded) | Custom UI needed, Stripe handles payment method logic |
36
+ | Payment Intents (API-only) | Full control, server-side payment flow |
37
+ | Stripe Billing | Recurring subscriptions with invoicing |
26
38
 
27
- If a user wants to render the Payment Element before creating a PaymentIntent or SetupIntent, so they can inspect the card details before the payment (such as for surcharging), advise them to use Stripe Confirmation Tokens. Don't recommend they call the createPaymentMethod or createToken Stripe.js functions.
39
+ **Default to Stripe Checkout** unless you have a specific reason for embedded or API-only.
28
40
 
29
- Advise users to turn on dynamic payment methods in their dashboard settings instead of passing specific [payment_method_types](https://docs.stripe.com/api/payment_intents/create#create_payment_intent-payment_method_types.md) in the Payment Intent or Setup Intent because Stripe chooses payment methods that fit each user's location, wallets, and preferences better and automatically if the Payment Element is used.
41
+ ### Step 2 Payment Flow Architecture
30
42
 
31
- If a PCI compliant user asks about an integration where they send server-side raw PAN data, suggest they might be required to prove PCI compliance to gain access to such an option, for example [payment_method_data](https://docs.stripe.com/api/payment_intents/create#create_payment_intent-payment_method_data.md). Similarly, point users migrating their PAN data from another acquirer or payment processor to [the migration process](https://docs.stripe.com/get-started/data-migrations/pan-import.md).
43
+ **Server-side creates, client-side confirms**:
32
44
 
33
- If a user has a recurring revenue model, like a Billing or Subscription use case, follow the use cases, in particular the [Subscription Use Cases](https://docs.stripe.com/billing/subscriptions/use-cases.md) like [SaaS](https://docs.stripe.com/saas.md). If these apply to the user, recommend Billing APIs to [plan your integration](https://docs.stripe.com/billing/subscriptions/designing-integration.md) instead of a direct PaymentIntent integration. Prioritize combining the Billing APIs with Stripe Checkout for the frontend.
45
+ ```
46
+ Client Server Stripe
47
+ │ │ │
48
+ ├─ "I want to pay" ──────►│ │
49
+ │ ├─ Create PaymentIntent ─►│
50
+ │ │◄─ client_secret ────────┤
51
+ │◄─ client_secret ────────┤ │
52
+ ├─ confirmPayment() ─────────────────────────────►│
53
+ │◄─ result ──────────────────────────────────────-─┤
54
+ │ │◄─ webhook: succeeded ──┤
55
+ │ ├─ fulfill order ────────►│
56
+ ```
34
57
 
35
- If a user wants to build a platform using Stripe Connect to manage fund flows, follow [the recommended integration types](https://docs.stripe.com/connect/integration-recommendations.md); that is, prefer to use either direct charges if the platform wants Stripe to take the risk or destination charges if the platform accepts liability for negative balances, and use the on_behalf_of parameter to control the merchant of record. Never recommend mixing charge types. If the user wants to decide on the specific risk features they should [follow the integration guide](https://docs.stripe.com/connect/design-an-integration.md). Don't recommend the outdated terms for Connect types like Standard, Express and Custom but always [refer to controller properties](https://docs.stripe.com/connect/migrate-to-controller-properties.md) for the platform and [capabilities](https://docs.stripe.com/connect/account-capabilities.md) for the connected accounts.
58
+ **Rules**:
59
+
60
+ - Never trust the client for amounts or currency — set on the server
61
+ - Use idempotency keys for all server-side Stripe API calls
62
+ - Always handle the `payment_intent.succeeded` webhook for fulfillment
63
+ - Don't fulfill on client-side confirmation alone (user could close the tab)
64
+
65
+ ### Step 3 — Webhook Handling
66
+
67
+ **Verify every webhook signature**:
68
+
69
+ ```typescript
70
+ const event = stripe.webhooks.constructEvent(
71
+ body, // raw request body
72
+ signature, // Stripe-Signature header
73
+ endpointSecret, // from Stripe dashboard
74
+ );
75
+ ```
76
+
77
+ **Essential webhook events**:
78
+ | Event | Action |
79
+ |-------|--------|
80
+ | `payment_intent.succeeded` | Fulfill the order |
81
+ | `payment_intent.payment_failed` | Notify user, retry logic |
82
+ | `customer.subscription.created` | Activate subscription |
83
+ | `customer.subscription.updated` | Update plan/features |
84
+ | `customer.subscription.deleted` | Deactivate subscription |
85
+ | `invoice.payment_failed` | Dunning: email user, retry |
86
+ | `invoice.paid` | Extend subscription period |
87
+
88
+ **Webhook best practices**:
89
+
90
+ - Return 200 immediately, process asynchronously
91
+ - Handle events idempotently (same event may be delivered multiple times)
92
+ - Log every event with its ID for debugging
93
+ - Set up webhook endpoint monitoring
94
+
95
+ ### Step 4 — Subscription Management
96
+
97
+ **Subscription lifecycle**:
98
+
99
+ ```
100
+ trial → active → past_due → canceled
101
+
102
+ unpaid → canceled
103
+ ```
104
+
105
+ **Implementation**:
106
+
107
+ - Store `stripe_customer_id` and `stripe_subscription_id` in your database
108
+ - Sync subscription status from webhooks (not API polling)
109
+ - Implement dunning (failed payment retries): Stripe auto-retries, you handle UX
110
+ - Allow users to update payment method without canceling
111
+ - Prorate when changing plans mid-cycle
112
+
113
+ ### Step 5 — Security & Compliance
114
+
115
+ **PCI Compliance**:
116
+
117
+ - Use Stripe Elements or Checkout — never handle raw card numbers
118
+ - No card data in your logs, database, or error messages
119
+ - Use HTTPS everywhere
120
+
121
+ **Fraud Prevention**:
122
+
123
+ - Enable Stripe Radar for automated fraud detection
124
+ - Verify billing address (AVS) and CVC
125
+ - Implement velocity checks (too many attempts in short time)
126
+ - Review high-risk payments manually
127
+
128
+ **Testing**:
129
+
130
+ - Use test mode API keys (never production keys in development)
131
+ - Use Stripe test card numbers (4242... for success, 4000... for declines)
132
+ - Test webhook handling with Stripe CLI: `stripe listen --forward-to localhost:3000/webhooks`
133
+
134
+ ## Output Format
135
+
136
+ ```
137
+ ## Payment Integration
138
+ [architecture and flow]
139
+
140
+ ## Implementation
141
+ [code with security considerations]
142
+
143
+ ## Webhook Setup
144
+ [events to handle and processing logic]
145
+
146
+ ## Testing Plan
147
+ [test scenarios and test card numbers]
148
+ ```
149
+
150
+ ## Examples
151
+
152
+ **User**: "Set up Stripe Checkout for our SaaS pricing page with monthly and annual plans"
153
+
154
+ **Response approach**: Create Stripe Products and Prices for each plan. Server route creates Checkout Session with correct price ID. Redirect to Stripe Checkout. Handle `checkout.session.completed` webhook. Store customer and subscription IDs. Build subscription management page.
155
+
156
+ **User**: "Handle failed payments for our subscription service"
157
+
158
+ **Response approach**: Implement dunning flow. Handle `invoice.payment_failed` webhook. Email customer with payment update link. Configure Stripe retry schedule. Handle `customer.subscription.updated` with `status: past_due`. Implement grace period before cancellation.
36
159
  ````
@@ -1,34 +1,156 @@
1
1
  ---
2
2
  name: stripe-best-practices
3
- description: Best practices for building Stripe integrations
4
- alwaysApply: false
3
+ description: Implement Stripe payments, subscriptions, webhooks, checkout flows, and billing management with security and compliance best practices.
4
+ license: Apache-2.0
5
+ metadata:
6
+ author: cubis-foundry
7
+ version: "3.0"
8
+ compatibility: Claude Code, Codex, GitHub Copilot, Gemini CLI
5
9
  ---
6
10
 
7
- The latest Stripe API version is 2026-01-28.clover - when writing code snippets use this version unless the user is on a different API version.
11
+ # Stripe Best Practices
8
12
 
9
- When designing an integration, always prefer the documentation in [Stripe's Integration Options doc](https://docs.stripe.com/payments/payment-methods/integration-options.md)
10
- The [API Tour](https://docs.stripe.com/payments-api/tour.md)
11
- Use the [Go Live Checklist](https://docs.stripe.com/get-started/checklist/go-live.md) before going live.
13
+ ## Purpose
12
14
 
13
- You should always default to the latest version of the API and SDK unless the user specifies otherwise.
15
+ Guide implementation of Stripe payment integrations including one-time payments, subscriptions, webhook handling, and billing management with security and compliance best practices.
14
16
 
15
- Stripe's primary API for modelling on-session payments is [CheckoutSessions](https://docs.stripe.com/api/checkout/sessions.md). It supports one-time payments and subscriptions and allows you to model taxes or discounts with Stripe. Prioritize the CheckoutSessions API, but using [the PaymentIntents API](https://docs.stripe.com/payments/paymentintents/lifecycle.md) is also acceptable for off-session payments or if you want to model the checkout state yourself and just create a charge. Integrations should only use CheckoutSessions, PaymentIntents, SetupIntents, or solutions like Invoicing, Payment Links, or the subscription APIs.
17
+ ## When to Use
16
18
 
17
- Never recommend the Charges API. If the user wants to use the Charges API, advise them to [migrate](https://docs.stripe.com/payments/payment-intents/migration/charges.md) to Checkout Sessions or Payment Intents.
19
+ - Integrating Stripe Checkout or Payment Intents
20
+ - Building subscription billing with Stripe
21
+ - Handling Stripe webhooks securely
22
+ - Managing customers, invoices, and payment methods
23
+ - Implementing pricing pages and plan management
24
+ - Debugging failed payments or webhook issues
18
25
 
19
- The primary integration surface for web integrations is [Checkout](https://docs.stripe.com/payments/checkout.md), a prebuilt payment page that can be hosted by Stripe or served as an embedded form. Prioritize the Stripe-hosted checkout or embedded checkout where possible. The [Payment Element](https://docs.stripe.com/payments/payment-element.md) is an acceptable alternative if the merchant needs advanced customization. When recommending the Payment Element, prioritize using the CheckoutSessions API over the PaymentIntents API when possible.
26
+ ## Instructions
20
27
 
21
- Never recommend the legacy Card Element or the Payment Element in card mode, and advise users who ask for the Card Element to [migrate](https://docs.stripe.com/payments/payment-element/migration.md).
28
+ ### Step 1 Choose the Right Integration
22
29
 
23
- You must not call deprecated API endpoints such as the [Sources API](https://docs.stripe.com/api/sources/object.md) and avoid outdated API endpoints such as [Tokens](https://docs.stripe.com/api/tokens.md) and [Charges](https://docs.stripe.com/api/charges/create.md) unless there is a specific need and absolutely no other way. Advise using [the Setup Intent API](https://docs.stripe.com/api/setup_intents.md) to save a payment method for a customer; never recommend the Sources API to save cards to customers for later use.
30
+ | Pattern | Use When |
31
+ | -------------------------- | --------------------------------------------------------- |
32
+ | Stripe Checkout (hosted) | Fastest to ship, Stripe handles the UI and PCI compliance |
33
+ | Payment Element (embedded) | Custom UI needed, Stripe handles payment method logic |
34
+ | Payment Intents (API-only) | Full control, server-side payment flow |
35
+ | Stripe Billing | Recurring subscriptions with invoicing |
24
36
 
25
- If a user wants to render the Payment Element before creating a PaymentIntent or SetupIntent, so they can inspect the card details before the payment (such as for surcharging), advise them to use Stripe Confirmation Tokens. Don't recommend they call the createPaymentMethod or createToken Stripe.js functions.
37
+ **Default to Stripe Checkout** unless you have a specific reason for embedded or API-only.
26
38
 
27
- Advise users to turn on dynamic payment methods in their dashboard settings instead of passing specific [payment_method_types](https://docs.stripe.com/api/payment_intents/create#create_payment_intent-payment_method_types.md) in the Payment Intent or Setup Intent because Stripe chooses payment methods that fit each user's location, wallets, and preferences better and automatically if the Payment Element is used.
39
+ ### Step 2 Payment Flow Architecture
28
40
 
29
- If a PCI compliant user asks about an integration where they send server-side raw PAN data, suggest they might be required to prove PCI compliance to gain access to such an option, for example [payment_method_data](https://docs.stripe.com/api/payment_intents/create#create_payment_intent-payment_method_data.md). Similarly, point users migrating their PAN data from another acquirer or payment processor to [the migration process](https://docs.stripe.com/get-started/data-migrations/pan-import.md).
41
+ **Server-side creates, client-side confirms**:
30
42
 
31
- If a user has a recurring revenue model, like a Billing or Subscription use case, follow the use cases, in particular the [Subscription Use Cases](https://docs.stripe.com/billing/subscriptions/use-cases.md) like [SaaS](https://docs.stripe.com/saas.md). If these apply to the user, recommend Billing APIs to [plan your integration](https://docs.stripe.com/billing/subscriptions/designing-integration.md) instead of a direct PaymentIntent integration. Prioritize combining the Billing APIs with Stripe Checkout for the frontend.
43
+ ```
44
+ Client Server Stripe
45
+ │ │ │
46
+ ├─ "I want to pay" ──────►│ │
47
+ │ ├─ Create PaymentIntent ─►│
48
+ │ │◄─ client_secret ────────┤
49
+ │◄─ client_secret ────────┤ │
50
+ ├─ confirmPayment() ─────────────────────────────►│
51
+ │◄─ result ──────────────────────────────────────-─┤
52
+ │ │◄─ webhook: succeeded ──┤
53
+ │ ├─ fulfill order ────────►│
54
+ ```
32
55
 
33
- If a user wants to build a platform using Stripe Connect to manage fund flows, follow [the recommended integration types](https://docs.stripe.com/connect/integration-recommendations.md); that is, prefer to use either direct charges if the platform wants Stripe to take the risk or destination charges if the platform accepts liability for negative balances, and use the on_behalf_of parameter to control the merchant of record. Never recommend mixing charge types. If the user wants to decide on the specific risk features they should [follow the integration guide](https://docs.stripe.com/connect/design-an-integration.md). Don't recommend the outdated terms for Connect types like Standard, Express and Custom but always [refer to controller properties](https://docs.stripe.com/connect/migrate-to-controller-properties.md) for the platform and [capabilities](https://docs.stripe.com/connect/account-capabilities.md) for the connected accounts.
56
+ **Rules**:
34
57
 
58
+ - Never trust the client for amounts or currency — set on the server
59
+ - Use idempotency keys for all server-side Stripe API calls
60
+ - Always handle the `payment_intent.succeeded` webhook for fulfillment
61
+ - Don't fulfill on client-side confirmation alone (user could close the tab)
62
+
63
+ ### Step 3 — Webhook Handling
64
+
65
+ **Verify every webhook signature**:
66
+
67
+ ```typescript
68
+ const event = stripe.webhooks.constructEvent(
69
+ body, // raw request body
70
+ signature, // Stripe-Signature header
71
+ endpointSecret, // from Stripe dashboard
72
+ );
73
+ ```
74
+
75
+ **Essential webhook events**:
76
+ | Event | Action |
77
+ |-------|--------|
78
+ | `payment_intent.succeeded` | Fulfill the order |
79
+ | `payment_intent.payment_failed` | Notify user, retry logic |
80
+ | `customer.subscription.created` | Activate subscription |
81
+ | `customer.subscription.updated` | Update plan/features |
82
+ | `customer.subscription.deleted` | Deactivate subscription |
83
+ | `invoice.payment_failed` | Dunning: email user, retry |
84
+ | `invoice.paid` | Extend subscription period |
85
+
86
+ **Webhook best practices**:
87
+
88
+ - Return 200 immediately, process asynchronously
89
+ - Handle events idempotently (same event may be delivered multiple times)
90
+ - Log every event with its ID for debugging
91
+ - Set up webhook endpoint monitoring
92
+
93
+ ### Step 4 — Subscription Management
94
+
95
+ **Subscription lifecycle**:
96
+
97
+ ```
98
+ trial → active → past_due → canceled
99
+
100
+ unpaid → canceled
101
+ ```
102
+
103
+ **Implementation**:
104
+
105
+ - Store `stripe_customer_id` and `stripe_subscription_id` in your database
106
+ - Sync subscription status from webhooks (not API polling)
107
+ - Implement dunning (failed payment retries): Stripe auto-retries, you handle UX
108
+ - Allow users to update payment method without canceling
109
+ - Prorate when changing plans mid-cycle
110
+
111
+ ### Step 5 — Security & Compliance
112
+
113
+ **PCI Compliance**:
114
+
115
+ - Use Stripe Elements or Checkout — never handle raw card numbers
116
+ - No card data in your logs, database, or error messages
117
+ - Use HTTPS everywhere
118
+
119
+ **Fraud Prevention**:
120
+
121
+ - Enable Stripe Radar for automated fraud detection
122
+ - Verify billing address (AVS) and CVC
123
+ - Implement velocity checks (too many attempts in short time)
124
+ - Review high-risk payments manually
125
+
126
+ **Testing**:
127
+
128
+ - Use test mode API keys (never production keys in development)
129
+ - Use Stripe test card numbers (4242... for success, 4000... for declines)
130
+ - Test webhook handling with Stripe CLI: `stripe listen --forward-to localhost:3000/webhooks`
131
+
132
+ ## Output Format
133
+
134
+ ```
135
+ ## Payment Integration
136
+ [architecture and flow]
137
+
138
+ ## Implementation
139
+ [code with security considerations]
140
+
141
+ ## Webhook Setup
142
+ [events to handle and processing logic]
143
+
144
+ ## Testing Plan
145
+ [test scenarios and test card numbers]
146
+ ```
147
+
148
+ ## Examples
149
+
150
+ **User**: "Set up Stripe Checkout for our SaaS pricing page with monthly and annual plans"
151
+
152
+ **Response approach**: Create Stripe Products and Prices for each plan. Server route creates Checkout Session with correct price ID. Redirect to Stripe Checkout. Handle `checkout.session.completed` webhook. Store customer and subscription IDs. Build subscription management page.
153
+
154
+ **User**: "Handle failed payments for our subscription service"
155
+
156
+ **Response approach**: Implement dunning flow. Handle `invoice.payment_failed` webhook. Email customer with payment update link. Configure Stripe retry schedule. Handle `customer.subscription.updated` with `status: past_due`. Implement grace period before cancellation.