@defai.digital/automatosx 5.6.35 → 5.7.2
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.
- package/CHANGELOG.md +142 -0
- package/README.md +44 -2
- package/dist/index.js +1129 -345
- package/examples/agents/.automatosx/abilities/accessibility.md +115 -0
- package/examples/agents/.automatosx/abilities/api-design.md +159 -0
- package/examples/agents/.automatosx/abilities/best-practices.md +102 -0
- package/examples/agents/.automatosx/abilities/caching-strategy.md +165 -0
- package/examples/agents/.automatosx/abilities/ci-cd.md +61 -0
- package/examples/agents/.automatosx/abilities/clean-code.md +398 -0
- package/examples/agents/.automatosx/abilities/code-generation.md +95 -0
- package/examples/agents/.automatosx/abilities/code-review.md +42 -0
- package/examples/agents/.automatosx/abilities/component-architecture.md +112 -0
- package/examples/agents/.automatosx/abilities/content-creation.md +97 -0
- package/examples/agents/.automatosx/abilities/data-modeling.md +171 -0
- package/examples/agents/.automatosx/abilities/data-validation.md +50 -0
- package/examples/agents/.automatosx/abilities/db-modeling.md +158 -0
- package/examples/agents/.automatosx/abilities/debugging.md +43 -0
- package/examples/agents/.automatosx/abilities/dependency-audit.md +60 -0
- package/examples/agents/.automatosx/abilities/design-patterns.md +437 -0
- package/examples/agents/.automatosx/abilities/design-system-implementation.md +126 -0
- package/examples/agents/.automatosx/abilities/documentation.md +54 -0
- package/examples/agents/.automatosx/abilities/error-analysis.md +107 -0
- package/examples/agents/.automatosx/abilities/etl-pipelines.md +44 -0
- package/examples/agents/.automatosx/abilities/feasibility-study.md +20 -0
- package/examples/agents/.automatosx/abilities/general-assistance.md +26 -0
- package/examples/agents/.automatosx/abilities/idea-evaluation.md +21 -0
- package/examples/agents/.automatosx/abilities/infra-as-code.md +57 -0
- package/examples/agents/.automatosx/abilities/job-orchestration.md +44 -0
- package/examples/agents/.automatosx/abilities/literature-review.md +19 -0
- package/examples/agents/.automatosx/abilities/logical-analysis.md +21 -0
- package/examples/agents/.automatosx/abilities/longform-report.md +25 -0
- package/examples/agents/.automatosx/abilities/mathematical-reasoning.md +170 -0
- package/examples/agents/.automatosx/abilities/mission-analysis.md +49 -0
- package/examples/agents/.automatosx/abilities/observability.md +61 -0
- package/examples/agents/.automatosx/abilities/orbital-mechanics.md +50 -0
- package/examples/agents/.automatosx/abilities/our-architecture-decisions.md +180 -0
- package/examples/agents/.automatosx/abilities/our-code-review-checklist.md +149 -0
- package/examples/agents/.automatosx/abilities/our-coding-standards.md +270 -0
- package/examples/agents/.automatosx/abilities/our-project-structure.md +183 -0
- package/examples/agents/.automatosx/abilities/performance-analysis.md +56 -0
- package/examples/agents/.automatosx/abilities/performance.md +80 -0
- package/examples/agents/.automatosx/abilities/problem-solving.md +50 -0
- package/examples/agents/.automatosx/abilities/propulsion-systems.md +50 -0
- package/examples/agents/.automatosx/abilities/quantum-algorithm-design.md +54 -0
- package/examples/agents/.automatosx/abilities/quantum-error-correction.md +56 -0
- package/examples/agents/.automatosx/abilities/quantum-frameworks-transpilation.md +53 -0
- package/examples/agents/.automatosx/abilities/quantum-noise-modeling.md +58 -0
- package/examples/agents/.automatosx/abilities/refactoring.md +223 -0
- package/examples/agents/.automatosx/abilities/release-strategy.md +58 -0
- package/examples/agents/.automatosx/abilities/risk-assessment.md +19 -0
- package/examples/agents/.automatosx/abilities/secrets-policy.md +61 -0
- package/examples/agents/.automatosx/abilities/secure-coding-review.md +51 -0
- package/examples/agents/.automatosx/abilities/security-audit.md +65 -0
- package/examples/agents/.automatosx/abilities/software-architecture.md +394 -0
- package/examples/agents/.automatosx/abilities/solid-principles.md +341 -0
- package/examples/agents/.automatosx/abilities/sql-optimization.md +84 -0
- package/examples/agents/.automatosx/abilities/state-management.md +96 -0
- package/examples/agents/.automatosx/abilities/task-planning.md +65 -0
- package/examples/agents/.automatosx/abilities/technical-writing.md +77 -0
- package/examples/agents/.automatosx/abilities/telemetry-diagnostics.md +51 -0
- package/examples/agents/.automatosx/abilities/testing.md +47 -0
- package/examples/agents/.automatosx/abilities/threat-modeling.md +49 -0
- package/examples/agents/.automatosx/abilities/troubleshooting.md +80 -0
- package/examples/agents/.automatosx/agents/aerospace-scientist.yaml +75 -0
- package/examples/agents/.automatosx/agents/backend.yaml +152 -0
- package/examples/agents/.automatosx/agents/ceo.yaml +63 -0
- package/examples/agents/.automatosx/agents/creative-marketer.yaml +121 -0
- package/examples/agents/.automatosx/agents/cto.yaml +72 -0
- package/examples/agents/.automatosx/agents/data-scientist.yaml +124 -0
- package/examples/agents/.automatosx/agents/data.yaml +77 -0
- package/examples/agents/.automatosx/agents/design.yaml +74 -0
- package/examples/agents/.automatosx/agents/devops.yaml +89 -0
- package/examples/agents/.automatosx/agents/frontend.yaml +139 -0
- package/examples/agents/.automatosx/agents/fullstack.yaml +151 -0
- package/examples/agents/.automatosx/agents/mobile.yaml +161 -0
- package/examples/agents/.automatosx/agents/product.yaml +72 -0
- package/examples/agents/.automatosx/agents/quality.yaml +79 -0
- package/examples/agents/.automatosx/agents/quantum-engineer.yaml +75 -0
- package/examples/agents/.automatosx/agents/researcher.yaml +71 -0
- package/examples/agents/.automatosx/agents/security.yaml +86 -0
- package/examples/agents/.automatosx/agents/stan.yaml +189 -0
- package/examples/agents/.automatosx/agents/writer.yaml +78 -0
- package/examples/agents/.automatosx/teams/business.yaml +56 -0
- package/examples/agents/.automatosx/teams/core.yaml +60 -0
- package/examples/agents/.automatosx/teams/design.yaml +58 -0
- package/examples/agents/.automatosx/teams/engineering.yaml +69 -0
- package/examples/agents/.automatosx/teams/research.yaml +56 -0
- package/examples/agents/.automatosx/templates/analyst.yaml +60 -0
- package/examples/agents/.automatosx/templates/assistant.yaml +48 -0
- package/examples/agents/.automatosx/templates/basic-agent.yaml +28 -0
- package/examples/agents/.automatosx/templates/code-reviewer.yaml +52 -0
- package/examples/agents/.automatosx/templates/debugger.yaml +63 -0
- package/examples/agents/.automatosx/templates/designer.yaml +69 -0
- package/examples/agents/.automatosx/templates/developer.yaml +60 -0
- package/examples/agents/.automatosx/templates/fullstack-developer.yaml +395 -0
- package/examples/agents/.automatosx/templates/qa-specialist.yaml +71 -0
- package/examples/agents/.claude/commands/ax-agent.md +37 -0
- package/examples/agents/.claude/commands/ax-clear.md +22 -0
- package/examples/agents/.claude/commands/ax-init.md +25 -0
- package/examples/agents/.claude/commands/ax-list.md +19 -0
- package/examples/agents/.claude/commands/ax-memory.md +25 -0
- package/examples/agents/.claude/commands/ax-status.md +24 -0
- package/examples/agents/.claude/commands/ax-update.md +28 -0
- package/examples/agents/.claude/mcp/automatosx.json +244 -0
- package/examples/agents/CLAUDE.md +262 -0
- package/package.json +1 -1
|
@@ -0,0 +1,398 @@
|
|
|
1
|
+
# Clean Code Ability
|
|
2
|
+
|
|
3
|
+
Expert knowledge and application of clean code principles for writing maintainable, readable, and high-quality software.
|
|
4
|
+
|
|
5
|
+
## Overview
|
|
6
|
+
|
|
7
|
+
Clean code is code that is easy to read, understand, and modify. It communicates intent clearly and minimizes cognitive load for future developers (including yourself).
|
|
8
|
+
|
|
9
|
+
## Fundamental Principles
|
|
10
|
+
|
|
11
|
+
### 1. Meaningful Names
|
|
12
|
+
|
|
13
|
+
**Rule**: Names should reveal intent without requiring comments
|
|
14
|
+
|
|
15
|
+
**Guidelines**:
|
|
16
|
+
- Use intention-revealing names
|
|
17
|
+
- Avoid disinformation and encodings
|
|
18
|
+
- Make meaningful distinctions
|
|
19
|
+
- Use pronounceable and searchable names
|
|
20
|
+
- Avoid mental mapping
|
|
21
|
+
|
|
22
|
+
**Examples**:
|
|
23
|
+
```typescript
|
|
24
|
+
// ❌ BAD: Cryptic names
|
|
25
|
+
const d = new Date(); // elapsed time in days
|
|
26
|
+
const arr = ['Bob', 'Alice'];
|
|
27
|
+
|
|
28
|
+
// ✅ GOOD: Intention-revealing
|
|
29
|
+
const elapsedTimeInDays = new Date();
|
|
30
|
+
const userNames = ['Bob', 'Alice'];
|
|
31
|
+
|
|
32
|
+
// ❌ BAD: Hungarian notation, noise words
|
|
33
|
+
const strName = 'Bob';
|
|
34
|
+
const userData = { name: 'Bob' };
|
|
35
|
+
const userInfo = { name: 'Bob' }; // What's the difference?
|
|
36
|
+
|
|
37
|
+
// ✅ GOOD: Clean, semantic names
|
|
38
|
+
const userName = 'Bob';
|
|
39
|
+
const user = { name: 'Bob' };
|
|
40
|
+
const userProfile = { name: 'Bob', bio: '...' };
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
**Variable Naming**:
|
|
44
|
+
- Use nouns or noun phrases
|
|
45
|
+
- Boolean: `isActive`, `hasPermission`, `canEdit`
|
|
46
|
+
- Collections: Use plural (`users`, `orders`, `products`)
|
|
47
|
+
|
|
48
|
+
**Function Naming**:
|
|
49
|
+
- Use verbs or verb phrases
|
|
50
|
+
- `getUser()`, `calculateTotal()`, `validateInput()`
|
|
51
|
+
- Boolean returning: `isValid()`, `hasErrors()`, `canProceed()`
|
|
52
|
+
|
|
53
|
+
**Class Naming**:
|
|
54
|
+
- Use nouns
|
|
55
|
+
- Avoid "Manager", "Processor", "Data" suffixes
|
|
56
|
+
- `UserRepository`, `EmailService`, `OrderValidator`
|
|
57
|
+
|
|
58
|
+
### 2. Functions
|
|
59
|
+
|
|
60
|
+
**Rule**: Functions should do one thing, do it well, and do it only
|
|
61
|
+
|
|
62
|
+
**Small Functions**:
|
|
63
|
+
- Keep functions small (< 20 lines ideal)
|
|
64
|
+
- Each function should be one level of abstraction
|
|
65
|
+
- Functions should not have side effects
|
|
66
|
+
|
|
67
|
+
**Single Responsibility**:
|
|
68
|
+
```typescript
|
|
69
|
+
// ❌ BAD: Multiple responsibilities
|
|
70
|
+
function processUser(user: User) {
|
|
71
|
+
validateUser(user);
|
|
72
|
+
saveToDatabase(user);
|
|
73
|
+
sendEmail(user);
|
|
74
|
+
logAudit(user);
|
|
75
|
+
updateCache(user);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
// ✅ GOOD: Single responsibility
|
|
79
|
+
function registerUser(user: User) {
|
|
80
|
+
const validated = validateUser(user);
|
|
81
|
+
return userRepository.save(validated);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
function notifyUserRegistered(user: User) {
|
|
85
|
+
emailService.sendWelcome(user);
|
|
86
|
+
auditLogger.log('USER_REGISTERED', user.id);
|
|
87
|
+
}
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
**Function Arguments**:
|
|
91
|
+
- Zero arguments (niladic) is ideal
|
|
92
|
+
- One argument (monadic) is good
|
|
93
|
+
- Two arguments (dyadic) are okay
|
|
94
|
+
- Three+ arguments (triadic+) require justification
|
|
95
|
+
- Avoid flag arguments (split into two functions)
|
|
96
|
+
|
|
97
|
+
**Examples**:
|
|
98
|
+
```typescript
|
|
99
|
+
// ❌ BAD: Too many arguments
|
|
100
|
+
function createUser(name: string, email: string, age: number, role: string, active: boolean) {}
|
|
101
|
+
|
|
102
|
+
// ✅ GOOD: Use object parameter
|
|
103
|
+
function createUser(userData: UserData) {}
|
|
104
|
+
|
|
105
|
+
// ❌ BAD: Flag argument
|
|
106
|
+
function saveUser(user: User, validate: boolean) {}
|
|
107
|
+
|
|
108
|
+
// ✅ GOOD: Separate functions
|
|
109
|
+
function saveUser(user: User) {}
|
|
110
|
+
function saveUserWithoutValidation(user: User) {}
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
**Command Query Separation**:
|
|
114
|
+
- Functions should either DO something or ANSWER something, not both
|
|
115
|
+
- Commands modify state, queries return values
|
|
116
|
+
|
|
117
|
+
```typescript
|
|
118
|
+
// ❌ BAD: Does both
|
|
119
|
+
function setAndReturn(value: string): boolean {
|
|
120
|
+
this.value = value; // Command
|
|
121
|
+
return this.value === value; // Query
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
// ✅ GOOD: Separated
|
|
125
|
+
function setValue(value: string): void {
|
|
126
|
+
this.value = value;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
function getValue(): string {
|
|
130
|
+
return this.value;
|
|
131
|
+
}
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
### 3. Comments
|
|
135
|
+
|
|
136
|
+
**Rule**: Good code mostly documents itself; use comments wisely
|
|
137
|
+
|
|
138
|
+
**When to Comment**:
|
|
139
|
+
- Explain WHY, not WHAT
|
|
140
|
+
- Clarify complex business rules
|
|
141
|
+
- Warn of consequences
|
|
142
|
+
- TODO/FIXME notes (with tickets)
|
|
143
|
+
- Legal comments (copyright, license)
|
|
144
|
+
- API documentation (JSDoc, docstrings)
|
|
145
|
+
|
|
146
|
+
**When NOT to Comment**:
|
|
147
|
+
- Don't comment bad code, rewrite it
|
|
148
|
+
- Avoid redundant comments
|
|
149
|
+
- Don't comment out code (use version control)
|
|
150
|
+
- Avoid journal comments
|
|
151
|
+
- Avoid position markers
|
|
152
|
+
|
|
153
|
+
**Examples**:
|
|
154
|
+
```typescript
|
|
155
|
+
// ❌ BAD: Redundant comments
|
|
156
|
+
// Get the user by ID
|
|
157
|
+
function getUserById(id: string): User {
|
|
158
|
+
// Return the user
|
|
159
|
+
return users.find(u => u.id === id);
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
// ✅ GOOD: Self-documenting code
|
|
163
|
+
function getUserById(id: string): User {
|
|
164
|
+
return users.find(u => u.id === id);
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
// ❌ BAD: Commented-out code
|
|
168
|
+
function processOrder(order: Order) {
|
|
169
|
+
// validateOrder(order);
|
|
170
|
+
// checkInventory(order);
|
|
171
|
+
saveOrder(order);
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
// ✅ GOOD: Clear intent without noise
|
|
175
|
+
/**
|
|
176
|
+
* Processes order for payment and fulfillment.
|
|
177
|
+
* NOTE: Validation and inventory check are handled upstream.
|
|
178
|
+
*/
|
|
179
|
+
function processOrder(order: Order) {
|
|
180
|
+
saveOrder(order);
|
|
181
|
+
}
|
|
182
|
+
```
|
|
183
|
+
|
|
184
|
+
### 4. Formatting
|
|
185
|
+
|
|
186
|
+
**Rule**: Code formatting is about communication
|
|
187
|
+
|
|
188
|
+
**Vertical Formatting**:
|
|
189
|
+
- Small files are better (< 500 lines)
|
|
190
|
+
- Blank lines separate concepts
|
|
191
|
+
- Related code should be close together
|
|
192
|
+
- Declare variables close to usage
|
|
193
|
+
- Dependent functions should be close
|
|
194
|
+
|
|
195
|
+
**Horizontal Formatting**:
|
|
196
|
+
- Keep lines short (< 120 characters)
|
|
197
|
+
- Use whitespace to associate related things
|
|
198
|
+
- Indent to show hierarchy
|
|
199
|
+
|
|
200
|
+
**Example**:
|
|
201
|
+
```typescript
|
|
202
|
+
// ✅ GOOD: Well-formatted
|
|
203
|
+
class UserService {
|
|
204
|
+
constructor(
|
|
205
|
+
private userRepository: UserRepository,
|
|
206
|
+
private emailService: EmailService
|
|
207
|
+
) {}
|
|
208
|
+
|
|
209
|
+
async registerUser(userData: UserData): Promise<User> {
|
|
210
|
+
const validated = this.validateUserData(userData);
|
|
211
|
+
const user = await this.userRepository.create(validated);
|
|
212
|
+
await this.sendWelcomeEmail(user);
|
|
213
|
+
return user;
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
private validateUserData(userData: UserData): UserData {
|
|
217
|
+
if (!userData.email) throw new Error('Email required');
|
|
218
|
+
if (!userData.name) throw new Error('Name required');
|
|
219
|
+
return userData;
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
private async sendWelcomeEmail(user: User): Promise<void> {
|
|
223
|
+
await this.emailService.send(user.email, 'Welcome!');
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
```
|
|
227
|
+
|
|
228
|
+
### 5. Objects and Data Structures
|
|
229
|
+
|
|
230
|
+
**Rule**: Objects hide data, expose behavior. Data structures expose data, have no behavior.
|
|
231
|
+
|
|
232
|
+
**Law of Demeter**:
|
|
233
|
+
- Don't talk to strangers
|
|
234
|
+
- Method should only call methods on:
|
|
235
|
+
- Itself
|
|
236
|
+
- Its parameters
|
|
237
|
+
- Objects it creates
|
|
238
|
+
- Its direct dependencies
|
|
239
|
+
|
|
240
|
+
```typescript
|
|
241
|
+
// ❌ BAD: Violates Law of Demeter (train wreck)
|
|
242
|
+
const street = user.getAddress().getStreet().getName();
|
|
243
|
+
|
|
244
|
+
// ✅ GOOD: Tell, don't ask
|
|
245
|
+
const street = user.getStreetName();
|
|
246
|
+
|
|
247
|
+
// Inside User class:
|
|
248
|
+
getStreetName(): string {
|
|
249
|
+
return this.address.street.name;
|
|
250
|
+
}
|
|
251
|
+
```
|
|
252
|
+
|
|
253
|
+
### 6. Error Handling
|
|
254
|
+
|
|
255
|
+
**Rule**: Error handling is important, but it shouldn't obscure logic
|
|
256
|
+
|
|
257
|
+
**Use Exceptions**:
|
|
258
|
+
```typescript
|
|
259
|
+
// ❌ BAD: Error codes
|
|
260
|
+
function processPayment(amount: number): number {
|
|
261
|
+
if (amount <= 0) return -1;
|
|
262
|
+
if (insufficientFunds()) return -2;
|
|
263
|
+
return 0; // success
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
// ✅ GOOD: Exceptions
|
|
267
|
+
function processPayment(amount: number): void {
|
|
268
|
+
if (amount <= 0) {
|
|
269
|
+
throw new InvalidAmountError('Amount must be positive');
|
|
270
|
+
}
|
|
271
|
+
if (insufficientFunds()) {
|
|
272
|
+
throw new InsufficientFundsError('Not enough balance');
|
|
273
|
+
}
|
|
274
|
+
// Process payment
|
|
275
|
+
}
|
|
276
|
+
```
|
|
277
|
+
|
|
278
|
+
**Don't Return Null**:
|
|
279
|
+
```typescript
|
|
280
|
+
// ❌ BAD: Null checks everywhere
|
|
281
|
+
const users = getUsers();
|
|
282
|
+
if (users !== null) {
|
|
283
|
+
for (const user of users) {
|
|
284
|
+
if (user !== null) {
|
|
285
|
+
// ...
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
// ✅ GOOD: Return empty collection
|
|
291
|
+
function getUsers(): User[] {
|
|
292
|
+
return users ?? [];
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
// Or use Optional/Maybe pattern
|
|
296
|
+
function getUserById(id: string): User | undefined {
|
|
297
|
+
return users.find(u => u.id === id);
|
|
298
|
+
}
|
|
299
|
+
```
|
|
300
|
+
|
|
301
|
+
### 7. DRY (Don't Repeat Yourself)
|
|
302
|
+
|
|
303
|
+
**Rule**: Every piece of knowledge should have a single representation in the system
|
|
304
|
+
|
|
305
|
+
```typescript
|
|
306
|
+
// ❌ BAD: Duplication
|
|
307
|
+
function calculateOrderTotal(order: Order): number {
|
|
308
|
+
let total = 0;
|
|
309
|
+
for (const item of order.items) {
|
|
310
|
+
total += item.price * item.quantity;
|
|
311
|
+
}
|
|
312
|
+
total += total * 0.1; // Tax
|
|
313
|
+
total += 5; // Shipping
|
|
314
|
+
return total;
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
function calculateInvoiceTotal(invoice: Invoice): number {
|
|
318
|
+
let total = 0;
|
|
319
|
+
for (const item of invoice.items) {
|
|
320
|
+
total += item.price * item.quantity;
|
|
321
|
+
}
|
|
322
|
+
total += total * 0.1; // Tax
|
|
323
|
+
total += 5; // Shipping
|
|
324
|
+
return total;
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
// ✅ GOOD: Extract common logic
|
|
328
|
+
function calculateSubtotal(items: Item[]): number {
|
|
329
|
+
return items.reduce((sum, item) => sum + item.price * item.quantity, 0);
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
function addTaxAndShipping(subtotal: number): number {
|
|
333
|
+
const tax = subtotal * 0.1;
|
|
334
|
+
const shipping = 5;
|
|
335
|
+
return subtotal + tax + shipping;
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
function calculateTotal(items: Item[]): number {
|
|
339
|
+
const subtotal = calculateSubtotal(items);
|
|
340
|
+
return addTaxAndShipping(subtotal);
|
|
341
|
+
}
|
|
342
|
+
```
|
|
343
|
+
|
|
344
|
+
## Code Quality Checklist
|
|
345
|
+
|
|
346
|
+
**Naming**:
|
|
347
|
+
- [ ] All names reveal intent
|
|
348
|
+
- [ ] No abbreviations or encodings
|
|
349
|
+
- [ ] Boolean names start with is/has/can
|
|
350
|
+
- [ ] Collections are plural
|
|
351
|
+
- [ ] Functions are verbs, classes are nouns
|
|
352
|
+
|
|
353
|
+
**Functions**:
|
|
354
|
+
- [ ] Functions are small (< 20 lines)
|
|
355
|
+
- [ ] Functions do one thing
|
|
356
|
+
- [ ] One level of abstraction per function
|
|
357
|
+
- [ ] Few arguments (prefer 0-2)
|
|
358
|
+
- [ ] No flag arguments
|
|
359
|
+
- [ ] No side effects
|
|
360
|
+
|
|
361
|
+
**Comments**:
|
|
362
|
+
- [ ] Comments explain WHY, not WHAT
|
|
363
|
+
- [ ] No commented-out code
|
|
364
|
+
- [ ] No redundant comments
|
|
365
|
+
- [ ] API documentation present where needed
|
|
366
|
+
|
|
367
|
+
**Formatting**:
|
|
368
|
+
- [ ] Consistent indentation
|
|
369
|
+
- [ ] Lines < 120 characters
|
|
370
|
+
- [ ] Blank lines separate concepts
|
|
371
|
+
- [ ] Related code is together
|
|
372
|
+
|
|
373
|
+
**Error Handling**:
|
|
374
|
+
- [ ] Use exceptions, not error codes
|
|
375
|
+
- [ ] Don't return null (use empty collections or Optional)
|
|
376
|
+
- [ ] Exceptions are specific and meaningful
|
|
377
|
+
|
|
378
|
+
**General**:
|
|
379
|
+
- [ ] No duplication (DRY)
|
|
380
|
+
- [ ] Code is self-documenting
|
|
381
|
+
- [ ] Tests exist and pass
|
|
382
|
+
- [ ] No dead code
|
|
383
|
+
|
|
384
|
+
## The Boy Scout Rule
|
|
385
|
+
|
|
386
|
+
**"Leave the code better than you found it."**
|
|
387
|
+
|
|
388
|
+
- Clean up small messes when you see them
|
|
389
|
+
- Improve names, extract functions, add tests
|
|
390
|
+
- Continuous improvement over time
|
|
391
|
+
- Don't need permission for small improvements
|
|
392
|
+
|
|
393
|
+
## Further Reading
|
|
394
|
+
|
|
395
|
+
- "Clean Code" by Robert C. Martin
|
|
396
|
+
- "Code Complete" by Steve McConnell
|
|
397
|
+
- "The Pragmatic Programmer" by Hunt and Thomas
|
|
398
|
+
- "Refactoring" by Martin Fowler
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
# Code Generation
|
|
2
|
+
|
|
3
|
+
Generate high-quality, production-ready code following best practices and patterns.
|
|
4
|
+
|
|
5
|
+
## Core Principles
|
|
6
|
+
|
|
7
|
+
### 1. Type Safety & Validation
|
|
8
|
+
- Use strong typing (TypeScript interfaces, Python type hints)
|
|
9
|
+
- Validate inputs before processing
|
|
10
|
+
- Define clear return types
|
|
11
|
+
- Use enums for fixed value sets
|
|
12
|
+
|
|
13
|
+
### 2. Error Handling
|
|
14
|
+
- Use try-catch for I/O operations
|
|
15
|
+
- Provide specific error messages with context
|
|
16
|
+
- Log errors appropriately
|
|
17
|
+
- Never swallow errors silently
|
|
18
|
+
- Return typed error objects or throw typed exceptions
|
|
19
|
+
|
|
20
|
+
### 3. Function Design
|
|
21
|
+
- Single responsibility per function
|
|
22
|
+
- Clear, descriptive names
|
|
23
|
+
- Document complex logic with comments
|
|
24
|
+
- Keep functions small (<50 lines)
|
|
25
|
+
- Minimize side effects
|
|
26
|
+
|
|
27
|
+
### 4. API Design
|
|
28
|
+
- RESTful conventions (GET/POST/PUT/DELETE)
|
|
29
|
+
- Consistent response formats
|
|
30
|
+
- Proper HTTP status codes
|
|
31
|
+
- Request/response validation
|
|
32
|
+
- API versioning when needed
|
|
33
|
+
|
|
34
|
+
### 5. Testing
|
|
35
|
+
- Write unit tests for business logic
|
|
36
|
+
- Test error cases and edge conditions
|
|
37
|
+
- Use descriptive test names
|
|
38
|
+
- Aim for >80% coverage on critical paths
|
|
39
|
+
- Mock external dependencies
|
|
40
|
+
|
|
41
|
+
### 6. Code Quality
|
|
42
|
+
- Follow project coding standards
|
|
43
|
+
- Use linting and formatting tools
|
|
44
|
+
- Write self-documenting code
|
|
45
|
+
- Keep complexity low (cyclomatic complexity <10)
|
|
46
|
+
- Remove dead code and TODOs
|
|
47
|
+
|
|
48
|
+
### 7. Security
|
|
49
|
+
- Validate and sanitize all inputs
|
|
50
|
+
- Use parameterized queries (prevent SQL injection)
|
|
51
|
+
- Never log sensitive data
|
|
52
|
+
- Follow principle of least privilege
|
|
53
|
+
- Keep dependencies updated
|
|
54
|
+
|
|
55
|
+
### 8. Performance
|
|
56
|
+
- Avoid N+1 queries
|
|
57
|
+
- Use appropriate data structures
|
|
58
|
+
- Cache when beneficial
|
|
59
|
+
- Lazy load when possible
|
|
60
|
+
- Profile before optimizing
|
|
61
|
+
|
|
62
|
+
## Language-Specific Patterns
|
|
63
|
+
|
|
64
|
+
### TypeScript/JavaScript
|
|
65
|
+
- Async/await for promises
|
|
66
|
+
- Optional chaining (?.) and nullish coalescing (??)
|
|
67
|
+
- Destructuring for cleaner code
|
|
68
|
+
- Use const by default, let when needed
|
|
69
|
+
- Avoid var
|
|
70
|
+
|
|
71
|
+
### Python
|
|
72
|
+
- Type hints for function signatures
|
|
73
|
+
- List/dict comprehensions for data transformation
|
|
74
|
+
- Context managers (with statement) for resources
|
|
75
|
+
- Follow PEP 8 style guide
|
|
76
|
+
- Use dataclasses for data models
|
|
77
|
+
|
|
78
|
+
### SQL
|
|
79
|
+
- Use indexes on frequently queried columns
|
|
80
|
+
- Avoid SELECT *
|
|
81
|
+
- Use JOINs efficiently
|
|
82
|
+
- Parameterize queries
|
|
83
|
+
- Use transactions for multi-step operations
|
|
84
|
+
|
|
85
|
+
## Quick Checklist
|
|
86
|
+
|
|
87
|
+
Before submitting code:
|
|
88
|
+
- [ ] Types and interfaces defined
|
|
89
|
+
- [ ] Error handling implemented
|
|
90
|
+
- [ ] Input validation added
|
|
91
|
+
- [ ] Tests written and passing
|
|
92
|
+
- [ ] Code formatted and linted
|
|
93
|
+
- [ ] No console.log/print in production code
|
|
94
|
+
- [ ] Security considerations addressed
|
|
95
|
+
- [ ] Performance optimized where needed
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
# Code Review Ability
|
|
2
|
+
|
|
3
|
+
Perform thorough code reviews focusing on quality, security, and maintainability.
|
|
4
|
+
|
|
5
|
+
## Review Areas
|
|
6
|
+
|
|
7
|
+
1. **Correctness**
|
|
8
|
+
- Logic errors and bugs
|
|
9
|
+
- Edge case handling
|
|
10
|
+
- Error handling and validation
|
|
11
|
+
|
|
12
|
+
2. **Security**
|
|
13
|
+
- Input validation
|
|
14
|
+
- SQL injection, XSS vulnerabilities
|
|
15
|
+
- Secrets and credentials exposure
|
|
16
|
+
- Authentication and authorization
|
|
17
|
+
|
|
18
|
+
3. **Performance**
|
|
19
|
+
- Algorithm complexity (Big O)
|
|
20
|
+
- Resource usage (memory, CPU)
|
|
21
|
+
- Database query optimization
|
|
22
|
+
- Caching opportunities
|
|
23
|
+
|
|
24
|
+
4. **Maintainability**
|
|
25
|
+
- Code clarity and readability
|
|
26
|
+
- Documentation quality
|
|
27
|
+
- Test coverage
|
|
28
|
+
- Modularity and coupling
|
|
29
|
+
|
|
30
|
+
5. **Style**
|
|
31
|
+
- Coding standards compliance
|
|
32
|
+
- Naming conventions
|
|
33
|
+
- Code organization
|
|
34
|
+
- Consistent formatting
|
|
35
|
+
|
|
36
|
+
## Review Process
|
|
37
|
+
|
|
38
|
+
1. Understand the context and requirements
|
|
39
|
+
2. Review code systematically (file by file)
|
|
40
|
+
3. Identify issues and improvements
|
|
41
|
+
4. Prioritize findings (critical/major/minor)
|
|
42
|
+
5. Provide actionable, constructive feedback
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
# Component Architecture
|
|
2
|
+
|
|
3
|
+
## Overview
|
|
4
|
+
Design and implement reusable, maintainable component structures following modern frontend architecture patterns. Focus on composition, separation of concerns, and clear component hierarchies.
|
|
5
|
+
|
|
6
|
+
## Core Principles
|
|
7
|
+
|
|
8
|
+
### 1. Single Responsibility
|
|
9
|
+
Each component should have one clear purpose. Avoid components that try to do too much.
|
|
10
|
+
|
|
11
|
+
### 2. Composition Over Inheritance
|
|
12
|
+
Build complex UIs by composing smaller, focused components rather than creating deep inheritance chains.
|
|
13
|
+
|
|
14
|
+
### 3. Container/Presentational Pattern
|
|
15
|
+
- **Container components**: Handle logic, state, and side effects
|
|
16
|
+
- **Presentational components**: Focus purely on rendering UI based on props
|
|
17
|
+
|
|
18
|
+
### 4. Props Design
|
|
19
|
+
- Keep props interfaces simple and explicit
|
|
20
|
+
- Use TypeScript for type safety
|
|
21
|
+
- Avoid prop drilling—use context or state management for deep data
|
|
22
|
+
|
|
23
|
+
## Component Structure
|
|
24
|
+
|
|
25
|
+
```
|
|
26
|
+
/components
|
|
27
|
+
/Button
|
|
28
|
+
Button.tsx # Component implementation
|
|
29
|
+
Button.test.tsx # Tests
|
|
30
|
+
Button.stories.tsx # Storybook stories
|
|
31
|
+
index.ts # Public exports
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
## Atomic Design
|
|
35
|
+
|
|
36
|
+
Organize components by complexity:
|
|
37
|
+
- **Atoms**: Button, Input, Label
|
|
38
|
+
- **Molecules**: FormField (Input + Label), SearchBar
|
|
39
|
+
- **Organisms**: LoginForm, Header, Card
|
|
40
|
+
- **Templates**: Page layouts
|
|
41
|
+
- **Pages**: Complete pages
|
|
42
|
+
|
|
43
|
+
## Best Practices
|
|
44
|
+
|
|
45
|
+
### Component Design
|
|
46
|
+
- Single responsibility principle
|
|
47
|
+
- TypeScript interfaces for props
|
|
48
|
+
- Proper error boundaries
|
|
49
|
+
- Clear naming conventions
|
|
50
|
+
|
|
51
|
+
### Performance
|
|
52
|
+
- Memoization where appropriate (React.memo, useMemo)
|
|
53
|
+
- Callback memoization (useCallback)
|
|
54
|
+
- Code splitting for heavy components
|
|
55
|
+
- Lazy loading with Suspense
|
|
56
|
+
|
|
57
|
+
### Testing
|
|
58
|
+
- Unit tests for component logic
|
|
59
|
+
- Integration tests for user interactions
|
|
60
|
+
- Accessibility testing
|
|
61
|
+
- Visual regression tests
|
|
62
|
+
|
|
63
|
+
## Anti-Patterns to Avoid
|
|
64
|
+
|
|
65
|
+
### 1. God Components
|
|
66
|
+
Components that handle too many responsibilities
|
|
67
|
+
|
|
68
|
+
### 2. Prop Drilling
|
|
69
|
+
Passing props through many levels—use Context API or state management
|
|
70
|
+
|
|
71
|
+
### 3. Tight Coupling
|
|
72
|
+
Components depending on specific parent or child implementations
|
|
73
|
+
|
|
74
|
+
### 4. Mixed Concerns
|
|
75
|
+
Mixing business logic, API calls, and rendering in one component
|
|
76
|
+
|
|
77
|
+
## Component Checklist
|
|
78
|
+
|
|
79
|
+
- [ ] Single responsibility
|
|
80
|
+
- [ ] TypeScript interfaces for props
|
|
81
|
+
- [ ] Proper error boundaries
|
|
82
|
+
- [ ] Memoization where appropriate
|
|
83
|
+
- [ ] Accessibility attributes (ARIA)
|
|
84
|
+
- [ ] Unit tests for logic
|
|
85
|
+
- [ ] Integration tests for interactions
|
|
86
|
+
- [ ] Storybook documentation
|
|
87
|
+
- [ ] Performance optimized
|
|
88
|
+
- [ ] Code split if heavy
|
|
89
|
+
|
|
90
|
+
## Performance Considerations
|
|
91
|
+
|
|
92
|
+
### Memoization
|
|
93
|
+
- Memoize expensive computations (useMemo)
|
|
94
|
+
- Memoize callback functions (useCallback)
|
|
95
|
+
- Memoize components that render often (React.memo)
|
|
96
|
+
|
|
97
|
+
### Code Splitting
|
|
98
|
+
- Lazy load heavy components
|
|
99
|
+
- Use Suspense for loading states
|
|
100
|
+
- Route-based code splitting
|
|
101
|
+
|
|
102
|
+
### Optimization Techniques
|
|
103
|
+
- Virtual scrolling for long lists
|
|
104
|
+
- Debounce/throttle for frequent events
|
|
105
|
+
- Avoid unnecessary re-renders
|
|
106
|
+
- Use production builds
|
|
107
|
+
|
|
108
|
+
## Resources
|
|
109
|
+
|
|
110
|
+
- [React Component Patterns](https://reactpatterns.com/)
|
|
111
|
+
- [Atomic Design Methodology](https://atomicdesign.bradfrost.com/)
|
|
112
|
+
- [Testing Library Best Practices](https://testing-library.com/docs/react-testing-library/intro)
|