@champpaba/claude-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.
- package/LICENSE +21 -0
- package/README.md +561 -0
- package/bin/cli.js +61 -0
- package/lib/init.js +52 -0
- package/lib/update.js +73 -0
- package/package.json +47 -0
- package/template/.claude/CHANGELOG-v1.1.1.md +259 -0
- package/template/.claude/CLAUDE.md +329 -0
- package/template/.claude/agents/01-integration.md +797 -0
- package/template/.claude/agents/02-uxui-frontend.md +899 -0
- package/template/.claude/agents/03-test-debug.md +759 -0
- package/template/.claude/agents/04-frontend.md +1099 -0
- package/template/.claude/agents/05-backend.md +1217 -0
- package/template/.claude/agents/06-database.md +969 -0
- package/template/.claude/commands/agentsetup.md +1464 -0
- package/template/.claude/commands/cdev.md +327 -0
- package/template/.claude/commands/csetup.md +447 -0
- package/template/.claude/commands/cstatus.md +60 -0
- package/template/.claude/commands/cview.md +364 -0
- package/template/.claude/commands/psetup.md +101 -0
- package/template/.claude/contexts/design/accessibility.md +611 -0
- package/template/.claude/contexts/design/box-thinking.md +553 -0
- package/template/.claude/contexts/design/color-theory.md +498 -0
- package/template/.claude/contexts/design/index.md +247 -0
- package/template/.claude/contexts/design/layout.md +400 -0
- package/template/.claude/contexts/design/responsive.md +551 -0
- package/template/.claude/contexts/design/shadows.md +522 -0
- package/template/.claude/contexts/design/spacing.md +428 -0
- package/template/.claude/contexts/design/typography.md +465 -0
- package/template/.claude/contexts/domain/README.md +164 -0
- package/template/.claude/contexts/patterns/agent-coordination.md +388 -0
- package/template/.claude/contexts/patterns/agent-discovery.md +182 -0
- package/template/.claude/contexts/patterns/change-workflow.md +538 -0
- package/template/.claude/contexts/patterns/code-standards.md +515 -0
- package/template/.claude/contexts/patterns/development-principles.md +513 -0
- package/template/.claude/contexts/patterns/error-handling.md +478 -0
- package/template/.claude/contexts/patterns/error-recovery.md +365 -0
- package/template/.claude/contexts/patterns/frontend-component-strategy.md +365 -0
- package/template/.claude/contexts/patterns/git-workflow.md +207 -0
- package/template/.claude/contexts/patterns/logging.md +424 -0
- package/template/.claude/contexts/patterns/task-breakdown.md +452 -0
- package/template/.claude/contexts/patterns/task-classification.md +523 -0
- package/template/.claude/contexts/patterns/tdd-classification.md +516 -0
- package/template/.claude/contexts/patterns/testing.md +413 -0
- package/template/.claude/contexts/patterns/ui-component-consistency.md +304 -0
- package/template/.claude/contexts/patterns/validation-framework.md +776 -0
- package/template/.claude/lib/README.md +39 -0
- package/template/.claude/lib/agent-executor.md +258 -0
- package/template/.claude/lib/agent-router.md +572 -0
- package/template/.claude/lib/flags-updater.md +469 -0
- package/template/.claude/lib/tdd-classifier.md +345 -0
- package/template/.claude/lib/validation-gates.md +484 -0
- package/template/.claude/settings.local.json +42 -0
- package/template/.claude/templates/context-template.md +45 -0
- package/template/.claude/templates/flags-template.json +42 -0
- package/template/.claude/templates/phase-templates.json +124 -0
- package/template/.claude/templates/phases-sections/accessibility-test.md +17 -0
- package/template/.claude/templates/phases-sections/api-design.md +37 -0
- package/template/.claude/templates/phases-sections/backend-tests.md +16 -0
- package/template/.claude/templates/phases-sections/backend.md +37 -0
- package/template/.claude/templates/phases-sections/business-logic-validation.md +16 -0
- package/template/.claude/templates/phases-sections/component-tests.md +17 -0
- package/template/.claude/templates/phases-sections/contract-backend.md +16 -0
- package/template/.claude/templates/phases-sections/contract-frontend.md +16 -0
- package/template/.claude/templates/phases-sections/database.md +35 -0
- package/template/.claude/templates/phases-sections/documentation.md +17 -0
- package/template/.claude/templates/phases-sections/e2e-tests.md +16 -0
- package/template/.claude/templates/phases-sections/fix-implementation.md +17 -0
- package/template/.claude/templates/phases-sections/frontend-integration.md +18 -0
- package/template/.claude/templates/phases-sections/frontend-mockup.md +123 -0
- package/template/.claude/templates/phases-sections/manual-flow-test.md +15 -0
- package/template/.claude/templates/phases-sections/manual-ux-test.md +16 -0
- package/template/.claude/templates/phases-sections/refactor-implementation.md +17 -0
- package/template/.claude/templates/phases-sections/refactor.md +16 -0
- package/template/.claude/templates/phases-sections/regression-tests.md +15 -0
- package/template/.claude/templates/phases-sections/report.md +16 -0
- package/template/.claude/templates/phases-sections/responsive-test.md +16 -0
- package/template/.claude/templates/phases-sections/script-implementation.md +43 -0
- package/template/.claude/templates/phases-sections/test-coverage.md +16 -0
- package/template/.claude/templates/phases-sections/user-approval.md +14 -0
|
@@ -0,0 +1,515 @@
|
|
|
1
|
+
# Code Standards & Conventions
|
|
2
|
+
|
|
3
|
+
**Goal:** Consistent, readable, maintainable code across all projects.
|
|
4
|
+
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
## File Size Guidelines
|
|
8
|
+
|
|
9
|
+
| File Type | Max Lines | Reasoning |
|
|
10
|
+
|-----------|-----------|-----------|
|
|
11
|
+
| **Components** | 300 lines | Single responsibility, easier to test |
|
|
12
|
+
| **API Routes** | 200 lines | Delegate complex logic to services |
|
|
13
|
+
| **Services** | 400 lines | Single domain focus |
|
|
14
|
+
| **Utilities** | 150 lines | Pure functions, simple modules |
|
|
15
|
+
| **Tests** | 500 lines | Comprehensive coverage per module |
|
|
16
|
+
|
|
17
|
+
### When to Split Files
|
|
18
|
+
|
|
19
|
+
**❌ Too Large:**
|
|
20
|
+
```typescript
|
|
21
|
+
// user-management.ts (800 lines)
|
|
22
|
+
class UserManagement {
|
|
23
|
+
createUser() { /* 100 lines */ }
|
|
24
|
+
updateUser() { /* 100 lines */ }
|
|
25
|
+
deleteUser() { /* 100 lines */ }
|
|
26
|
+
sendWelcomeEmail() { /* 100 lines */ }
|
|
27
|
+
generateReport() { /* 100 lines */ }
|
|
28
|
+
exportToCSV() { /* 100 lines */ }
|
|
29
|
+
// ... more methods
|
|
30
|
+
}
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
**✅ Properly Split:**
|
|
34
|
+
```typescript
|
|
35
|
+
// services/user-service.ts (150 lines)
|
|
36
|
+
class UserService {
|
|
37
|
+
createUser() { /* ... */ }
|
|
38
|
+
updateUser() { /* ... */ }
|
|
39
|
+
deleteUser() { /* ... */ }
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
// services/email-service.ts (100 lines)
|
|
43
|
+
class EmailService {
|
|
44
|
+
sendWelcomeEmail() { /* ... */ }
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
// services/report-service.ts (120 lines)
|
|
48
|
+
class ReportService {
|
|
49
|
+
generateReport() { /* ... */ }
|
|
50
|
+
exportToCSV() { /* ... */ }
|
|
51
|
+
}
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
---
|
|
55
|
+
|
|
56
|
+
## Function Complexity
|
|
57
|
+
|
|
58
|
+
| Function Type | Max Lines | Max Nesting |
|
|
59
|
+
|---------------|-----------|-------------|
|
|
60
|
+
| **React Components** | 100 lines | 3 levels |
|
|
61
|
+
| **Hooks** | 80 lines | 2 levels |
|
|
62
|
+
| **API Handlers** | 50 lines | 2 levels |
|
|
63
|
+
| **Service Methods** | 60 lines | 3 levels |
|
|
64
|
+
| **Utility Functions** | 40 lines | 2 levels |
|
|
65
|
+
|
|
66
|
+
### Reducing Complexity
|
|
67
|
+
|
|
68
|
+
**❌ Complex (6 levels deep):**
|
|
69
|
+
```typescript
|
|
70
|
+
function processOrder(order: Order) {
|
|
71
|
+
if (order.items.length > 0) {
|
|
72
|
+
if (order.user.isPremium) {
|
|
73
|
+
if (order.total > 100) {
|
|
74
|
+
if (order.shippingAddress) {
|
|
75
|
+
if (order.paymentMethod === 'card') {
|
|
76
|
+
if (order.user.hasValidCard) {
|
|
77
|
+
// Deep nesting hell
|
|
78
|
+
return processPayment(order)
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
**✅ Simple (Early Returns):**
|
|
89
|
+
```typescript
|
|
90
|
+
function processOrder(order: Order) {
|
|
91
|
+
// Guard clauses
|
|
92
|
+
if (order.items.length === 0) throw new Error('Empty order')
|
|
93
|
+
if (!order.user.isPremium) throw new Error('Premium required')
|
|
94
|
+
if (order.total <= 100) throw new Error('Minimum $100')
|
|
95
|
+
if (!order.shippingAddress) throw new Error('Address required')
|
|
96
|
+
if (order.paymentMethod !== 'card') throw new Error('Card payment only')
|
|
97
|
+
if (!order.user.hasValidCard) throw new Error('Invalid card')
|
|
98
|
+
|
|
99
|
+
// Happy path
|
|
100
|
+
return processPayment(order)
|
|
101
|
+
}
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
---
|
|
105
|
+
|
|
106
|
+
## Naming Conventions
|
|
107
|
+
|
|
108
|
+
### TypeScript/JavaScript (Next.js, React, Node.js)
|
|
109
|
+
|
|
110
|
+
| Type | Convention | Example |
|
|
111
|
+
|------|-----------|---------|
|
|
112
|
+
| **Files/Folders** | kebab-case | `user-profile.tsx`, `api-routes/` |
|
|
113
|
+
| **Components** | PascalCase | `UserProfile`, `AssessmentCard` |
|
|
114
|
+
| **Functions/Variables** | camelCase | `calculateTotal`, `isAuthenticated` |
|
|
115
|
+
| **Constants** | UPPER_SNAKE_CASE | `MAX_FILE_SIZE`, `API_BASE_URL` |
|
|
116
|
+
| **Types/Interfaces** | PascalCase | `User`, `SessionData` |
|
|
117
|
+
| **Enums** | PascalCase | `UserRole`, `PaymentStatus` |
|
|
118
|
+
| **Private Fields** | _camelCase | `_internalState` |
|
|
119
|
+
|
|
120
|
+
**Examples:**
|
|
121
|
+
|
|
122
|
+
```typescript
|
|
123
|
+
// Files
|
|
124
|
+
user-profile.tsx
|
|
125
|
+
session-manager.ts
|
|
126
|
+
api-routes/users/route.ts
|
|
127
|
+
|
|
128
|
+
// Components
|
|
129
|
+
export default function UserProfile() { /* ... */ }
|
|
130
|
+
export function AssessmentCard({ data }: Props) { /* ... */ }
|
|
131
|
+
|
|
132
|
+
// Functions
|
|
133
|
+
function calculateBandScore(score: number) { /* ... */ }
|
|
134
|
+
const isAuthenticated = (user: User) => !!user.token
|
|
135
|
+
|
|
136
|
+
// Constants
|
|
137
|
+
const MAX_RECORDING_TIME = 120 // seconds
|
|
138
|
+
const API_BASE_URL = process.env.NEXT_PUBLIC_API_URL
|
|
139
|
+
|
|
140
|
+
// Types
|
|
141
|
+
interface User {
|
|
142
|
+
id: string
|
|
143
|
+
email: string
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
type SessionStatus = 'active' | 'expired' | 'invalid'
|
|
147
|
+
|
|
148
|
+
enum UserRole {
|
|
149
|
+
Admin = 'ADMIN',
|
|
150
|
+
User = 'USER',
|
|
151
|
+
Guest = 'GUEST'
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
// Private
|
|
155
|
+
class SessionStore {
|
|
156
|
+
private _sessions = new Map()
|
|
157
|
+
}
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
---
|
|
161
|
+
|
|
162
|
+
### Python (FastAPI, Django, Flask)
|
|
163
|
+
|
|
164
|
+
| Type | Convention | Example |
|
|
165
|
+
|------|-----------|---------|
|
|
166
|
+
| **Files/Modules** | snake_case | `user_service.py`, `api_routes.py` |
|
|
167
|
+
| **Classes** | PascalCase | `UserService`, `DatabaseClient` |
|
|
168
|
+
| **Functions/Variables** | snake_case | `calculate_total`, `is_authenticated` |
|
|
169
|
+
| **Constants** | UPPER_SNAKE_CASE | `MAX_FILE_SIZE`, `API_BASE_URL` |
|
|
170
|
+
| **Private** | _snake_case | `_internal_method` |
|
|
171
|
+
|
|
172
|
+
**Examples:**
|
|
173
|
+
|
|
174
|
+
```python
|
|
175
|
+
# Files
|
|
176
|
+
user_service.py
|
|
177
|
+
session_manager.py
|
|
178
|
+
|
|
179
|
+
# Classes
|
|
180
|
+
class UserService:
|
|
181
|
+
pass
|
|
182
|
+
|
|
183
|
+
class DatabaseClient:
|
|
184
|
+
pass
|
|
185
|
+
|
|
186
|
+
# Functions
|
|
187
|
+
def calculate_band_score(score: float) -> float:
|
|
188
|
+
pass
|
|
189
|
+
|
|
190
|
+
def is_authenticated(user: User) -> bool:
|
|
191
|
+
return user.token is not None
|
|
192
|
+
|
|
193
|
+
# Constants
|
|
194
|
+
MAX_RECORDING_TIME = 120 # seconds
|
|
195
|
+
API_BASE_URL = os.getenv("API_BASE_URL")
|
|
196
|
+
|
|
197
|
+
# Private
|
|
198
|
+
class SessionStore:
|
|
199
|
+
def __init__(self):
|
|
200
|
+
self._sessions = {}
|
|
201
|
+
```
|
|
202
|
+
|
|
203
|
+
---
|
|
204
|
+
|
|
205
|
+
## Database Naming
|
|
206
|
+
|
|
207
|
+
### Prisma (TypeScript)
|
|
208
|
+
|
|
209
|
+
| Type | Convention | Example |
|
|
210
|
+
|------|-----------|---------|
|
|
211
|
+
| **Models** | PascalCase singular | `User`, `Session`, `Order` |
|
|
212
|
+
| **Fields** | camelCase | `userId`, `createdAt`, `firstName` |
|
|
213
|
+
| **Relations** | camelCase | `user`, `orders`, `sessions` |
|
|
214
|
+
| **Enums** | PascalCase | `UserRole`, `OrderStatus` |
|
|
215
|
+
|
|
216
|
+
```prisma
|
|
217
|
+
model User {
|
|
218
|
+
id String @id @default(uuid())
|
|
219
|
+
email String @unique
|
|
220
|
+
firstName String
|
|
221
|
+
lastName String
|
|
222
|
+
createdAt DateTime @default(now())
|
|
223
|
+
updatedAt DateTime @updatedAt
|
|
224
|
+
|
|
225
|
+
// Relations
|
|
226
|
+
sessions Session[]
|
|
227
|
+
orders Order[]
|
|
228
|
+
|
|
229
|
+
@@map("users")
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
enum UserRole {
|
|
233
|
+
ADMIN
|
|
234
|
+
USER
|
|
235
|
+
GUEST
|
|
236
|
+
|
|
237
|
+
@@map("user_roles")
|
|
238
|
+
}
|
|
239
|
+
```
|
|
240
|
+
|
|
241
|
+
---
|
|
242
|
+
|
|
243
|
+
### SQLAlchemy (Python)
|
|
244
|
+
|
|
245
|
+
| Type | Convention | Example |
|
|
246
|
+
|------|-----------|---------|
|
|
247
|
+
| **Models** | PascalCase | `User`, `Session`, `Order` |
|
|
248
|
+
| **Tables** | snake_case | `users`, `sessions`, `orders` |
|
|
249
|
+
| **Columns** | snake_case | `user_id`, `created_at`, `first_name` |
|
|
250
|
+
|
|
251
|
+
```python
|
|
252
|
+
class User(Base):
|
|
253
|
+
__tablename__ = "users"
|
|
254
|
+
|
|
255
|
+
id = Column(String, primary_key=True, default=lambda: str(uuid4()))
|
|
256
|
+
email = Column(String, unique=True, nullable=False)
|
|
257
|
+
first_name = Column(String, nullable=False)
|
|
258
|
+
last_name = Column(String, nullable=False)
|
|
259
|
+
created_at = Column(DateTime, default=datetime.utcnow)
|
|
260
|
+
updated_at = Column(DateTime, onupdate=datetime.utcnow)
|
|
261
|
+
|
|
262
|
+
# Relations
|
|
263
|
+
sessions = relationship("Session", back_populates="user")
|
|
264
|
+
orders = relationship("Order", back_populates="user")
|
|
265
|
+
```
|
|
266
|
+
|
|
267
|
+
---
|
|
268
|
+
|
|
269
|
+
## Code Organization
|
|
270
|
+
|
|
271
|
+
### Next.js App Router
|
|
272
|
+
|
|
273
|
+
```
|
|
274
|
+
project/
|
|
275
|
+
├── app/
|
|
276
|
+
│ ├── api/
|
|
277
|
+
│ │ ├── users/
|
|
278
|
+
│ │ │ ├── route.ts # API endpoint
|
|
279
|
+
│ │ │ └── [id]/route.ts # Dynamic route
|
|
280
|
+
│ │ └── auth/
|
|
281
|
+
│ │ └── route.ts
|
|
282
|
+
│ ├── (dashboard)/ # Route group
|
|
283
|
+
│ │ ├── layout.tsx
|
|
284
|
+
│ │ └── page.tsx
|
|
285
|
+
│ └── page.tsx # Home page
|
|
286
|
+
├── components/
|
|
287
|
+
│ ├── ui/ # Reusable UI components
|
|
288
|
+
│ │ ├── button.tsx
|
|
289
|
+
│ │ └── card.tsx
|
|
290
|
+
│ └── features/ # Feature-specific components
|
|
291
|
+
│ ├── user-profile.tsx
|
|
292
|
+
│ └── assessment-card.tsx
|
|
293
|
+
├── lib/
|
|
294
|
+
│ ├── db.ts # Database client
|
|
295
|
+
│ ├── logger.ts # Logging utility
|
|
296
|
+
│ ├── validators/ # Zod schemas
|
|
297
|
+
│ │ ├── user.ts
|
|
298
|
+
│ │ └── session.ts
|
|
299
|
+
│ ├── services/ # Business logic
|
|
300
|
+
│ │ ├── user-service.ts
|
|
301
|
+
│ │ └── email-service.ts
|
|
302
|
+
│ ├── types/ # TypeScript types
|
|
303
|
+
│ │ ├── user.ts
|
|
304
|
+
│ │ └── session.ts
|
|
305
|
+
│ └── utils/ # Utility functions
|
|
306
|
+
│ ├── formatters.ts
|
|
307
|
+
│ └── validators.ts
|
|
308
|
+
├── prisma/
|
|
309
|
+
│ ├── schema.prisma
|
|
310
|
+
│ └── migrations/
|
|
311
|
+
├── tests/
|
|
312
|
+
│ ├── unit/
|
|
313
|
+
│ │ └── lib/
|
|
314
|
+
│ ├── integration/
|
|
315
|
+
│ │ └── api/
|
|
316
|
+
│ └── e2e/
|
|
317
|
+
└── public/
|
|
318
|
+
```
|
|
319
|
+
|
|
320
|
+
---
|
|
321
|
+
|
|
322
|
+
### FastAPI
|
|
323
|
+
|
|
324
|
+
```
|
|
325
|
+
project/
|
|
326
|
+
├── app/
|
|
327
|
+
│ ├── main.py # FastAPI app
|
|
328
|
+
│ ├── api/
|
|
329
|
+
│ │ ├── __init__.py
|
|
330
|
+
│ │ ├── users.py # User routes
|
|
331
|
+
│ │ └── auth.py # Auth routes
|
|
332
|
+
│ ├── models/ # SQLAlchemy models
|
|
333
|
+
│ │ ├── __init__.py
|
|
334
|
+
│ │ ├── user.py
|
|
335
|
+
│ │ └── session.py
|
|
336
|
+
│ ├── schemas/ # Pydantic schemas
|
|
337
|
+
│ │ ├── __init__.py
|
|
338
|
+
│ │ ├── user.py
|
|
339
|
+
│ │ └── session.py
|
|
340
|
+
│ ├── services/ # Business logic
|
|
341
|
+
│ │ ├── __init__.py
|
|
342
|
+
│ │ ├── user_service.py
|
|
343
|
+
│ │ └── email_service.py
|
|
344
|
+
│ └── utils/ # Utilities
|
|
345
|
+
│ ├── __init__.py
|
|
346
|
+
│ ├── logger.py
|
|
347
|
+
│ └── validators.py
|
|
348
|
+
├── tests/
|
|
349
|
+
│ ├── unit/
|
|
350
|
+
│ └── integration/
|
|
351
|
+
└── alembic/ # Database migrations
|
|
352
|
+
```
|
|
353
|
+
|
|
354
|
+
---
|
|
355
|
+
|
|
356
|
+
## Import Order
|
|
357
|
+
|
|
358
|
+
### TypeScript/JavaScript
|
|
359
|
+
|
|
360
|
+
```typescript
|
|
361
|
+
// 1. External libraries
|
|
362
|
+
import { useState, useEffect } from 'react'
|
|
363
|
+
import { z } from 'zod'
|
|
364
|
+
|
|
365
|
+
// 2. Internal absolute imports (@/)
|
|
366
|
+
import { Button } from '@/components/ui/button'
|
|
367
|
+
import { logger } from '@/lib/logger'
|
|
368
|
+
import { userService } from '@/lib/services/user-service'
|
|
369
|
+
|
|
370
|
+
// 3. Types
|
|
371
|
+
import type { User, SessionData } from '@/lib/types'
|
|
372
|
+
|
|
373
|
+
// 4. Relative imports
|
|
374
|
+
import { calculateScore } from './utils'
|
|
375
|
+
import type { LocalProps } from './types'
|
|
376
|
+
```
|
|
377
|
+
|
|
378
|
+
---
|
|
379
|
+
|
|
380
|
+
### Python
|
|
381
|
+
|
|
382
|
+
```python
|
|
383
|
+
# 1. Standard library
|
|
384
|
+
import os
|
|
385
|
+
import sys
|
|
386
|
+
from datetime import datetime
|
|
387
|
+
|
|
388
|
+
# 2. Third-party libraries
|
|
389
|
+
from fastapi import FastAPI, HTTPException
|
|
390
|
+
from sqlalchemy import Column, String
|
|
391
|
+
|
|
392
|
+
# 3. Local application imports
|
|
393
|
+
from app.models.user import User
|
|
394
|
+
from app.services.user_service import UserService
|
|
395
|
+
from app.utils.logger import logger
|
|
396
|
+
```
|
|
397
|
+
|
|
398
|
+
---
|
|
399
|
+
|
|
400
|
+
## Comments & Documentation
|
|
401
|
+
|
|
402
|
+
### When to Comment
|
|
403
|
+
|
|
404
|
+
**✅ Good Comments:**
|
|
405
|
+
- Explain **why** (not what)
|
|
406
|
+
- Document non-obvious business logic
|
|
407
|
+
- Warn about edge cases
|
|
408
|
+
- Explain workarounds
|
|
409
|
+
|
|
410
|
+
**❌ Bad Comments:**
|
|
411
|
+
```typescript
|
|
412
|
+
// Increment counter by 1
|
|
413
|
+
counter++
|
|
414
|
+
|
|
415
|
+
// Check if user is admin
|
|
416
|
+
if (user.role === 'ADMIN') { /* ... */ }
|
|
417
|
+
```
|
|
418
|
+
|
|
419
|
+
**✅ Good Comments:**
|
|
420
|
+
```typescript
|
|
421
|
+
// Use exponential backoff to avoid overwhelming the API during rate limiting
|
|
422
|
+
// Speechace API allows max 16 TPS, so we use delay = 2^attempt * 100ms
|
|
423
|
+
await retryWithBackoff(() => callSpeechaceAPI(), { maxRetries: 3 })
|
|
424
|
+
|
|
425
|
+
// WORKAROUND: Next.js 15 requires 'use client' for localStorage access
|
|
426
|
+
// See: https://github.com/vercel/next.js/issues/12345
|
|
427
|
+
'use client'
|
|
428
|
+
export function useLocalStorage() { /* ... */ }
|
|
429
|
+
```
|
|
430
|
+
|
|
431
|
+
---
|
|
432
|
+
|
|
433
|
+
### JSDoc / Docstrings
|
|
434
|
+
|
|
435
|
+
**TypeScript:**
|
|
436
|
+
```typescript
|
|
437
|
+
/**
|
|
438
|
+
* Calculates IELTS band score from Speechace percentage score.
|
|
439
|
+
*
|
|
440
|
+
* Speechace scores range from 0-100, IELTS ranges from 0-9.
|
|
441
|
+
* Conversion uses linear mapping with rounding to nearest 0.5.
|
|
442
|
+
*
|
|
443
|
+
* @param speechaceScore - Score from Speechace API (0-100)
|
|
444
|
+
* @returns IELTS band score (0-9, rounded to nearest 0.5)
|
|
445
|
+
* @throws {ValidationError} If speechaceScore is outside 0-100 range
|
|
446
|
+
*
|
|
447
|
+
* @example
|
|
448
|
+
* calculateBandScore(85) // Returns 7.5
|
|
449
|
+
* calculateBandScore(60) // Returns 5.5
|
|
450
|
+
*/
|
|
451
|
+
export function calculateBandScore(speechaceScore: number): number {
|
|
452
|
+
// Implementation
|
|
453
|
+
}
|
|
454
|
+
```
|
|
455
|
+
|
|
456
|
+
**Python:**
|
|
457
|
+
```python
|
|
458
|
+
def calculate_band_score(speechace_score: float) -> float:
|
|
459
|
+
"""
|
|
460
|
+
Calculates IELTS band score from Speechace percentage score.
|
|
461
|
+
|
|
462
|
+
Speechace scores range from 0-100, IELTS ranges from 0-9.
|
|
463
|
+
Conversion uses linear mapping with rounding to nearest 0.5.
|
|
464
|
+
|
|
465
|
+
Args:
|
|
466
|
+
speechace_score: Score from Speechace API (0-100)
|
|
467
|
+
|
|
468
|
+
Returns:
|
|
469
|
+
IELTS band score (0-9, rounded to nearest 0.5)
|
|
470
|
+
|
|
471
|
+
Raises:
|
|
472
|
+
ValidationError: If speechace_score is outside 0-100 range
|
|
473
|
+
|
|
474
|
+
Examples:
|
|
475
|
+
>>> calculate_band_score(85)
|
|
476
|
+
7.5
|
|
477
|
+
>>> calculate_band_score(60)
|
|
478
|
+
5.5
|
|
479
|
+
"""
|
|
480
|
+
# Implementation
|
|
481
|
+
```
|
|
482
|
+
|
|
483
|
+
---
|
|
484
|
+
|
|
485
|
+
## Quick Reference
|
|
486
|
+
|
|
487
|
+
### TypeScript
|
|
488
|
+
|
|
489
|
+
| Element | Convention |
|
|
490
|
+
|---------|-----------|
|
|
491
|
+
| Files | `kebab-case.tsx` |
|
|
492
|
+
| Components | `PascalCase` |
|
|
493
|
+
| Functions | `camelCase` |
|
|
494
|
+
| Constants | `UPPER_SNAKE_CASE` |
|
|
495
|
+
| Types | `PascalCase` |
|
|
496
|
+
|
|
497
|
+
### Python
|
|
498
|
+
|
|
499
|
+
| Element | Convention |
|
|
500
|
+
|---------|-----------|
|
|
501
|
+
| Files | `snake_case.py` |
|
|
502
|
+
| Classes | `PascalCase` |
|
|
503
|
+
| Functions | `snake_case` |
|
|
504
|
+
| Constants | `UPPER_SNAKE_CASE` |
|
|
505
|
+
|
|
506
|
+
### Database
|
|
507
|
+
|
|
508
|
+
| ORM | Model | Table | Column |
|
|
509
|
+
|-----|-------|-------|--------|
|
|
510
|
+
| Prisma | `PascalCase` | `snake_case` | `camelCase` |
|
|
511
|
+
| SQLAlchemy | `PascalCase` | `snake_case` | `snake_case` |
|
|
512
|
+
|
|
513
|
+
---
|
|
514
|
+
|
|
515
|
+
**💡 Remember:** Consistency is more important than perfection!
|