summaryrefslogtreecommitdiff
path: root/.cursor/rules/separation-of-concerns.mdc
blob: 0dd97118c2b32946aa145e0ee2b2b9bad57b9331 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
---
alwaysApply: true
---

# Separation of Concerns

## Core Principle

Each file should have one single purpose/responsibility. Related functionality should be grouped together, unrelated functionality should be separated.

## Good Separation

- One file per major concern (auth, validation, data transformation)
- Group related utilities together
- Extract shared logic into dedicated files
- Keep API routes focused on their specific endpoint logic

Examples:

```javascript
// ✅ Good: Each file has clear responsibility
/lib/rate-limit.ts          // Rate limiting utilities
/lib/validation.ts          // Input validation schemas
/lib/freesound-api.ts       // External API integration
/api/sounds/search/route.ts // Route handler only
```

## Bad Mixing of Concerns

Avoid cramming multiple responsibilities into one file:

```javascript
// ❌ Bad: Route file doing everything
/api/sounds/search/route.ts
- Rate limiting logic
- Validation schemas
- API transformation
- External API calls
- Response formatting
- Error handling utilities
```

## When to Separate

- File is getting long (>500 lines)
- Multiple distinct responsibilities in one file
- Logic could be reused elsewhere
- Complex utilities that distract from main purpose

## Rule

One file, one responsibility. Extract shared concerns into focused utility files