Code Style¶
Atlas ERP enforces a strict but pragmatic code style to ensure consistency across a large codebase.
Tooling¶
- ESLint: Catches potential errors and anti-patterns.
- Prettier: Handles all code formatting (spacing, quotes, line lengths).
Both are configured in the packages/config directory and shared across apps/api and apps/web.
TypeScript Conventions¶
- Strict Mode: TypeScript
strictmode is enabled. Do not useanyunless absolutely necessary (useunknownif you must bypass type checking temporarily). - Interfaces over Types: Prefer
interfaceovertypefor defining object shapes, as interfaces are slightly more performant for the TypeScript compiler to merge. - PascalCase for Types: All classes, interfaces, types, and enums must use
PascalCase. - camelCase for Variables: All variables, functions, and instances must use
camelCase. - UPPER_SNAKE_CASE for Constants: Global, hardcoded constants must use
UPPER_SNAKE_CASE.
Backend (NestJS) Conventions¶
- Dependency Injection: Never use
new ClassName(). Always inject dependencies via the constructor. - DTOs: Every
POST,PUT, andPATCHroute MUST have a dedicated DTO class usingclass-validator. - Fat Services, Skinny Controllers: Controllers should only extract the request payload, call a service, and return the result. All business logic belongs in the service.
- Early Returns: Prefer early
returnorthrowstatements over deeply nestedif/elseblocks.
Frontend (React) Conventions¶
- Functional Components: Always use functional components with Hooks. Do not use Class components.
- Destructuring: Destructure props in the function signature.
- Tailwind Class Sorting: Use the Prettier Tailwind plugin to automatically sort classes consistently.
- Colocation: Keep component-specific hooks, styles, or sub-components in the same folder as the main component.