A modern real-time chat application built with Spring Boot and WebSocket for instant messaging, integrated with MySQL for data persistence and Js for a dynamic frontend. This app enables users to join chat rooms, send messages, and receive real-time updates, providing a seamless communication experience. 🚀
- 💬 Real-Time Messaging: Send and receive messages instantly via WebSocket.
- 👥 User Management: Register and authenticate users with Spring Security.
- 📚 Chat Rooms: Create and join multiple chat rooms for group conversations.
- 🗄️ Message Persistence: Store chat history in MySQL for retrieval.
- 🔍 Search Messages: Search past messages by keyword or user.
- 📱 Responsive UI: React-based frontend for desktop and mobile compatibility.
- 🔒 Secure Authentication: JWT-based login for secure access.
- ☕ Java 17 or later
- 📦 Maven for dependency management
- 🌐 Node.js and npm for the React frontend
- 🗄️ MySQL 5.7 or later
- 🌍 Modern browser (Chrome, Firefox, Edge)
-
Clone the Repository 📂
git clone https://github.com/yourusername/springboot-websocket-chat.git cd springboot-websocket-chat/backend
-
Configure Database 🗄️
- Create a MySQL database named
chat_db
. - Update
src/main/resources/application.properties
:spring.datasource.url=jdbc:mysql://localhost:3306/chat_db spring.datasource.username=your_username spring.datasource.password=your_password spring.jpa.hibernate.ddl-auto=update spring.security.jwt.secret=your_jwt_secret_key
- Create a MySQL database named
-
Build and Run 🏃
mvn clean install mvn spring-boot:run
- Backend runs on
http://localhost:8080
.
- Backend runs on
-
Navigate to Frontend 📂
cd ../frontend
-
Install Dependencies 📦
npm install
-
Start Frontend 🌐
npm start
- Frontend runs on
http://localhost:3000
.
- Frontend runs on
-
Access the App 🌐
- Open
http://localhost:3000
. - Register or log in with credentials 🔐.
- Open
-
Start Chatting 💬
- Join or create a chat room from the dashboard.
- Send messages and see real-time updates via WebSocket.
- Search chat history by keyword or user.
-
Key API Endpoints 📡
- User Registration:
POST /api/auth/register
{ "username": "user1", "password": "pass123" }
- Join Room:
POST /api/rooms/join
{ "userId": 1, "roomId": "room1" }
- Send Message: WebSocket endpoint
/ws/chat
{ "roomId": "room1", "userId": 1, "message": "Hello!" }
- Health Check:
GET /actuator/health
- User Registration:
springboot-websocket-chat/
├── backend/ # Spring Boot backend 🖥️
│ ├── src/main/
│ │ ├── java/com/example/chat/
│ │ │ ├── controller/ # REST and WebSocket controllers ⚙️
│ │ │ ├── service/ # Business logic 🛠️
│ │ │ ├── model/ # Entities (User, Message, Room) 📋
│ │ │ ├── config/ # WebSocket and Security config 🔧
│ │ ├── resources/
│ │ │ ├── application.properties # Configuration ⚙️
│ ├── pom.xml # Maven dependencies 📦
├── frontend/ # React frontend 🌐
│ ├── src/
│ │ ├── components/ # React components 🧩
│ │ ├── App.js # Main React app 🚀
│ ├── package.json # Node dependencies 📦
├── README.md # This file 📄
Contributions are welcome! To contribute:
- 🍴 Fork the repository.
- 🌿 Create a branch:
git checkout -b feature/your-feature
. - ✍️ Commit changes:
git commit -m "Add your feature"
. - 🚀 Push branch:
git push origin feature/your-feature
. - 📬 Open a pull request.
🌍 Connect instantly with real-time chat! Happy coding! 🚀