Skip to content

A real-time chat application with a React frontend and Spring Boot backend. Features encrypted messaging, WebSocket communication, and responsive design. πŸš€

License

Notifications You must be signed in to change notification settings

aditya-620/ChatterBox

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

19 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

ChatterBox

ChatterBox is a real-time chat application built with a React frontend and a Spring Boot backend. It supports creating and joining chat rooms, sending and receiving encrypted messages, and real-time communication using WebSockets.


Table of Contents


Features

  • Create and join chat rooms.
  • Real-time messaging using WebSockets.
  • Messages are encrypted before being stored in the database.
  • Pagination support for retrieving chat history.
  • Dark mode support for the frontend.
  • Responsive design for mobile and desktop.

Technologies Used

Frontend

  • React: For building the user interface.
  • Vite: For fast development and build tooling.
  • TailwindCSS: For styling.
  • React Router: For navigation.
  • Axios: For API requests.
  • SockJS & STOMP.js: For WebSocket communication.

Backend

  • Spring Boot: For building the backend.
  • MongoDB: For storing chat room and message data.
  • WebSocket: For real-time communication.
  • Lombok: For reducing boilerplate code.
  • Maven: For dependency management and building the project.

Project Structure

Frontend


ChatterBox-frontend/
β”œβ”€β”€ src/
β”‚   β”œβ”€β”€ components/        # Reusable React components
β”‚   β”œβ”€β”€ config/            # Configuration files (Axios, Routes, etc.)
β”‚   β”œβ”€β”€ context/           # React Context API for global state management
β”‚   β”œβ”€β”€ services/          # API service functions
β”‚   β”œβ”€β”€ App.jsx            # Main App component
β”‚   β”œβ”€β”€ main.jsx           # Entry point for React/Vite
β”‚   └── index.css          # Global styles
β”œβ”€β”€ public/                # Static assets like favicon, index.html
β”œβ”€β”€ vite.config.js         # Vite configuration file
└── package.json           # Project dependencies and scripts

Backend

ChatterBox-backend/
β”œβ”€β”€ src/
β”‚   β”œβ”€β”€ main/
β”‚   β”‚   β”œβ”€β”€ java/com/adityarastogi/ChatterBox_backend/
β”‚   β”‚   β”‚   β”œβ”€β”€ config/             # WebSocket configuration
β”‚   β”‚   β”‚   β”œβ”€β”€ controllers/        # REST and WebSocket controllers
β”‚   β”‚   β”‚   β”œβ”€β”€ entities/           # MongoDB entities
β”‚   β”‚   β”‚   β”œβ”€β”€ repositories/       # MongoDB repositories
β”‚   β”‚   β”‚   β”œβ”€β”€ utils/              # Utility classes (e.g., encryption)
β”‚   β”‚   β”‚   └── ChatterBoxBackendApplication.java  # Main application
β”‚   β”‚   └── resources/
β”‚   β”‚       └── application.properties  # Backend configuration
β”‚   └── test/                          # Unit tests
β”œβ”€β”€ Dockerfile                         # Docker configuration
β”œβ”€β”€ pom.xml                            # Backend dependencies and build config
└── mvnw                               # Maven wrapper

Setup Instructions

Prerequisites

  • Node.js (v18 or higher)
  • Java 17
  • MongoDB
  • Maven
  • Docker (optional)

Frontend Setup

  1. Navigate to the frontend directory:
    cd ChatterBox-frontend
    
  2. Install dependencies:
    npm install
    
  3. Create a .env file in the root of the ChatterBox-frontend directory and add the following:
    VITE_API_URL=http://localhost:8080
    
  4. Start the development server:
    npm run dev
    
  5. Open your browser and navigate to http://localhost:5173.

Backend Setup

  1. Navigate to the backend directory:
    cd ChatterBox-backend
    
  2. Create a .env file in the src/main/resources directory and add the following:
     MONGODB_URI=mongodb://localhost:27017/chatterbox
     MONGODB_DATABASE=chatterbox
     FRONTEND_URL=http://localhost:5173
    
  3. Build and run the backend:
    ./mvnw spring-boot:run
    
  4. The backend will be available at http://localhost:8080.

Environment Variables

Frontend

  • VITE_API_URL: The base URL for the backend API.

Backend

  • MONGODB_URI: MongoDB connection string.
  • MONGODB_DATABASE: Name of the MongoDB database.
  • FRONTEND_URL: URL of the frontend application (used for CORS configuration).

API Endpoints

Room Management

  • POST /api/v1/rooms β€” Create a new chat room.
  • GET /api/v1/rooms/{roomId} β€” Join an existing chat room.

Messages

  • GET /api/v1/rooms/{roomId}/messages β€” Retrieve messages for a room with pagination.

WebSocket Configuration

  • Endpoint: /chat
  • Subscribe: /topic/room/{roomId}
  • Send: /app/sendMessage/{roomId}

Encryption

Messages are encrypted using AES-256 before being stored in the database.
The encryption key is hardcoded in the backend's EncryptionUtil class.
Important: Replace this key with a secure, environment-specific key before deploying to production.


Docker Support

Build and Run the Backend with Docker

  1. Navigate to the backend directory:

    cd ChatterBox-backend
  2. Build the Docker image:

    docker build -t chatterbox-backend .
  3. Run the Docker container:

    docker run -p 8080:8080 chatterbox-backend

License

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

About

A real-time chat application with a React frontend and Spring Boot backend. Features encrypted messaging, WebSocket communication, and responsive design. πŸš€

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published