Skip to content

techrivers/Multi-AI-Chat-Proxy-Server

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

2 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

AI Chat Proxy

A full-stack multi-user AI chat application that allows users to interact with multiple AI models (OpenAI, Anthropic, Google Gemini) through a unified interface. Built with React, Node.js/Express, PostgreSQL, and Docker.

โœจ Features

  • Multi-AI Model Support: Chat with GPT-3.5, GPT-4, Claude 3, Claude 3.5, Gemini Pro, and more
  • User Authentication: JWT-based authentication with admin and user roles
  • Chat Management: Create, manage, and delete chat conversations
  • File Upload: Upload and share images and documents in chats
  • Real-time Chat Interface: Modern, responsive chat UI
  • Admin Panel: Admins can create new users
  • Docker Support: Complete containerized setup
  • API Key Management: Secure environment-based API key configuration

๐Ÿ—๏ธ Architecture

ai-chat-proxy/
โ”œโ”€โ”€ backend/                 # Node.js/Express API
โ”‚   โ”œโ”€โ”€ src/
โ”‚   โ”‚   โ”œโ”€โ”€ controllers/     # Request handlers
โ”‚   โ”‚   โ”œโ”€โ”€ models/          # Database models (Sequelize)
โ”‚   โ”‚   โ”œโ”€โ”€ routes/          # API routes
โ”‚   โ”‚   โ”œโ”€โ”€ middleware/      # Auth, upload, etc.
โ”‚   โ”‚   โ”œโ”€โ”€ services/        # AI service integrations
โ”‚   โ”‚   โ””โ”€โ”€ config/          # Database configuration
โ”‚   โ””โ”€โ”€ uploads/             # File storage
โ”œโ”€โ”€ frontend/                # React/Vite application
โ”‚   โ”œโ”€โ”€ src/
โ”‚   โ”‚   โ”œโ”€โ”€ components/      # React components
โ”‚   โ”‚   โ”œโ”€โ”€ pages/           # Page components
โ”‚   โ”‚   โ”œโ”€โ”€ services/        # API client
โ”‚   โ”‚   โ””โ”€โ”€ context/         # React context
โ””โ”€โ”€ docker-compose.yml       # Container orchestration

๐Ÿš€ Quick Start

Prerequisites

  • Docker and Docker Compose
  • Node.js 18+ (for local development)
  • PostgreSQL (if running locally)

1. Clone and Setup

git clone <repository-url>
cd ai-chat-proxy
cp .env.example .env

2. Configure Environment Variables

Edit .env file with your settings:

# Database Configuration
DATABASE_URL=postgresql://postgres:postgres123@localhost:5432/chatproxy

# JWT Configuration
JWT_SECRET=your-super-secret-jwt-key-change-this-in-production
JWT_REFRESH_SECRET=your-super-secret-refresh-key-change-this-in-production

# Admin User (for seeding)
ADMIN_EMAIL=admin@chatproxy.com
ADMIN_PASSWORD=admin123

# AI API Keys (Add your own API keys)
OPENAI_API_KEY=your-openai-api-key-here
ANTHROPIC_API_KEY=your-anthropic-api-key-here
GOOGLE_GEMINI_API_KEY=your-google-gemini-api-key-here

# Server Configuration
PORT=8000
FRONTEND_URL=http://localhost:3000

3. Start with Docker

# Build and start all services
docker-compose up --build

# Or run in background
docker-compose up -d --build

4. Initialize Database

# Seed the database with admin user
docker-compose exec backend npm run seed

5. Access Application

Default Admin Login:

  • Email: admin@chatproxy.com
  • Password: admin123

๐Ÿ› ๏ธ Local Development

Backend Development

cd backend
npm install
npm run dev

Frontend Development

cd frontend
npm install
npm run dev

Database Setup (Local)

# Install PostgreSQL and create database
createdb chatproxy

# Run migrations and seed
cd backend
npm run seed

๐Ÿ“š API Documentation

Authentication

# Login
POST /api/auth/login
{
  "email": "user@example.com",
  "password": "password"
}

# Get Profile
GET /api/auth/profile
Authorization: Bearer <token>

# Create User (Admin only)
POST /api/auth/users
Authorization: Bearer <admin-token>
{
  "email": "newuser@example.com",
  "password": "password"
}

Chat Management

# Get all chats
GET /api/chats
Authorization: Bearer <token>

# Create new chat
POST /api/chats
Authorization: Bearer <token>
{
  "model_used": "gpt-4",
  "title": "My Chat"
}

# Get specific chat
GET /api/chats/:chatId
Authorization: Bearer <token>

# Delete chat
DELETE /api/chats/:chatId
Authorization: Bearer <token>

AI Integration

# Get available models
GET /api/ai/models
Authorization: Bearer <token>

# Send message to AI
POST /api/ai/chat
Authorization: Bearer <token>
{
  "chatId": "uuid",
  "message": "Hello AI!",
  "model": "gpt-4"
}

File Upload

# Upload file
POST /api/files/upload
Authorization: Bearer <token>
Content-Type: multipart/form-data
[file data]

# Get user files
GET /api/files
Authorization: Bearer <token>

# Delete file
DELETE /api/files/:fileId
Authorization: Bearer <token>

๐Ÿค– Supported AI Models

OpenAI Models

  • GPT-3.5 Turbo
  • GPT-4
  • GPT-4o

Anthropic Models

  • Claude 3 Haiku
  • Claude 3 Sonnet
  • Claude 3 Opus
  • Claude 3.5 Sonnet

Google Models

  • Gemini Pro
  • Gemini Pro Vision

๐Ÿ” Security Features

  • JWT-based authentication with refresh tokens
  • Password hashing with bcrypt
  • Role-based access control (Admin/User)
  • File upload validation and size limits
  • Rate limiting for API endpoints
  • CORS configuration
  • Input validation and sanitization

๐Ÿ—„๏ธ Database Schema

Users Table

id (UUID, Primary Key)
email (String, Unique)
password (String, Hashed)
role (Enum: admin/user)
created_at, updated_at

Chats Table

id (UUID, Primary Key)
user_id (UUID, Foreign Key)
model_used (String)
title (String)
created_at, updated_at

Messages Table

id (UUID, Primary Key)
chat_id (UUID, Foreign Key)
role (Enum: user/assistant)
content (Text)
file_url (String, Nullable)
created_at, updated_at

Files Table

id (UUID, Primary Key)
filename (String)
original_name (String)
file_path (String)
file_size (Integer)
mime_type (String)
user_id (UUID, Foreign Key)
created_at, updated_at

๐Ÿณ Docker Configuration

The application uses Docker Compose with three services:

  • postgres: PostgreSQL database
  • backend: Node.js API server
  • frontend: React development server

Production Deployment

For production, modify docker-compose.yml:

# Use production builds
frontend:
  build:
    context: ./frontend
    dockerfile: Dockerfile.prod
  command: ["npm", "run", "build"]

# Add nginx for serving static files
nginx:
  image: nginx:alpine
  ports:
    - "80:80"
  volumes:
    - ./nginx.conf:/etc/nginx/nginx.conf

๐Ÿ”ง Configuration

Environment Variables

Variable Description Default
DATABASE_URL PostgreSQL connection string Required
JWT_SECRET JWT signing secret Required
JWT_REFRESH_SECRET Refresh token secret Required
ADMIN_EMAIL Default admin email admin@chatproxy.com
ADMIN_PASSWORD Default admin password admin123
OPENAI_API_KEY OpenAI API key Optional
ANTHROPIC_API_KEY Anthropic API key Optional
GOOGLE_GEMINI_API_KEY Google Gemini API key Optional
PORT Backend server port 8000
FRONTEND_URL Frontend URL for CORS http://localhost:3000

File Upload Limits

  • Maximum file size: 10MB
  • Supported formats: Images (JPEG, PNG, GIF), Documents (PDF, DOC, DOCX, TXT, MD)
  • Files are stored locally in the uploads/ directory

๐Ÿš€ Deployment

Using Docker Compose (Recommended)

# Production deployment
docker-compose -f docker-compose.prod.yml up -d

Manual Deployment

  1. Set up PostgreSQL database
  2. Configure environment variables
  3. Build and deploy backend
  4. Build and deploy frontend
  5. Set up reverse proxy (nginx)

๐Ÿงช Testing

# Backend tests
cd backend
npm test

# Frontend tests
cd frontend
npm test

# Integration tests
npm run test:integration

๐Ÿค 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

๐Ÿ“ License

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

๐Ÿ†˜ Troubleshooting

Common Issues

Database Connection Issues:

# Check PostgreSQL is running
docker-compose ps

# View logs
docker-compose logs postgres

API Key Issues:

  • Ensure API keys are properly set in .env
  • Check API key validity and permissions
  • Verify correct model names in requests

File Upload Issues:

  • Check upload directory permissions
  • Verify file size limits
  • Ensure supported file formats

Getting Help

  • Check the Issues section
  • Review API documentation
  • Check Docker logs: docker-compose logs [service-name]

๐Ÿ”ฎ Roadmap

  • Real-time chat with WebSockets
  • Voice message support
  • Advanced file processing (OCR, PDF parsing)
  • Chat export functionality
  • Usage analytics and billing
  • Multi-language support
  • Mobile app (React Native)
  • Plugin system for custom AI models

Built with โค๏ธ using React, Node.js, PostgreSQL, and Docker.

About

A comprehensive chat proxy platform that unifies multiple AI providers (OpenAI, Anthropic, Google) into a single secure API. Features enterprise-grade security, JWT authentication, file upload support, and real-time streaming responses with conversation history persistence. Demo Video: https://www.youtube.com/watch?v=e7vzb-sCXpg&t=2s&pp=0gcJCccJAYc

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages