This is the backend service for the Private Chat App, a real-time messaging platform. The backend is built with Spring Boot and provides RESTful APIs and WebSocket endpoints for user management, authentication, and private messaging. The frontend is a separate React application, available here: private-chat-app-react.
- Features
- Tech Stack
- Project Structure
- Database Models
- API Endpoints
- WebSocket Messaging
- Configuration
- Running the Project
- Connecting with the React Frontend
- Contributing
- License
- User registration and authentication (session-based)
- Real-time private messaging using WebSocket (STOMP)
- RESTful APIs for user and message management
- Chat history retrieval
- User search
- MySQL database integration
- Environment-based configuration (dev, prod)
- Java 17
- Spring Boot 3.1.1
- Spring Web, Spring Data JPA, Spring WebSocket
- MySQL
- Lombok
- Maven
- Frontend: React
private-chat-app/
├── src/
│ ├── main/
│ │ ├── java/com/chatapp/
│ │ │ ├── controllers/ # REST and WebSocket controllers
│ │ │ ├── services/ # Business logic
│ │ │ ├── repositories/ # JPA repositories
│ │ │ ├── entities/ # JPA entities (User, Message)
│ │ │ ├── DTO/ # Data Transfer Objects
│ │ │ ├── payloads/ # Request/response payloads
│ │ │ ├── helpers/ # Utility classes
│ │ │ └── configs/ # CORS, WebSocket configs
│ │ └── resources/
│ │ ├── application.properties
│ │ ├── application-dev.properties
│ │ └── application-prod.properties
│ └── test/
│ └── java/com/chatapp/ # Test classes
├── pom.xml
└── README.md
id
(int, PK)username
(String, unique, required)password
(String, required)image
(String, required)joinDate
(Timestamp)
id
(int, PK)sender
(User, FK)receiver
(User, FK)content
(String)timestamp
(Timestamp)
All endpoints are prefixed with /api/v1
.
POST /register
— Register a new userPOST /login
— Login (session-based)GET /getUser/{userId}
— Get user by IDGET /search/{username}
— Search users by username
GET /chatStarted
— Get users with whom the logged-in user has started chatsGET /chatStarted/{userId}
— Get chat list for a specific userGET /get-my-message/{userId}
— Get messages for a userGET /get-our-message/{senderId}/{receiverId}
— Get messages between two usersPOST /addMessage
— Add a new message
- Session is managed via HTTP session (not JWT). Ensure your frontend supports cookies/session.
- WebSocket endpoint:
/ws
(configured inWebSocketConfig.java
) - Uses STOMP protocol
- Send message: client sends to
/app/chat
- Receive message: client subscribes to
/user/queue/message
- See Spring WebSocket Guide for integration details
- application.properties: Common settings (port, profile)
- application-dev.properties: Development DB config (local MySQL)
- application-prod.properties: Production DB config (e.g., Railway)
Example (dev):
spring.datasource.url=jdbc:mysql://localhost:3306/private-chat-app
spring.datasource.username=root
spring.datasource.password=
spring.jpa.hibernate.ddl-auto=update
Set the active profile via environment variable ENV
(defaults to dev
).
- Java 17+
- Maven
- MySQL (local or remote)
- Clone the repository
git clone <this-repo-url> cd private-chat-app
- Configure the database
- Update
src/main/resources/application-dev.properties
orapplication-prod.properties
with your DB credentials.
- Update
- Build and run
The backend will start on http://localhost:1234 by default.
mvn clean install mvn spring-boot:run
- Use the private-chat-app-react repository for the UI.
- Ensure both backend and frontend are running and configured to communicate (CORS is enabled in backend).
- The frontend should connect to the backend REST API and WebSocket endpoint (
/ws
).
Pull requests are welcome! For major changes, please open an issue first to discuss what you would like to change.
This project is open source and available under the MIT License.
This repository contains the back-end codebase for the Private Chat App, built using Java Spring Boot. The application provides APIs for handling user authentication, message storage, and real-time communication.
- User Authentication: Secure login and registration system to authenticate users.
- Real-time Communication: API endpoints for real-time messaging between users.
- Data Persistence: Utilizes Spring JPA and MySQL for data storage and management.
-
Clone the repository:
git clone https://github.com/ShubratoDn/private-chat-app-java.git
-
Import the project into your preferred Java IDE (e.g., IntelliJ IDEA, Eclipse).
-
Set up a MySQL database and configure the database connection in
application.properties
. -
Build and run the application.
-
Access the API endpoints for integrating with the front end.
Contributions are welcome! Please fork the repository and submit a pull request with your changes.
This project is licensed under the MIT License. See the LICENSE file for details.