TypeScript conventions
Strict mode
Contafy uses TypeScript strict mode (enabled intsconfig.json:7):
- No implicit
anytypes - Strict null checks
- Strict function types
- Strict property initialization
No any type
Never use any. Instead:
Interfaces over types
Prefer interfaces for object shapes: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: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'):
- Pages
- Layouts
- Data fetching
- Static content
- SEO-critical content
Client Components (‘use client’)
Only add'use client' when necessary:
- 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:- React and Next.js
- External packages
- Internal components
- Internal utilities
- Types
- Styles (if any)
Export patterns
Prefer named exports: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:- Only call hooks at the top level
- Only call hooks from React functions
- 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
Usecn() utility for conditional classes: