{"owner":"miurla","repo":"morphic","hasSkills":true,"hasMcp":false,"mcpConfig":null,"found":["AGENTS.md"],"files":{"AGENTS.md":"# CLAUDE.md\n\nThis file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.\n\n## Key Commands\n\n### Development\n\n- `bun dev` - Start development server with Turbopack (http://localhost:3000)\n- `bun run build` - Create production build\n- `bun start` - Start production server\n- `bun lint` - Run ESLint for code quality checks and import sorting\n- `bun typecheck` - Run TypeScript type checking\n- `bun format` - Format code with Prettier\n- `bun format:check` - Check code formatting without modifying files\n- `bun migrate` - Run database migrations\n- `bun run test` - Run tests with Vitest (use this, NOT `bun test`)\n- `bun run test:watch` - Run tests in watch mode\n\n### Docker\n\n- `docker compose up -d` - Run the application with Docker (includes PostgreSQL 17, Redis, Morphic app, and SearXNG)\n- `docker compose down` - Stop all containers\n- `docker compose down -v` - Stop all containers and remove volumes (deletes database data)\n- `docker pull ghcr.io/miurla/morphic:latest` - Pull prebuilt Docker image\n\n#### Docker Authentication\n\n**Default Behavior**: Docker deployments run in **anonymous mode** (authentication disabled).\n\nWhen 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.\n\n**⚠️ Security Warning:**\n\n- Anonymous mode is **only for personal, single-user local environments**\n- All chat history is shared under one user ID\n- **NOT suitable** for multi-user or production deployments\n- Morphic Cloud deployments block `ENABLE_AUTH=false` automatically\n\n**Enabling Authentication:**\nTo require Supabase authentication, set:\n\n```bash\nENABLE_AUTH=true  # or remove ENABLE_AUTH from docker-compose.yaml\nNEXT_PUBLIC_SUPABASE_URL=[your-supabase-url]\nNEXT_PUBLIC_SUPABASE_PUBLISHABLE_KEY=[your-supabase-publishable-key]\nSUPABASE_SECRET_KEY=[your-supabase-secret-key]\n```\n\n**Implementation:**\n\n- Auth logic: [lib/auth/get-current-user.ts:22-40](lib/auth/get-current-user.ts#L22-L40)\n- Always warns when `ENABLE_AUTH=false` (except in tests)\n- Guards against `MORPHIC_CLOUD_DEPLOYMENT=true`\n\n## Architecture Overview\n\n### Tech Stack\n\n- **Next.js 16.2.1** with App Router, React Server Components, and Turbopack\n- **React 19.2.0** with TypeScript for type safety\n- **Vercel AI SDK 5.0.0-alpha.2** for AI streaming and GenerativeUI\n- **Supabase** for authentication and backend services\n- **PostgreSQL** with Drizzle ORM for database and chat history storage\n- **Redis** (Upstash or local) for SearXNG advanced search caching\n- **Tailwind CSS** with shadcn/ui components\n\n### Core Architecture\n\n1. **App Router Structure** (`/app`)\n   - `/api/` - Backend API routes for chat, search, and auth endpoints\n   - `/auth/` - Authentication pages (login, signup, password reset)\n   - `/search/` - Search functionality and results display\n   - `/share/` - Sharing functionality for search results\n\n2. **AI Integration** (`/lib`)\n   - `/lib/agents/` - AI agents for research and question generation\n   - `/lib/config/` - Model configuration management\n   - `/lib/streaming/` - Stream handling for AI responses\n   - `/lib/tools/` - Search and retrieval tool implementations\n   - Models configured in `public/config/models.json`\n\n3. **Database** (`/lib/db`)\n   - PostgreSQL database with Drizzle ORM\n   - Schema defined in `/lib/db/schema.ts`\n   - Migrations in `/lib/db/migrations/`\n   - Database actions in `/lib/actions/chat-db.ts`\n\n4. **Search System**\n   - Multiple providers: Tavily (default), SearXNG (self-hosted), Exa (neural), Brave (optional)\n   - Brave Search is optional; if API key is not provided, type=\"general\" searches fall back to primary provider\n   - Video/image search support depends on configured providers (Brave provides best multimedia support)\n   - URL-specific search capabilities\n   - Configurable search depth and result limits\n\n5. **Component Organization** (`/components`)\n   - `/artifact/` - Search result and AI response display components\n   - `/sidebar/` - Chat history and navigation\n   - `/ui/` - Reusable UI components from shadcn/ui\n   - Feature-specific components (auth forms, chat interfaces)\n\n6. **State Management**\n   - Server-side state via React Server Components\n   - Client-side hooks in `/hooks/`\n   - Redis for persistent chat history\n   - Supabase for user data\n\n## Environment Configuration\n\n### Required Variables\n\n```bash\nOPENAI_API_KEY=      # Default AI provider\nTAVILY_API_KEY=      # Default search provider\nDATABASE_URL=        # PostgreSQL connection string\n```\n\n### Optional Features\n\n- Chat history: Set `ENABLE_SAVE_CHAT_HISTORY=true` and configure Redis\n- Alternative AI providers: Add corresponding API keys (ANTHROPIC_API_KEY, GOOGLE_GENERATIVE_AI_API_KEY, etc.)\n- Alternative search: Configure SEARCH_API and provider-specific settings\n- Sharing: Set `NEXT_PUBLIC_ENABLE_SHARE=true`\n\n## Key Development Patterns\n\n1. **AI Streaming**: Uses Vercel AI SDK's streaming capabilities for real-time responses\n2. **GenerativeUI**: Dynamic UI components generated based on AI responses\n3. **Type Safety**: Strict TypeScript configuration with comprehensive type definitions in `/lib/types/`\n4. **Schema Validation**: Zod schemas in `/lib/schema/` for data validation\n5. **Error Handling**: Comprehensive error boundaries and fallback UI components\n\n## Testing Approach\n\n- Unit and integration tests with Vitest\n- Test files located alongside source files with `.test.ts` or `.test.tsx` extension\n- **Run `bun run test` to execute all tests** (NOT `bun test` - that uses Bun's built-in test runner which lacks Vitest features)\n- Run `bun run test:watch` for development with watch mode\n- CI automatically runs `bun run test` to ensure all tests pass\n\n## Pre-PR Requirements\n\nBefore creating a pull request, you MUST ensure all of the following checks pass:\n\n1. **Linting**: Run `bun lint` and fix all ESLint errors and warnings (includes import sorting)\n2. **Type checking**: Run `bun typecheck` to ensure no TypeScript errors\n3. **Formatting**: Run `bun format:check` to verify code formatting (or `bun format` to auto-fix)\n4. **Build**: Run `bun run build` to ensure the application builds successfully\n5. **Tests**: Run `bun run test` to ensure all tests pass\n\nThese checks are enforced in CI/CD and PRs will fail if any of these steps don't pass.\n\nNote: 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.\n\n## Model Configuration\n\nModels are defined in `public/config/models.json` with:\n\n- `id`: Model identifier\n- `provider`: Display name\n- `providerId`: Provider key for API routing\n- `enabled`: Toggle availability\n- `toolCallType`: \"native\" or \"manual\" for function calling\n- `toolCallModel`: Optional override for tool calls\n\n## Database Management\n\n- Run `bun migrate` to apply database migrations\n- Migrations are located in `/drizzle/` directory\n- Schema changes should be made in `/lib/db/schema.ts`\n- Use Drizzle Kit for generating migrations\n\n## MCP (Model Context Protocol) Integration\n\nThis project supports MCP for enhanced AI assistant integration with Next.js 16.\n\n### Built-in Next.js MCP Server\n\nNext.js 16 provides a built-in MCP server at `http://localhost:3000/_next/mcp` when the dev server is running.\n\n**Available Tools:**\n\n- `get_project_metadata` - Get project path and dev server URL\n- `get_errors` - Retrieve current error state (global errors, runtime errors, build errors)\n- `get_page_metadata` - Get runtime metadata about current page renders\n- `get_logs` - Access Next.js development log file path\n- `get_server_action_by_id` - Locate Server Actions by ID\n\n**Usage:**\n\n1. Start the dev server: `bun dev`\n2. MCP endpoint is automatically available at `/_next/mcp`\n3. AI assistants can query real-time app state, errors, and logs\n\n### Next DevTools MCP (External)\n\nThe project includes `.mcp.json` configuration for the Next DevTools MCP package, which provides:\n\n- Next.js knowledge base access\n- Automated migration tools\n- Cache optimization guides\n- Browser testing capabilities\n\n**Setup:**\nThe `.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.\n\n**Benefits:**\n\n- Real-time access to application internal state\n- Improved debugging and error diagnostics\n- Context-aware code suggestions\n- Live application state querying\n"}}