{"id":31829524,"url":"https://github.com/stackthecode/messaging-app","last_synced_at":"2026-05-15T22:03:05.134Z","repository":{"id":316011300,"uuid":"1028133187","full_name":"StackTheCode/messaging-app","owner":"StackTheCode","description":"Real Time messaging app with different features developed on Spring Boot (Cortex)","archived":false,"fork":false,"pushed_at":"2025-10-02T19:06:25.000Z","size":87,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"master","last_synced_at":"2025-10-02T21:09:34.097Z","etag":null,"topics":["java","jwt","messaging","spring-boot","websocket"],"latest_commit_sha":null,"homepage":"https://messaging-frontend-fj7p.vercel.app","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/StackTheCode.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2025-07-29T04:54:10.000Z","updated_at":"2025-10-02T19:06:29.000Z","dependencies_parsed_at":"2025-09-22T07:24:10.615Z","dependency_job_id":null,"html_url":"https://github.com/StackTheCode/messaging-app","commit_stats":null,"previous_names":["stackthecode/messaging-app"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/StackTheCode/messaging-app","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/StackTheCode%2Fmessaging-app","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/StackTheCode%2Fmessaging-app/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/StackTheCode%2Fmessaging-app/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/StackTheCode%2Fmessaging-app/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/StackTheCode","download_url":"https://codeload.github.com/StackTheCode/messaging-app/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/StackTheCode%2Fmessaging-app/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":279008619,"owners_count":26084480,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-10-11T02:00:06.511Z","response_time":55,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["java","jwt","messaging","spring-boot","websocket"],"created_at":"2025-10-11T20:28:23.185Z","updated_at":"2025-10-11T20:28:23.989Z","avatar_url":"https://github.com/StackTheCode.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"# ⚙️ The backend implements a real-time chat system using Spring Boot + WebSockets (STOMP) + REST APIs + JPA.\nMessages can include text or files, support read/unread status, and are persisted in the database.\n\n\nThis is the **backend** for a real-time chat application.  \nIt’s built with **Spring Boot** and provides secure APIs and WebSocket connections for instant communication. The backend takes care of authentication, message delivery, and storing chat history so the frontend (React + TailwindCSS) can focus on the user experience.  \n\n---\n\n## ✨ What this backend does\n- Handles **real-time messaging** through WebSockets with \u003c200ms latency\n- Provides **REST APIs** for authentication, user management, and sessions\n- Uses **JWT tokens** for secure login and multi-device access\n- Stores messages and sessions in a **PostgreSQL database**\n- Scales to support thousands of concurrent users\n- Works seamlessly with the React frontend (separate repo)\n\n---\n\n## 🛠 Tech Stack\n- **Spring Boot** (REST + WebSocket)\n- **PostgreSQL** for persistence\n- **JWT** for authentication\n- **Maven** for dependency management\n- **Docker** for containerization\n- **Render / AWS** for deployment\n\n---\n\n## 1. Message Entity\nRepresents a chat message stored in the database.\n\nFields\n\n- id → Primary key (auto-generated).\n\n\n- sender → User who sends the message.\n\n\n- recipient → User who receives the message (nullable for public messages).\n\n\n- content → Text content of the message.\n\n\n- fileName → Optional file name if a file is attached.\n\n\n- timestamp → Time the message was sent.\n\n\n- messageType → Enum (TEXT, IMAGE, FILE, etc.).\n\n\n- isRead → Whether recipient has read the message.\n\n\n---\n\n## 2. MessageController\nProvides both REST endpoints and WebSocket endpoints for chat.\n\n| Method   | Endpoint                                    | Description                               |\n| -------- | ------------------------------------------- | ----------------------------------------- |\n| `GET`    | `/api/messages/history/{userId}/{user2Id}`  | Get chat history between two users.       |\n| `DELETE` | `/api/messages/history/{user1Id}/{user2Id}` | Clear chat history between two users.     |\n| `DELETE` | `/api/messages/{messageId}`                 | Delete a single message (only by sender). |\n\n\n\n\n\n# WebSocket Endpoints\n\n- /app/chat.send → Send message (STOMP).\n\n- /app/chat.typing → Send typing indicator.\n\n\n\n## WebSocket Subscriptions\n\n/user/{userId}/queue/messages → Private user queue for receiving messages.\n\n/user/{userId}/queue/typing → Private queue for typing status.\n\n/topic/chat → Public chat broadcast.\n\n/topic/delete → Notify clients when a message is deleted.\n\n---\n\n\n## 3. MessageService\n\nBusiness logic for handling chat.\n\nKey Methods:\n\n- saveMessage(Message msg) → Saves a new message to DB.\n\n- deleteMessage(Long messageId, Long userId) → Deletes a message if current user is sender.\n\n - clearChatHistory(Long user1Id, Long user2Id) → Deletes all messages between two users.\n\n- userCanAccessMessage(Long messageId, Long userId) → Verifies if user can access a message.\n\n\n\n\n\n---\n\n\n\n## 4. Messaging Flow\n   Sending a Message\n\nUser sends message via WebSocket → /app/chat.send.\n\nMessageController builds a Message object and persists it.\n\nSaved message is mapped into a MessageDTO (with generated ID).\n\nMessage is delivered to:\n\nRecipient’s private queue → /user/{recipientId}/queue/messages.\n\nSender’s own queue → /user/{senderId}/queue/messages.\n\n.....................................................................................\n\nReceiving Messages\n\nClients subscribe to /user/{id}/queue/messages to receive private messages.\n\nClients subscribe to /topic/chat for public messages.\n\n.....................................................................................\n\nTyping Indicator\n\nClient sends typing status via /app/chat.typing.\n\nRecipient receives it on /user/{recipientId}/queue/typing.\n\n.....................................................................................\n\nDeleting a Message\n\nSender issues DELETE  :  /api/messages/{messageId}.\n\nMessageService verifies ownership.\n\nIf deleted → backend broadcasts /topic/delete with {id: messageId} so UIs can remove it in real-time.\n\n\n---\n\n\n## 5. User Entity\nRepresents a chat message stored in the database.\n\nFields:\n\n- id → Primary key (auto-generated).\n\n- username → Unique username for login and display.\n\n- email → Unique email address.\n\n- password → Hashed password (nullable for OAuth users).\n\n- role → Role of the user (e.g., USER, ADMIN).\n\n- googleId → Optional field for Google OAuth authentication.\n\n- createdAt → Date when the user was registered.\n\n- updatedAt → Date of the last profile update.\n\n---\n## 5. User Controller\n\n| Method   | Endpoint                                | Description                                  |\n| -------- | --------------------------------------- | -------------------------------------------- |\n| `GET`    | `/api/users/{id}`                       | Get user by ID.                              |\n| `GET`    | `/api/users/username/{username}`        | Get user by username.                        |\n| `GET`    | `/api/users/email/{email}`              | Get user by email.                           |\n| `GET`    | `/api/users/search?username={username}` | Search users by username (case-insensitive). |\n| `POST`   | `/api/users/register`                   | Register a new user.                         |\n| `POST`   | `/api/users/oauth/google`               | Register/Login user via Google OAuth.        |\n| `PUT`    | `/api/users/{id}`                       | Update user details.                         |\n| `DELETE` | `/api/users/{id}`                       | Delete user account.                         |\n\n---\n## 6. User Service\n\n# Contains the business logic for user management.\n\nKey Methods\n\n - loadUserByUsername(String username) → Loads a user for authentication (used by Spring Security).\n\n - getUserIdByUsername(String username) → Retrieves user ID by username.\n\n - registerUser(User user) → Registers a new user with validation.\n\n - findByEmail(String email) → Finds user by email.\n\n- findByUsername(String username) → Finds user by username.\n\n - findByGoogleId(String googleId) → Finds user registered via Google.\n\n - updateUser(Long id, User user) → Updates existing user details.\n\n - deleteUser(Long id) → Deletes a user account.\n\n\n\n\n\n---\n\n## 🚀 Getting Started\n\nClone the repo and build the project:\n\n```bash\ngit clone https://github.com/your-username/realtime-chat-backend.git\ncd realtime-chat-backend\n./mvnw clean install\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstackthecode%2Fmessaging-app","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fstackthecode%2Fmessaging-app","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstackthecode%2Fmessaging-app/lists"}