agcel 1.0.1

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 (100) hide show
  1. package/.agent/workflows/api-gen.md +59 -0
  2. package/.agent/workflows/architect.md +44 -0
  3. package/.agent/workflows/brainstorm.md +223 -0
  4. package/.agent/workflows/build.md +38 -0
  5. package/.agent/workflows/changelog.md +51 -0
  6. package/.agent/workflows/checkpoint.md +138 -0
  7. package/.agent/workflows/commit.md +223 -0
  8. package/.agent/workflows/debug.md +57 -0
  9. package/.agent/workflows/deploy.md +76 -0
  10. package/.agent/workflows/doc.md +247 -0
  11. package/.agent/workflows/execute-plan.md +225 -0
  12. package/.agent/workflows/feature.md +255 -0
  13. package/.agent/workflows/fix.md +323 -0
  14. package/.agent/workflows/help.md +63 -0
  15. package/.agent/workflows/index.md +148 -0
  16. package/.agent/workflows/load.md +112 -0
  17. package/.agent/workflows/mode.md +170 -0
  18. package/.agent/workflows/optimize.md +53 -0
  19. package/.agent/workflows/plan.md +337 -0
  20. package/.agent/workflows/pr.md +74 -0
  21. package/.agent/workflows/product-plan.md +36 -0
  22. package/.agent/workflows/production-deploy.md +39 -0
  23. package/.agent/workflows/refactor.md +63 -0
  24. package/.agent/workflows/research.md +116 -0
  25. package/.agent/workflows/review.md +344 -0
  26. package/.agent/workflows/security-scan.md +56 -0
  27. package/.agent/workflows/ship.md +221 -0
  28. package/.agent/workflows/spawn.md +177 -0
  29. package/.agent/workflows/status.md +59 -0
  30. package/.agent/workflows/tdd.md +139 -0
  31. package/.agent/workflows/test.md +340 -0
  32. package/.agent/workflows/verify.md +35 -0
  33. package/LICENSE +21 -0
  34. package/README.md +67 -0
  35. package/dist/commands/init.js +142 -0
  36. package/dist/commands/install.js +98 -0
  37. package/dist/commands/list.js +49 -0
  38. package/dist/commands/restart.js +17 -0
  39. package/dist/commands/start.js +41 -0
  40. package/dist/commands/status.js +24 -0
  41. package/dist/commands/stop.js +29 -0
  42. package/dist/commands/uninstall.js +78 -0
  43. package/dist/index.js +58 -0
  44. package/dist/server/index.js +174 -0
  45. package/dist/utils/index.js +63 -0
  46. package/package.json +54 -0
  47. package/skills/api-security-best-practices/SKILL.md +291 -0
  48. package/skills/api-security-best-practices/references/examples.md +617 -0
  49. package/skills/architecture/SKILL.md +59 -0
  50. package/skills/architecture/context-discovery.md +43 -0
  51. package/skills/architecture/examples.md +94 -0
  52. package/skills/architecture/pattern-selection.md +68 -0
  53. package/skills/architecture/patterns-reference.md +50 -0
  54. package/skills/architecture/trade-off-analysis.md +77 -0
  55. package/skills/aws-serverless/SKILL.md +327 -0
  56. package/skills/brainstorming/SKILL.md +234 -0
  57. package/skills/c4-context/SKILL.md +154 -0
  58. package/skills/ci-cd-engineer/SKILL.md +50 -0
  59. package/skills/code-auditing/SKILL.md +55 -0
  60. package/skills/copywriting/SKILL.md +248 -0
  61. package/skills/database-engineer/SKILL.md +47 -0
  62. package/skills/doc-coauthoring/SKILL.md +379 -0
  63. package/skills/docker-expert/SKILL.md +412 -0
  64. package/skills/langgraph/SKILL.md +291 -0
  65. package/skills/postgresql/SKILL.md +73 -0
  66. package/skills/pricing-strategy/SKILL.md +360 -0
  67. package/skills/product-manager/SKILL.md +57 -0
  68. package/skills/prompt-engineer/README.md +659 -0
  69. package/skills/prompt-engineer/SKILL.md +256 -0
  70. package/skills/python-patterns/SKILL.md +445 -0
  71. package/skills/qa-engineer/SKILL.md +42 -0
  72. package/skills/rag-engineer/SKILL.md +94 -0
  73. package/skills/react-patterns/SKILL.md +202 -0
  74. package/skills/secure-refactoring/SKILL.md +54 -0
  75. package/skills/security-documentation/SKILL.md +53 -0
  76. package/skills/senior-architect/SKILL.md +213 -0
  77. package/skills/senior-architect/references/architecture_patterns.md +103 -0
  78. package/skills/senior-architect/references/system_design_workflows.md +103 -0
  79. package/skills/senior-architect/references/tech_decision_guide.md +103 -0
  80. package/skills/senior-architect/scripts/architecture_diagram_generator.py +114 -0
  81. package/skills/senior-architect/scripts/dependency_analyzer.py +114 -0
  82. package/skills/senior-architect/scripts/project_architect.py +114 -0
  83. package/skills/seo-audit/SKILL.md +491 -0
  84. package/skills/sql-injection-testing/SKILL.md +452 -0
  85. package/skills/test-driven-development/SKILL.md +375 -0
  86. package/skills/test-driven-development/testing-anti-patterns.md +299 -0
  87. package/skills/test-fixing/SKILL.md +123 -0
  88. package/skills/testing-patterns/SKILL.md +263 -0
  89. package/skills/typescript-expert/SKILL.md +202 -0
  90. package/skills/typescript-expert/references/advanced-topics.md +252 -0
  91. package/skills/typescript-expert/references/tsconfig-strict.json +92 -0
  92. package/skills/typescript-expert/references/typescript-cheatsheet.md +383 -0
  93. package/skills/typescript-expert/references/utility-types.ts +335 -0
  94. package/skills/typescript-expert/scripts/ts_diagnostic.py +203 -0
  95. package/skills/ui-ux-designer/SKILL.md +46 -0
  96. package/skills/vercel-deployment/SKILL.md +83 -0
  97. package/skills/vulnerability-scanner/SKILL.md +280 -0
  98. package/skills/vulnerability-scanner/checklists.md +121 -0
  99. package/skills/vulnerability-scanner/scripts/security_scan.py +458 -0
  100. package/skills/writing-plans/SKILL.md +120 -0
@@ -0,0 +1,256 @@
1
+ ---
2
+ name: prompt-engineer
3
+ description: "Transforms user prompts into optimized prompts using frameworks (RTF, RISEN, Chain of Thought, RODES, Chain of Density, RACE, RISE, STAR, SOAP, CLEAR, GROW)"
4
+ version: 1.1.0
5
+ author: Eric Andrade
6
+ created: 2025-02-01
7
+ updated: 2026-02-04
8
+ platforms: [github-copilot-cli, claude-code, codex]
9
+ category: automation
10
+ tags: [prompt-engineering, optimization, frameworks, ai-enhancement]
11
+ risk: safe
12
+ ---
13
+
14
+ ## Purpose
15
+
16
+ This skill transforms raw, unstructured user prompts into highly optimized prompts using established prompting frameworks. It analyzes user intent, identifies task complexity, and intelligently selects the most appropriate framework(s) to maximize Claude/ChatGPT output quality.
17
+
18
+ The skill operates in "magic mode" - it works silently behind the scenes, only interacting with users when clarification is critically needed. Users receive polished, ready-to-use prompts without technical explanations or framework jargon.
19
+
20
+ This is a **universal skill** that works in any terminal context, not limited to Obsidian vaults or specific project structures.
21
+
22
+ ## When to Use
23
+
24
+ Invoke this skill when:
25
+
26
+ - User provides a vague or generic prompt (e.g., "help me code Python")
27
+ - User has a complex idea but struggles to articulate it clearly
28
+ - User's prompt lacks structure, context, or specific requirements
29
+ - Task requires step-by-step reasoning (debugging, analysis, design)
30
+ - User needs a prompt for a specific AI task but doesn't know prompting frameworks
31
+ - User wants to improve an existing prompt's effectiveness
32
+ - User asks variations of "how do I ask AI to..." or "create a prompt for..."
33
+
34
+ ## Workflow
35
+
36
+ ### Step 1: Analyze Intent
37
+
38
+ **Objective:** Understand what the user truly wants to accomplish.
39
+
40
+ **Actions:**
41
+ 1. Read the raw prompt provided by the user
42
+ 2. Detect task characteristics:
43
+ - **Type:** coding, writing, analysis, design, learning, planning, decision-making, creative, etc.
44
+ - **Complexity:** simple (one-step), moderate (multi-step), complex (requires reasoning/design)
45
+ - **Clarity:** clear intention vs. ambiguous/vague
46
+ - **Domain:** technical, business, creative, academic, personal, etc.
47
+ 3. Identify implicit requirements:
48
+ - Does user need examples?
49
+ - Is output format specified?
50
+ - Are there constraints (time, resources, scope)?
51
+ - Is this exploratory or execution-focused?
52
+
53
+ **Detection Patterns:**
54
+ - **Simple tasks:** Short prompts (<50 chars), single verb, no context
55
+ - **Complex tasks:** Long prompts (>200 chars), multiple requirements, conditional logic
56
+ - **Ambiguous tasks:** Generic verbs ("help", "improve"), missing object/context
57
+ - **Structured tasks:** Mentions steps, phases, deliverables, stakeholders
58
+
59
+
60
+ ### Step 3: Select Framework(s)
61
+
62
+ **Objective:** Map task characteristics to optimal prompting framework(s).
63
+
64
+ **Framework Mapping Logic:**
65
+
66
+ | Task Type | Recommended Framework(s) | Rationale |
67
+ |-----------|-------------------------|-----------|
68
+ | **Role-based tasks** (act as expert, consultant) | **RTF** (Role-Task-Format) | Clear role definition + task + output format |
69
+ | **Step-by-step reasoning** (debugging, proof, logic) | **Chain of Thought** | Encourages explicit reasoning steps |
70
+ | **Structured projects** (multi-phase, deliverables) | **RISEN** (Role, Instructions, Steps, End goal, Narrowing) | Comprehensive structure for complex work |
71
+ | **Complex design/analysis** (systems, architecture) | **RODES** (Role, Objective, Details, Examples, Sense check) | Balances detail with validation |
72
+ | **Summarization** (compress, synthesize) | **Chain of Density** | Iterative refinement to essential info |
73
+ | **Communication** (reports, presentations, storytelling) | **RACE** (Role, Audience, Context, Expectation) | Audience-aware messaging |
74
+ | **Investigation/analysis** (research, diagnosis) | **RISE** (Research, Investigate, Synthesize, Evaluate) | Systematic analytical approach |
75
+ | **Contextual situations** (problem-solving with background) | **STAR** (Situation, Task, Action, Result) | Context-rich problem framing |
76
+ | **Documentation** (medical, technical, records) | **SOAP** (Subjective, Objective, Assessment, Plan) | Structured information capture |
77
+ | **Goal-setting** (OKRs, objectives, targets) | **CLEAR** (Collaborative, Limited, Emotional, Appreciable, Refinable) | Goal clarity and actionability |
78
+ | **Coaching/development** (mentoring, growth) | **GROW** (Goal, Reality, Options, Will) | Developmental conversation structure |
79
+
80
+ **Blending Strategy:**
81
+ - **Combine 2-3 frameworks** when task spans multiple types
82
+ - Example: Complex technical project → **RODES + Chain of Thought** (structure + reasoning)
83
+ - Example: Leadership decision → **CLEAR + GROW** (goal clarity + development)
84
+
85
+ **Selection Criteria:**
86
+ - Primary framework = best match to core task type
87
+ - Secondary framework(s) = address additional complexity dimensions
88
+ - Avoid over-engineering: simple tasks get simple frameworks
89
+
90
+ **Critical Rule:** This selection happens **silently** - do not explain framework choice to user.
91
+
92
+ Role: You are a senior software architect. [RTF - Role]
93
+
94
+ Objective: Design a microservices architecture for [system]. [RODES - Objective]
95
+
96
+ Approach this step-by-step: [Chain of Thought]
97
+ 1. Analyze current monolithic constraints
98
+ 2. Identify service boundaries
99
+ 3. Design inter-service communication
100
+ 4. Plan data consistency strategy
101
+
102
+ Details: [RODES - Details]
103
+ - Expected traffic: [X]
104
+ - Data volume: [Y]
105
+ - Team size: [Z]
106
+
107
+ Output Format: [RTF - Format]
108
+ Provide architecture diagram description, service definitions, and migration roadmap.
109
+
110
+ Sense Check: [RODES - Sense check]
111
+ Validate that services are loosely coupled, independently deployable, and aligned with business domains.
112
+ ```
113
+
114
+ **4.5. Language Adaptation**
115
+ - If original prompt is in Portuguese, generate prompt in Portuguese
116
+ - If original prompt is in English, generate prompt in English
117
+ - If mixed, default to English (more universal for AI models)
118
+
119
+ **4.6. Quality Checks**
120
+ Before finalizing, verify:
121
+ - [ ] Prompt is self-contained (no external context needed)
122
+ - [ ] Task is specific and measurable
123
+ - [ ] Output format is clear
124
+ - [ ] No ambiguous language
125
+ - [ ] Appropriate level of detail for task complexity
126
+
127
+
128
+ ## Critical Rules
129
+
130
+ ### **NEVER:**
131
+
132
+ - ❌ Assume information that wasn't provided - ALWAYS ask if critical details are missing
133
+ - ❌ Explain which framework was selected or why (magic mode - keep it invisible)
134
+ - ❌ Generate generic, one-size-fits-all prompts - always customize to context
135
+ - ❌ Use technical jargon in the final prompt (unless user's domain is technical)
136
+ - ❌ Ask more than 3 clarifying questions (avoid user fatigue)
137
+ - ❌ Include meta-commentary in the output ("This prompt uses...", "Note that...")
138
+ - ❌ Present output without code block formatting
139
+ - ❌ Mix languages inconsistently (if user writes in PT, respond in PT)
140
+
141
+ ### **ALWAYS:**
142
+
143
+ - ✅ Analyze intent before generating (Step 1 is mandatory)
144
+ - ✅ Ask clarifying questions if critical information is ambiguous (Step 2 conditional)
145
+ - ✅ Select framework(s) based on task type and complexity (Step 3 mapping)
146
+ - ✅ Blend multiple frameworks when it improves prompt quality
147
+ - ✅ Adapt prompt length to original input complexity (simple → short, complex → detailed)
148
+ - ✅ Include output format specification in generated prompts
149
+ - ✅ Present final prompt in clean Markdown code block
150
+ - ✅ Make prompts self-contained (no dependency on external context)
151
+ - ✅ Use examples in complex prompts to illustrate expected output
152
+ - ✅ Validate prompt completeness before presenting (quality checks in Step 4.6)
153
+
154
+
155
+ ### **Example 2: Complex Clear Prompt → RODES + Chain of Thought (No Clarification)**
156
+
157
+ **User Input:**
158
+ ```
159
+ copilot> create prompt for: I need to build a product recommendation system considering purchase history, user preferences, and market trends
160
+ ```
161
+
162
+ **Skill Internal Process:**
163
+ 1. **Analyze:** Clear intent, complex task (ML system design), technical domain
164
+ 2. **Clarify:** Skip (sufficient information)
165
+ 3. **Select:** RODES (complex design) + Chain of Thought (reasoning needed)
166
+
167
+ **Skill Output:**
168
+
169
+ ````markdown
170
+ ```
171
+ Role: You are a senior machine learning engineer specializing in recommendation systems.
172
+
173
+ Objective: Design a product recommendation system that combines user purchase history, preferences, and market trends.
174
+
175
+ Details:
176
+ - Input data sources: user transaction logs, preference surveys, market trend APIs
177
+ - Algorithm considerations: collaborative filtering, content-based filtering, hybrid approaches
178
+ - Performance metrics: precision, recall, diversity, novelty
179
+ - Scalability: system must handle 100k+ users
180
+ - Real-time constraints: recommendations updated within 500ms
181
+
182
+ Approach step-by-step:
183
+ 1. Analyze the three data sources and their relationships
184
+ 2. Propose 2-3 algorithm approaches with trade-offs analysis
185
+ 3. Design data pipeline architecture (ingestion, processing, serving)
186
+ 4. Define evaluation metrics and A/B testing strategy
187
+ 5. Outline implementation roadmap with phases
188
+
189
+ Examples:
190
+ - Show pseudocode for core recommendation logic
191
+ - Illustrate data flow diagram
192
+ - Provide sample API response structure
193
+
194
+ Sense Check: Validate that the proposed solution balances personalization with discovery, scales to production load, and incorporates real-time market trends effectively.
195
+
196
+ Output format: Technical design document with architecture diagrams, algorithm justification, and implementation roadmap.
197
+ ```
198
+ ````
199
+
200
+
201
+ ### **Example 4: Code Debugging → Chain of Thought**
202
+
203
+ **User Input:**
204
+ ```
205
+ copilot> optimize prompt: my Python code isn't working, needs debugging
206
+ ```
207
+
208
+ **Skill Internal Process:**
209
+ 1. **Analyze:** Debugging task, needs step-by-step reasoning
210
+ 2. **Clarify:** Skip (user will provide code context later)
211
+ 3. **Select:** Chain of Thought
212
+
213
+ **Skill Output:**
214
+
215
+ ````markdown
216
+ ```
217
+ You are an expert Python debugger.
218
+
219
+ Task: Debug the Python code provided by the user by analyzing it step-by-step.
220
+
221
+ Debugging approach:
222
+ 1. Read and understand the code's intended purpose
223
+ 2. Identify the error or unexpected behavior
224
+ 3. Trace variable states at each execution step
225
+ 4. Locate the root cause of the issue
226
+ 5. Propose fix with explanation
227
+ 6. Suggest preventive measures to avoid similar bugs
228
+
229
+ For each step, show your reasoning:
230
+ - What you're checking
231
+ - What you found
232
+ - Why it matters
233
+
234
+ Output format:
235
+ - **Issue identified:** [Describe the bug]
236
+ - **Root cause:** [Why it's happening]
237
+ - **Fix:** [Corrected code with comments]
238
+ - **Prevention:** [Best practices to avoid this in the future]
239
+
240
+ Include a working example to verify the fix.
241
+ ```
242
+ ````
243
+
244
+
245
+ ## Notes
246
+
247
+ This skill is **platform-agnostic** and works in any terminal context where GitHub Copilot CLI is available. It does not depend on:
248
+ - Obsidian vault structure
249
+ - Specific project configurations
250
+ - External files or templates
251
+
252
+ The skill is entirely self-contained, operating purely on user input and framework knowledge.
253
+
254
+
255
+ ## Gap Analysis Rule
256
+ Always identify gaps and suggest next steps to users. In case there is no gaps anymore, then AI should clearly state that there is no gap left.
@@ -0,0 +1,445 @@
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.
442
+
443
+
444
+ ## Gap Analysis Rule
445
+ Always identify gaps and suggest next steps to users. In case there is no gaps anymore, then AI should clearly state that there is no gap left.