Skip to content

MeRitik/chat

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

41 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

๐Ÿ’ฌ Real-Time Chat Application

A full-stack real-time chat application built with Spring Boot (backend) and React (frontend), featuring JWT authentication, WebSocket communication, and group messaging capabilities.

๐Ÿ—๏ธ Architecture Overview

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”    WebSocket/HTTP    โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚                 โ”‚โ—„โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ–บโ”‚                  โ”‚
โ”‚  React Frontend โ”‚                      โ”‚  Spring Boot     โ”‚
โ”‚  (Vite + React) โ”‚                      โ”‚  Backend         โ”‚
โ”‚                 โ”‚                      โ”‚                  โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜                      โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                                                   โ”‚
                                                   โ”‚ JPA/Hibernate
                                                   โ–ผ
                                         โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
                                         โ”‚                  โ”‚
                                         โ”‚  MySQL Database  โ”‚
                                         โ”‚                  โ”‚
                                         โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

โœจ Features

๐Ÿ” Authentication & Security

  • 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

๐Ÿ’ฌ Real-Time Messaging

  • 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 Management

  • 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

๐ŸŽจ Frontend Features

  • 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

๐Ÿ› ๏ธ Technology Stack

Backend

  • 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

Frontend

  • 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

๐Ÿ“ Project Structure

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

๐Ÿš€ Getting Started

Prerequisites

  • Java 21 or higher
  • Node.js 18+ and npm
  • MySQL 8.0+
  • Maven 3.6+

๐Ÿ—„๏ธ Database Setup

  1. Install MySQL and create a database:
CREATE DATABASE chat;
  1. 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

๐Ÿ”ง Backend Setup

  1. Clone the repository:
git clone <repository-url>
cd chat-backend
  1. Build and run the Spring Boot application:
mvn clean install
mvn spring-boot:run

The backend will start on http://localhost:8080

๐ŸŽจ Frontend Setup

  1. Navigate to the frontend directory:
cd frontend/chat-frontend
  1. Install dependencies:
npm install
  1. Start the development server:
npm run dev

The frontend will start on http://localhost:5173

๐Ÿ”ง Configuration

JWT Configuration

Update JWT settings in application.properties:

jwt.secret=your-secret-key
jwt.expiration=jwt-expiration-time (in ms)

WebSocket Configuration

The WebSocket endpoint is configured at /chat with SockJS fallback. Frontend connects to this endpoint for real-time communication.

CORS Configuration

CORS is configured to allow requests from http://localhost:5173 (frontend development server).

๐Ÿ“ก API Endpoints

Authentication

  • POST /auth/register - Register new user
  • POST /auth/login - User login

Groups

  • GET /groups - Get user's groups
  • POST /groups - Create new group
  • POST /groups/{groupId}/join - Join group
  • POST /groups/{groupId}/add-user - Add user to group

Profile

  • GET /profile - Get user profile

Chat (WebSocket)

  • /app/sendMessage - Send message to group
  • /topic/group/{groupId} - Subscribe to group messages

๐Ÿงช Testing

Run backend tests:

mvn test

Run frontend tests:

cd frontend/chat-frontend
npm run test

๐Ÿ“ฆ Building for Production

Backend

mvn clean package
java -jar target/chat-backend-0.0.1-SNAPSHOT.jar

Frontend

cd frontend/chat-frontend
npm run build

๐Ÿ”ฎ Future Improvements

๐Ÿš€ Scalability & Performance

  • 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

๐ŸŽฏ Additional Features

  • Message Encryption: End-to-end encryption for secure communication
  • Admin Dashboard: Administrative interface for user and group management

๐Ÿค Contributing

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

๐Ÿ“ License

This project is licensed under the MIT License - see the LICENSE file for details.

๐Ÿ‘จโ€๐Ÿ’ป Author

Ritik - MeRitik

๐Ÿ™ Acknowledgments

  • 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!

About

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages