Guidelines by Alberto Basalo for developing clean NestJS APIs using TypeScript. These rules emphasize strong typing, clean code principles, and architectural best practices.
TypeScript General Principles
- Always declare the type of each variable and function (parameters and return value)
- Avoid using any; create necessary types instead
- Use JSDoc for public classes and methods
- One export per file
Naming Conventions
- PascalCase for classes
- camelCase for variables and functions
- kebab-case for files and directories
- UPPERCASE for environment variables
- Boolean variables use prefixes: isX, hasX, canX
Function Design
- Write short functions with a single purpose. Less than 20 instructions
- Use early returns to avoid nesting
- Apply RO-RO pattern: pass objects for multiple parameters, return objects for results
Data and Classes