Skip to content

majiayu000/spellbook / skills/typescript-project

typescript-project

Flagged

Modern TypeScript project architecture guide for 2025. Use when creating new TS projects, setting up configurations, or designing project structure. Covers tech stack selection, layered architecture, and best practices.

templates/project/src/lib/config.ts

View on GitHub
/**
 * Application configuration
 *
 * All configuration is loaded from environment variables.
 * Default values are provided for development.
 */

function getEnv(key: string, defaultValue?: string): string {
  const value = process.env[key] ?? defaultValue;
  if (value === undefined) {
    throw new Error(`Missing required environment variable: ${key}`);
  }
  return value;
}

function getEnvNumber(key: string, defaultValue: number): number {
  const value = process.env[key];
  if (value === undefined) return defaultValue;
  const num = Number(value);
  if (Number.isNaN(num)) {
    throw new Error(`Invalid number for environment variable: ${key}`);
  }
  return num;
}

export const config = {
  env: getEnv('NODE_ENV', 'development') as 'development' | 'staging' | 'production',
  port: getEnvNumber('PORT', 3000),
  logLevel: getEnv('LOG_LEVEL', 'info') as 'debug' | 'info' | 'warn' | 'error',

  // LiteLLM proxy configuration
  llm: {
    baseUrl: getEnv('LITELLM_URL', 'http://localhost:4000'),
    apiKey: getEnv('LITELLM_API_KEY', 'sk-1234'),
    defaultModel: getEnv('LLM_MODEL', 'gpt-4o'),
  },

  // Database (uncomment when needed)
  // db: {
  //   url: getEnv('DATABASE_URL'),
  //   poolSize: getEnvNumber('DB_POOL_SIZE', 10),
  // },

  // Redis (uncomment when needed)
  // redis: {
  //   url: getEnv('REDIS_URL', 'redis://localhost:6379'),
  // },

  isDev: getEnv('NODE_ENV', 'development') === 'development',
  isProd: getEnv('NODE_ENV', 'development') === 'production',
} as const;

export type Config = typeof config;
brainstormingobra/superpowersYou MUST use this before any creative work - creating features, building components, adding functionality, modifying behavior, or planning anything new, in software or out of it (a talk, a business, a renovation).Stars: 322kUpdated Claude CodeCodexVerifiedInstall
brand-guidelinesanthropics/skillsApplies Anthropic's official brand colors and typography to any sort of artifact that may benefit from having Anthropic's look-and-feel. Use it when brand colors or style guidelines, visual formatting, or company design standards apply.Stars: 198kUpdated Claude CodeCodexVerifiedInstall
frontend-designanthropics/skillsGuidance for distinctive, intentional visual design when building new UI or reshaping an existing one. Helps with aesthetic direction, typography, and making choices that don't read as templated defaults.Stars: 198kUpdated Claude CodeCodexVerifiedInstall
mcp-builderanthropics/skillsGuide for creating high-quality MCP (Model Context Protocol) servers that enable LLMs to interact with external services through well-designed tools. Use when building MCP servers to integrate external APIs or services, whether in Python (FastMCP) or Node/TypeScript (MCP SDK).Stars: 198kUpdated Claude CodeCodexVerifiedInstall