Skip to content

A modern, production-ready AI chat application starter template built with Next.js 15, TypeScript, and comprehensive testing. Perfect for building AI-powered chat interfaces with multiple provider support.

License

wilsonwangdev/ai-chat-starter

Repository files navigation

πŸ€– AI Chat Starter Template

A modern, production-ready AI chat application starter template built with Next.js 15, TypeScript, and comprehensive testing. Perfect for building AI-powered chat interfaces with multiple provider support.

AI Chat Starter TypeScript Testing

✨ Features

πŸš€ Modern Tech Stack

  • Next.js 15 with App Router
  • TypeScript 5.7 with strict configuration
  • Tailwind CSS with shadcn/ui components
  • ESM-only modules throughout
  • Monorepo structure with Turborepo

πŸ§ͺ Comprehensive Testing

  • Vitest for lightning-fast tests
  • React Testing Library for component testing
  • MSW for API mocking
  • 23 tests with 100% pass rate
  • Type-safe testing throughout

🎨 UI/UX Excellence

  • Responsive design for all devices
  • Dark/light mode support
  • Accessible components with Radix UI
  • Modern chat interface with message bubbles
  • Loading states and error handling

πŸ”§ Developer Experience

  • Hot reload development
  • ESLint 9 with flat config
  • Prettier code formatting
  • Husky git hooks
  • Lint-staged for pre-commit checks
  • Turbo for optimized builds

🌐 AI Provider Ready

  • Multiple AI providers (OpenAI, Anthropic, etc.)
  • Configurable models per provider
  • Mock responses for development
  • Fallback API routes for reliability

πŸš€ Quick Start

Prerequisites

  • Node.js 18+
  • pnpm 8.12+ (recommended) or npm/yarn

Installation

# Clone the template
git clone <your-repo-url> my-ai-chat-app
cd my-ai-chat-app

# Install dependencies
pnpm install

# Start development server
pnpm dev

Visit http://localhost:3000 to see your chat app!

Environment Setup

# Copy environment template
cp apps/web/.env.example apps/web/.env.local

# Add your AI provider API keys
OPENAI_API_KEY=your_openai_key_here
ANTHROPIC_API_KEY=your_anthropic_key_here

πŸ“ Project Structure

ai-chat-starter/
β”œβ”€β”€ apps/
β”‚   └── web/                 # Next.js chat application
β”‚       β”œβ”€β”€ src/
β”‚       β”‚   β”œβ”€β”€ app/         # App Router pages & API routes
β”‚       β”‚   β”œβ”€β”€ components/  # App-specific components
β”‚       β”‚   └── mocks/       # MSW mock handlers
β”‚       └── public/          # Static assets
β”œβ”€β”€ packages/
β”‚   β”œβ”€β”€ ui/                  # Shared UI components
β”‚   β”‚   β”œβ”€β”€ src/components/  # Reusable components
β”‚   β”‚   └── src/lib/         # Utilities
β”‚   β”œβ”€β”€ types/               # Shared TypeScript types
β”‚   └── config/              # Shared configurations
β”œβ”€β”€ docs/                    # Documentation
└── .kiro/                   # Kiro AI assistant config

πŸ› οΈ Available Scripts

Development

pnpm dev              # Start development servers
pnpm build            # Build all packages
pnpm test             # Run all tests
pnpm test:watch       # Run tests in watch mode
pnpm lint             # Lint all packages
pnpm lint:fix         # Fix linting issues
pnpm format           # Format code with Prettier
pnpm type-check       # Type check all packages
pnpm clean            # Clean build artifacts

Package-specific

# Work with specific packages
pnpm --filter @ai-chat/web dev
pnpm --filter @ai-chat/ui test:watch
pnpm --filter @ai-chat/types build

πŸ§ͺ Testing

The template includes comprehensive testing setup:

# Run all tests
pnpm test

# Run tests in watch mode
pnpm test:watch

# Run tests for specific package
pnpm --filter @ai-chat/ui test

Test Coverage

  • UI Components: 14 tests covering all interactive elements
  • Type Definitions: 6 tests ensuring type safety
  • Application: 3 tests for main functionality
  • Total: 23 tests with 100% pass rate

🎨 UI Components

Available Components

  • ChatContainer: Main chat interface
  • MessageBubble: Individual message display
  • Button: Accessible button component
  • Avatar: User/AI avatar display

Adding New Components

# Create new component in UI package
cd packages/ui/src/components
# Add your component with tests
# Export from packages/ui/src/index.ts

πŸ”Œ AI Provider Integration

Supported Providers

  • OpenAI (GPT-4, GPT-3.5)
  • Anthropic (Claude 3)
  • Custom providers (easily extensible)

Adding New Providers

  1. Update apps/web/src/mocks/handlers.ts for development
  2. Create API route in apps/web/src/app/api/
  3. Add provider configuration
  4. Update UI selector

πŸš€ Deployment

Vercel (Recommended)

# Install Vercel CLI
npm i -g vercel

# Deploy
vercel --prod

Docker

# Build Docker image
docker build -t ai-chat-app .

# Run container
docker run -p 3000:3000 ai-chat-app

Environment Variables

Required for production:

  • OPENAI_API_KEY
  • ANTHROPIC_API_KEY
  • NEXT_PUBLIC_APP_URL

πŸ“š Documentation

🀝 Contributing

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

Development Guidelines

  • Follow TypeScript strict mode
  • Write tests for new features
  • Use conventional commits
  • Ensure all tests pass
  • Format code with Prettier

πŸ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.

πŸ™ Acknowledgments

πŸ†˜ Support


Happy coding! πŸš€

About

A modern, production-ready AI chat application starter template built with Next.js 15, TypeScript, and comprehensive testing. Perfect for building AI-powered chat interfaces with multiple provider support.

Resources

License

Contributing

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published