@musashishao/agent-kit 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of @musashishao/agent-kit might be problematic. Click here for more details.

Files changed (220) hide show
  1. package/.agent/.shared/ui-ux-pro-max/data/charts.csv +26 -0
  2. package/.agent/.shared/ui-ux-pro-max/data/colors.csv +97 -0
  3. package/.agent/.shared/ui-ux-pro-max/data/icons.csv +101 -0
  4. package/.agent/.shared/ui-ux-pro-max/data/landing.csv +31 -0
  5. package/.agent/.shared/ui-ux-pro-max/data/products.csv +97 -0
  6. package/.agent/.shared/ui-ux-pro-max/data/prompts.csv +24 -0
  7. package/.agent/.shared/ui-ux-pro-max/data/react-performance.csv +45 -0
  8. package/.agent/.shared/ui-ux-pro-max/data/stacks/flutter.csv +53 -0
  9. package/.agent/.shared/ui-ux-pro-max/data/stacks/html-tailwind.csv +56 -0
  10. package/.agent/.shared/ui-ux-pro-max/data/stacks/jetpack-compose.csv +53 -0
  11. package/.agent/.shared/ui-ux-pro-max/data/stacks/nextjs.csv +53 -0
  12. package/.agent/.shared/ui-ux-pro-max/data/stacks/nuxt-ui.csv +51 -0
  13. package/.agent/.shared/ui-ux-pro-max/data/stacks/nuxtjs.csv +59 -0
  14. package/.agent/.shared/ui-ux-pro-max/data/stacks/react-native.csv +52 -0
  15. package/.agent/.shared/ui-ux-pro-max/data/stacks/react.csv +54 -0
  16. package/.agent/.shared/ui-ux-pro-max/data/stacks/shadcn.csv +61 -0
  17. package/.agent/.shared/ui-ux-pro-max/data/stacks/svelte.csv +54 -0
  18. package/.agent/.shared/ui-ux-pro-max/data/stacks/swiftui.csv +51 -0
  19. package/.agent/.shared/ui-ux-pro-max/data/stacks/vue.csv +50 -0
  20. package/.agent/.shared/ui-ux-pro-max/data/styles.csv +59 -0
  21. package/.agent/.shared/ui-ux-pro-max/data/typography.csv +58 -0
  22. package/.agent/.shared/ui-ux-pro-max/data/ui-reasoning.csv +101 -0
  23. package/.agent/.shared/ui-ux-pro-max/data/ux-guidelines.csv +100 -0
  24. package/.agent/.shared/ui-ux-pro-max/data/web-interface.csv +31 -0
  25. package/.agent/.shared/ui-ux-pro-max/scripts/core.py +258 -0
  26. package/.agent/.shared/ui-ux-pro-max/scripts/design_system.py +487 -0
  27. package/.agent/.shared/ui-ux-pro-max/scripts/search.py +76 -0
  28. package/.agent/ARCHITECTURE.md +225 -0
  29. package/.agent/CONTEXT.md +229 -0
  30. package/.agent/FEATURE_ROADMAP.md +435 -0
  31. package/.agent/PROMPT_TEMPLATES.md +261 -0
  32. package/.agent/agents/backend-specialist.md +263 -0
  33. package/.agent/agents/database-architect.md +226 -0
  34. package/.agent/agents/debugger.md +225 -0
  35. package/.agent/agents/devops-engineer.md +242 -0
  36. package/.agent/agents/documentation-writer.md +104 -0
  37. package/.agent/agents/explorer-agent.md +73 -0
  38. package/.agent/agents/frontend-specialist.md +556 -0
  39. package/.agent/agents/game-developer.md +162 -0
  40. package/.agent/agents/mobile-developer.md +377 -0
  41. package/.agent/agents/orchestrator.md +416 -0
  42. package/.agent/agents/penetration-tester.md +188 -0
  43. package/.agent/agents/performance-optimizer.md +187 -0
  44. package/.agent/agents/project-planner.md +403 -0
  45. package/.agent/agents/security-auditor.md +170 -0
  46. package/.agent/agents/seo-specialist.md +111 -0
  47. package/.agent/agents/test-engineer.md +158 -0
  48. package/.agent/rules/GEMINI.md +251 -0
  49. package/.agent/skills/api-patterns/SKILL.md +81 -0
  50. package/.agent/skills/api-patterns/api-style.md +42 -0
  51. package/.agent/skills/api-patterns/auth.md +24 -0
  52. package/.agent/skills/api-patterns/documentation.md +26 -0
  53. package/.agent/skills/api-patterns/graphql.md +41 -0
  54. package/.agent/skills/api-patterns/rate-limiting.md +31 -0
  55. package/.agent/skills/api-patterns/response.md +37 -0
  56. package/.agent/skills/api-patterns/rest.md +40 -0
  57. package/.agent/skills/api-patterns/scripts/api_validator.py +211 -0
  58. package/.agent/skills/api-patterns/security-testing.md +122 -0
  59. package/.agent/skills/api-patterns/trpc.md +41 -0
  60. package/.agent/skills/api-patterns/versioning.md +22 -0
  61. package/.agent/skills/app-builder/SKILL.md +75 -0
  62. package/.agent/skills/app-builder/agent-coordination.md +71 -0
  63. package/.agent/skills/app-builder/feature-building.md +53 -0
  64. package/.agent/skills/app-builder/project-detection.md +34 -0
  65. package/.agent/skills/app-builder/scaffolding.md +118 -0
  66. package/.agent/skills/app-builder/tech-stack.md +40 -0
  67. package/.agent/skills/app-builder/templates/SKILL.md +39 -0
  68. package/.agent/skills/app-builder/templates/astro-static/TEMPLATE.md +76 -0
  69. package/.agent/skills/app-builder/templates/chrome-extension/TEMPLATE.md +92 -0
  70. package/.agent/skills/app-builder/templates/cli-tool/TEMPLATE.md +88 -0
  71. package/.agent/skills/app-builder/templates/electron-desktop/TEMPLATE.md +88 -0
  72. package/.agent/skills/app-builder/templates/express-api/TEMPLATE.md +83 -0
  73. package/.agent/skills/app-builder/templates/flutter-app/TEMPLATE.md +90 -0
  74. package/.agent/skills/app-builder/templates/monorepo-turborepo/TEMPLATE.md +90 -0
  75. package/.agent/skills/app-builder/templates/nextjs-fullstack/TEMPLATE.md +82 -0
  76. package/.agent/skills/app-builder/templates/nextjs-saas/TEMPLATE.md +100 -0
  77. package/.agent/skills/app-builder/templates/nextjs-static/TEMPLATE.md +106 -0
  78. package/.agent/skills/app-builder/templates/nuxt-app/TEMPLATE.md +101 -0
  79. package/.agent/skills/app-builder/templates/python-fastapi/TEMPLATE.md +83 -0
  80. package/.agent/skills/app-builder/templates/react-native-app/TEMPLATE.md +93 -0
  81. package/.agent/skills/architecture/SKILL.md +55 -0
  82. package/.agent/skills/architecture/context-discovery.md +43 -0
  83. package/.agent/skills/architecture/examples.md +94 -0
  84. package/.agent/skills/architecture/pattern-selection.md +68 -0
  85. package/.agent/skills/architecture/patterns-reference.md +50 -0
  86. package/.agent/skills/architecture/trade-off-analysis.md +77 -0
  87. package/.agent/skills/bash-linux/SKILL.md +199 -0
  88. package/.agent/skills/behavioral-modes/SKILL.md +242 -0
  89. package/.agent/skills/brainstorming/SKILL.md +163 -0
  90. package/.agent/skills/brainstorming/dynamic-questioning.md +350 -0
  91. package/.agent/skills/clean-code/SKILL.md +201 -0
  92. package/.agent/skills/code-review-checklist/SKILL.md +109 -0
  93. package/.agent/skills/database-design/SKILL.md +52 -0
  94. package/.agent/skills/database-design/database-selection.md +43 -0
  95. package/.agent/skills/database-design/indexing.md +39 -0
  96. package/.agent/skills/database-design/migrations.md +48 -0
  97. package/.agent/skills/database-design/optimization.md +36 -0
  98. package/.agent/skills/database-design/orm-selection.md +30 -0
  99. package/.agent/skills/database-design/schema-design.md +56 -0
  100. package/.agent/skills/database-design/scripts/schema_validator.py +172 -0
  101. package/.agent/skills/deployment-procedures/SKILL.md +241 -0
  102. package/.agent/skills/doc.md +177 -0
  103. package/.agent/skills/docker-expert/SKILL.md +409 -0
  104. package/.agent/skills/documentation-templates/SKILL.md +194 -0
  105. package/.agent/skills/frontend-design/SKILL.md +396 -0
  106. package/.agent/skills/frontend-design/animation-guide.md +331 -0
  107. package/.agent/skills/frontend-design/color-system.md +311 -0
  108. package/.agent/skills/frontend-design/decision-trees.md +418 -0
  109. package/.agent/skills/frontend-design/motion-graphics.md +306 -0
  110. package/.agent/skills/frontend-design/scripts/accessibility_checker.py +183 -0
  111. package/.agent/skills/frontend-design/scripts/ux_audit.py +722 -0
  112. package/.agent/skills/frontend-design/typography-system.md +345 -0
  113. package/.agent/skills/frontend-design/ux-psychology.md +541 -0
  114. package/.agent/skills/frontend-design/visual-effects.md +383 -0
  115. package/.agent/skills/game-development/2d-games/SKILL.md +119 -0
  116. package/.agent/skills/game-development/3d-games/SKILL.md +135 -0
  117. package/.agent/skills/game-development/SKILL.md +167 -0
  118. package/.agent/skills/game-development/game-art/SKILL.md +185 -0
  119. package/.agent/skills/game-development/game-audio/SKILL.md +190 -0
  120. package/.agent/skills/game-development/game-design/SKILL.md +129 -0
  121. package/.agent/skills/game-development/mobile-games/SKILL.md +108 -0
  122. package/.agent/skills/game-development/multiplayer/SKILL.md +132 -0
  123. package/.agent/skills/game-development/pc-games/SKILL.md +144 -0
  124. package/.agent/skills/game-development/vr-ar/SKILL.md +123 -0
  125. package/.agent/skills/game-development/web-games/SKILL.md +150 -0
  126. package/.agent/skills/geo-fundamentals/SKILL.md +156 -0
  127. package/.agent/skills/geo-fundamentals/scripts/geo_checker.py +289 -0
  128. package/.agent/skills/i18n-localization/SKILL.md +154 -0
  129. package/.agent/skills/i18n-localization/scripts/i18n_checker.py +241 -0
  130. package/.agent/skills/lint-and-validate/SKILL.md +45 -0
  131. package/.agent/skills/lint-and-validate/scripts/lint_runner.py +172 -0
  132. package/.agent/skills/lint-and-validate/scripts/type_coverage.py +173 -0
  133. package/.agent/skills/mcp-builder/SKILL.md +176 -0
  134. package/.agent/skills/mobile-design/SKILL.md +394 -0
  135. package/.agent/skills/mobile-design/decision-trees.md +516 -0
  136. package/.agent/skills/mobile-design/mobile-backend.md +491 -0
  137. package/.agent/skills/mobile-design/mobile-color-system.md +420 -0
  138. package/.agent/skills/mobile-design/mobile-debugging.md +122 -0
  139. package/.agent/skills/mobile-design/mobile-design-thinking.md +357 -0
  140. package/.agent/skills/mobile-design/mobile-navigation.md +458 -0
  141. package/.agent/skills/mobile-design/mobile-performance.md +767 -0
  142. package/.agent/skills/mobile-design/mobile-testing.md +356 -0
  143. package/.agent/skills/mobile-design/mobile-typography.md +433 -0
  144. package/.agent/skills/mobile-design/platform-android.md +666 -0
  145. package/.agent/skills/mobile-design/platform-ios.md +561 -0
  146. package/.agent/skills/mobile-design/scripts/mobile_audit.py +670 -0
  147. package/.agent/skills/mobile-design/touch-psychology.md +537 -0
  148. package/.agent/skills/nestjs-expert/SKILL.md +552 -0
  149. package/.agent/skills/nextjs-best-practices/SKILL.md +203 -0
  150. package/.agent/skills/nodejs-best-practices/SKILL.md +333 -0
  151. package/.agent/skills/parallel-agents/SKILL.md +175 -0
  152. package/.agent/skills/performance-profiling/SKILL.md +143 -0
  153. package/.agent/skills/performance-profiling/scripts/lighthouse_audit.py +76 -0
  154. package/.agent/skills/plan-writing/SKILL.md +152 -0
  155. package/.agent/skills/powershell-windows/SKILL.md +167 -0
  156. package/.agent/skills/prisma-expert/SKILL.md +355 -0
  157. package/.agent/skills/python-patterns/SKILL.md +441 -0
  158. package/.agent/skills/react-patterns/SKILL.md +198 -0
  159. package/.agent/skills/red-team-tactics/SKILL.md +199 -0
  160. package/.agent/skills/seo-fundamentals/SKILL.md +129 -0
  161. package/.agent/skills/seo-fundamentals/scripts/seo_checker.py +219 -0
  162. package/.agent/skills/server-management/SKILL.md +161 -0
  163. package/.agent/skills/systematic-debugging/SKILL.md +109 -0
  164. package/.agent/skills/tailwind-patterns/SKILL.md +269 -0
  165. package/.agent/skills/tdd-workflow/SKILL.md +149 -0
  166. package/.agent/skills/testing-patterns/SKILL.md +178 -0
  167. package/.agent/skills/testing-patterns/scripts/test_runner.py +219 -0
  168. package/.agent/skills/typescript-expert/SKILL.md +429 -0
  169. package/.agent/skills/typescript-expert/references/tsconfig-strict.json +92 -0
  170. package/.agent/skills/typescript-expert/references/typescript-cheatsheet.md +383 -0
  171. package/.agent/skills/typescript-expert/references/utility-types.ts +335 -0
  172. package/.agent/skills/typescript-expert/scripts/ts_diagnostic.py +203 -0
  173. package/.agent/skills/ui-ux-pro-max/SKILL.md +351 -0
  174. package/.agent/skills/ui-ux-pro-max/data/charts.csv +26 -0
  175. package/.agent/skills/ui-ux-pro-max/data/colors.csv +97 -0
  176. package/.agent/skills/ui-ux-pro-max/data/icons.csv +101 -0
  177. package/.agent/skills/ui-ux-pro-max/data/landing.csv +31 -0
  178. package/.agent/skills/ui-ux-pro-max/data/products.csv +97 -0
  179. package/.agent/skills/ui-ux-pro-max/data/prompts.csv +24 -0
  180. package/.agent/skills/ui-ux-pro-max/data/react-performance.csv +45 -0
  181. package/.agent/skills/ui-ux-pro-max/data/stacks/flutter.csv +53 -0
  182. package/.agent/skills/ui-ux-pro-max/data/stacks/html-tailwind.csv +56 -0
  183. package/.agent/skills/ui-ux-pro-max/data/stacks/nextjs.csv +53 -0
  184. package/.agent/skills/ui-ux-pro-max/data/stacks/nuxt-ui.csv +51 -0
  185. package/.agent/skills/ui-ux-pro-max/data/stacks/nuxtjs.csv +59 -0
  186. package/.agent/skills/ui-ux-pro-max/data/stacks/react-native.csv +52 -0
  187. package/.agent/skills/ui-ux-pro-max/data/stacks/react.csv +54 -0
  188. package/.agent/skills/ui-ux-pro-max/data/stacks/shadcn.csv +61 -0
  189. package/.agent/skills/ui-ux-pro-max/data/stacks/svelte.csv +54 -0
  190. package/.agent/skills/ui-ux-pro-max/data/stacks/swiftui.csv +51 -0
  191. package/.agent/skills/ui-ux-pro-max/data/stacks/vue.csv +50 -0
  192. package/.agent/skills/ui-ux-pro-max/data/styles.csv +59 -0
  193. package/.agent/skills/ui-ux-pro-max/data/typography.csv +58 -0
  194. package/.agent/skills/ui-ux-pro-max/data/ui-reasoning.csv +101 -0
  195. package/.agent/skills/ui-ux-pro-max/data/ux-guidelines.csv +100 -0
  196. package/.agent/skills/ui-ux-pro-max/data/web-interface.csv +31 -0
  197. package/.agent/skills/ui-ux-pro-max/scripts/core.py +257 -0
  198. package/.agent/skills/ui-ux-pro-max/scripts/design_system.py +487 -0
  199. package/.agent/skills/ui-ux-pro-max/scripts/search.py +76 -0
  200. package/.agent/skills/vulnerability-scanner/SKILL.md +276 -0
  201. package/.agent/skills/vulnerability-scanner/checklists.md +121 -0
  202. package/.agent/skills/vulnerability-scanner/scripts/security_scan.py +458 -0
  203. package/.agent/skills/webapp-testing/SKILL.md +187 -0
  204. package/.agent/skills/webapp-testing/scripts/playwright_runner.py +173 -0
  205. package/.agent/workflows/brainstorm.md +113 -0
  206. package/.agent/workflows/create.md +59 -0
  207. package/.agent/workflows/debug.md +103 -0
  208. package/.agent/workflows/deploy.md +176 -0
  209. package/.agent/workflows/enhance.md +63 -0
  210. package/.agent/workflows/orchestrate.md +237 -0
  211. package/.agent/workflows/plan.md +89 -0
  212. package/.agent/workflows/preview.md +80 -0
  213. package/.agent/workflows/status.md +86 -0
  214. package/.agent/workflows/test.md +144 -0
  215. package/.agent/workflows/ui-ux-pro-max.md +231 -0
  216. package/LICENSE +21 -0
  217. package/README.md +101 -0
  218. package/bin/cli.js +235 -0
  219. package/index.js +1 -0
  220. package/package.json +43 -0
@@ -0,0 +1,441 @@
1
+ ---
2
+ name: python-patterns
3
+ description: Python development principles and decision-making. Framework selection, async patterns, type hints, project structure. Teaches thinking, not copying.
4
+ allowed-tools: Read, Write, Edit, Glob, Grep
5
+ ---
6
+
7
+ # Python Patterns
8
+
9
+ > Python development principles and decision-making for 2025.
10
+ > **Learn to THINK, not memorize patterns.**
11
+
12
+ ---
13
+
14
+ ## ⚠️ How to Use This Skill
15
+
16
+ This skill teaches **decision-making principles**, not fixed code to copy.
17
+
18
+ - ASK user for framework preference when unclear
19
+ - Choose async vs sync based on CONTEXT
20
+ - Don't default to same framework every time
21
+
22
+ ---
23
+
24
+ ## 1. Framework Selection (2025)
25
+
26
+ ### Decision Tree
27
+
28
+ ```
29
+ What are you building?
30
+
31
+ ├── API-first / Microservices
32
+ │ └── FastAPI (async, modern, fast)
33
+
34
+ ├── Full-stack web / CMS / Admin
35
+ │ └── Django (batteries-included)
36
+
37
+ ├── Simple / Script / Learning
38
+ │ └── Flask (minimal, flexible)
39
+
40
+ ├── AI/ML API serving
41
+ │ └── FastAPI (Pydantic, async, uvicorn)
42
+
43
+ └── Background workers
44
+ └── Celery + any framework
45
+ ```
46
+
47
+ ### Comparison Principles
48
+
49
+ | Factor | FastAPI | Django | Flask |
50
+ |--------|---------|--------|-------|
51
+ | **Best for** | APIs, microservices | Full-stack, CMS | Simple, learning |
52
+ | **Async** | Native | Django 5.0+ | Via extensions |
53
+ | **Admin** | Manual | Built-in | Via extensions |
54
+ | **ORM** | Choose your own | Django ORM | Choose your own |
55
+ | **Learning curve** | Low | Medium | Low |
56
+
57
+ ### Selection Questions to Ask:
58
+ 1. Is this API-only or full-stack?
59
+ 2. Need admin interface?
60
+ 3. Team familiar with async?
61
+ 4. Existing infrastructure?
62
+
63
+ ---
64
+
65
+ ## 2. Async vs Sync Decision
66
+
67
+ ### When to Use Async
68
+
69
+ ```
70
+ async def is better when:
71
+ ├── I/O-bound operations (database, HTTP, file)
72
+ ├── Many concurrent connections
73
+ ├── Real-time features
74
+ ├── Microservices communication
75
+ └── FastAPI/Starlette/Django ASGI
76
+
77
+ def (sync) is better when:
78
+ ├── CPU-bound operations
79
+ ├── Simple scripts
80
+ ├── Legacy codebase
81
+ ├── Team unfamiliar with async
82
+ └── Blocking libraries (no async version)
83
+ ```
84
+
85
+ ### The Golden Rule
86
+
87
+ ```
88
+ I/O-bound → async (waiting for external)
89
+ CPU-bound → sync + multiprocessing (computing)
90
+
91
+ Don't:
92
+ ├── Mix sync and async carelessly
93
+ ├── Use sync libraries in async code
94
+ └── Force async for CPU work
95
+ ```
96
+
97
+ ### Async Library Selection
98
+
99
+ | Need | Async Library |
100
+ |------|---------------|
101
+ | HTTP client | httpx |
102
+ | PostgreSQL | asyncpg |
103
+ | Redis | aioredis / redis-py async |
104
+ | File I/O | aiofiles |
105
+ | Database ORM | SQLAlchemy 2.0 async, Tortoise |
106
+
107
+ ---
108
+
109
+ ## 3. Type Hints Strategy
110
+
111
+ ### When to Type
112
+
113
+ ```
114
+ Always type:
115
+ ├── Function parameters
116
+ ├── Return types
117
+ ├── Class attributes
118
+ ├── Public APIs
119
+
120
+ Can skip:
121
+ ├── Local variables (let inference work)
122
+ ├── One-off scripts
123
+ ├── Tests (usually)
124
+ ```
125
+
126
+ ### Common Type Patterns
127
+
128
+ ```python
129
+ # These are patterns, understand them:
130
+
131
+ # Optional → might be None
132
+ from typing import Optional
133
+ def find_user(id: int) -> Optional[User]: ...
134
+
135
+ # Union → one of multiple types
136
+ def process(data: str | dict) -> None: ...
137
+
138
+ # Generic collections
139
+ def get_items() -> list[Item]: ...
140
+ def get_mapping() -> dict[str, int]: ...
141
+
142
+ # Callable
143
+ from typing import Callable
144
+ def apply(fn: Callable[[int], str]) -> str: ...
145
+ ```
146
+
147
+ ### Pydantic for Validation
148
+
149
+ ```
150
+ When to use Pydantic:
151
+ ├── API request/response models
152
+ ├── Configuration/settings
153
+ ├── Data validation
154
+ ├── Serialization
155
+
156
+ Benefits:
157
+ ├── Runtime validation
158
+ ├── Auto-generated JSON schema
159
+ ├── Works with FastAPI natively
160
+ └── Clear error messages
161
+ ```
162
+
163
+ ---
164
+
165
+ ## 4. Project Structure Principles
166
+
167
+ ### Structure Selection
168
+
169
+ ```
170
+ Small project / Script:
171
+ ├── main.py
172
+ ├── utils.py
173
+ └── requirements.txt
174
+
175
+ Medium API:
176
+ ├── app/
177
+ │ ├── __init__.py
178
+ │ ├── main.py
179
+ │ ├── models/
180
+ │ ├── routes/
181
+ │ ├── services/
182
+ │ └── schemas/
183
+ ├── tests/
184
+ └── pyproject.toml
185
+
186
+ Large application:
187
+ ├── src/
188
+ │ └── myapp/
189
+ │ ├── core/
190
+ │ ├── api/
191
+ │ ├── services/
192
+ │ ├── models/
193
+ │ └── ...
194
+ ├── tests/
195
+ └── pyproject.toml
196
+ ```
197
+
198
+ ### FastAPI Structure Principles
199
+
200
+ ```
201
+ Organize by feature or layer:
202
+
203
+ By layer:
204
+ ├── routes/ (API endpoints)
205
+ ├── services/ (business logic)
206
+ ├── models/ (database models)
207
+ ├── schemas/ (Pydantic models)
208
+ └── dependencies/ (shared deps)
209
+
210
+ By feature:
211
+ ├── users/
212
+ │ ├── routes.py
213
+ │ ├── service.py
214
+ │ └── schemas.py
215
+ └── products/
216
+ └── ...
217
+ ```
218
+
219
+ ---
220
+
221
+ ## 5. Django Principles (2025)
222
+
223
+ ### Django Async (Django 5.0+)
224
+
225
+ ```
226
+ Django supports async:
227
+ ├── Async views
228
+ ├── Async middleware
229
+ ├── Async ORM (limited)
230
+ └── ASGI deployment
231
+
232
+ When to use async in Django:
233
+ ├── External API calls
234
+ ├── WebSocket (Channels)
235
+ ├── High-concurrency views
236
+ └── Background task triggering
237
+ ```
238
+
239
+ ### Django Best Practices
240
+
241
+ ```
242
+ Model design:
243
+ ├── Fat models, thin views
244
+ ├── Use managers for common queries
245
+ ├── Abstract base classes for shared fields
246
+
247
+ Views:
248
+ ├── Class-based for complex CRUD
249
+ ├── Function-based for simple endpoints
250
+ ├── Use viewsets with DRF
251
+
252
+ Queries:
253
+ ├── select_related() for FKs
254
+ ├── prefetch_related() for M2M
255
+ ├── Avoid N+1 queries
256
+ └── Use .only() for specific fields
257
+ ```
258
+
259
+ ---
260
+
261
+ ## 6. FastAPI Principles
262
+
263
+ ### async def vs def in FastAPI
264
+
265
+ ```
266
+ Use async def when:
267
+ ├── Using async database drivers
268
+ ├── Making async HTTP calls
269
+ ├── I/O-bound operations
270
+ └── Want to handle concurrency
271
+
272
+ Use def when:
273
+ ├── Blocking operations
274
+ ├── Sync database drivers
275
+ ├── CPU-bound work
276
+ └── FastAPI runs in threadpool automatically
277
+ ```
278
+
279
+ ### Dependency Injection
280
+
281
+ ```
282
+ Use dependencies for:
283
+ ├── Database sessions
284
+ ├── Current user / Auth
285
+ ├── Configuration
286
+ ├── Shared resources
287
+
288
+ Benefits:
289
+ ├── Testability (mock dependencies)
290
+ ├── Clean separation
291
+ ├── Automatic cleanup (yield)
292
+ ```
293
+
294
+ ### Pydantic v2 Integration
295
+
296
+ ```python
297
+ # FastAPI + Pydantic are tightly integrated:
298
+
299
+ # Request validation
300
+ @app.post("/users")
301
+ async def create(user: UserCreate) -> UserResponse:
302
+ # user is already validated
303
+ ...
304
+
305
+ # Response serialization
306
+ # Return type becomes response schema
307
+ ```
308
+
309
+ ---
310
+
311
+ ## 7. Background Tasks
312
+
313
+ ### Selection Guide
314
+
315
+ | Solution | Best For |
316
+ |----------|----------|
317
+ | **BackgroundTasks** | Simple, in-process tasks |
318
+ | **Celery** | Distributed, complex workflows |
319
+ | **ARQ** | Async, Redis-based |
320
+ | **RQ** | Simple Redis queue |
321
+ | **Dramatiq** | Actor-based, simpler than Celery |
322
+
323
+ ### When to Use Each
324
+
325
+ ```
326
+ FastAPI BackgroundTasks:
327
+ ├── Quick operations
328
+ ├── No persistence needed
329
+ ├── Fire-and-forget
330
+ └── Same process
331
+
332
+ Celery/ARQ:
333
+ ├── Long-running tasks
334
+ ├── Need retry logic
335
+ ├── Distributed workers
336
+ ├── Persistent queue
337
+ └── Complex workflows
338
+ ```
339
+
340
+ ---
341
+
342
+ ## 8. Error Handling Principles
343
+
344
+ ### Exception Strategy
345
+
346
+ ```
347
+ In FastAPI:
348
+ ├── Create custom exception classes
349
+ ├── Register exception handlers
350
+ ├── Return consistent error format
351
+ └── Log without exposing internals
352
+
353
+ Pattern:
354
+ ├── Raise domain exceptions in services
355
+ ├── Catch and transform in handlers
356
+ └── Client gets clean error response
357
+ ```
358
+
359
+ ### Error Response Philosophy
360
+
361
+ ```
362
+ Include:
363
+ ├── Error code (programmatic)
364
+ ├── Message (human readable)
365
+ ├── Details (field-level when applicable)
366
+ └── NOT stack traces (security)
367
+ ```
368
+
369
+ ---
370
+
371
+ ## 9. Testing Principles
372
+
373
+ ### Testing Strategy
374
+
375
+ | Type | Purpose | Tools |
376
+ |------|---------|-------|
377
+ | **Unit** | Business logic | pytest |
378
+ | **Integration** | API endpoints | pytest + httpx/TestClient |
379
+ | **E2E** | Full workflows | pytest + DB |
380
+
381
+ ### Async Testing
382
+
383
+ ```python
384
+ # Use pytest-asyncio for async tests
385
+
386
+ import pytest
387
+ from httpx import AsyncClient
388
+
389
+ @pytest.mark.asyncio
390
+ async def test_endpoint():
391
+ async with AsyncClient(app=app, base_url="http://test") as client:
392
+ response = await client.get("/users")
393
+ assert response.status_code == 200
394
+ ```
395
+
396
+ ### Fixtures Strategy
397
+
398
+ ```
399
+ Common fixtures:
400
+ ├── db_session → Database connection
401
+ ├── client → Test client
402
+ ├── authenticated_user → User with token
403
+ └── sample_data → Test data setup
404
+ ```
405
+
406
+ ---
407
+
408
+ ## 10. Decision Checklist
409
+
410
+ Before implementing:
411
+
412
+ - [ ] **Asked user about framework preference?**
413
+ - [ ] **Chosen framework for THIS context?** (not just default)
414
+ - [ ] **Decided async vs sync?**
415
+ - [ ] **Planned type hint strategy?**
416
+ - [ ] **Defined project structure?**
417
+ - [ ] **Planned error handling?**
418
+ - [ ] **Considered background tasks?**
419
+
420
+ ---
421
+
422
+ ## 11. Anti-Patterns to Avoid
423
+
424
+ ### ❌ DON'T:
425
+ - Default to Django for simple APIs (FastAPI may be better)
426
+ - Use sync libraries in async code
427
+ - Skip type hints for public APIs
428
+ - Put business logic in routes/views
429
+ - Ignore N+1 queries
430
+ - Mix async and sync carelessly
431
+
432
+ ### ✅ DO:
433
+ - Choose framework based on context
434
+ - Ask about async requirements
435
+ - Use Pydantic for validation
436
+ - Separate concerns (routes → services → repos)
437
+ - Test critical paths
438
+
439
+ ---
440
+
441
+ > **Remember**: Python patterns are about decision-making for YOUR specific context. Don't copy code—think about what serves your application best.
@@ -0,0 +1,198 @@
1
+ ---
2
+ name: react-patterns
3
+ description: Modern React patterns and principles. Hooks, composition, performance, TypeScript best practices.
4
+ allowed-tools: Read, Write, Edit, Glob, Grep
5
+ ---
6
+
7
+ # React Patterns
8
+
9
+ > Principles for building production-ready React applications.
10
+
11
+ ---
12
+
13
+ ## 1. Component Design Principles
14
+
15
+ ### Component Types
16
+
17
+ | Type | Use | State |
18
+ |------|-----|-------|
19
+ | **Server** | Data fetching, static | None |
20
+ | **Client** | Interactivity | useState, effects |
21
+ | **Presentational** | UI display | Props only |
22
+ | **Container** | Logic/state | Heavy state |
23
+
24
+ ### Design Rules
25
+
26
+ - One responsibility per component
27
+ - Props down, events up
28
+ - Composition over inheritance
29
+ - Prefer small, focused components
30
+
31
+ ---
32
+
33
+ ## 2. Hook Patterns
34
+
35
+ ### When to Extract Hooks
36
+
37
+ | Pattern | Extract When |
38
+ |---------|-------------|
39
+ | **useLocalStorage** | Same storage logic needed |
40
+ | **useDebounce** | Multiple debounced values |
41
+ | **useFetch** | Repeated fetch patterns |
42
+ | **useForm** | Complex form state |
43
+
44
+ ### Hook Rules
45
+
46
+ - Hooks at top level only
47
+ - Same order every render
48
+ - Custom hooks start with "use"
49
+ - Clean up effects on unmount
50
+
51
+ ---
52
+
53
+ ## 3. State Management Selection
54
+
55
+ | Complexity | Solution |
56
+ |------------|----------|
57
+ | Simple | useState, useReducer |
58
+ | Shared local | Context |
59
+ | Server state | React Query, SWR |
60
+ | Complex global | Zustand, Redux Toolkit |
61
+
62
+ ### State Placement
63
+
64
+ | Scope | Where |
65
+ |-------|-------|
66
+ | Single component | useState |
67
+ | Parent-child | Lift state up |
68
+ | Subtree | Context |
69
+ | App-wide | Global store |
70
+
71
+ ---
72
+
73
+ ## 4. React 19 Patterns
74
+
75
+ ### New Hooks
76
+
77
+ | Hook | Purpose |
78
+ |------|---------|
79
+ | **useActionState** | Form submission state |
80
+ | **useOptimistic** | Optimistic UI updates |
81
+ | **use** | Read resources in render |
82
+
83
+ ### Compiler Benefits
84
+
85
+ - Automatic memoization
86
+ - Less manual useMemo/useCallback
87
+ - Focus on pure components
88
+
89
+ ---
90
+
91
+ ## 5. Composition Patterns
92
+
93
+ ### Compound Components
94
+
95
+ - Parent provides context
96
+ - Children consume context
97
+ - Flexible slot-based composition
98
+ - Example: Tabs, Accordion, Dropdown
99
+
100
+ ### Render Props vs Hooks
101
+
102
+ | Use Case | Prefer |
103
+ |----------|--------|
104
+ | Reusable logic | Custom hook |
105
+ | Render flexibility | Render props |
106
+ | Cross-cutting | Higher-order component |
107
+
108
+ ---
109
+
110
+ ## 6. Performance Principles
111
+
112
+ ### When to Optimize
113
+
114
+ | Signal | Action |
115
+ |--------|--------|
116
+ | Slow renders | Profile first |
117
+ | Large lists | Virtualize |
118
+ | Expensive calc | useMemo |
119
+ | Stable callbacks | useCallback |
120
+
121
+ ### Optimization Order
122
+
123
+ 1. Check if actually slow
124
+ 2. Profile with DevTools
125
+ 3. Identify bottleneck
126
+ 4. Apply targeted fix
127
+
128
+ ---
129
+
130
+ ## 7. Error Handling
131
+
132
+ ### Error Boundary Usage
133
+
134
+ | Scope | Placement |
135
+ |-------|-----------|
136
+ | App-wide | Root level |
137
+ | Feature | Route/feature level |
138
+ | Component | Around risky component |
139
+
140
+ ### Error Recovery
141
+
142
+ - Show fallback UI
143
+ - Log error
144
+ - Offer retry option
145
+ - Preserve user data
146
+
147
+ ---
148
+
149
+ ## 8. TypeScript Patterns
150
+
151
+ ### Props Typing
152
+
153
+ | Pattern | Use |
154
+ |---------|-----|
155
+ | Interface | Component props |
156
+ | Type | Unions, complex |
157
+ | Generic | Reusable components |
158
+
159
+ ### Common Types
160
+
161
+ | Need | Type |
162
+ |------|------|
163
+ | Children | ReactNode |
164
+ | Event handler | MouseEventHandler |
165
+ | Ref | RefObject<Element> |
166
+
167
+ ---
168
+
169
+ ## 9. Testing Principles
170
+
171
+ | Level | Focus |
172
+ |-------|-------|
173
+ | Unit | Pure functions, hooks |
174
+ | Integration | Component behavior |
175
+ | E2E | User flows |
176
+
177
+ ### Test Priorities
178
+
179
+ - User-visible behavior
180
+ - Edge cases
181
+ - Error states
182
+ - Accessibility
183
+
184
+ ---
185
+
186
+ ## 10. Anti-Patterns
187
+
188
+ | ❌ Don't | ✅ Do |
189
+ |----------|-------|
190
+ | Prop drilling deep | Use context |
191
+ | Giant components | Split smaller |
192
+ | useEffect for everything | Server components |
193
+ | Premature optimization | Profile first |
194
+ | Index as key | Stable unique ID |
195
+
196
+ ---
197
+
198
+ > **Remember:** React is about composition. Build small, combine thoughtfully.