Skip to content
Kusagra9308Public

About

Real-time distributed chat platform built with Java 17, Spring Boot, Native WebSockets, MongoDB document storage, and a modern React 19 + TypeScript frontend.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

6 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 

Repository files navigation

NexusChat

Java Spring Boot MongoDB React License: MIT

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.

Features

  • WebSocket Messaging: Native Spring @EnableWebSocket text 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 Users collections.
  • 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.

Quick Start

Prerequisites

  • Java 17+
  • Maven 3.8+
  • Node.js 20+
  • MongoDB 6.x (running locally on port 27017 or via MongoDB Atlas)

Installation

# 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 dev

Configuration

Backend properties in nexuschat/src/main/resources/application.properties:

server.port=8080
spring.data.mongodb.uri=mongodb://localhost:27017/nexuschat

Usage

WebSocket Connection

Connect your client to: ws://localhost:8080/ws/chat?username=john

Outbound Frame (JSON)

{
  "sender": "john",
  "recipient": "anna",
  "text": "Hello Anna!"
}

Inbound Confirmation Frame

{
  "sender": "john",
  "chatWith": "john",
  "text": "Hello Anna!"
}

REST API Examples

# 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=john

Architecture

flowchart 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]
Loading

Limitations & Roadmap

  • Add support for image and file attachments.
  • Add Spring Security JWT authentication guards to WebSocket handshakes.
  • Add STOMP protocol and SockJS fallback support.

Contributing

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/my-feature)
  3. Commit your changes (git commit -m "add my feature")
  4. Push to the branch (git push origin feature/my-feature)
  5. Open a Pull Request

License

Distributed under the MIT License.

About

Real-time distributed chat platform built with Java 17, Spring Boot, Native WebSockets, MongoDB document storage, and a modern React 19 + TypeScript frontend.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages