Overview
Provide comprehensive Next.js support for Chatfield with reference implementations, SDK patterns, and developer success documentation.
Primary Goal
Make Next.js developers highly successful with Chatfield through clear patterns, examples, and best practices.
Secondary Goal
Demonstrate production-ready LiteLLM proxy integration for secure API key handling.
Deliverables
1. Next.js Reference Implementation
Stack:
- Next.js 14+ (App Router + Pages Router examples)
- @chatfield/react hooks
- LiteLLM proxy for API key security
- TypeScript throughout
Features to demonstrate:
- Server Components for interview definition
- Client Components for conversation UI
- API routes for proxy communication
- Environment variable configuration
- Error boundaries and loading states
- Production deployment considerations
2. LiteLLM Proxy Integration
Setup:
- Docker Compose configuration (PostgreSQL + LiteLLM)
- Next.js API route that proxies to LiteLLM
- Secure token management
- Rate limiting and usage tracking
- Development vs production configurations
Security model:
- No API keys in browser code
- Server-side proxy handles authentication
- Audit trail in PostgreSQL
- Read-only virtual keys for development
3. Developer Success Documentation
Getting Started Guide:
# Chatfield + Next.js Quick Start
## Installation
npm install @chatfield/core @chatfield/react
## 1. Define Interview (Server Component or shared)
// app/interviews/contact.ts
export const contactInterview = chatfield()
.field('name', 'Your name')
.field('email', 'Email address')
.build()
## 2. Create Conversation UI (Client Component)
// app/components/ContactForm.tsx
'use client'
export function ContactForm() {
const [state, actions] = useChatfield(contactInterview)
// ... UI implementation
}
## 3. Configure Proxy
// .env.local
NEXT_PUBLIC_LITELLM_PROXY=http://localhost:4000
OPENAI_API_KEY=sk-...
## 4. Run Development Server
npm run dev
Advanced Topics:
- Streaming responses (future)
- Multi-step interviews across pages
- Server Actions integration
- Edge runtime compatibility
- Vercel deployment
- Self-hosted deployment
4. Example Applications
Example 1: Contact Form (Simple)
- Single page app
- Basic interview with 3-4 fields
- Shows minimal setup
Example 2: Job Application (Complex)
- Multi-page flow
- Conditional fields
- File uploads (future)
- Progress persistence
Example 3: Customer Onboarding (Production-Ready)
- Full authentication
- Database integration
- Email notifications
- Analytics tracking
5. SDK Patterns
Recommended Architecture:
next-app/
├── app/
│ ├── api/
│ │ └── chat/route.ts # Proxy endpoint
│ ├── interviews/
│ │ ├── contact.ts # Interview definitions
│ │ └── onboarding.ts
│ └── components/
│ └── ChatfieldConversation.tsx
├── lib/
│ ├── chatfield-client.ts # Client-side utilities
│ └── chatfield-server.ts # Server-side utilities
└── docker-compose.yml # LiteLLM stack
Key Patterns:
- Interview definitions as shared modules
- Client/server boundary best practices
- Proxy configuration patterns
- State management (URL params, cookies, database)
- Error handling and retry logic
Implementation Plan
Phase 1: Basic Next.js Support
Phase 2: LiteLLM Integration
Phase 3: Comprehensive Documentation
Phase 4: Advanced Examples
Phase 5: Developer Success
Success Metrics
- Next.js developer can go from zero to working Chatfield app in < 15 minutes
- Clear production deployment path
- No security footguns (API keys in client code, etc.)
- Works with latest Next.js stable version
Out of Scope
- ❌ Create React App (deprecated)
- ❌ Remix (separate issue if requested)
- ❌ Gatsby (separate issue if requested)
- ❌ Vue/Nuxt (different framework)
Dependencies
References
Overview
Provide comprehensive Next.js support for Chatfield with reference implementations, SDK patterns, and developer success documentation.
Primary Goal
Make Next.js developers highly successful with Chatfield through clear patterns, examples, and best practices.
Secondary Goal
Demonstrate production-ready LiteLLM proxy integration for secure API key handling.
Deliverables
1. Next.js Reference Implementation
Stack:
Features to demonstrate:
2. LiteLLM Proxy Integration
Setup:
Security model:
3. Developer Success Documentation
Getting Started Guide:
Advanced Topics:
4. Example Applications
Example 1: Contact Form (Simple)
Example 2: Job Application (Complex)
Example 3: Customer Onboarding (Production-Ready)
5. SDK Patterns
Recommended Architecture:
Key Patterns:
Implementation Plan
Phase 1: Basic Next.js Support
examples/nextjs-basic/with minimal appPhase 2: LiteLLM Integration
Phase 3: Comprehensive Documentation
Documentation/Next.js.mdPhase 4: Advanced Examples
Phase 5: Developer Success
Success Metrics
Out of Scope
Dependencies
References