This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
bun dev- Start development server with Turbopack (http://localhost:3000)bun run build- Create production buildbun start- Start production serverbun lint- Run ESLint for code quality checks and import sortingbun typecheck- Run TypeScript type checkingbun format- Format code with Prettierbun format:check- Check code formatting without modifying filesbun migrate- Run database migrationsbun run test- Run tests with Vitest (use this, NOTbun test)bun run test:watch- Run tests in watch mode
docker compose up -d- Run the application with Docker (includes PostgreSQL 17, Redis, Morphic app, and SearXNG)docker compose down- Stop all containersdocker compose down -v- Stop all containers and remove volumes (deletes database data)docker pull ghcr.io/miurla/morphic:latest- Pull prebuilt Docker image
Default Behavior: Docker deployments run in anonymous mode (authentication disabled).
When running with Docker Compose, ENABLE_AUTH=false is set by default, allowing personal use without Supabase setup. All users share a single anonymous user ID.
- Anonymous mode is only for personal, single-user local environments
- All chat history is shared under one user ID
- NOT suitable for multi-user or production deployments
- Morphic Cloud deployments block
ENABLE_AUTH=falseautomatically
Enabling Authentication: To require Supabase authentication, set:
ENABLE_AUTH=true # or remove ENABLE_AUTH from docker-compose.yaml
NEXT_PUBLIC_SUPABASE_URL=[your-supabase-url]
NEXT_PUBLIC_SUPABASE_PUBLISHABLE_KEY=[your-supabase-publishable-key]
SUPABASE_SECRET_KEY=[your-supabase-secret-key]Implementation:
- Auth logic: lib/auth/get-current-user.ts:22-40
- Always warns when
ENABLE_AUTH=false(except in tests) - Guards against
MORPHIC_CLOUD_DEPLOYMENT=true
- Next.js 16.2.1 with App Router, React Server Components, and Turbopack
- React 19.2.0 with TypeScript for type safety
- Vercel AI SDK 5.0.0-alpha.2 for AI streaming and GenerativeUI
- Supabase for authentication and backend services
- PostgreSQL with Drizzle ORM for database and chat history storage
- Redis (Upstash or local) for SearXNG advanced search caching
- Tailwind CSS with shadcn/ui components
-
App Router Structure (
/app)/api/- Backend API routes for chat, search, and auth endpoints/auth/- Authentication pages (login, signup, password reset)/search/- Search functionality and results display/share/- Sharing functionality for search results
-
AI Integration (
/lib)/lib/agents/- AI agents for research and question generation/lib/config/- Model configuration management/lib/streaming/- Stream handling for AI responses/lib/tools/- Search and retrieval tool implementations- Models configured in
public/config/models.json
-
Database (
/lib/db)- PostgreSQL database with Drizzle ORM
- Schema defined in
/lib/db/schema.ts - Migrations in
/lib/db/migrations/ - Database actions in
/lib/actions/chat-db.ts
-
Search System
- Multiple providers: Tavily (default), SearXNG (self-hosted), Exa (neural), Brave (optional)
- Brave Search is optional; if API key is not provided, type="general" searches fall back to primary provider
- Video/image search support depends on configured providers (Brave provides best multimedia support)
- URL-specific search capabilities
- Configurable search depth and result limits
-
Component Organization (
/components)/artifact/- Search result and AI response display components/sidebar/- Chat history and navigation/ui/- Reusable UI components from shadcn/ui- Feature-specific components (auth forms, chat interfaces)
-
State Management
- Server-side state via React Server Components
- Client-side hooks in
/hooks/ - Redis for persistent chat history
- Supabase for user data
OPENAI_API_KEY= # Default AI provider
TAVILY_API_KEY= # Default search provider
DATABASE_URL= # PostgreSQL connection string- Chat history: Set
ENABLE_SAVE_CHAT_HISTORY=trueand configure Redis - Alternative AI providers: Add corresponding API keys (ANTHROPIC_API_KEY, GOOGLE_GENERATIVE_AI_API_KEY, etc.)
- Alternative search: Configure SEARCH_API and provider-specific settings
- Sharing: Set
NEXT_PUBLIC_ENABLE_SHARE=true
- AI Streaming: Uses Vercel AI SDK's streaming capabilities for real-time responses
- GenerativeUI: Dynamic UI components generated based on AI responses
- Type Safety: Strict TypeScript configuration with comprehensive type definitions in
/lib/types/ - Schema Validation: Zod schemas in
/lib/schema/for data validation - Error Handling: Comprehensive error boundaries and fallback UI components
- Unit and integration tests with Vitest
- Test files located alongside source files with
.test.tsor.test.tsxextension - Run
bun run testto execute all tests (NOTbun test- that uses Bun's built-in test runner which lacks Vitest features) - Run
bun run test:watchfor development with watch mode - CI automatically runs
bun run testto ensure all tests pass
Before creating a pull request, you MUST ensure all of the following checks pass:
- Linting: Run
bun lintand fix all ESLint errors and warnings (includes import sorting) - Type checking: Run
bun typecheckto ensure no TypeScript errors - Formatting: Run
bun format:checkto verify code formatting (orbun formatto auto-fix) - Build: Run
bun run buildto ensure the application builds successfully - Tests: Run
bun run testto ensure all tests pass
These checks are enforced in CI/CD and PRs will fail if any of these steps don't pass.
Note: Import sorting is handled by ESLint using eslint-plugin-simple-import-sort. Run bun lint --fix to automatically sort imports according to the configured order.
Models are defined in public/config/models.json with:
id: Model identifierprovider: Display nameproviderId: Provider key for API routingenabled: Toggle availabilitytoolCallType: "native" or "manual" for function callingtoolCallModel: Optional override for tool calls
- Run
bun migrateto apply database migrations - Migrations are located in
/drizzle/directory - Schema changes should be made in
/lib/db/schema.ts - Use Drizzle Kit for generating migrations
This project supports MCP for enhanced AI assistant integration with Next.js 16.
Next.js 16 provides a built-in MCP server at http://localhost:3000/_next/mcp when the dev server is running.
Available Tools:
get_project_metadata- Get project path and dev server URLget_errors- Retrieve current error state (global errors, runtime errors, build errors)get_page_metadata- Get runtime metadata about current page rendersget_logs- Access Next.js development log file pathget_server_action_by_id- Locate Server Actions by ID
Usage:
- Start the dev server:
bun dev - MCP endpoint is automatically available at
/_next/mcp - AI assistants can query real-time app state, errors, and logs
The project includes .mcp.json configuration for the Next DevTools MCP package, which provides:
- Next.js knowledge base access
- Automated migration tools
- Cache optimization guides
- Browser testing capabilities
Setup:
The .mcp.json file in the project root enables team-wide MCP tool sharing. AI assistants like Claude Code will prompt for approval before using project-scoped servers.
Benefits:
- Real-time access to application internal state
- Improved debugging and error diagnostics
- Context-aware code suggestions
- Live application state querying