Coding Standards¶
The engineering guardrails for dichit-backend. The authoritative source is AGENTS.md at the repo root — treat this page as the developer-facing summary.
Non-negotiable¶
- Never use
any. - No business logic in controllers.
- No direct Prisma calls in controllers.
- No new libraries unless explicitly requested.
- No refactoring unrelated files.
TypeScript¶
- Strict mode enabled.
- Explicit return types on functions/methods.
- Prefer interfaces over types for contracts.
- Use
readonlywhere appropriate. - Avoid optional chaining when it hides a null bug.
- Reuse DTO/entity shapes before creating new ones.
- Keep exported surfaces intentional — avoid barrel churn.
Fastify¶
- Schema validation on every route (see validation.md).
- Thin controllers: validate → delegate → format.
- Correct HTTP status codes; never leak internal error messages.
- Follow the versioned route structure under
src/interfaces/http/routes.
Prisma & data¶
- All DB access through services/repositories (
unitOfWorkfor transactions). - Prefer one efficient query over many; raw SQL only in repositories (see database/optimization.md).
- Always paginate list endpoints with deterministic ordering.
Error handling¶
- Typed custom errors from
src/shared/errors. - Map domain → HTTP centrally; never expose stack traces.
- Reuse existing error shapes before inventing new ones.
Logging¶
- Structured logging, never sensitive data, always correlation/request ids (see infrastructure/logging.md).
Formatting & linting¶
lint-staged + husky run prettier/eslint on staged files at commit time.
Verifying changes¶
Follow the full verification order from AGENTS.md: