@iamnishankhan/opencode-kit-grok 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (198) hide show
  1. package/bin/cli.js +46 -0
  2. package/kit/.opencode/AGENTS.md +392 -0
  3. package/kit/.opencode/README.md +71 -0
  4. package/kit/.opencode/USAGE.md +405 -0
  5. package/kit/.opencode/agents/backend-specialist.md +278 -0
  6. package/kit/.opencode/agents/code-archaeologist.md +114 -0
  7. package/kit/.opencode/agents/database-architect.md +233 -0
  8. package/kit/.opencode/agents/debugger.md +234 -0
  9. package/kit/.opencode/agents/devops-engineer.md +252 -0
  10. package/kit/.opencode/agents/documentation-writer.md +111 -0
  11. package/kit/.opencode/agents/explorer-agent.md +83 -0
  12. package/kit/.opencode/agents/frontend-specialist.md +606 -0
  13. package/kit/.opencode/agents/game-developer.md +169 -0
  14. package/kit/.opencode/agents/mobile-developer.md +385 -0
  15. package/kit/.opencode/agents/orchestrator.md +213 -0
  16. package/kit/.opencode/agents/penetration-tester.md +197 -0
  17. package/kit/.opencode/agents/performance-optimizer.md +194 -0
  18. package/kit/.opencode/agents/product-manager.md +120 -0
  19. package/kit/.opencode/agents/product-owner.md +103 -0
  20. package/kit/.opencode/agents/project-planner.md +418 -0
  21. package/kit/.opencode/agents/qa-automation-engineer.md +113 -0
  22. package/kit/.opencode/agents/security-auditor.md +179 -0
  23. package/kit/.opencode/agents/seo-specialist.md +119 -0
  24. package/kit/.opencode/agents/test-engineer.md +169 -0
  25. package/kit/.opencode/commands/brainstorm.md +113 -0
  26. package/kit/.opencode/commands/coordinate.md +72 -0
  27. package/kit/.opencode/commands/create.md +63 -0
  28. package/kit/.opencode/commands/debug.md +102 -0
  29. package/kit/.opencode/commands/deploy.md +175 -0
  30. package/kit/.opencode/commands/enhance.md +62 -0
  31. package/kit/.opencode/commands/orchestrate.md +241 -0
  32. package/kit/.opencode/commands/plan.md +89 -0
  33. package/kit/.opencode/commands/preview.md +80 -0
  34. package/kit/.opencode/commands/remember.md +67 -0
  35. package/kit/.opencode/commands/status.md +86 -0
  36. package/kit/.opencode/commands/test.md +143 -0
  37. package/kit/.opencode/commands/verify.md +71 -0
  38. package/kit/.opencode/memory/MEMORY.md +6 -0
  39. package/kit/.opencode/memory/feedback-history.md +9 -0
  40. package/kit/.opencode/memory/project-conventions.md +16 -0
  41. package/kit/.opencode/memory/tech-decisions.md +10 -0
  42. package/kit/.opencode/memory/user-preferences.md +9 -0
  43. package/kit/.opencode/opencode.json +15 -0
  44. package/kit/.opencode/scripts/README.md +95 -0
  45. package/kit/.opencode/scripts/auto_preview.py +149 -0
  46. package/kit/.opencode/scripts/checklist.py +75 -0
  47. package/kit/.opencode/scripts/component_registry.py +238 -0
  48. package/kit/.opencode/scripts/dependency_graph.py +73 -0
  49. package/kit/.opencode/scripts/generate_manifest.py +44 -0
  50. package/kit/.opencode/scripts/session_manager.py +120 -0
  51. package/kit/.opencode/scripts/tests/test_toolkit.py +238 -0
  52. package/kit/.opencode/scripts/validate_kit.py +397 -0
  53. package/kit/.opencode/scripts/validation_runner.py +216 -0
  54. package/kit/.opencode/scripts/verify_all.py +85 -0
  55. package/kit/.opencode/skills/api-patterns/SKILL.md +83 -0
  56. package/kit/.opencode/skills/api-patterns/api-style.md +42 -0
  57. package/kit/.opencode/skills/api-patterns/auth.md +24 -0
  58. package/kit/.opencode/skills/api-patterns/documentation.md +26 -0
  59. package/kit/.opencode/skills/api-patterns/graphql.md +41 -0
  60. package/kit/.opencode/skills/api-patterns/rate-limiting.md +31 -0
  61. package/kit/.opencode/skills/api-patterns/response.md +37 -0
  62. package/kit/.opencode/skills/api-patterns/rest.md +40 -0
  63. package/kit/.opencode/skills/api-patterns/scripts/api_validator.py +211 -0
  64. package/kit/.opencode/skills/api-patterns/security-testing.md +122 -0
  65. package/kit/.opencode/skills/api-patterns/trpc.md +41 -0
  66. package/kit/.opencode/skills/api-patterns/versioning.md +22 -0
  67. package/kit/.opencode/skills/app-builder/SKILL.md +78 -0
  68. package/kit/.opencode/skills/app-builder/agent-coordination.md +71 -0
  69. package/kit/.opencode/skills/app-builder/feature-building.md +53 -0
  70. package/kit/.opencode/skills/app-builder/project-detection.md +45 -0
  71. package/kit/.opencode/skills/app-builder/scaffolding.md +110 -0
  72. package/kit/.opencode/skills/app-builder/tech-stack.md +41 -0
  73. package/kit/.opencode/skills/app-builder/templates/SKILL.md +39 -0
  74. package/kit/.opencode/skills/app-builder/templates/astro-static/TEMPLATE.md +78 -0
  75. package/kit/.opencode/skills/app-builder/templates/chrome-extension/TEMPLATE.md +96 -0
  76. package/kit/.opencode/skills/app-builder/templates/cli-tool/TEMPLATE.md +88 -0
  77. package/kit/.opencode/skills/app-builder/templates/electron-desktop/TEMPLATE.md +97 -0
  78. package/kit/.opencode/skills/app-builder/templates/express-api/TEMPLATE.md +89 -0
  79. package/kit/.opencode/skills/app-builder/templates/flutter-app/TEMPLATE.md +93 -0
  80. package/kit/.opencode/skills/app-builder/templates/monorepo-turborepo/TEMPLATE.md +97 -0
  81. package/kit/.opencode/skills/app-builder/templates/nextjs-fullstack/TEMPLATE.md +126 -0
  82. package/kit/.opencode/skills/app-builder/templates/nextjs-saas/TEMPLATE.md +125 -0
  83. package/kit/.opencode/skills/app-builder/templates/nextjs-static/TEMPLATE.md +174 -0
  84. package/kit/.opencode/skills/app-builder/templates/nuxt-app/TEMPLATE.md +127 -0
  85. package/kit/.opencode/skills/app-builder/templates/python-fastapi/TEMPLATE.md +94 -0
  86. package/kit/.opencode/skills/app-builder/templates/react-native-app/TEMPLATE.md +121 -0
  87. package/kit/.opencode/skills/architecture/SKILL.md +57 -0
  88. package/kit/.opencode/skills/architecture/context-discovery.md +43 -0
  89. package/kit/.opencode/skills/architecture/examples.md +94 -0
  90. package/kit/.opencode/skills/architecture/pattern-selection.md +68 -0
  91. package/kit/.opencode/skills/architecture/patterns-reference.md +50 -0
  92. package/kit/.opencode/skills/architecture/trade-off-analysis.md +77 -0
  93. package/kit/.opencode/skills/bash-linux/SKILL.md +201 -0
  94. package/kit/.opencode/skills/batch-operations/SKILL.md +105 -0
  95. package/kit/.opencode/skills/behavioral-modes/SKILL.md +253 -0
  96. package/kit/.opencode/skills/brainstorming/SKILL.md +178 -0
  97. package/kit/.opencode/skills/brainstorming/dynamic-questioning.md +350 -0
  98. package/kit/.opencode/skills/clean-code/SKILL.md +201 -0
  99. package/kit/.opencode/skills/code-review-checklist/SKILL.md +111 -0
  100. package/kit/.opencode/skills/code-review-graph/SKILL.md +305 -0
  101. package/kit/.opencode/skills/context-compression/SKILL.md +145 -0
  102. package/kit/.opencode/skills/coordinator-mode/SKILL.md +208 -0
  103. package/kit/.opencode/skills/database-design/SKILL.md +54 -0
  104. package/kit/.opencode/skills/database-design/database-selection.md +43 -0
  105. package/kit/.opencode/skills/database-design/indexing.md +39 -0
  106. package/kit/.opencode/skills/database-design/migrations.md +48 -0
  107. package/kit/.opencode/skills/database-design/optimization.md +36 -0
  108. package/kit/.opencode/skills/database-design/orm-selection.md +30 -0
  109. package/kit/.opencode/skills/database-design/schema-design.md +56 -0
  110. package/kit/.opencode/skills/database-design/scripts/schema_validator.py +172 -0
  111. package/kit/.opencode/skills/deployment-procedures/SKILL.md +243 -0
  112. package/kit/.opencode/skills/design-spec/SKILL.md +185 -0
  113. package/kit/.opencode/skills/design-spec/collection.md +106 -0
  114. package/kit/.opencode/skills/documentation-templates/SKILL.md +196 -0
  115. package/kit/.opencode/skills/frontend-architecture/SKILL.md +245 -0
  116. package/kit/.opencode/skills/frontend-design/SKILL.md +1222 -0
  117. package/kit/.opencode/skills/frontend-design/redesign.md +178 -0
  118. package/kit/.opencode/skills/frontend-design/scripts/accessibility_checker.py +145 -0
  119. package/kit/.opencode/skills/frontend-design/scripts/ux_audit.py +722 -0
  120. package/kit/.opencode/skills/frontend-design/style-brutalist.md +92 -0
  121. package/kit/.opencode/skills/frontend-design/style-minimalist.md +85 -0
  122. package/kit/.opencode/skills/game-development/2d-games/SKILL.md +118 -0
  123. package/kit/.opencode/skills/game-development/3d-games/SKILL.md +134 -0
  124. package/kit/.opencode/skills/game-development/SKILL.md +169 -0
  125. package/kit/.opencode/skills/game-development/game-art/SKILL.md +184 -0
  126. package/kit/.opencode/skills/game-development/game-audio/SKILL.md +189 -0
  127. package/kit/.opencode/skills/game-development/game-design/SKILL.md +128 -0
  128. package/kit/.opencode/skills/game-development/mobile-games/SKILL.md +107 -0
  129. package/kit/.opencode/skills/game-development/multiplayer/SKILL.md +131 -0
  130. package/kit/.opencode/skills/game-development/pc-games/SKILL.md +143 -0
  131. package/kit/.opencode/skills/game-development/vr-ar/SKILL.md +122 -0
  132. package/kit/.opencode/skills/game-development/web-games/SKILL.md +149 -0
  133. package/kit/.opencode/skills/geo-fundamentals/SKILL.md +158 -0
  134. package/kit/.opencode/skills/geo-fundamentals/scripts/geo_checker.py +273 -0
  135. package/kit/.opencode/skills/i18n-localization/SKILL.md +156 -0
  136. package/kit/.opencode/skills/i18n-localization/scripts/i18n_checker.py +223 -0
  137. package/kit/.opencode/skills/intelligent-routing/SKILL.md +337 -0
  138. package/kit/.opencode/skills/lint-and-validate/SKILL.md +47 -0
  139. package/kit/.opencode/skills/lint-and-validate/scripts/lint_runner.py +184 -0
  140. package/kit/.opencode/skills/lint-and-validate/scripts/type_coverage.py +245 -0
  141. package/kit/.opencode/skills/mcp-builder/SKILL.md +205 -0
  142. package/kit/.opencode/skills/memory-system/SKILL.md +181 -0
  143. package/kit/.opencode/skills/mobile-design/SKILL.md +396 -0
  144. package/kit/.opencode/skills/mobile-design/decision-trees.md +516 -0
  145. package/kit/.opencode/skills/mobile-design/mobile-backend.md +491 -0
  146. package/kit/.opencode/skills/mobile-design/mobile-color-system.md +420 -0
  147. package/kit/.opencode/skills/mobile-design/mobile-debugging.md +122 -0
  148. package/kit/.opencode/skills/mobile-design/mobile-design-thinking.md +357 -0
  149. package/kit/.opencode/skills/mobile-design/mobile-navigation.md +458 -0
  150. package/kit/.opencode/skills/mobile-design/mobile-performance.md +767 -0
  151. package/kit/.opencode/skills/mobile-design/mobile-testing.md +356 -0
  152. package/kit/.opencode/skills/mobile-design/mobile-typography.md +433 -0
  153. package/kit/.opencode/skills/mobile-design/platform-android.md +666 -0
  154. package/kit/.opencode/skills/mobile-design/platform-ios.md +561 -0
  155. package/kit/.opencode/skills/mobile-design/scripts/mobile_audit.py +670 -0
  156. package/kit/.opencode/skills/mobile-design/touch-psychology.md +537 -0
  157. package/kit/.opencode/skills/nextjs-react-expert/1-async-eliminating-waterfalls.md +351 -0
  158. package/kit/.opencode/skills/nextjs-react-expert/2-bundle-bundle-size-optimization.md +240 -0
  159. package/kit/.opencode/skills/nextjs-react-expert/3-server-server-side-performance.md +490 -0
  160. package/kit/.opencode/skills/nextjs-react-expert/4-client-client-side-data-fetching.md +264 -0
  161. package/kit/.opencode/skills/nextjs-react-expert/5-rerender-re-render-optimization.md +581 -0
  162. package/kit/.opencode/skills/nextjs-react-expert/6-rendering-rendering-performance.md +432 -0
  163. package/kit/.opencode/skills/nextjs-react-expert/7-js-javascript-performance.md +684 -0
  164. package/kit/.opencode/skills/nextjs-react-expert/8-advanced-advanced-patterns.md +150 -0
  165. package/kit/.opencode/skills/nextjs-react-expert/9-cache-components.md +103 -0
  166. package/kit/.opencode/skills/nextjs-react-expert/SKILL.md +293 -0
  167. package/kit/.opencode/skills/nextjs-react-expert/scripts/convert_rules.py +222 -0
  168. package/kit/.opencode/skills/nextjs-react-expert/scripts/react_performance_checker.py +281 -0
  169. package/kit/.opencode/skills/nodejs-best-practices/SKILL.md +336 -0
  170. package/kit/.opencode/skills/parallel-agents/SKILL.md +192 -0
  171. package/kit/.opencode/skills/performance-profiling/SKILL.md +145 -0
  172. package/kit/.opencode/skills/performance-profiling/scripts/bundle_analyzer.py +120 -0
  173. package/kit/.opencode/skills/performance-profiling/scripts/lighthouse_audit.py +108 -0
  174. package/kit/.opencode/skills/plan-writing/SKILL.md +153 -0
  175. package/kit/.opencode/skills/powershell-windows/SKILL.md +169 -0
  176. package/kit/.opencode/skills/python-patterns/SKILL.md +443 -0
  177. package/kit/.opencode/skills/red-team-tactics/SKILL.md +201 -0
  178. package/kit/.opencode/skills/rust-pro/SKILL.md +177 -0
  179. package/kit/.opencode/skills/seo-fundamentals/SKILL.md +131 -0
  180. package/kit/.opencode/skills/seo-fundamentals/scripts/seo_checker.py +219 -0
  181. package/kit/.opencode/skills/server-management/SKILL.md +163 -0
  182. package/kit/.opencode/skills/simplify-code/SKILL.md +131 -0
  183. package/kit/.opencode/skills/skillify/SKILL.md +115 -0
  184. package/kit/.opencode/skills/systematic-debugging/SKILL.md +111 -0
  185. package/kit/.opencode/skills/tailwind-patterns/SKILL.md +271 -0
  186. package/kit/.opencode/skills/tdd-workflow/SKILL.md +151 -0
  187. package/kit/.opencode/skills/testing-patterns/SKILL.md +180 -0
  188. package/kit/.opencode/skills/testing-patterns/scripts/test_runner.py +219 -0
  189. package/kit/.opencode/skills/verify-changes/SKILL.md +127 -0
  190. package/kit/.opencode/skills/vulnerability-scanner/SKILL.md +278 -0
  191. package/kit/.opencode/skills/vulnerability-scanner/checklists.md +124 -0
  192. package/kit/.opencode/skills/vulnerability-scanner/scripts/dependency_analyzer.py +144 -0
  193. package/kit/.opencode/skills/vulnerability-scanner/scripts/security_scan.py +410 -0
  194. package/kit/.opencode/skills/web-design-guidelines/SKILL.md +56 -0
  195. package/kit/.opencode/skills/webapp-testing/SKILL.md +189 -0
  196. package/kit/.opencode/skills/webapp-testing/scripts/playwright_runner.py +123 -0
  197. package/lib/init.js +61 -0
  198. package/package.json +21 -0
@@ -0,0 +1,443 @@
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
+ compatibility: opencode
5
+ metadata:
6
+ when_to_use: "\"When writing Python code, selecting Python frameworks, implementing type hints, or structuring Python projects.\""
7
+ version: "1.0.0"
8
+ ---
9
+ # Python Patterns
10
+
11
+ > Python development principles and decision-making.
12
+ > **Learn to THINK, not memorize patterns.**
13
+
14
+ ---
15
+
16
+ ## ⚠️ How to Use This Skill
17
+
18
+ This skill teaches **decision-making principles**, not fixed code to copy.
19
+
20
+ - ASK user for framework preference when unclear
21
+ - Choose async vs sync based on CONTEXT
22
+ - Don't default to same framework every time
23
+
24
+ ---
25
+
26
+ ## 1. Framework Selection
27
+
28
+ ### Decision Tree
29
+
30
+ ```
31
+ What are you building?
32
+
33
+ ├── API-first / Microservices
34
+ │ └── FastAPI (async, modern, fast)
35
+
36
+ ├── Full-stack web / CMS / Admin
37
+ │ └── Django (batteries-included)
38
+
39
+ ├── Simple / Script / Learning
40
+ │ └── Flask (minimal, flexible)
41
+
42
+ ├── AI/ML API serving
43
+ │ └── FastAPI (Pydantic, async, uvicorn)
44
+
45
+ └── Background workers
46
+ └── Celery + any framework
47
+ ```
48
+
49
+ ### Comparison Principles
50
+
51
+ | Factor | FastAPI | Django | Flask |
52
+ |--------|---------|--------|-------|
53
+ | **Best for** | APIs, microservices | Full-stack, CMS | Simple, learning |
54
+ | **Async** | Native | Django 5.0+ | Via extensions |
55
+ | **Admin** | Manual | Built-in | Via extensions |
56
+ | **ORM** | Choose your own | Django ORM | Choose your own |
57
+ | **Learning curve** | Low | Medium | Low |
58
+
59
+ ### Selection Questions to Ask:
60
+ 1. Is this API-only or full-stack?
61
+ 2. Need admin interface?
62
+ 3. Team familiar with async?
63
+ 4. Existing infrastructure?
64
+
65
+ ---
66
+
67
+ ## 2. Async vs Sync Decision
68
+
69
+ ### When to Use Async
70
+
71
+ ```
72
+ async def is better when:
73
+ ├── I/O-bound operations (database, HTTP, file)
74
+ ├── Many concurrent connections
75
+ ├── Real-time features
76
+ ├── Microservices communication
77
+ └── FastAPI/Starlette/Django ASGI
78
+
79
+ def (sync) is better when:
80
+ ├── CPU-bound operations
81
+ ├── Simple scripts
82
+ ├── Legacy codebase
83
+ ├── Team unfamiliar with async
84
+ └── Blocking libraries (no async version)
85
+ ```
86
+
87
+ ### The Golden Rule
88
+
89
+ ```
90
+ I/O-bound → async (waiting for external)
91
+ CPU-bound → sync + multiprocessing (computing)
92
+
93
+ Don't:
94
+ ├── Mix sync and async carelessly
95
+ ├── Use sync libraries in async code
96
+ └── Force async for CPU work
97
+ ```
98
+
99
+ ### Async Library Selection
100
+
101
+ | Need | Async Library |
102
+ |------|---------------|
103
+ | HTTP client | httpx |
104
+ | PostgreSQL | asyncpg |
105
+ | Redis | redis-py (`redis.asyncio`) |
106
+ | File I/O | aiofiles |
107
+ | Database ORM | SQLAlchemy 2.0 async, Tortoise |
108
+
109
+ ---
110
+
111
+ ## 3. Type Hints Strategy
112
+
113
+ ### When to Type
114
+
115
+ ```
116
+ Always type:
117
+ ├── Function parameters
118
+ ├── Return types
119
+ ├── Class attributes
120
+ ├── Public APIs
121
+
122
+ Can skip:
123
+ ├── Local variables (let inference work)
124
+ ├── One-off scripts
125
+ ├── Tests (usually)
126
+ ```
127
+
128
+ ### Common Type Patterns
129
+
130
+ ```python
131
+ # These are patterns, understand them:
132
+
133
+ # Optional → might be None
134
+ from typing import Optional
135
+ def find_user(id: int) -> Optional[User]: ...
136
+
137
+ # Union → one of multiple types
138
+ def process(data: str | dict) -> None: ...
139
+
140
+ # Generic collections
141
+ def get_items() -> list[Item]: ...
142
+ def get_mapping() -> dict[str, int]: ...
143
+
144
+ # Callable
145
+ from typing import Callable
146
+ def apply(fn: Callable[[int], str]) -> str: ...
147
+ ```
148
+
149
+ ### Pydantic for Validation
150
+
151
+ ```
152
+ When to use Pydantic:
153
+ ├── API request/response models
154
+ ├── Configuration/settings
155
+ ├── Data validation
156
+ ├── Serialization
157
+
158
+ Benefits:
159
+ ├── Runtime validation
160
+ ├── Auto-generated JSON schema
161
+ ├── Works with FastAPI natively
162
+ └── Clear error messages
163
+ ```
164
+
165
+ ---
166
+
167
+ ## 4. Project Structure Principles
168
+
169
+ ### Structure Selection
170
+
171
+ ```
172
+ Small project / Script:
173
+ ├── main.py
174
+ ├── utils.py
175
+ └── requirements.txt
176
+
177
+ Medium API:
178
+ ├── app/
179
+ │ ├── __init__.py
180
+ │ ├── main.py
181
+ │ ├── models/
182
+ │ ├── routes/
183
+ │ ├── services/
184
+ │ └── schemas/
185
+ ├── tests/
186
+ └── pyproject.toml
187
+
188
+ Large application:
189
+ ├── src/
190
+ │ └── myapp/
191
+ │ ├── core/
192
+ │ ├── api/
193
+ │ ├── services/
194
+ │ ├── models/
195
+ │ └── ...
196
+ ├── tests/
197
+ └── pyproject.toml
198
+ ```
199
+
200
+ ### FastAPI Structure Principles
201
+
202
+ ```
203
+ Organize by feature or layer:
204
+
205
+ By layer:
206
+ ├── routes/ (API endpoints)
207
+ ├── services/ (business logic)
208
+ ├── models/ (database models)
209
+ ├── schemas/ (Pydantic models)
210
+ └── dependencies/ (shared deps)
211
+
212
+ By feature:
213
+ ├── users/
214
+ │ ├── routes.py
215
+ │ ├── service.py
216
+ │ └── schemas.py
217
+ └── products/
218
+ └── ...
219
+ ```
220
+
221
+ ---
222
+
223
+ ## 5. Django Principles
224
+
225
+ ### Django Async (Django 5.0+)
226
+
227
+ ```
228
+ Django supports async:
229
+ ├── Async views
230
+ ├── Async middleware
231
+ ├── Async ORM (limited)
232
+ └── ASGI deployment
233
+
234
+ When to use async in Django:
235
+ ├── External API calls
236
+ ├── WebSocket (Channels)
237
+ ├── High-concurrency views
238
+ └── Background task triggering
239
+ ```
240
+
241
+ ### Django Best Practices
242
+
243
+ ```
244
+ Model design:
245
+ ├── Fat models, thin views
246
+ ├── Use managers for common queries
247
+ ├── Abstract base classes for shared fields
248
+
249
+ Views:
250
+ ├── Class-based for complex CRUD
251
+ ├── Function-based for simple endpoints
252
+ ├── Use viewsets with DRF
253
+
254
+ Queries:
255
+ ├── select_related() for FKs
256
+ ├── prefetch_related() for M2M
257
+ ├── Avoid N+1 queries
258
+ └── Use .only() for specific fields
259
+ ```
260
+
261
+ ---
262
+
263
+ ## 6. FastAPI Principles
264
+
265
+ ### async def vs def in FastAPI
266
+
267
+ ```
268
+ Use async def when:
269
+ ├── Using async database drivers
270
+ ├── Making async HTTP calls
271
+ ├── I/O-bound operations
272
+ └── Want to handle concurrency
273
+
274
+ Use def when:
275
+ ├── Blocking operations
276
+ ├── Sync database drivers
277
+ ├── CPU-bound work
278
+ └── FastAPI runs in threadpool automatically
279
+ ```
280
+
281
+ ### Dependency Injection
282
+
283
+ ```
284
+ Use dependencies for:
285
+ ├── Database sessions
286
+ ├── Current user / Auth
287
+ ├── Configuration
288
+ ├── Shared resources
289
+
290
+ Benefits:
291
+ ├── Testability (mock dependencies)
292
+ ├── Clean separation
293
+ ├── Automatic cleanup (yield)
294
+ ```
295
+
296
+ ### Pydantic v2 Integration
297
+
298
+ ```python
299
+ # FastAPI + Pydantic are tightly integrated:
300
+
301
+ # Request validation
302
+ @app.post("/users")
303
+ async def create(user: UserCreate) -> UserResponse:
304
+ # user is already validated
305
+ ...
306
+
307
+ # Response serialization
308
+ # Return type becomes response schema
309
+ ```
310
+
311
+ ---
312
+
313
+ ## 7. Background Tasks
314
+
315
+ ### Selection Guide
316
+
317
+ | Solution | Best For |
318
+ |----------|----------|
319
+ | **BackgroundTasks** | Simple, in-process tasks |
320
+ | **Celery** | Distributed, complex workflows |
321
+ | **ARQ** | Async, Redis-based |
322
+ | **RQ** | Simple Redis queue |
323
+ | **Dramatiq** | Actor-based, simpler than Celery |
324
+
325
+ ### When to Use Each
326
+
327
+ ```
328
+ FastAPI BackgroundTasks:
329
+ ├── Quick operations
330
+ ├── No persistence needed
331
+ ├── Fire-and-forget
332
+ └── Same process
333
+
334
+ Celery/ARQ:
335
+ ├── Long-running tasks
336
+ ├── Need retry logic
337
+ ├── Distributed workers
338
+ ├── Persistent queue
339
+ └── Complex workflows
340
+ ```
341
+
342
+ ---
343
+
344
+ ## 8. Error Handling Principles
345
+
346
+ ### Exception Strategy
347
+
348
+ ```
349
+ In FastAPI:
350
+ ├── Create custom exception classes
351
+ ├── Register exception handlers
352
+ ├── Return consistent error format
353
+ └── Log without exposing internals
354
+
355
+ Pattern:
356
+ ├── Raise domain exceptions in services
357
+ ├── Catch and transform in handlers
358
+ └── Client gets clean error response
359
+ ```
360
+
361
+ ### Error Response Philosophy
362
+
363
+ ```
364
+ Include:
365
+ ├── Error code (programmatic)
366
+ ├── Message (human readable)
367
+ ├── Details (field-level when applicable)
368
+ └── NOT stack traces (security)
369
+ ```
370
+
371
+ ---
372
+
373
+ ## 9. Testing Principles
374
+
375
+ ### Testing Strategy
376
+
377
+ | Type | Purpose | Tools |
378
+ |------|---------|-------|
379
+ | **Unit** | Business logic | pytest |
380
+ | **Integration** | API endpoints | pytest + httpx/TestClient |
381
+ | **E2E** | Full workflows | pytest + DB |
382
+
383
+ ### Async Testing
384
+
385
+ ```python
386
+ # Use pytest-asyncio for async tests
387
+
388
+ import pytest
389
+ from httpx import AsyncClient
390
+
391
+ @pytest.mark.asyncio
392
+ async def test_endpoint():
393
+ async with AsyncClient(app=app, base_url="http://test") as client:
394
+ response = await client.get("/users")
395
+ assert response.status_code == 200
396
+ ```
397
+
398
+ ### Fixtures Strategy
399
+
400
+ ```
401
+ Common fixtures:
402
+ ├── db_session → Database connection
403
+ ├── client → Test client
404
+ ├── authenticated_user → User with token
405
+ └── sample_data → Test data setup
406
+ ```
407
+
408
+ ---
409
+
410
+ ## 10. Decision Checklist
411
+
412
+ Before implementing:
413
+
414
+ - [ ] **Asked user about framework preference?**
415
+ - [ ] **Chosen framework for THIS context?** (not just default)
416
+ - [ ] **Decided async vs sync?**
417
+ - [ ] **Planned type hint strategy?**
418
+ - [ ] **Defined project structure?**
419
+ - [ ] **Planned error handling?**
420
+ - [ ] **Considered background tasks?**
421
+
422
+ ---
423
+
424
+ ## 11. Anti-Patterns to Avoid
425
+
426
+ ### ❌ DON'T:
427
+ - Default to Django for simple APIs (FastAPI may be better)
428
+ - Use sync libraries in async code
429
+ - Skip type hints for public APIs
430
+ - Put business logic in routes/views
431
+ - Ignore N+1 queries
432
+ - Mix async and sync carelessly
433
+
434
+ ### ✅ DO:
435
+ - Choose framework based on context
436
+ - Ask about async requirements
437
+ - Use Pydantic for validation
438
+ - Separate concerns (routes → services → repos)
439
+ - Test critical paths
440
+
441
+ ---
442
+
443
+ > **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,201 @@
1
+ ---
2
+ name: red-team-tactics
3
+ description: Red team tactics principles based on MITRE ATT&CK. Attack phases, detection evasion, reporting.
4
+ compatibility: opencode
5
+ metadata:
6
+ when_to_use: "\"When performing penetration testing, red team exercises, or evaluating attack surfaces using MITRE ATT&CK framework.\""
7
+ version: "1.0.0"
8
+ ---
9
+ # Red Team Tactics
10
+
11
+ > Adversary simulation principles based on MITRE ATT&CK framework.
12
+
13
+ ---
14
+
15
+ ## 1. MITRE ATT&CK Phases
16
+
17
+ ### Attack Lifecycle
18
+
19
+ ```
20
+ RECONNAISSANCE → INITIAL ACCESS → EXECUTION → PERSISTENCE
21
+ ↓ ↓ ↓ ↓
22
+ PRIVILEGE ESC → DEFENSE EVASION → CRED ACCESS → DISCOVERY
23
+ ↓ ↓ ↓ ↓
24
+ LATERAL MOVEMENT → COLLECTION → C2 → EXFILTRATION → IMPACT
25
+ ```
26
+
27
+ ### Phase Objectives
28
+
29
+ | Phase | Objective |
30
+ |-------|-----------|
31
+ | **Recon** | Map attack surface |
32
+ | **Initial Access** | Get first foothold |
33
+ | **Execution** | Run code on target |
34
+ | **Persistence** | Survive reboots |
35
+ | **Privilege Escalation** | Get admin/root |
36
+ | **Defense Evasion** | Avoid detection |
37
+ | **Credential Access** | Harvest credentials |
38
+ | **Discovery** | Map internal network |
39
+ | **Lateral Movement** | Spread to other systems |
40
+ | **Collection** | Gather target data |
41
+ | **C2** | Maintain command channel |
42
+ | **Exfiltration** | Extract data |
43
+
44
+ ---
45
+
46
+ ## 2. Reconnaissance Principles
47
+
48
+ ### Passive vs Active
49
+
50
+ | Type | Trade-off |
51
+ |------|-----------|
52
+ | **Passive** | No target contact, limited info |
53
+ | **Active** | Direct contact, more detection risk |
54
+
55
+ ### Information Targets
56
+
57
+ | Category | Value |
58
+ |----------|-------|
59
+ | Technology stack | Attack vector selection |
60
+ | Employee info | Social engineering |
61
+ | Network ranges | Scanning scope |
62
+ | Third parties | Supply chain attack |
63
+
64
+ ---
65
+
66
+ ## 3. Initial Access Vectors
67
+
68
+ ### Selection Criteria
69
+
70
+ | Vector | When to Use |
71
+ |--------|-------------|
72
+ | **Phishing** | Human target, email access |
73
+ | **Public exploits** | Vulnerable services exposed |
74
+ | **Valid credentials** | Leaked or cracked |
75
+ | **Supply chain** | Third-party access |
76
+
77
+ ---
78
+
79
+ ## 4. Privilege Escalation Principles
80
+
81
+ ### Windows Targets
82
+
83
+ | Check | Opportunity |
84
+ |-------|-------------|
85
+ | Unquoted service paths | Write to path |
86
+ | Weak service permissions | Modify service |
87
+ | Token privileges | Abuse SeDebug, etc. |
88
+ | Stored credentials | Harvest |
89
+
90
+ ### Linux Targets
91
+
92
+ | Check | Opportunity |
93
+ |-------|-------------|
94
+ | SUID binaries | Execute as owner |
95
+ | Sudo misconfiguration | Command execution |
96
+ | Kernel vulnerabilities | Kernel exploits |
97
+ | Cron jobs | Writable scripts |
98
+
99
+ ---
100
+
101
+ ## 5. Defense Evasion Principles
102
+
103
+ ### Key Techniques
104
+
105
+ | Technique | Purpose |
106
+ |-----------|---------|
107
+ | LOLBins | Use legitimate tools |
108
+ | Obfuscation | Hide malicious code |
109
+ | Timestomping | Hide file modifications |
110
+ | Log clearing | Remove evidence |
111
+
112
+ ### Operational Security
113
+
114
+ - Work during business hours
115
+ - Mimic legitimate traffic patterns
116
+ - Use encrypted channels
117
+ - Blend with normal behavior
118
+
119
+ ---
120
+
121
+ ## 6. Lateral Movement Principles
122
+
123
+ ### Credential Types
124
+
125
+ | Type | Use |
126
+ |------|-----|
127
+ | Password | Standard auth |
128
+ | Hash | Pass-the-hash |
129
+ | Ticket | Pass-the-ticket |
130
+ | Certificate | Certificate auth |
131
+
132
+ ### Movement Paths
133
+
134
+ - Admin shares
135
+ - Remote services (RDP, SSH, WinRM)
136
+ - Exploitation of internal services
137
+
138
+ ---
139
+
140
+ ## 7. Active Directory Attacks
141
+
142
+ ### Attack Categories
143
+
144
+ | Attack | Target |
145
+ |--------|--------|
146
+ | Kerberoasting | Service account passwords |
147
+ | AS-REP Roasting | Accounts without pre-auth |
148
+ | DCSync | Domain credentials |
149
+ | Golden Ticket | Persistent domain access |
150
+
151
+ ---
152
+
153
+ ## 8. Reporting Principles
154
+
155
+ ### Attack Narrative
156
+
157
+ Document the full attack chain:
158
+ 1. How initial access was gained
159
+ 2. What techniques were used
160
+ 3. What objectives were achieved
161
+ 4. Where detection failed
162
+
163
+ ### Detection Gaps
164
+
165
+ For each successful technique:
166
+ - What should have detected it?
167
+ - Why didn't detection work?
168
+ - How to improve detection
169
+
170
+ ---
171
+
172
+ ## 9. Ethical Boundaries
173
+
174
+ ### Always
175
+
176
+ - Stay within scope
177
+ - Minimize impact
178
+ - Report immediately if real threat found
179
+ - Document all actions
180
+
181
+ ### Never
182
+
183
+ - Destroy production data
184
+ - Cause denial of service (unless scoped)
185
+ - Access beyond proof of concept
186
+ - Retain sensitive data
187
+
188
+ ---
189
+
190
+ ## 10. Anti-Patterns
191
+
192
+ | ❌ Don't | ✅ Do |
193
+ |----------|-------|
194
+ | Rush to exploitation | Follow methodology |
195
+ | Cause damage | Minimize impact |
196
+ | Skip reporting | Document everything |
197
+ | Ignore scope | Stay within boundaries |
198
+
199
+ ---
200
+
201
+ > **Remember:** Red team simulates attackers to improve defenses, not to cause harm.