Skip to content

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

  1. Never use any.
  2. No business logic in controllers.
  3. No direct Prisma calls in controllers.
  4. No new libraries unless explicitly requested.
  5. No refactoring unrelated files.

TypeScript

  • Strict mode enabled.
  • Explicit return types on functions/methods.
  • Prefer interfaces over types for contracts.
  • Use readonly where 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 (unitOfWork for 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

Formatting & linting

pnpm check            # typecheck + lint
pnpm format:check     # prettier check
pnpm knip             # dead code

lint-staged + husky run prettier/eslint on staged files at commit time.

Verifying changes

Follow the full verification order from AGENTS.md:

pnpm docker:test:up -> pnpm check -> pnpm build:ci -> pnpm test -> pnpm docker:test:down