This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
ModelHub is a unified AI gateway that proxies requests to multiple AI providers (OpenAI, Anthropic, Google, Groq, Mistral, Cohere, HuggingFace, OpenRouter, etc.) through a single OpenAI-compatible API. It includes a web chat interface, credential management, and usage dashboard. The project is written in Portuguese (Brazilian).
pnpm install # Install dependencies (auto-runs prisma:generate via postinstall)
pnpm dev # Start dev server at localhost:3000
pnpm build # Production build
pnpm lint # ESLint
pnpm typecheck # TypeScript type checking (tsc --noEmit)
pnpm test # Run all tests with Vitest
pnpm test -- path/to/file.test.ts # Run a single test file
pnpm prisma:generate # Regenerate Prisma client
pnpm prisma:migrate # Run database migrations (dev)
pnpm prisma:push # Push schema changes without migration (dev)All Prisma commands require --config prisma.config.ts which the npm scripts already include.
The app runs as a Next.js 16 App Router application, but the API layer is a Hono app (server/app.ts) mounted via a Next.js route handler (server/route-handler.ts). The Hono app handles all /v1/*, provider-specific, and proxy routes. Next.js handles pages, auth middleware, and the frontend.
Each AI provider lives in server/providers/<name>.ts and exports a fetch handler + static model list (+ optional dynamic fetchModels). All providers are registered in server/providers/registry.ts as a providerRegistry record. Many providers use server/lib/openai-compatible.ts for OpenAI-compatible API translation. Models are cached via server/lib/model-cache.ts.
Authentication uses Neon Auth (@neondatabase/auth). Auth logic is in lib/auth/server.ts (server) and lib/auth/client.ts (client). Middleware in proxy.ts protects authenticated routes (/account/*, /chat, /dashboard, /setup).
PostgreSQL via Neon (serverless), accessed through Prisma 7 with the @prisma/adapter-neon adapter (PrismaNeonHttp in server/lib/db.ts). Schema at prisma/schema.prisma, generated client output to generated/prisma/. Key models: User, ApiKey, ProviderCredential, Conversation, Message, ConversationAttachment, UsageLog, UserMemory, UserSettings.
app/(app)/- authenticated pages (chat, dashboard, setup)components/- React components organized by feature (chat/, dashboard/, landing/, setup/, ui/)- UI built with shadcn/ui (config in
components.json), Radix UI, Tailwind CSS v4, Recharts - Markdown rendering with react-markdown, rehype-highlight, remark-gfm, KaTeX math support
- Attachment processing: images, PDFs (pdfjs-dist), documents (jsdom) in
lib/chat-attachments.ts
server/lib/security.ts handles CORS, access protection, rate limiting, and security headers. Provider credentials are encrypted via server/lib/crypto.ts using the ENCRYPTION_KEY env var. The server/env.ts module validates all environment variables at startup (strict in Vercel preview/production).
@/* maps to the project root (configured in tsconfig.json and vitest.config.ts).
Copy .env.example to .env. Required variables: DATABASE_URL, DIRECT_URL, NEON_AUTH_BASE_URL, NEON_AUTH_COOKIE_SECRET, ENCRYPTION_KEY (64 hex chars). Provider API keys are optional and enable shared-credential mode for that provider.
GitHub Actions runs lint, typecheck, test, and build in parallel on push/PR to main and develop branches. Build step requires dummy env vars (see .github/workflows/ci.yml).
- Conventional Commits:
feat(scope):,fix(scope):,docs(scope):, etc. - File naming: kebab-case for files, PascalCase for components, camelCase for functions
- 2-space indentation, single quotes, semicolons (Prettier configured in
.prettierrc) - Prefer Server Components; use
"use client"only when needed - Tests colocated with source files (e.g.,
lib/chat-stream.test.ts)
This version has breaking changes — APIs, conventions, and file structure may all differ from your training data. Read the relevant guide in node_modules/next/dist/docs/ (resolved from this file's directory; in monorepos the next package may not be visible from the repo root) before writing any code. Heed deprecation notices.
This block is written and re-added by next dev — verify at node_modules/next/dist/server/lib/generate-agent-files.js. Removing it from a diff only re-creates the uncommitted change; committing it with your work keeps the tree clean.