A ChatGPT-like frontend application built with Next.js, TypeScript, TailwindCSS, and NextAuth.
- π Authentication with NextAuth (Google OAuth)
- π¬ ChatGPT-like interface with sidebar and chat area
- π Markdown support for messages
- π¨ Responsive design with TailwindCSS
- π Built with Next.js App Router
- π§ TypeScript for type safety
- π Backend API Integration Ready
This frontend is designed to work with a custom inferencing backend. The Next.js application acts as a proxy between the browser and your backend API.
Important: Backend API authentication credentials must be configured using environment variables. See docs/backend-authentication.md for detailed setup instructions.
-
Set Environment Variables:
BACKEND_URL=https://your-backend-api.com BACKEND_API_USERNAME=your-api-username BACKEND_API_PASSWORD=your-api-password
-
Implement Required Endpoints: Your backend must provide these endpoints with Basic authentication:
POST /chat/inference- Chat inference with streamingGET /conversations- List conversationsPUT /conversations/{id}/pin- Pin/unpin conversationDELETE /conversations/{id}- Delete conversationGET /conversations/{id}/chats- Get chat history
-
Authentication:
- All requests include
Authorization: Basic <base64>header - JWT is obtained from NextAuth session
- Backend should validate JWT as per your authentication system
- All requests include
-
Streaming Response:
- Chat inference uses streaming with prefixed messages
- Format:
convid:[id]followed byc:[base64(chunk)]for each text chunk
See docs/api-draft.md for complete API specifications, request/response schemas, and integration examples.
-
Clone and setup:
git clone <repository-url> cd chatgpt-frontend make setup
-
Start both services:
make dev
-
Open in browser:
- Frontend: http://localhost:3000
- Mock Backend: http://localhost:8000
-
Install dependencies:
# Install frontend dependencies bun install # Install mock server dependencies cd mock-server && bun install && cd ..
-
Environment Configuration:
Copy the example environment file:
cp .env.example .env.local
The
.env.localfile should include:# Frontend Configuration NEXTAUTH_URL=http://localhost:3000 NEXTAUTH_SECRET=development-secret-key MOCK_AUTH=false # Backend Integration BACKEND_URL=http://localhost:8000 # Backend API Authentication BACKEND_API_USERNAME=apiuser BACKEND_API_PASSWORD=securepass123 # Optional: Google OAuth (for real authentication) # GOOGLE_CLIENT_ID=your-google-client-id # GOOGLE_CLIENT_SECRET=your-google-client-secret
-
Start services:
Option A: Start both services together
make dev # Or bun run dev:fullOption B: Start services separately
# Terminal 1: Start mock backend bun run dev:backend # Or: make dev-backend # Terminal 2: Start frontend bun run dev:frontend # Or: make dev-frontend
# Full development setup (backend + frontend)
make dev
bun run dev:full
# Individual services
make dev-backend # Start only mock backend
make dev-frontend # Start only frontend
bun run dev:backend
bun run dev:frontend
# Utility commands
make status # Check running services
make stop # Stop all services
make clean # Clean up generated files
make install # Install all dependencies
# Database operations
make db-reset # Reset database
make db-backup # Backup database
make db-restore # Restore databaseWhen MOCK_AUTH=true is set in development:
- The app bypasses real authentication
- Uses a mock user with the following details:
- Name: John Doe
- Email: [email protected]
- Profile Image: Random avatar
- No Google OAuth setup required
- Perfect for UI development and testing
src/
βββ app/
β βββ auth/signin/ # Authentication pages
β βββ chat/ # Chat interface
β βββ api/auth/ # NextAuth API routes
β βββ globals.css # Global styles
βββ components/
β βββ Sidebar.tsx # Left sidebar component
β βββ Providers.tsx # Session provider wrapper
βββ lib/
β βββ mock-session.ts # Mock session utilities
βββ auth.ts # NextAuth configuration
bun run dev- Start development serverbun run build- Build for productionbun run start- Start production serverbun run lint- Run ESLint
This frontend integrates with a custom backend API through the following architecture:
Browser Client β Next.js API Routes β Custom Backend
- Browser makes requests to Next.js API routes (e.g.,
/api/conversations) - Next.js API Routes extract JWT from NextAuth session
- Next.js API Routes forward requests to backend with JWT in Authorization header
- Backend processes requests and returns responses
- Next.js API Routes return responses to the browser
All API requests are automatically authenticated:
- JWT tokens are extracted from NextAuth sessions
- Tokens are forwarded to backend in
Authorization: Bearer <token>header - No manual token management required in frontend code
Your backend must implement these endpoints:
POST /chat/inference- Chat inference with streamingGET /conversations- List conversationsPUT /conversations/:id/pin- Toggle conversation pinDELETE /conversations/:id- Delete conversationGET /conversations/:id/chats- Get chat history
All API requests include JWT authentication:
Authorization: Bearer <jwt_token>A complete mock backend is included in the mock-server/ directory:
# Start mock backend
make dev-backend
# Or
bun run dev:backendThe mock server provides:
- β Rich markdown responses
- β Streaming chat responses
- β Persistent JSON storage
- β Complete CRUD operations
- β CORS support
# =============================================================================
# API CONFIGURATION
# =============================================================================
# Backend URL for server-side API calls
BACKEND_URL=http://localhost:8000
# Backend API Authentication
# Basic auth credentials for backend API access
BACKEND_API_USERNAME=apiuser
BACKEND_API_PASSWORD=securepass123
# =============================================================================
# AUTHENTICATION CONFIGURATION
# =============================================================================
# NextAuth Configuration
NEXTAUTH_URL=http://localhost:3000
NEXTAUTH_SECRET=your-secret-key-here- Next.js 15 - React framework with App Router
- TypeScript - Type safety
- TailwindCSS - Utility-first CSS framework
- NextAuth - Authentication library
- React Markdown - Markdown rendering
- Bun - Package manager and runtime
- Axios - HTTP client for API calls
- Set a secure
NEXTAUTH_SECRET - Set your backend endpoint and credential
BACKEND_URL,BACKEND_API_USERNAME,BACKEND_API_PASSWORD - Deploy to your preferred platform (Vercel, Netlify, etc.)
- Fork the repository
- Create your feature branch
- Commit your changes
- Push to the branch
- Create a Pull Request