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.
- Features
- Technologies Used
- Project Structure
- Setup Instructions
- Environment Variables
- API Endpoints
- WebSocket Configuration
- Encryption
- Docker Support
- License
- 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.
- 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.
- 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.
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
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
- Node.js (v18 or higher)
- Java 17
- MongoDB
- Maven
- Docker (optional)
- Navigate to the frontend directory:
cd ChatterBox-frontend - Install dependencies:
npm install
- Create a .env file in the root of the ChatterBox-frontend directory and add the following:
VITE_API_URL=http://localhost:8080
- Start the development server:
npm run dev
- Open your browser and navigate to http://localhost:5173.
- Navigate to the backend directory:
cd ChatterBox-backend - 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
- Build and run the backend:
./mvnw spring-boot:run
- The backend will be available at http://localhost:8080.
VITE_API_URL: The base URL for the backend API.
MONGODB_URI: MongoDB connection string.MONGODB_DATABASE: Name of the MongoDB database.FRONTEND_URL: URL of the frontend application (used for CORS configuration).
POST /api/v1/roomsβ Create a new chat room.GET /api/v1/rooms/{roomId}β Join an existing chat room.
GET /api/v1/rooms/{roomId}/messagesβ Retrieve messages for a room with pagination.
- Endpoint:
/chat - Subscribe:
/topic/room/{roomId} - Send:
/app/sendMessage/{roomId}
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.
-
Navigate to the backend directory:
cd ChatterBox-backend -
Build the Docker image:
docker build -t chatterbox-backend . -
Run the Docker container:
docker run -p 8080:8080 chatterbox-backend
This project is licensed under the MIT License.
See the LICENSE file for details.