agentleFS
girijashankarjgirijashankarj/cursor-handbook/.cursor/rules/backend/code-organization.mdc

cursor-handbook / backend

Cursor rule30 starsChanged 3 months agoMITView on GitHub

Backend code organization and structure rules. Apply when organizing backend source.

The file

We split this code-organization.mdc into the rules it gives an agent

5 rules. About 0 are common, 3 are distinctive, and 2 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈3

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 2

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Very specific:

    NEVER: use DELETE FROM statements

    line 80
  2. Very specific:

    All tables MUST have: {{CONFIG.database.timestampFields.created}}, {{CONFIG.database.timestampFields.updated}}, …

    line 81
  3. Distinctive:

    Use parameterized queries — NEVER concatenate SQL strings

    line 82
  4. Distinctive:

    Use migrations for all schema changes

    line 84
  5. Distinctive:

    Always specify return types explicitly

    line 92

≈ “Common” is an estimate: at least 1 in 5 of the 7,324 Cursor rule files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
code-organization.mdc
---
description: "Backend code organization and structure rules. Apply when organizing backend source."
alwaysApply: false
globs: "**/api/**/*,**/services/**/*,**/models/**/*,**/handlers/**/*"
---

# Code Organization Rules

## Project Structure
```
{{CONFIG.paths.source}}/
├── {{CONFIG.paths.apiPath}}/
│   ├── {{CONFIG.folderNames.common}}/     # Shared API utilities
│   │   ├── errors/                         # Error classes
│   │   ├── middleware/                      # Shared middleware
│   │   ├── {{CONFIG.folderNames.types}}/   # Shared type definitions
│   │   ├── validators/                     # Shared validators
│   │   └── logger.ts                       # Logging utility
│   └── handlers/
│       └── v1/                             # Versioned handlers
│           ├── {entity}/
│           │   ├── create/
│           │   ├── read/
│           │   ├── update/
│           │   └── list/
├── {{CONFIG.paths.eventsPath}}/            # Event handlers
├── {{CONFIG.folderNames.services}}/        # Business services
├── {{CONFIG.folderNames.models}}/          # Data models
└── config/                                 # Configuration
```

## Naming Conventions

### Files
| Type | Pattern | Example |
|------|---------|---------|
| Handler | `kebab-case` | `create-order.ts` |
| Service | `kebab-case.service` | `order.service.ts` |
| Model | `kebab-case.model` | `order.model.ts` |
| Type | `kebab-case.types` | `order.types.ts` |
| Test | `kebab-case.test` | `order.service.test.ts` |
| Constants | `kebab-case.constants` | `order.constants.ts` |
| Utility | `kebab-case.util` | `date.util.ts` |
| Middleware | `kebab-case.middleware` | `auth.middleware.ts` |

### Code
| Type | Convention | Example |
|------|-----------|---------|
| Variables | camelCase | `orderTotal` |
| Functions | camelCase | `calculateTotal()` |
| Classes | PascalCase | `OrderService` |
| Interfaces | PascalCase with I prefix (optional) | `OrderInput` or `IOrderInput` |
| Constants | UPPER_SNAKE_CASE | `MAX_RETRY_COUNT` |
| Enums | PascalCase | `OrderStatus` |
| Database columns | snake_case | `created_at` |

## Import Rules
1. External packages first (alphabetical)
2. Internal packages (`{{CONFIG.packages.internalPrefix}}/...`) second
3. Relative imports last (parent → sibling → child)
4. Blank line between each group
5. No circular dependencies

```{{CONFIG.techStack.language}}
// 1. External packages
import express from 'express';
import { z } from 'zod';

// 2. Internal packages
import { logger } from '{{CONFIG.packages.internalPrefix}}/logger';

// 3. Relative imports
import { OrderService } from '../services/order.service';
import { OrderInput } from './types/order.types';
import { validateOrder } from './validators/order.validator';
```

## Database Rules
- **Soft delete ONLY** — use `UPDATE {{CONFIG.database.softDeleteField}} = false`
- **NEVER** use `DELETE FROM` statements
- All tables MUST have: `{{CONFIG.database.timestampFields.created}}`, `{{CONFIG.database.timestampFields.updated}}`, `{{CONFIG.database.softDeleteField}}`
- Use parameterized queries — NEVER concatenate SQL strings
- Database column naming: `{{CONFIG.database.naming}}`
- Use migrations for all schema changes
- Index frequently queried columns

## Function Guidelines
- Maximum function length: 30 lines (prefer < 20)
- Maximum parameters: 3 (use an options object for more)
- Single responsibility — one function, one purpose
- Pure functions preferred — side effects at boundaries only
- Always specify return types explicitly

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.