This project is a web-based AI chat application inspired by platforms like chat.deepseek.com, featuring chat history, sharing, API key management, user administration, and multi-provider support. It consists of a Node.js/Express backend and a React/Vite frontend.
ai-chatbox/
├── backend/ # Node.js/Express backend code
│ ├── config/
│ ├── controllers/
│ ├── middleware/
│ ├── models/
│ ├── routes/
│ ├── uploads/ # Default location for file uploads (consider cloud storage for production)
│ ├── .env # Environment variables (local development, DO NOT COMMIT)
│ ├── package.json
│ └── server.js # Main backend entry point
├── frontend/ # React/Vite frontend code
│ └── client/
│ ├── public/
│ │ └── _redirects # Netlify redirect rule for SPA routing
│ ├── src/
│ │ ├── components/
│ │ ├── pages/
│ │ ├── services/
│ │ ├── types/
│ │ ├── App.tsx
│ │ ├── i18n.ts
│ │ ├── index.css
│ │ ├── main.tsx # Main frontend entry point
│ │ └── vite-env.d.ts
│ ├── .env # Environment variables (local development, DO NOT COMMIT)
│ ├── index.html
│ ├── package.json
│ ├── vite.config.js # Vite config including proxy for local dev
│ └── tsconfig.json
└── .gitignore # Git ignore rules for the whole project
- User Authentication: Secure login and registration system using JWT.
- Chat History: Sidebar displays past chat sessions for easy navigation.
- Chat Sharing: Generate unique, shareable links for specific chat sessions.
- Multi-Provider Support: Integrates with multiple AI providers:
- Anthropic (Claude models)
- OpenAI (GPT models)
- Google (Gemini models)
- DeepSeek (DeepSeek models)
- Model Selection: Choose specific models from enabled providers for each chat message.
- Streaming Responses: Real-time AI responses using Server-Sent Events (SSE).
- Streaming Toggle: Option to enable/disable streaming mode per user preference.
- File Attachments: Attach files (including basic PDF text extraction) to messages.
- Admin Panel:
- Manage API keys for different providers (add, enable/disable, set priority).
- Manage users (view, edit roles, delete).
- Manage disabled models.
- Manage referral codes.
- Dark Mode: Toggle between light and dark themes.
- Internationalization (i18n): Basic setup for multi-language support.
- Responsive Design: Adapts to different screen sizes.
- Node.js (v18 or later recommended)
- npm
- MongoDB (local instance or connection string for Atlas)
- Navigate to the backend directory:
cd backend - Create a
.envfile by copying.env.example(if it exists) or creating a new one. - Set the following environment variables in
.env:MONGODB_URI: Your MongoDB connection string (local or Atlas).JWT_SECRET: A strong secret string for signing tokens.JWT_EXPIRE: Token expiration time (e.g.,30d).PORT: Port for the backend server (e.g.,5001).NODE_ENV:development
- Install dependencies:
npm install - Start the server:
npm start(usesnode server.js) - (Optional) Create Initial Admin User: To create the default admin user (
admin/password), run the seeder:node seeder.js -i. Change this password immediately after first login!
- Navigate to the frontend client directory:
cd ../frontend/client - Install dependencies:
npm install - Start the development server:
npm run dev(Usenpm run dev -- --hostto expose on your local network for mobile testing). Thevite.config.jsfile includes a proxy to redirect/apirequests to your backend (defaulting tohttp://localhost:5001).
This guide uses Render for the backend and Netlify for the frontend as examples.
- Copy Project: Create a separate copy of this entire
ai-chatboxdirectory for deployment. - Version Control (Git):
- Navigate into the copied directory.
- Initialize Git:
git init - Ensure a
.gitignorefile exists in the root (see example below or use the one provided). It must ignore.envfiles,node_modules, and build output (dist). - Stage all files:
git add . - Commit:
git commit -m "Initial commit for deployment" - Create a new private repository on GitHub/GitLab.
- Link and push your local repository to the remote:
git remote add origin <your-remote-repo-url> git branch -M main git push -u origin main
- Database (MongoDB Atlas):
- Ensure you have an Atlas cluster ready.
- Create a Database User with read/write permissions. Save the password securely.
- Configure Network Access to allow connections (use
0.0.0.0/0for Render, restrict later if possible). - Get the Connection String and replace
<username>,<password>, and add your database name (e.g.,compassai-db). This is yourMONGODB_URI.
- Render Setup:
- Create a new "Web Service" on Render, connecting your GitHub repository.
- Settings:
- Root Directory:
backend - Build Command:
npm install - Start Command:
npm start
- Root Directory:
- Environment Variables:
MONGODB_URI: Your full Atlas connection string.JWT_SECRET: A new, strong, random secret for production.JWT_EXPIRE:30d(or your desired expiration).NODE_ENV:productionPORT: Render typically sets this automatically, but you can set it if needed (e.g.,10000).
- Deploy the service.
- Copy the backend URL provided by Render (e.g.,
https://your-backend.onrender.com). - (Optional) Seed Initial Admin: Connect to your deployed backend environment (e.g., Render Shell, SSH) navigate to the
backenddirectory, and runnode seeder.js -ionce to create the default admin user.
- Netlify Setup:
- Create a new "Site from Git" on Netlify, connecting the same GitHub repository.
- Build Settings:
- Base directory:
frontend/client - Build command:
npm run build - Publish directory:
frontend/client/dist
- Base directory:
- Environment Variables:
VITE_API_BASE_URL: The full URL of your deployed Render backend, including/api/v1(e.g.,https://your-backend.onrender.com/api/v1).
- Deploy the site.
- Ensure the
frontend/client/public/_redirectsfile exists with/* /index.html 200to handle SPA routing.
- Backend CORS: Verify the
origininbackend/server.js'scorsOptionsincludes your deployed Netlify frontend URL. If you had to update it after getting the Netlify URL, commit, push, and redeploy the backend. - Initial Login: If you ran the seeder, log in with
admin/passwordand change the password immediately. Otherwise, register the first user through the UI. - Test: Access your Netlify URL and test registration, login, chat functionality (streaming/non-streaming, file uploads), sharing, and admin features.
- Secrets: Never commit
.envfiles or hardcode secrets (DB URI, JWT Secret). Use hosting platform environment variables. - Uploads: The file upload implementation saves files to the backend server's filesystem (
backend/uploads/). The system creates this directory on-demand when needed. While this works for both local development and the current deployment, for long-term production use on platforms with truly ephemeral filesystems, consider integrating a cloud storage service (e.g., AWS S3, Google Cloud Storage, Cloudinary). - Security: Restrict database IP access in Atlas once your backend IP is stable. Use strong secrets. Implement rate limiting and input validation on the backend.