Structuring a NestJS Backend So AI Coding Agents Follow Your Conventions
AI coding agents write competent NestJS code but tend to ignore project-specific conventions, such as placing queries in controllers or returning raw entities. The author argues the solution is a repository that states its rules explicitly, makes correct changes easy to verify, and enforces critical rules mechanically rather than relying on better prompts. A single AGENTS.md file, which most major agents read, holds the project's rules, with CLAUDE.md importing it for Claude Code and Gemini CLI configurable to use it. The guidance includes explicit stop rules, such as not generating migrations or running seeds without user approval and leaving formatting to pre-commit hooks, along with a defined folder structure and a strict controller-service-repository dependency flow. Additional safeguards cover response mapping, user-owned data access, server-owned fields, and a single standardized error-handling approach.
This is an AI-generated summary. ShortSingh links to the original source for the complete article.


Discussion (0)
Log in to join the discussion and vote.
Log in