@avisek_yorkie/cursor-rules 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.
@@ -0,0 +1,411 @@
1
+ # Documentation Standards - JavaScript/TypeScript
2
+
3
+ Good documentation is as important as good code. These standards apply to JS/TS projects.
4
+
5
+ ---
6
+
7
+ ## Core Documentation Principles
8
+
9
+ ### Why Document?
10
+ - **For Future You** - You'll forget why you made decisions
11
+ - **For Your Team** - Others need to understand your code
12
+ - **For New Developers** - Reduce onboarding time
13
+ - **For Users** - If you build an API or library
14
+
15
+ ### What to Document
16
+ ✅ **DO Document:**
17
+ - WHY decisions were made
18
+ - Complex algorithms and logic
19
+ - Public APIs and interfaces
20
+ - Setup and installation steps
21
+ - Architecture and design decisions
22
+ - Known limitations and gotchas
23
+ - Examples of usage
24
+
25
+ ❌ **DON'T Document:**
26
+ - Obvious code (let code self-document)
27
+ - Implementation details that might change
28
+ - What the code does (code shows this)
29
+
30
+ ### General Rules
31
+ - Write self-documenting code as the primary documentation
32
+ - Keep documentation close to the code it describes
33
+ - Update documentation when code changes
34
+ - Remove outdated or incorrect documentation
35
+
36
+ ---
37
+
38
+ ## README.md - Every Project Needs One
39
+
40
+ ### Essential Sections
41
+
42
+ ```markdown
43
+ # Project Name
44
+
45
+ Brief description of what this project does (1-2 sentences).
46
+
47
+ ## Table of Contents
48
+ - [Features](#features)
49
+ - [Installation](#installation)
50
+ - [Usage](#usage)
51
+ - [Configuration](#configuration)
52
+ - [Contributing](#contributing)
53
+ - [License](#license)
54
+
55
+ ## Features
56
+ - Feature 1
57
+ - Feature 2
58
+ - Feature 3
59
+
60
+ ## Prerequisites
61
+ - Node.js 18+
62
+ - (Add: database, API keys, etc.)
63
+
64
+ ## Installation
65
+
66
+ \`\`\`bash
67
+ git clone https://github.com/org/project.git
68
+ cd project
69
+ npm install
70
+ cp .env.example .env
71
+ # Edit .env with your configuration
72
+ npm run dev
73
+ \`\`\`
74
+
75
+ ## Usage
76
+
77
+ ### Basic Example
78
+ \`\`\`javascript
79
+ const result = doSomething();
80
+ \`\`\`
81
+
82
+ ### Advanced Example
83
+ \`\`\`javascript
84
+ const advancedResult = doSomethingComplex({
85
+ option1: 'value',
86
+ option2: 123
87
+ });
88
+ \`\`\`
89
+
90
+ ## Configuration
91
+
92
+ | Variable | Description | Default |
93
+ |----------|-------------|---------|
94
+ | API_URL | API endpoint | http://localhost:3000 |
95
+ | DB_HOST | Database host | localhost |
96
+
97
+ ## Testing
98
+
99
+ \`\`\`bash
100
+ npm test
101
+ npm run test:integration
102
+ npm run test:e2e
103
+ \`\`\`
104
+
105
+ ## Contributing
106
+
107
+ See [CONTRIBUTING.md](CONTRIBUTING.md)
108
+
109
+ ## License
110
+
111
+ MIT - See [LICENSE](LICENSE)
112
+ ```
113
+
114
+ ### README Best Practices
115
+ - ✅ Keep it concise but complete
116
+ - ✅ Include code examples (JavaScript/TypeScript)
117
+ - ✅ Update when features change
118
+ - ✅ Add badges (build status, coverage) when applicable
119
+ - ❌ Don't duplicate full API docs (link to them)
120
+ - ❌ Don't include outdated information
121
+
122
+ ### Optional but Recommended
123
+ - **Architecture Overview** - High-level system design
124
+ - **Troubleshooting** - Common issues and solutions
125
+ - **Changelog** - Link to CHANGELOG.md or version history
126
+ - **Roadmap** - Future plans and features
127
+
128
+ ---
129
+
130
+ ## Code Comments
131
+
132
+ ### When to Comment
133
+
134
+ ```javascript
135
+ // ✅ GOOD - Explains WHY and complex logic
136
+ // Use exponential backoff to avoid overwhelming the API
137
+ // during rate limit periods. Max wait time is 32 seconds.
138
+ const backoffDelay = Math.min(Math.pow(2, retryCount) * 1000, 32000);
139
+
140
+ // ✅ GOOD - Documents non-obvious behavior
141
+ // Note: This must run before initializeDatabase() due to
142
+ // connection pool limitations in PostgreSQL
143
+ await setupConnectionPool();
144
+
145
+ // ✅ GOOD - Explains workaround
146
+ // HACK: Force repaint to fix Safari rendering bug
147
+ // See: https://bugs.webkit.org/show_bug.cgi?id=123456
148
+ element.style.display = 'none';
149
+ element.offsetHeight; // Force reflow
150
+ element.style.display = 'block';
151
+
152
+ // ❌ BAD - States the obvious
153
+ // Set count to zero
154
+ const count = 0;
155
+
156
+ // ❌ BAD - Redundant comment
157
+ // Loop through users
158
+ for (const user of users) {
159
+ // ...
160
+ }
161
+ ```
162
+
163
+ ### TODO Comments
164
+
165
+ ```javascript
166
+ // ✅ GOOD - TODO with context
167
+ // TODO(PROJ-123): Refactor this to use new caching system
168
+ // Current implementation has O(n²) complexity
169
+ function slowSearch(items, query) {
170
+ // ...
171
+ }
172
+
173
+ // ❌ BAD - TODO without context
174
+ // TODO: Fix this
175
+ function doSomething() {
176
+ // ...
177
+ }
178
+ ```
179
+
180
+ ### Comment Formatting
181
+ - **Single-line:** `// Comment text`
182
+ - **Multi-line:** Use `/* ... */` or multiple `//` lines; for JSDoc use `/** ... */`
183
+
184
+ ### Inline Comment Guidelines
185
+ - Explain "why", not "what"
186
+ - Document non-obvious code behavior
187
+ - Include references to issues or external docs (e.g. MDN, GitHub issues)
188
+ - Use TODO comments sparingly and always with context/ticket
189
+
190
+ ---
191
+
192
+ ## Function/Method Documentation (JSDoc)
193
+
194
+ ### Document Public APIs
195
+ Document every public and exported function. Use JSDoc for JavaScript; TypeScript can use JSDoc or TSDoc.
196
+
197
+ ```javascript
198
+ /**
199
+ * Calculate the total price including tax and discounts.
200
+ *
201
+ * @param {number} basePrice - The base price before tax
202
+ * @param {number} taxRate - Tax rate as decimal (e.g., 0.08 for 8%)
203
+ * @param {Object} options - Additional options
204
+ * @param {number} options.discount - Discount percentage (0-100)
205
+ * @param {string} options.currency - Currency code (default: 'USD')
206
+ * @returns {number} Total price after tax and discount
207
+ * @throws {Error} If basePrice is negative
208
+ *
209
+ * @example
210
+ * // Calculate price with 8% tax and 10% discount
211
+ * const total = calculateTotal(100, 0.08, { discount: 10 });
212
+ * // Returns: 97.2
213
+ */
214
+ function calculateTotal(basePrice, taxRate, options = {}) {
215
+ if (basePrice < 0) {
216
+ throw new Error('Base price cannot be negative');
217
+ }
218
+
219
+ const { discount = 0, currency = 'USD' } = options;
220
+ const discountedPrice = basePrice * (1 - discount / 100);
221
+ return discountedPrice * (1 + taxRate);
222
+ }
223
+ ```
224
+
225
+ ### With TypeScript Types
226
+
227
+ ```typescript
228
+ /**
229
+ * Fetches a user by ID from the API.
230
+ *
231
+ * @param userId - Unique user identifier
232
+ * @returns The user object or null if not found
233
+ * @throws {ApiError} When the API request fails
234
+ *
235
+ * @example
236
+ * const user = await getUserById('usr_123');
237
+ */
238
+ async function getUserById(userId: string): Promise<User | null> {
239
+ // implementation
240
+ }
241
+ ```
242
+
243
+ ### Documentation Elements to Include
244
+ - ✅ Brief description of what the function does
245
+ - ✅ Parameters with types and descriptions
246
+ - ✅ Return value and type
247
+ - ✅ Exceptions/errors it might throw
248
+ - ✅ Usage examples for non-trivial functions
249
+ - ❌ Implementation details
250
+ - ❌ Private helper functions (unless complex and non-obvious)
251
+
252
+ ### Class/Module Documentation
253
+ - Document the purpose and responsibility of each class/module
254
+ - Document public properties and methods with JSDoc
255
+ - Include usage examples for complex classes
256
+ - Document dependencies and requirements (e.g. peer dependencies)
257
+
258
+ ---
259
+
260
+ ## API Documentation
261
+
262
+ ### REST Endpoints
263
+ Document each endpoint with:
264
+ - HTTP method and path
265
+ - Request parameters (query, path, body)
266
+ - Request body schema (e.g. JSON)
267
+ - Response schema and status codes
268
+ - Authentication/authorization requirements
269
+ - Example requests and responses
270
+ - Error responses and status codes
271
+
272
+ ### Tools and Standards
273
+ - Use **OpenAPI (Swagger)** for REST APIs
274
+ - Keep API documentation in sync with code (generate from code or keep specs in version control)
275
+ - Include versioning (e.g. `/v1/users`) and document in README or dedicated API doc
276
+
277
+ ---
278
+
279
+ ## Architecture Documentation
280
+
281
+ ### ADR (Architecture Decision Records)
282
+ Document significant decisions in `/docs/adr/` (e.g. `001-postgres-as-primary-db.md`):
283
+
284
+ ```markdown
285
+ # ADR-001: Use PostgreSQL for Primary Database
286
+
287
+ ## Status
288
+ Accepted
289
+
290
+ ## Context
291
+ We need a reliable database for storing user data, transactions,
292
+ and analytics. Key requirements:
293
+ - ACID compliance
294
+ - Complex query support
295
+ - Horizontal scalability
296
+ - Strong community support
297
+
298
+ ## Decision
299
+ Use PostgreSQL as our primary database.
300
+
301
+ ## Consequences
302
+
303
+ ### Positive
304
+ - Strong ACID guarantees
305
+ - Excellent JSON support for flexible schemas
306
+ - Mature ecosystem and tooling
307
+ - Great performance for complex queries
308
+
309
+ ### Negative
310
+ - More complex to scale horizontally than MongoDB
311
+ - Requires schema migrations
312
+ - Steeper learning curve than simpler databases
313
+
314
+ ## Alternatives Considered
315
+ - MongoDB: Too flexible, less data integrity
316
+ - MySQL: Weaker JSON support, less feature-rich
317
+ - DynamoDB: Vendor lock-in, complex pricing
318
+ ```
319
+
320
+ ### System Architecture Diagrams
321
+ Use ASCII or link to diagrams (Mermaid, draw.io, etc.) in markdown:
322
+
323
+ ```markdown
324
+ ## System Architecture
325
+
326
+ \`\`\`
327
+ ┌─────────────┐ ┌──────────────┐ ┌──────────────┐
328
+ │ Client │─────▶│ API Gateway │─────▶│ Auth Svc │
329
+ └─────────────┘ └──────────────┘ └──────────────┘
330
+
331
+
332
+ ┌──────────────┐
333
+ │ User Svc │
334
+ └──────────────┘
335
+
336
+
337
+ ┌──────────────┐
338
+ │ PostgreSQL │
339
+ └──────────────┘
340
+ \`\`\`
341
+ ```
342
+
343
+ ### What to Document
344
+ - System architecture and design decisions
345
+ - Component interactions and data flow
346
+ - Deployment architecture
347
+ - Technology choices and trade-offs
348
+
349
+ ---
350
+
351
+ ## Change Documentation
352
+
353
+ - Document breaking changes prominently (README, CHANGELOG, release notes)
354
+ - Maintain a **CHANGELOG.md** (e.g. Keep a Changelog format)
355
+ - Use **semantic versioning** (MAJOR.MINOR.PATCH)
356
+ - Document migration guides for major changes
357
+ - Include deprecation notices with timelines and alternatives
358
+
359
+ ---
360
+
361
+ ## Code Examples in Documentation
362
+
363
+ - Include working JavaScript/TypeScript examples
364
+ - Keep examples simple and focused
365
+ - Show common use cases and optional configuration
366
+ - Include error handling where relevant
367
+ - Ensure examples run (e.g. via tests or manual verification)
368
+
369
+ ---
370
+
371
+ ## Documentation Maintenance
372
+
373
+ - Review documentation during code reviews
374
+ - Update documentation as part of the development process
375
+ - Remove outdated documentation
376
+ - Keep documentation in version control
377
+ - Use tools (e.g. TypeDoc, ESLint JSDoc rules) to check completeness
378
+
379
+ ---
380
+
381
+ ## Documentation Tools (JS/TS)
382
+
383
+ - **JSDoc** - Inline API docs for JavaScript
384
+ - **TypeDoc** - Generate docs from TypeScript
385
+ - **API docs** - OpenAPI/Swagger for REST APIs
386
+ - **Storybook** - Component documentation for UI libraries (React, Vue, etc.)
387
+
388
+ ---
389
+
390
+ ## Documentation Review Checklist
391
+
392
+ - [ ] All public APIs and exported functions are documented (JSDoc)
393
+ - [ ] README is complete and up-to-date
394
+ - [ ] Code examples are correct and use JS/TS
395
+ - [ ] Installation and prerequisites are accurate
396
+ - [ ] API documentation matches implementation
397
+ - [ ] Breaking changes and CHANGELOG are updated
398
+ - [ ] No outdated or incorrect information
399
+ - [ ] Architecture/ADR docs exist for major decisions
400
+
401
+ ---
402
+
403
+ ## Documentation Best Practices
404
+
405
+ - Write for your audience (developers, users, contributors)
406
+ - Use clear, concise language
407
+ - Include diagrams where helpful
408
+ - Keep documentation organized and navigable (e.g. Table of Contents)
409
+ - Use consistent formatting and style
410
+ - Link related documentation
411
+ - Keep documentation in the repo and up to date
@@ -0,0 +1,291 @@
1
+ # Naming Conventions
2
+
3
+ ## General Naming Principles
4
+
5
+ ### 1. Core Principles
6
+ - Use descriptive names that reveal intent
7
+ - Avoid abbreviations unless they are widely understood
8
+ - Use consistent naming patterns throughout the codebase
9
+ - Prefer longer, clearer names over short, cryptic ones
10
+ - Use names from the problem domain
11
+ - Avoid misleading names
12
+
13
+ ### 2. Variable Naming
14
+
15
+ #### General Rules:
16
+ - Use nouns or noun phrases for variables
17
+ - Be specific, not generic (avoid `data`, `info`, `temp`, `value`)
18
+ - Use singular for single items, plural for collections
19
+ - Use meaningful prefixes/suffixes when helpful
20
+
21
+ #### Good Examples:
22
+ ```javascript
23
+ const userEmail = "user@example.com";
24
+ const activeUsers = [];
25
+ const isAuthenticated = true;
26
+ const maxRetryAttempts = 3;
27
+ const customerOrderTotal = 100.50;
28
+ ```
29
+
30
+ #### Bad Examples:
31
+ ```javascript
32
+ const data = "user@example.com";
33
+ const arr = [];
34
+ const flag = true;
35
+ const num = 3;
36
+ const temp = 100.50;
37
+ ```
38
+
39
+ ### 3. Function/Method Naming
40
+
41
+ #### General Rules:
42
+ - Use verbs or verb phrases for functions
43
+ - Start with action words: `get`, `set`, `create`, `delete`, `update`, `calculate`, `validate`, `is`, `has`, `can`
44
+ - Be specific about what the function does
45
+ - Use consistent verb prefixes for similar operations
46
+
47
+ #### Good Examples:
48
+ ```javascript
49
+ function getUserById(id) { }
50
+ function calculateTotalPrice(items) { }
51
+ function isValidEmail(email) { }
52
+ function hasPermission(user, permission) { }
53
+ function createUserAccount(userData) { }
54
+ function deleteExpiredSessions() { }
55
+ ```
56
+
57
+ #### Bad Examples:
58
+ ```javascript
59
+ function process(data) { }
60
+ function doStuff() { }
61
+ function check(x) { }
62
+ function handle() { }
63
+ function run() { }
64
+ ```
65
+
66
+ ### 4. Class/Type Naming
67
+
68
+ #### General Rules:
69
+ - Use nouns or noun phrases
70
+ - Use PascalCase for class names
71
+ - Be specific and descriptive
72
+ - Avoid generic names like `Manager`, `Handler`, `Processor`
73
+
74
+ #### Good Examples:
75
+ ```javascript
76
+ class UserAccount { }
77
+ class EmailValidator { }
78
+ class PaymentProcessor { }
79
+ class DatabaseConnection { }
80
+ class OrderService { }
81
+ ```
82
+
83
+ #### Bad Examples:
84
+ ```javascript
85
+ class Manager { }
86
+ class Handler { }
87
+ class Processor { }
88
+ class Helper { }
89
+ class Utils { }
90
+ ```
91
+
92
+ ### 5. Constant Naming
93
+
94
+ #### General Rules:
95
+ - Use UPPER_SNAKE_CASE for constants
96
+ - Use descriptive names that explain the value
97
+ - Group related constants together
98
+ - Use constants for magic numbers and strings
99
+
100
+ #### Good Examples:
101
+ ```javascript
102
+ const MAX_RETRY_ATTEMPTS = 3;
103
+ const DEFAULT_TIMEOUT_MS = 5000;
104
+ const API_BASE_URL = "https://api.example.com";
105
+ const SUPPORTED_FILE_TYPES = ["jpg", "png", "gif"];
106
+ ```
107
+
108
+ #### Bad Examples:
109
+ ```javascript
110
+ const max = 3;
111
+ const timeout = 5000;
112
+ const url = "https://api.example.com";
113
+ const types = ["jpg", "png", "gif"];
114
+ ```
115
+
116
+ ### 6. Boolean Naming
117
+
118
+ #### General Rules:
119
+ - Use prefixes: `is`, `has`, `can`, `should`, `will`, `did`
120
+ - Use positive boolean names (avoid `isNot`, `hasNo`)
121
+ - Be specific about what the boolean represents
122
+
123
+ #### Good Examples:
124
+ ```javascript
125
+ const isAuthenticated = true;
126
+ const hasPermission = false;
127
+ const canEdit = true;
128
+ const shouldRetry = false;
129
+ const isEmpty = true;
130
+ const isActive = false;
131
+ ```
132
+
133
+ #### Bad Examples:
134
+ ```javascript
135
+ const authenticated = true; // unclear if it's a boolean
136
+ const permission = false;
137
+ const edit = true;
138
+ const notEmpty = false; // use positive names
139
+ const flag = true;
140
+ ```
141
+
142
+ ### 7. File and Directory Naming
143
+
144
+ #### General Rules:
145
+ - Use kebab-case for file and directory names
146
+ - Use descriptive names that indicate content
147
+ - Match file names to their primary export (if applicable)
148
+ - Use consistent naming patterns across the project
149
+
150
+ #### Good Examples:
151
+ ```
152
+ user-service.ts
153
+ email-validator.js
154
+ payment-processor.ts
155
+ user-account.component.tsx
156
+ api-client.ts
157
+ ```
158
+
159
+ #### Bad Examples:
160
+ ```
161
+ service.ts
162
+ validator.js
163
+ processor.ts
164
+ component.tsx
165
+ ```
166
+
167
+ ### 8. TypeScript/JavaScript Conventions
168
+
169
+ - **Variables/Functions**: camelCase
170
+ - **Classes/Interfaces/Types**: PascalCase
171
+ - **Constants**: UPPER_SNAKE_CASE
172
+ - **Files**: kebab-case
173
+ - **Private members**: prefix with underscore `_privateMethod()`
174
+
175
+ ```typescript
176
+ const userName = "John";
177
+ function getUserData() { }
178
+ class UserService { }
179
+ const MAX_RETRIES = 3;
180
+ interface UserAccount { }
181
+ ```
182
+
183
+ ### 9. Database Naming
184
+
185
+ #### Tables:
186
+ - Use plural nouns: `users`, `orders`, `products`
187
+ - Use snake_case: `user_accounts`, `order_items`
188
+
189
+ #### Columns:
190
+ - Use snake_case: `user_id`, `created_at`, `email_address`
191
+ - Use descriptive names: `first_name` not `fname`
192
+ - Use consistent suffixes: `_id` for foreign keys, `_at` for timestamps
193
+
194
+ #### Indexes:
195
+ - Use descriptive names: `idx_users_email`, `idx_orders_user_id`
196
+
197
+ ### 10. API Naming
198
+
199
+ #### REST Endpoints:
200
+ - Use nouns, not verbs: `/users` not `/getUsers`
201
+ - Use plural nouns: `/users` not `/user`
202
+ - Use kebab-case or camelCase consistently
203
+ - Use nested resources: `/users/123/orders`
204
+ - Use query parameters for filtering: `/users?status=active`
205
+
206
+ #### Good Examples:
207
+ ```
208
+ GET /users
209
+ GET /users/123
210
+ POST /users
211
+ PUT /users/123
212
+ DELETE /users/123
213
+ GET /users/123/orders
214
+ GET /users?status=active&limit=10
215
+ ```
216
+
217
+ #### Bad Examples:
218
+ ```
219
+ GET /getUsers
220
+ GET /user
221
+ POST /createUser
222
+ GET /userOrders/123
223
+ GET /users?Status=Active
224
+ ```
225
+
226
+ ### 11. Configuration Naming
227
+
228
+ #### Environment Variables:
229
+ - Use UPPER_SNAKE_CASE
230
+ - Use descriptive prefixes: `DB_`, `API_`, `APP_`
231
+ - Be specific about the purpose
232
+
233
+ #### Good Examples:
234
+ ```
235
+ DATABASE_URL
236
+ API_KEY
237
+ APP_ENVIRONMENT
238
+ MAX_CONNECTION_POOL_SIZE
239
+ REDIS_HOST
240
+ ```
241
+
242
+ #### Bad Examples:
243
+ ```
244
+ db_url
245
+ apiKey
246
+ env
247
+ max
248
+ redis
249
+ ```
250
+
251
+ ### 12. Test Naming
252
+
253
+ #### Test Functions:
254
+ - Use descriptive names that explain what is being tested
255
+ - Follow pattern: `test_<what>_<condition>_<expected_result>` or `should_<expected_behavior>_when_<condition>`
256
+
257
+ #### Good Examples:
258
+ ```javascript
259
+ test("should return user when valid id is provided")
260
+ test("should throw error when email is invalid")
261
+ test("should calculate total price correctly with tax")
262
+ ```
263
+
264
+ #### Bad Examples:
265
+ ```javascript
266
+ test("user test")
267
+ test("test1")
268
+ test("function works")
269
+ ```
270
+
271
+ ### 13. Naming Anti-Patterns to Avoid
272
+
273
+ - **Single letter variables**: Only acceptable in loops (`i`, `j`, `k`) or mathematical contexts
274
+ - **Abbreviations**: Avoid unless universally understood (`id`, `url`, `api`)
275
+ - **Generic names**: `data`, `info`, `temp`, `value`, `obj`, `arr`
276
+ - **Misleading names**: Names that don't match what they do
277
+ - **Hungarian notation**: Avoid type prefixes (`strName`, `intCount`)
278
+ - **Inconsistent casing**: Mixing camelCase and snake_case in the same context
279
+ - **Names that differ only by case**: `user` vs `User` in the same scope
280
+
281
+ ### 14. Naming Review Checklist
282
+ - [ ] Names are descriptive and reveal intent
283
+ - [ ] No abbreviations unless widely understood
284
+ - [ ] Consistent naming patterns throughout
285
+ - [ ] Boolean names use appropriate prefixes (`is`, `has`, `can`)
286
+ - [ ] Function names use action verbs
287
+ - [ ] Class names are nouns
288
+ - [ ] Constants are in UPPER_CASE
289
+ - [ ] File names match their content
290
+ - [ ] No misleading or confusing names
291
+ - [ ] Names follow TypeScript/JavaScript conventions