A real-time chat application built with Java 17, Spring Boot WebSockets, MongoDB, and a React 19 + TypeScript frontend.
NexusChat handles bidirectional messaging over WebSockets, active session tracking with thread-safe data structures (ConcurrentHashMap), and dual-side message persistence in MongoDB.
- WebSocket Messaging: Native Spring
@EnableWebSockettext handler registered on/ws/chat. - Session Registry: Thread-safe online connection management using
ConcurrentHashMap<String, WebSocketSession>. - Dual-Side Persistence: Atomically saves message history for both sender and recipient in MongoDB
Userscollections. - REST Endpoints: User registration, search, chat list retrieval, and conversation history APIs.
- React Frontend: Single-page interface built with React 19, TypeScript, Vite, and Axios.
- Java 17+
- Maven 3.8+
- Node.js 20+
- MongoDB 6.x (running locally on port 27017 or via MongoDB Atlas)
# 1. Clone repository
git clone https://github.com/Kusagra9308/NexusChat.git
cd NexusChat
# 2. Build and run Spring Boot backend
cd nexuschat
./mvnw clean spring-boot:run
# 3. In a separate terminal, run React frontend
cd ../nexuschat-frontend
npm install
npm run devBackend properties in nexuschat/src/main/resources/application.properties:
server.port=8080
spring.data.mongodb.uri=mongodb://localhost:27017/nexuschatConnect your client to:
ws://localhost:8080/ws/chat?username=john
{
"sender": "john",
"recipient": "anna",
"text": "Hello Anna!"
}{
"sender": "john",
"chatWith": "john",
"text": "Hello Anna!"
}# Register User
curl -X POST http://localhost:8080/user \
-H "Content-Type: application/json" \
-d '{"username":"john"}'
# Get User Chat List
curl http://localhost:8080/chatlist?username=johnflowchart TD
Client([React 19 Frontend]) -->|WebSocket Frame /ws/chat| WSHandler[ChatWebSocketHandler]
Client -->|REST Requests| Controller[ChatController]
WSHandler -->|Session Registry| SessionMap[ConcurrentHashMap]
WSHandler -->|Save Message| MongoRepo[ChatRepository]
Controller -->|Fetch History| MongoRepo
MongoRepo --> MongoDB[(MongoDB Document Store)]
WSHandler -->|Outbound Frame| Recipient[Active Recipient Session]
- Add support for image and file attachments.
- Add Spring Security JWT authentication guards to WebSocket handshakes.
- Add STOMP protocol and SockJS fallback support.
- Fork the repository
- Create your feature branch (
git checkout -b feature/my-feature) - Commit your changes (
git commit -m "add my feature") - Push to the branch (
git push origin feature/my-feature) - Open a Pull Request
Distributed under the MIT License.