Skip to content

Coding Standards

Detailed coding standards are in the .rules/ directory.

Quick Reference

TypeScript

  • Strict mode enabled
  • No any types
  • Explicit return types on exported functions
// Good
export function calculateTotal(items: Item[]): number {
  return items.reduce((sum, item) => sum + item.price, 0);
}

// Bad - implicit return type, uses any
export function calculateTotal(items: any) {
  return items.reduce((sum, item) => sum + item.price, 0);
}

Naming Conventions

Type Convention Example
Functions camelCase getUserById
Variables camelCase totalPrice
Types/Interfaces PascalCase UserProfile
Constants SCREAMING_SNAKE MAX_RETRIES
Files kebab-case user-profile.ts

React Components

  • Server Components by default
  • 'use client' only when needed
  • Feature folders in src/features/
// Server Component (default)
export default function UserProfile({ userId }: { userId: string }) {
  // Can use async/await directly
  const user = await getUser(userId);
  return <div>{user.name}</div>;
}

// Client Component (when needed)
'use client';
export function Counter() {
  const [count, setCount] = useState(0);
  return <button onClick={() => setCount(c => c + 1)}>{count}</button>;
}

API Routes

Use Result types, not thrown errors:

type ApiResult<T> =
  | { success: true; data: T }
  | { success: false; error: string; code?: string };

Example:

export async function GET(req: NextRequest): Promise<Response> {
  const session = await getServerSession(authOptions);

  if (!session) {
    return Response.json(
      { success: false, error: 'Unauthorized', code: 'AUTH_REQUIRED' },
      { status: 401 }
    );
  }

  const data = await fetchData();
  return Response.json({ success: true, data });
}

Error Codes

const ERROR_CODES = {
  AUTH_REQUIRED: 'Authentication required',
  AUTH_EXPIRED: 'Session expired',
  FORBIDDEN: 'Not authorized for this action',
  VALIDATION_ERROR: 'Invalid input data',
  NOT_FOUND: 'Resource not found',
} as const;

Full Standards

Standard File
TypeScript .rules/typescript.md
React .rules/react.md
API Routes .rules/api.md
Security .rules/security.md
Performance .rules/performance.md
Git .rules/git.md
Testing .rules/testing.md
AI/LLM .rules/ai-llm.md