Skip to content

Full-Stack LLM Chat Platform with authentication, organization management, credit system, and real-time notifications

Notifications You must be signed in to change notification settings

1234-ad/llm-chat-platform

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

33 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

LLM Chat Platform

A full-stack web application that provides a ChatGPT-style interface for interacting with Large Language Models (LLMs), featuring authentication, organization management, credit-based usage, and real-time notifications.

πŸš€ Features

βœ… Authentication & Onboarding

  • Username/Password Authentication: Secure sign-up and sign-in functionality
  • Google OAuth Integration: Ready for Google Sign-In implementation
  • Automatic Organization Creation: Default organization created on first registration
  • User Role Management: Admin and member roles with appropriate permissions

βœ… Chat Interface

  • ChatGPT-style UI: Clean, responsive design matching modern chat interfaces
  • Persistent Chat History: All conversations stored and retrievable
  • Multiple Chat Sessions: Create and manage multiple conversation threads
  • Real-time Messaging: Instant message delivery and responses
  • Token Usage Tracking: Monitor API usage and costs

βœ… Credit System

  • Usage-based Billing: Credits deducted based on token consumption
  • Real-time Credit Display: Live credit counter in the top bar
  • Usage Restrictions: Prevent messaging when credits are exhausted
  • Transparent Pricing: Clear indication of credit costs per message

βœ… Organization Management

  • Multi-organization Support: Users can belong to multiple organizations
  • Active Organization Switching: Switch between organizations seamlessly
  • Member Invitation System: Invite users by email (database record creation)
  • Role-based Access Control: Admin and member permissions
  • Organization CRUD Operations: Create, rename, and manage organizations

βœ… Real-time Notifications

  • Socket.IO Integration: WebSocket-based real-time communication
  • Global & Targeted Notifications: Broadcast or user-specific messages
  • Notification Panel: Expandable notification center with history
  • Persistent Storage: All notifications stored in database
  • Read/Unread Status: Track notification states

βœ… Technical Features

  • Responsive Design: Mobile-friendly interface
  • Error Handling: Comprehensive error management and user feedback
  • Loading States: Proper loading indicators throughout the app
  • Data Validation: Input validation on both client and server
  • Security: JWT authentication, rate limiting, and input sanitization

πŸ›  Tech Stack

Frontend

  • React.js 18 - Modern React with hooks
  • Material-UI (MUI) - Professional UI components
  • Redux Toolkit - State management
  • React Router - Client-side routing
  • Socket.IO Client - Real-time communication
  • Axios - HTTP client
  • React Hot Toast - Notifications

Backend

  • Node.js - JavaScript runtime
  • Express.js - Web framework
  • Socket.IO - WebSocket server
  • PostgreSQL - Primary database
  • JWT - Authentication tokens
  • bcryptjs - Password hashing
  • OpenAI API - LLM integration

DevOps & Deployment

  • Vite - Build tool
  • Concurrently - Development scripts
  • Helmet - Security headers
  • CORS - Cross-origin resource sharing
  • Rate Limiting - API protection

πŸ“‹ Prerequisites

  • Node.js (v16 or higher)
  • PostgreSQL (v12 or higher)
  • OpenAI API key
  • Git

πŸš€ Quick Start

1. Clone the Repository

git clone https://github.com/1234-ad/llm-chat-platform.git
cd llm-chat-platform

2. Install Dependencies

# Install root dependencies
npm install

# Install all dependencies (root, server, client)
npm run install-all

3. Database Setup

# Create PostgreSQL database
createdb llm_chat_platform

# Run migrations
cd server
npm run migrate

4. Environment Configuration

Server Environment (.env)

cd server
cp .env.example .env

Edit server/.env:

# Database
DATABASE_URL=postgresql://username:password@localhost:5432/llm_chat_platform

# JWT Secret (generate a secure random string)
JWT_SECRET=your-super-secret-jwt-key-here

# OpenAI API
OPENAI_API_KEY=your-openai-api-key

# Google OAuth (optional)
GOOGLE_CLIENT_ID=your-google-client-id
GOOGLE_CLIENT_SECRET=your-google-client-secret

# Server Configuration
PORT=5000
NODE_ENV=development
SESSION_SECRET=your-session-secret-key

# Frontend URL
FRONTEND_URL=http://localhost:3000

Client Environment (optional)

cd client

Create client/.env (optional):

REACT_APP_API_URL=http://localhost:5000/api
REACT_APP_SOCKET_URL=http://localhost:5000

5. Start Development Servers

# From root directory - starts both server and client
npm run dev

# Or start individually:
# Server only
npm run server

# Client only
npm run client

6. Access the Application

πŸ“š API Documentation

Authentication Endpoints

  • POST /api/auth/register - User registration
  • POST /api/auth/login - User login
  • POST /api/auth/google - Google OAuth (placeholder)

Chat Endpoints

  • GET /api/chat/sessions - Get user's chat sessions
  • POST /api/chat/sessions - Create new chat session
  • GET /api/chat/sessions/:id/messages - Get session messages
  • POST /api/chat/sessions/:id/messages - Send message
  • DELETE /api/chat/sessions/:id - Delete session
  • PATCH /api/chat/sessions/:id - Update session title

Organization Endpoints

  • GET /api/organizations - Get user's organizations
  • POST /api/organizations - Create organization
  • PATCH /api/organizations/:id - Update organization
  • GET /api/organizations/:id/members - Get members
  • POST /api/organizations/:id/invite - Invite member
  • DELETE /api/organizations/:id/members/:memberId - Remove member
  • POST /api/organizations/:id/activate - Set active organization

Notification Endpoints

  • GET /api/notifications - Get notifications
  • PATCH /api/notifications/:id/read - Mark as read
  • PATCH /api/notifications/read-all - Mark all as read
  • DELETE /api/notifications/:id - Delete notification

πŸ— Database Schema

Core Tables

  • users - User accounts and authentication
  • organizations - Organization entities
  • organization_members - User-organization relationships
  • user_active_organization - Current active organization per user
  • chat_sessions - Chat conversation sessions
  • messages - Individual chat messages
  • notifications - System and user notifications

Key Relationships

  • Users can belong to multiple organizations
  • Each user has one active organization at a time
  • Chat sessions belong to users and organizations
  • Messages belong to chat sessions
  • Notifications can be global or user-specific

πŸš€ Deployment

Frontend Deployment (Vercel/Netlify)

cd client
npm run build

# Deploy the 'build' folder to your hosting service

Backend Deployment (Render/Railway/Heroku)

# Set environment variables on your hosting platform
# Deploy the 'server' directory

Environment Variables for Production

Ensure all environment variables are set in your production environment:

  • DATABASE_URL - Production PostgreSQL connection string
  • JWT_SECRET - Secure random string
  • OPENAI_API_KEY - Your OpenAI API key
  • NODE_ENV=production
  • FRONTEND_URL - Your frontend domain

πŸ§ͺ Testing

Manual Testing Checklist

  • User registration and login
  • Chat session creation and messaging
  • Credit deduction and display
  • Organization creation and switching
  • Member invitation (database record)
  • Real-time notifications
  • Responsive design on mobile

Test User Accounts

Create test accounts to verify multi-user functionality:

  1. Register multiple users
  2. Create organizations
  3. Invite members
  4. Test real-time features

πŸ”§ Development

Project Structure

llm-chat-platform/
β”œβ”€β”€ client/                 # React frontend
β”‚   β”œβ”€β”€ src/
β”‚   β”‚   β”œβ”€β”€ components/     # Reusable UI components
β”‚   β”‚   β”œβ”€β”€ pages/          # Page components
β”‚   β”‚   β”œβ”€β”€ services/       # API and Socket services
β”‚   β”‚   β”œβ”€β”€ store/          # Redux store and slices
β”‚   β”‚   └── App.js          # Main app component
β”‚   └── package.json
β”œβ”€β”€ server/                 # Node.js backend
β”‚   β”œβ”€β”€ config/             # Database configuration
β”‚   β”œβ”€β”€ middleware/         # Express middleware
β”‚   β”œβ”€β”€ routes/             # API routes
β”‚   β”œβ”€β”€ scripts/            # Database migrations
β”‚   β”œβ”€β”€ socket/             # Socket.IO handlers
β”‚   └── index.js            # Server entry point
└── package.json            # Root package.json

Adding New Features

  1. Backend: Add routes in server/routes/
  2. Frontend: Create components in client/src/components/
  3. State Management: Add Redux slices in client/src/store/slices/
  4. Database: Update migration script in server/scripts/migrate.js

Code Style

  • Use ES6+ features
  • Follow React hooks patterns
  • Implement proper error handling
  • Add loading states for async operations
  • Use Material-UI components consistently

πŸ› Troubleshooting

Common Issues

Database Connection Error

# Check PostgreSQL is running
pg_ctl status

# Verify database exists
psql -l | grep llm_chat_platform

# Check connection string in .env

OpenAI API Errors

  • Verify API key is correct
  • Check API quota and billing
  • Ensure proper error handling for rate limits

Socket.IO Connection Issues

  • Check CORS configuration
  • Verify frontend and backend URLs match
  • Check browser console for connection errors

Build Errors

# Clear node_modules and reinstall
rm -rf node_modules package-lock.json
npm install

# Clear build cache
rm -rf client/build server/dist

πŸ“ License

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

🀝 Contributing

  1. Fork the repository
  2. Create a 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

πŸ“ž Support

For support and questions:

  • Create an issue in the GitHub repository
  • Check the troubleshooting section above
  • Review the API documentation

🎯 Future Enhancements

  • Google OAuth implementation
  • File upload and sharing
  • Voice message support
  • Advanced user roles and permissions
  • Usage analytics and reporting
  • Custom LLM model selection
  • Conversation export functionality
  • Advanced notification settings
  • Mobile app development
  • API rate limiting per organization

Built with ❀️ for the LLM Chat Platform Assignment

About

Full-Stack LLM Chat Platform with authentication, organization management, credit system, and real-time notifications

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published