Skip to content

πŸ“¦ PandaChats Server The backend for PandaChats – a real-time chat application using Node.js, Express, MongoDB, and Socket.IO. It handles authentication, user sessions, message routing, group chat logic, and WebSocket communication for real-time updates.

Notifications You must be signed in to change notification settings

subramanyamchoda/chat_backend

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

4 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ› οΈ PandaChats – Backend Server πŸΌπŸ’¬

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.


πŸ”— Live Links


πŸš€ Features

  • πŸ” 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

🧰 Tech Stack

Component Tech
Server Node.js + Express
Real-time Comm Socket.IO (WebSockets)
Database MongoDB + Mongoose
Auth JWT + Bcrypt
Deployment Render

πŸ“‚ Folder Structure

β”œβ”€β”€ 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

βš™οΈ Environment Variables

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 and your-secret-key with actual values.


▢️ Getting Started

1. Clone the Repo

git clone https://github.com/subramanyamchoda/chat_backend.git
cd chat_backend

2. Install Dependencies

npm install

3. Start the Server

npm run dev

Server will run at: http://localhost:5000


πŸ“‘ WebSocket Events (Socket.IO)

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

βœ… API Endpoints

πŸ‘€ Auth & Users

POST   /api/user/register   # Register
POST   /api/user/login      # Login
GET    /api/user?search=... # Search users

πŸ’¬ Chat

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

βœ‰οΈ Messages

POST   /api/message         # Send a message
GET    /api/message/:chatId # Get all messages for a chat

πŸ§ͺ Sample Request (JSON)

POST /api/user/login
{
  "email": "[email protected]",
  "password": "123456"
}

🀝 Contributing

# 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

πŸ™Œ Acknowledgments

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)

πŸ“Œ License

This project is open-source and free to use.


πŸ“ž Contact

Reach out on LinkedIn or star ⭐ the repo if you found it helpful!

About

πŸ“¦ PandaChats Server The backend for PandaChats – a real-time chat application using Node.js, Express, MongoDB, and Socket.IO. It handles authentication, user sessions, message routing, group chat logic, and WebSocket communication for real-time updates.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published