Skip to main content
The NCT Hub platform uses Next.js App Router API routes with consistent patterns for versioning, authentication, error handling, and workspace isolation. The API is designed to support both club management operations and external integrations.

Route Organization

Directory Structure

Versioned Public API

Pattern: /api/v1/*

Use for public-facing APIs that external clients consume.

Workspace-Scoped API

Pattern: /api/[wsId]/*

Use for workspace-specific operations with automatic workspace context.

AI Endpoints

Pattern: /api/ai/*

Use for AI-specific operations with model selection and token tracking.

Authentication Endpoints

Pattern: /api/auth/*

Use edge runtime for auth endpoints.

Error Response Standards

Standard Error Format

HTTP Status Codes

  • 200 - Success
  • 201 - Created
  • 204 - No Content
  • 400 - Bad Request (validation errors)
  • 401 - Unauthorized (not authenticated)
  • 403 - Forbidden (not authorized)
  • 404 - Not Found
  • 409 - Conflict
  • 422 - Unprocessable Entity
  • 429 - Too Many Requests
  • 500 - Internal Server Error

Error Handling Pattern

Middleware Pattern

Permission Middleware

Usage

CORS Configuration

Rate Limiting

Best Practices

✅ DO

  1. Always validate input
  2. Check authentication first
  3. Verify workspace permissions
  4. Use edge runtime for auth
  5. Set max duration for long operations

❌ DON’T

  1. Don’t expose sensitive errors
  2. Don’t skip workspace isolation
  3. Don’t use user client for mutations