This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
# Start development server (Ask before running - developer usually has this running)
pnpm dev
# Type checking (Recommended for validation)
pnpm type-check
# Build project (Safe to run for verification)
pnpm build
# Format code
pnpm format
pnpm format:check
# Create PR (Read .github/PULL_REQUEST_TEMPLATE.md first, push branch, then use --head, --title, --body)
gh pr create --head <branch-name> --title "fix(scope): description" --body "$(cat <<'EOF'\n<PR content>\nEOF\n)"# Quick check translation structure consistency
pnpm i18n:check
# Detailed validation of translations
pnpm i18n:validate
# Detect missing translation keys
pnpm i18n:detectAgentifUI is a Next.js 15 App Router application with the following key architectural layers:
- Framework: Next.js 15 (App Router), React 19, TypeScript
- Database: Supabase (Auth + Postgres + Storage)
- State Management: Zustand
- UI: Tailwind CSS 4, Radix UI components
- API Integration: Dify API for LLM services
- Package Manager: pnpm
app/ # Next.js routes and pages
├── api/ # API routes (Dify proxy, auth, admin)
├── admin/ # Admin dashboard pages
├── chat/ # Chat interface pages
├── apps/ # App launcher pages
└── settings/ # User settings pages
components/ # Reusable UI components
├── ui/ # Base UI components (buttons, inputs, etc.)
├── chat/ # Chat-specific components
├── admin/ # Admin-specific components
└── auth/ # Authentication components
lib/ # Core business logic
├── services/ # Service layer (API calls, data processing)
│ ├── dify/ # Dify API integration services
│ ├── db/ # Database services
│ └── admin/ # Admin services
├── stores/ # Zustand state stores
├── hooks/ # Custom React hooks
├── db/ # Database access layer
└── utils/ # Utility functions
supabase/ # Database migrations and configuration
└── migrations/ # SQL migration files
- Security-First: Uses Supabase RLS (Row Level Security) and encrypted API key storage
- Layered Architecture: Clear separation between UI, services, and data layers
- Type Safety: Full TypeScript coverage with strict typing
- Internationalization: Multi-language support with next-intl (en-US, zh-CN, es-ES, zh-TW, ja-JP, de-DE, fr-FR, ru-RU, it-IT, pt-PT)
- Real-time Updates: Supabase realtime subscriptions for live data
The Dify API integration follows a 3-layer pattern:
- Proxy Layer:
app/api/dify/[appId]/[...slug]/route.ts- Handles authentication and request forwarding - Service Layer:
lib/services/dify/*.ts- Business logic and API calls - Type Layer:
lib/services/dify/types.ts- TypeScript definitions
- Zustand stores in
lib/stores/for different domains (chat, sidebar, theme, etc.) - Custom hooks in
lib/hooks/for complex state logic - Real-time sync via Supabase subscriptions
- Access layer:
lib/db/*.ts- Direct database operations - Service layer:
lib/services/db/*.ts- Higher-level database services - Migrations:
supabase/migrations/- SQL schema and RLS policies
- Never run
pnpm devunless explicitly asked - developers usually have this running - Use
pnpm type-checkandpnpm buildfor validation - Follow the development workflow rule in
.cursor/rules/development-workflow-rule.mdc
- Always run
pnpm type-checkbefore submitting changes - Use
pnpm formatfor code formatting - Follow the existing code patterns and TypeScript conventions
Follow .cursor/rules/comment-rule.mdc:
- Language: All comments must be in English
- Purpose: Explain why, not just what
- Format: Use JSDoc for interfaces/functions, simple comments for logic
- Style: Concise and clear
Example JSDoc:
/**
* Send chat message to Dify API with streaming response
*
* @param payload - Request payload to send to Dify API
* @param appId - Dify application ID
* @returns Promise containing async generator and conversation metadata
* @throws Error if fetch request fails or API returns error status
*/- All user-facing text must be internationalized
- Add keys to
messages/en-US.jsonfirst (source language) - Maintain structure consistency across all language files
- Run
pnpm i18n:checkafter adding translations - NEVER replace existing
t()calls with hardcoded English text - NEVER use hardcoded strings like "Loading..." - always use translations
- English-first development: write in English, then translate to other languages
- Follow the 3-layer architecture pattern
- Define types in
lib/services/dify/types.ts - Implement services in appropriate
lib/services/dify/*.tsfiles - Use the proxy layer for secure API calls
- Follow conventional commit format:
type(scope): description - NEVER include Claude Code footer or co-authorship lines
- Examples:
feat(auth): add SSO login support fix(chat): resolve message ordering issue refactor(admin): optimize content management UI
- Database: Uses Supabase with comprehensive RLS policies
- Authentication: Supabase Auth with SSO support
- Styling: Tailwind CSS 4 with custom theme configuration
- File Structure: Follows Next.js 15 App Router conventions
- Error Handling: Comprehensive error boundaries and user feedback systems
- Development Rules: Follow
.cursor/rules/cursor-rules.mdcfor rule management
CRITICAL: AI agents MUST read .cursor/rules/cursor-rules.mdc first - the master rule index with dependencies and enforcement levels.
- Development Workflow: MUST analyze→evaluate→implement→validate→document
- Comment Standards: MUST use English, JSDoc format, explain "why" not "what"
- Git Commits: MUST follow
<type>(<scope>): <subject>format, English, imperative mood
- Database Changes: MUST follow 6-phase flow, sync TypeScript types
- I18n Work: MUST NOT hardcode text, maintain key structure consistency
- Dify API: MUST follow 3-layer architecture (proxy→service→type)
pnpm type-check # TypeScript validation
pnpm i18n:check # Translation validation- Read cursor-rules.mdc master index
- Apply rules in dependency order
- Run validation commands
- Update documentation when needed
Memory Anchor: These rule summaries provide persistent reference for AI agents, extracted from detailed rule files for quick compliance checking.
Uses Jest with React Testing Library. Husky handles precommit testing automatically.
Config: jest.config.js and jest.setup.js
Test files: *.test.{ts,tsx} or *.spec.{ts,tsx} in same directory, or in __tests__/ directory.
pnpm test# Essential linting
pnpm lint
pnpm fix:eslint
# Type checking
pnpm type-check- Logging Policy: Avoid
console.login production code except for debugging purposes - Type Safety: Avoid using
anytype, will be caught by lint checks
Do what has been asked; nothing more, nothing less. NEVER create files unless they're absolutely necessary for achieving your goal. ALWAYS prefer editing an existing file to creating a new one. NEVER proactively create documentation files (*.md) or README files. Only create documentation files if explicitly requested by the User.