actions.ts
: Server actions for login/registrationauth.ts
: NextAuth configuration and credentials providerauth.config.ts
: Authentication configuration settings
page.tsx
: Main chat interface with message historychat/[id]/page.tsx
: Individual chat session pagesapi/chat/route.ts
: Chat API endpoint handling
schema.ts
: Database schema definitions using Drizzle ORMqueries.ts
: Database operations (users, messages, chats)migrate.ts
: Database migration utilities
chat.tsx
: Main chat component with message handlingchat-header.tsx
: Chat interface header with controlsmessages.tsx
: Message display and renderingmultimodal-input.tsx
: Chat input with file upload support
model-selector.tsx
: AI model selection interfacevisibility-selector.tsx
: Chat visibility controlssidebar.tsx
: Navigation sidebarui/
: Reusable UI components (buttons, inputs, etc.)
AUTH_SECRET=your_auth_secret
POSTGRES_URL=your_postgres_connection_string
BLOB_READ_WRITE_TOKEN=your_blob_token
XAI_API_KEY=your_xai_api_key
- Uses Neon PostgreSQL for data storage
- Drizzle ORM for database operations
- Schema includes tables for:
- Users
- Chats
- Messages
- Documents
- Suggestions
- Votes
-
Registration (
app/(auth)/actions.ts
):- Validates email/password
- Checks for existing users
- Creates new user with hashed password
- Automatically signs in after registration
-
Login:
- Uses NextAuth with credentials provider
- Verifies password against hashed DB value
- Creates authenticated session
- User sends message through
MultimodalInput
- Message processed by chat API route
- AI response generated using xAI SDK
- Response streamed back to client
- Messages saved to database
- Uses Vercel Blob for file storage
- Supports file uploads in chat
- Processes attachments with AI model
# Database Operations
pnpm run db:generate # Generate migrations
pnpm run db:migrate # Run migrations
pnpm run db:studio # Open Drizzle Studio
# Development
pnpm run dev # Start development server
pnpm run build # Build for production
pnpm run lint # Run linting
/chat/route.ts
: Main chat endpoint/files/upload/route.ts
: File upload handling/vote/route.ts
: Message voting system
- Update
lib/ai/models.ts
- Implement model interface in
lib/ai/providers
- Add to model selector component
- Uses Tailwind CSS for styling
- shadcn/ui components for UI elements
- Dark/light mode support
-
Environment Variables:
- Keep sensitive keys in
.env
- Never commit secrets to repository
- Keep sensitive keys in
-
Authentication:
- Password hashing with bcrypt
- Secure session handling
- CSRF protection
-
Database:
- Use parameterized queries
- Validate user permissions
- Regular backups recommended
-
Database Connection:
- Verify POSTGRES_URL in .env
- Check database migrations
- Run
db:migrate
if needed
-
Authentication:
- Ensure AUTH_SECRET is set
- Check user table exists
- Verify password hashing
-
Chat Functionality:
- Validate XAI_API_KEY
- Check WebSocket connection
- Monitor server logs