A full-stack real-time chat application built with Spring Boot (backend) and React (frontend), featuring JWT authentication, WebSocket communication, and group messaging capabilities.
โโโโโโโโโโโโโโโโโโโ WebSocket/HTTP โโโโโโโโโโโโโโโโโโโโ
โ โโโโโโโโโโโโโโโโโโโโโโโบโ โ
โ React Frontend โ โ Spring Boot โ
โ (Vite + React) โ โ Backend โ
โ โ โ โ
โโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโโ
โ
โ JPA/Hibernate
โผ
โโโโโโโโโโโโโโโโโโโโ
โ โ
โ MySQL Database โ
โ โ
โโโโโโโโโโโโโโโโโโโโ
- JWT-based Authentication: Secure token-based authentication system
- Spring Security Integration: Role-based access control
- Password Encryption: Secure password hashing with BCrypt
- CORS Configuration: Cross-origin resource sharing setup
- WebSocket Communication: Real-time bidirectional communication using STOMP over WebSocket
- Group Messaging: Create and join chat groups
- Message Persistence: All messages are stored in the database
- Live Updates: Real-time message delivery without page refresh
- User Registration & Login: Complete user authentication flow
- Profile Management: User profile viewing and management
- Group Creation: Users can create new chat groups
- Group Membership: Join existing groups with group codes
- Modern React UI: Built with React 19 and modern hooks
- Responsive Design: Mobile-first responsive design with Tailwind CSS
- Real-time Updates: Live chat interface with message notifications
- State Management: Context API for global state management
- Routing: React Router for navigation
- Framework: Spring Boot 3.5.4
- Language: Java 21
- Database: MySQL
- ORM: Spring Data JPA with Hibernate
- Security: Spring Security with JWT
- WebSocket: Spring WebSocket with STOMP
- Build Tool: Maven
- Additional Libraries:
- ModelMapper for DTO mapping
- Lombok for boilerplate reduction
- JJWT for JWT handling
- Framework: React 19.1.0
- Build Tool: Vite 7.0.4
- Styling: Tailwind CSS 4.1.11
- HTTP Client: Axios
- WebSocket: @stomp/stompjs + SockJS
- Routing: React Router DOM
- UI Components: Lucide React icons
- Notifications: React Hot Toast
chat-backend/
โโโ src/main/java/com/ritik/chatbackend/
โ โโโ configurations/ # Spring configurations
โ โ โโโ AppConfig.java
โ โ โโโ JpaConfiguration.java
โ โ โโโ ModelMapperConfig.java
โ โ โโโ WebSocketConfig.java
โ โโโ controllers/ # REST controllers
โ โ โโโ AuthController.java
โ โ โโโ ChatController.java
โ โ โโโ GroupController.java
โ โ โโโ ProfileController.java
โ โโโ dtos/ # Data Transfer Objects
โ โโโ entities/ # JPA entities
โ โ โโโ AppUser.java
โ โ โโโ Group.java
โ โ โโโ Message.java
โ โโโ exceptions/ # Custom exceptions
โ โโโ repositories/ # JPA repositories
โ โโโ security/ # Security configurations
โ โโโ services/ # Business logic services
โโโ frontend/chat-frontend/
โ โโโ src/
โ โ โโโ components/ # Reusable React components
โ โ โโโ context/ # React context providers
โ โ โโโ hooks/ # Custom React hooks
โ โ โโโ pages/ # Page components
โ โ โโโ routes/ # Route protection components
โ โ โโโ services/ # API service layer
โ โ โโโ utils/ # Utility functions
โ โโโ public/ # Static assets
โโโ pom.xml # Maven configuration
- Java 21 or higher
- Node.js 18+ and npm
- MySQL 8.0+
- Maven 3.6+
- Install MySQL and create a database:
CREATE DATABASE chat;- Update database credentials in
src/main/resources/application.properties:
spring.datasource.url=jdbc:mysql://localhost:3306/chat
spring.datasource.username=your_username
spring.datasource.password=your_password- Clone the repository:
git clone <repository-url>
cd chat-backend- Build and run the Spring Boot application:
mvn clean install
mvn spring-boot:runThe backend will start on http://localhost:8080
- Navigate to the frontend directory:
cd frontend/chat-frontend- Install dependencies:
npm install- Start the development server:
npm run devThe frontend will start on http://localhost:5173
Update JWT settings in application.properties:
jwt.secret=your-secret-key
jwt.expiration=jwt-expiration-time (in ms)The WebSocket endpoint is configured at /chat with SockJS fallback. Frontend connects to this endpoint for real-time communication.
CORS is configured to allow requests from http://localhost:5173 (frontend development server).
POST /auth/register- Register new userPOST /auth/login- User login
GET /groups- Get user's groupsPOST /groups- Create new groupPOST /groups/{groupId}/join- Join groupPOST /groups/{groupId}/add-user- Add user to group
GET /profile- Get user profile
/app/sendMessage- Send message to group/topic/group/{groupId}- Subscribe to group messages
Run backend tests:
mvn testRun frontend tests:
cd frontend/chat-frontend
npm run testmvn clean package
java -jar target/chat-backend-0.0.1-SNAPSHOT.jarcd frontend/chat-frontend
npm run build-
Apache Kafka Integration:
- Implement Kafka for handling high-volume message queuing
- Enable horizontal scaling across multiple server instances
- Provide fault-tolerant message delivery with persistent storage
- Support for event sourcing and message replay capabilities
-
Elasticsearch Integration:
- Add full-text search capabilities for message history
- Implement advanced search filters (date range, user, group)
- Enable real-time message indexing for instant search results
- Support for fuzzy search and auto-completion
- Message Encryption: End-to-end encryption for secure communication
- Admin Dashboard: Administrative interface for user and group management
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add some amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.
Ritik - MeRitik
- Spring Boot team for the excellent framework
- React team for the amazing frontend library
- All contributors who helped improve this project
โญ If you found this project helpful, please give it a star!