This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
dev (all pull requests must target the dev branch)Pre-commit Checklist - Before committing, always run:
bun run build # Production build
bun run lint # Biome check
bun run lint:fix # Biome auto-fix
bun run typecheck # TypeScript check (uses tsgo)
bun run test # Run Vitest tests
# Development
bun install # Install dependencies
bun run dev # Start dev server (port 13500)
# Build & Production
bun run build # Build for production (copies VERSION to standalone)
bun run start # Start production server
# Quality Checks
bun run typecheck # Type check with tsgo (faster)
bun run typecheck:tsc # Type check with tsc
bun run lint # Lint with Biome
bun run lint:fix # Auto-fix lint issues
bun run format # Format code
# Testing
bun run test # Run unit tests (vitest)
bun run test:ui # Interactive test UI
bun run test:coverage # Coverage report
bunx vitest run <file> # Run single test file
bunx vitest run -t "test name" # Run specific test
# Dev environment (via dev/Makefile)
cd dev && make dev # Start all services (PG + Redis + app)
cd dev && make db # Start only database services
IMPORTANT: Never create SQL migration files manually. Always follow this workflow:
src/drizzle/schema.tsbun run db:generatedrizzle/ directoryApply migration - Run bun run db:migrate or let AUTO_MIGRATE=true handle it on startup
bun run db:generate # Generate Drizzle migrations from schema changes
bun run db:migrate # Apply migrations
bun run db:push # Push schema changes (dev only)
bun run db:studio # Open Drizzle Studio
src/
├── app/
│ ├── [locale]/dashboard/ # Dashboard UI pages
│ ├── api/ # Internal API routes
│ └── v1/ # Proxy API (Claude/OpenAI compatible)
│ └── _lib/
│ ├── proxy/ # Core proxy pipeline
│ ├── converters/ # Format converters (claude/openai/codex/gemini)
│ └── codex/ # Codex CLI adapter
├── actions/ # Server Actions (exposed via /api/actions)
├── lib/ # Core business logic
│ ├── session-manager.ts # Session & context caching
│ ├── circuit-breaker.ts # Provider health management
│ ├── rate-limit/ # Multi-dimensional rate limiting
│ └── redis/ # Redis utilities
├── repository/ # Drizzle ORM data access layer
└── drizzle/
└── schema.ts # Database schema definition
The proxy pipeline (src/app/v1/_lib/proxy-handler.ts) processes requests through a guard chain:
Request -> GuardPipeline -> [auth -> sensitive -> client -> model -> version -> probe ->
session -> warmup -> requestFilter -> rateLimit ->
provider -> providerRequestFilter -> messageContext] ->
ProxyForwarder -> ProxyResponseHandler -> Response
Key components:
guard-pipeline.ts): Configurable chain of request guardssession.ts): Request context holderforwarder.ts): Handles upstream API callsprovider-selector.ts): Load balancing with weight/priorityconverters/): Bidirectional format translation/v1/messages, /v1/chat/completions, /v1/responses/api/actions/{module}/{action} - Auto-generated OpenAPI docs/api/actions/scalar (Scalar UI), /api/actions/docs (Swagger)@/ maps to ./src/next-intl for internationalization (5 languages: zh-CN, zh-TW, en, ja, ru)tests/unit/, integration in tests/integration/, source-adjacent tests in src/**/*.test.tsCritical variables (see .env.example for full list):
ADMIN_TOKEN: Admin login token (required)DSN: PostgreSQL connection stringREDIS_URL: Redis connection URLENABLE_RATE_LIMIT: Toggle rate limitingSESSION_TTL: Session cache TTL (default 300s)AUTO_MIGRATE: Auto-run migrations on startup