Skip to main content
Contafy follows strict coding conventions to ensure consistency, maintainability, and code quality across the entire codebase.

TypeScript conventions

Strict mode

Contafy uses TypeScript strict mode (enabled in tsconfig.json:7):
This means:
  • No implicit any types
  • Strict null checks
  • Strict function types
  • Strict property initialization

No any type

Never use any. Instead:

Interfaces over types

Prefer interfaces for object shapes:
Use type for:
  • Unions: type Status = 'pending' | 'active' | 'completed'
  • Intersections: type Combined = User & Profile
  • Primitives: type ID = string
  • Mapped types: type Readonly<T> = { readonly [P in keyof T]: T[P] }

Type exports

Export types separately from values:
Import types with type keyword:

Naming conventions

Files and folders

  • Component files: PascalCase - DashboardHeader.tsx
  • Utility files: camelCase - pdf-export.ts
  • Type files: camelCase - invoices.ts
  • Folders: kebab-case - dashboard/, api-client/
  • Special Next.js files: lowercase - page.tsx, layout.tsx, error.tsx

Variables and functions

  • Variables: camelCase - const userName = 'John'
  • Constants: UPPER_SNAKE_CASE - const MAX_RETRIES = 3
  • Functions: camelCase - function getUserData() {}
  • Boolean variables: Use auxiliary verbs
    • isLoading, hasError, canEdit, shouldRefetch
    • Never: loading, error, edit, refetch

Components

  • Components: PascalCase - function DashboardHeader() {}
  • Component files: Match component name - DashboardHeader.tsx
  • Props interfaces: ComponentNameProps

Types and interfaces

  • Interfaces: PascalCase - interface Invoice {}
  • Type aliases: PascalCase - type Status = 'pending' | 'active'
  • Generics: Single uppercase letter or PascalCase - T, TData, TError

Component patterns

Server Components (default)

Components are Server Components by default (no 'use client'):
Use Server Components for:
  • Pages
  • Layouts
  • Data fetching
  • Static content
  • SEO-critical content

Client Components (‘use client’)

Only add 'use client' when necessary:
Use Client Components for:
  • Event handlers (onClick, onChange)
  • React hooks (useState, useEffect, useQuery)
  • Browser APIs (localStorage, window)
  • Interactive UI

Component composition

Follow the Container/Presentational pattern:

Props destructuring

Always destructure props in function signature:

Default props

Use default parameters:

File organization

Import order

Group imports in this order:
  1. React and Next.js
  2. External packages
  3. Internal components
  4. Internal utilities
  5. Types
  6. Styles (if any)

Export patterns

Prefer named exports:
Pages must use default export (Next.js requirement):

Functional programming

No classes

Use functions instead of classes:

Pure functions

Prefer pure functions (no side effects):

Immutability

Avoid mutating data:

React patterns

Hooks

Follow React hooks rules:
  1. Only call hooks at the top level
  2. Only call hooks from React functions
  3. Use ESLint plugin to enforce rules

Custom hooks

Extract reusable logic into custom hooks:

Error boundaries

Use error.tsx files for route-level error handling:

Styling conventions

Tailwind CSS

Use Tailwind utility classes:

Class merging

Use cn() utility for conditional classes:

Responsive design

Mobile-first approach:

Comments and documentation

When to comment

Comment why, not what:

JSDoc for public APIs

Document public functions with JSDoc:

TODO comments

Use TODO for future improvements:

Error handling

Try-catch for async operations

Type-safe error handling

Performance best practices

Avoid unnecessary re-renders

Use React.memo for expensive components:

Use useCallback and useMemo

Dynamic imports for heavy components

Testing conventions

While Contafy doesn’t currently have comprehensive tests, follow these patterns when adding tests:

Git conventions

Commit messages

Follow conventional commits:

Branch naming

See Deployment for production deployment guidelines.