What is the best Cursor workflow for NestJS backend development?
I’m looking for practical approaches for architecture, DTOs, services, repositories, tests, and maintaining consistency across a large codebase.
Hey, good request. For NestJS in a large codebase, the foundation of consistency is properly set up Project Rules .cursor/rules. Here are a few practical approaches:
Rules by architecture layers
- Create separate rule files by area controllers, services, DTOs, repositories, tests with globs so a rule is only loaded when the agent works in matching files. This keeps context focused and prevents the prompt from getting too big in a large project.
- Inside each rule, lock in conventions like module structure, DI pattern, where validation lives class-validator in DTOs, naming, error handling. The more specific examples you include in the rule, the more reliably the agent follows them across sessions.
Consistency across sessions
- A common pain in large projects is the agent forgetting architecture agreements after a restart. There is a detailed community discussion about this How to prevent Cursor Composer from ignoring architectural rules across session restarts (Full .cursorrules setup). It breaks down how to structure
.cursor/rulesso rules load reliably. - Another community framework with a ready-made structure New Advanced Cursor Rule Framwork - Autonomous Coding
Workflow for features
- For new features or unfamiliar parts of the codebase, use Plan mode. The agent first drafts a plan which modules, DTOs, services it will touch, you review it, then it implements. In large projects, this noticeably reduces drift from the architecture.
- For test generation, keep a separate rule with an example of your test pattern Jest plus describe/it structure, mocks, fixtures. The agent will copy the style.
Context
- Reference specific files and folders using @ instead of relying on the agent to find the right module on its own. In a large NestJS project, targeted context works better than guesswork.
Rules reference Rules | Cursor Docs
A similar breakdown of adapting Cursor in a team Java, but the ideas transfer Boosting Team Code Generation Adoption & Cursor UX: Our Enterprise Java Journey
If you tell me where consistency drifts DTO generation, services, or tests, I can give more targeted tips.