This is the backend server for PandaChats, a full-stack real-time chat application. It provides RESTful APIs, real-time WebSocket communication, and data persistence using MongoDB.
- π Frontend App: https://pandachats.vercel.app
- βοΈ Backend API: https://chat-5km8.onrender.com
- π Frontend Repo: https://github.com/subramanyamchoda/chat_client
- π Backend Repo: https://github.com/subramanyamchoda/chat_backend
- π User authentication using JWT
- π REST APIs for users, chats, and messages
- β‘ Real-time communication with Socket.IO
- π¬ One-to-one and group chat support
- βοΈ Typing indicators and online presence tracking
- π Media and file message handling
Component | Tech |
---|---|
Server | Node.js + Express |
Real-time Comm | Socket.IO (WebSockets) |
Database | MongoDB + Mongoose |
Auth | JWT + Bcrypt |
Deployment | Render |
βββ config/
β βββ db.js # MongoDB connection
βββ controllers/
β βββ userController.js # Auth & user logic
β βββ chatController.js # Chat creation
β βββ messageController.js # Message handling
βββ middleware/
β βββ authMiddleware.js # JWT auth guard
βββ models/
β βββ User.js
β βββ Chat.js
β βββ Message.js
βββ routes/
β βββ userRoutes.js
β βββ chatRoutes.js
β βββ messageRoutes.js
βββ .env # Env variables
βββ server.js # App entry point
Create a .env
file in the root directory with the following:
PORT=5000
MONGO_URI=your-mongodb-uri
JWT_SECRET=your-secret-key
π Replace
your-mongodb-uri
andyour-secret-key
with actual values.
git clone https://github.com/subramanyamchoda/chat_backend.git
cd chat_backend
npm install
npm run dev
Server will run at: http://localhost:5000
The server emits and listens to:
Event | Description |
---|---|
setup |
Initializes user socket |
join chat |
Joins a specific chat room |
typing / stop typing |
Typing status broadcast |
new message |
Sends/receives new messages |
disconnect |
Handles socket cleanup |
POST /api/user/register # Register
POST /api/user/login # Login
GET /api/user?search=... # Search users
POST /api/chat # Create one-to-one or group
GET /api/chat # Fetch user chats
PUT /api/chat/group # Rename group
PUT /api/chat/add # Add user to group
PUT /api/chat/remove # Remove user from group
POST /api/message # Send a message
GET /api/message/:chatId # Get all messages for a chat
POST /api/user/login
{
"email": "[email protected]",
"password": "123456"
}
# 1. Fork this repo
# 2. Create a branch
git checkout -b feature/your-feature
# 3. Commit changes
git commit -m "Add your-feature"
# 4. Push to your fork
git push origin feature/your-feature
# 5. Open a Pull Request
This backend was created to practice and demonstrate:
- π Secure authentication with JWT
- β‘ Real-time messaging with Socket.IO
- π Clean API architecture with Express
- βοΈ Full-stack MERN deployment (Render + Vercel)
This project is open-source and free to use.
Reach out on LinkedIn or star β the repo if you found it helpful!