{"id":25624008,"url":"https://github.com/morteza363831/spring-boot-chat-messenger","last_synced_at":"2025-10-30T22:43:12.087Z","repository":{"id":261101766,"uuid":"870729544","full_name":"Morteza363831/spring-boot-chat-messenger","owner":"Morteza363831","description":"This is a spring boot chat messenger","archived":false,"fork":false,"pushed_at":"2025-08-11T20:32:24.000Z","size":372,"stargazers_count":18,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-08-11T22:14:59.620Z","etag":null,"topics":["html-css-javascript","java","java17-spring-boot","springboot","websocket"],"latest_commit_sha":null,"homepage":"","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/Morteza363831.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}},"created_at":"2024-10-10T15:03:20.000Z","updated_at":"2025-08-11T20:32:20.000Z","dependencies_parsed_at":"2024-11-04T18:26:34.899Z","dependency_job_id":"e18ea1d6-57a8-4eb4-85fc-6157dd2ad5d5","html_url":"https://github.com/Morteza363831/spring-boot-chat-messenger","commit_stats":null,"previous_names":["morteza363831/spring-boot-chat-messenger"],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/Morteza363831/spring-boot-chat-messenger","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Morteza363831%2Fspring-boot-chat-messenger","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Morteza363831%2Fspring-boot-chat-messenger/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Morteza363831%2Fspring-boot-chat-messenger/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Morteza363831%2Fspring-boot-chat-messenger/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Morteza363831","download_url":"https://codeload.github.com/Morteza363831/spring-boot-chat-messenger/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Morteza363831%2Fspring-boot-chat-messenger/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":281896642,"owners_count":26580138,"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-30T02:00:06.501Z","response_time":61,"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":["html-css-javascript","java","java17-spring-boot","springboot","websocket"],"created_at":"2025-02-22T12:17:34.151Z","updated_at":"2025-10-30T22:43:12.072Z","avatar_url":"https://github.com/Morteza363831.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Spring Boot Chat Messenger - Enterprise Microservices Architecture\n\n## 📌 Overview\n\nThe Spring Boot Chat Messenger is a production-ready, enterprise-grade real-time chat application built using a microservices architecture with Spring Boot. It implements the Command Query Responsibility Segregation (CQRS) pattern, event-driven design, and WebSocket with STOMP protocol for instant messaging. The application emphasizes scalability, comprehensive security, and advanced search capabilities, making it suitable for enterprise-level deployments.\n\n---\n\n## ✨ Key Features\n\n### 🔥 Real-time Communication\n- WebSocket with STOMP protocol for seamless, instant messaging.\n- Session-based chat between users with support for one-to-one communication.\n- Message broadcasting via `/topic` and `/queue` destinations.\n- WebSocket connection endpoint: `/chat`.\n\n### 🏗️ Microservices Architecture\n- **messenger-core** (Port: 9090): Main API and WebSocket service.\n- **messenger-command** (Port: 8052): Handles write operations.\n- **messenger-query** (Port: 8051): Manages read operations.\n- **messenger-utilities**: Shared models and utilities across services.\n\n### 🔐 Enterprise Security\n- JWT-based authentication with custom filters.\n- Role-based access control (USER, ADMIN roles).\n- Method-level security using `@PreAuthorize` annotations.\n- AES-GCM encryption for message content.\n- CORS configuration for secure cross-origin requests.\n\n### 📊 Event-Driven Architecture\n- Apache Kafka for event streaming and synchronization.\n- CQRS pattern for separation of read and write operations.\n- Event sourcing to ensure consistency across services.\n- Dual database support: MySQL for queries and MS SQL Server for commands.\n\n### 🔍 Advanced Search \u0026 Analytics\n- Elasticsearch integration for efficient message search.\n- Real-time indexing of messages via Kafka events.\n- Optimized read queries with dedicated read models.\n\n---\n\n## 🏗 Architecture Diagram\n\n```\n┌─────────────────┐    ┌─────────────────┐    ┌─────────────────┐\n│   messenger-    │    │   messenger-    │    │   messenger-    │\n│     core        │    │    command      │    │     query       │\n│   (Port 9090)   │    │   (Port 8052)   │    │   (Port 8051)   │\n│                 │    │                 │    │                 │\n│ • REST APIs     │    │ • Write Ops     │    │ • Read Ops      │\n│ • WebSocket     │◄──►│ • MySQL         │    │ • MySQL         │\n│ • JWT Auth      │    │ • MS SQL        │    │ • Elasticsearch │\n│ • H2 Database   │    │ • Kafka Consumer│    │ • Kafka Consumer│\n└─────────────────┘    └─────────────────┘    └─────────────────┘\n         │                       │                       │\n         └───────────────────────┼───────────────────────┘\n                                 │\n                    ┌─────────────────┐\n                    │  Apache Kafka   │\n                    │   (Port 9092)   │\n                    │                 │\n                    │ • Event Stream  │\n                    │ • Command/Query │\n                    │ • Sync Events   │\n                    └─────────────────┘\n```\n\n---\n\n## 🛠 Technology Stack\n\n### Backend Technologies\n- **Java 17**: Latest LTS version for robust performance.\n- **Spring Boot 3.3.4**: Enterprise-grade framework for microservices.\n- **Spring Security**: Authentication and authorization.\n- **Spring WebSocket**: Real-time communication with STOMP.\n- **Spring Data JPA**: Data persistence and ORM.\n- **Spring Kafka**: Event streaming and messaging.\n\n### Databases\n- **H2**: In-memory database for development and testing.\n- **MySQL**: Primary database for query operations.\n- **MS SQL Server**: Database for command operations.\n- **Elasticsearch**: Search and analytics engine.\n\n### Message Broker\n- **Apache Kafka**: Event streaming platform.\n- **Zookeeper**: Coordination service for Kafka.\n\n### Tools \u0026 Libraries\n- **MapStruct**: Simplified object mapping.\n- **Lombok**: Reduction of boilerplate code.\n- **JWT (jjwt)**: Token-based authentication.\n- **Jackson**: JSON processing.\n- **SpringDoc OpenAPI**: Interactive API documentation.\n- **Docker \u0026 Docker Compose**: Containerization for deployment.\n- **Maven**: Multi-module build system.\n- **GitHub Actions**: CI/CD pipeline automation.\n\n---\n\n## 📊 Data Models\n\n### Core Entities\n\n#### UserEntity\n```java\npublic class UserEntity {\n    UUID id;\n    String username;\n    String email;\n    String firstName;\n    String lastName;\n    String authorities;\n    String password;\n    boolean enabled;\n}\n```\n\n#### SessionEntity\n```java\npublic class SessionEntity {\n    UUID id;\n    UserEntity user1;\n    UserEntity user2;\n}\n```\n\n#### MessageEntity\n```java\npublic class MessageEntity {\n    UUID id;\n    String content;\n    UUID sessionId;\n    String encryptedAesKey;\n}\n```\n\n---\n\n## 🚀 Quick Start\n\n### Prerequisites\n- Java 17+\n- Maven 3.6+\n- Docker \u0026 Docker Compose\n- MySQL 8.0+\n- MS SQL Server (optional for command database)\n- Elasticsearch (optional for search functionality)\n\n### 1. Clone Repository\n```bash\ngit clone https://github.com/Morteza363831/spring-boot-chat-messenger.git\ncd spring-boot-chat-messenger\n```\n\n### 2. Start Infrastructure\n```bash\n# Start Kafka \u0026 Zookeeper\ndocker-compose -f docker/kafka-compose.yml up -d\n\n# Start MySQL\ndocker-compose -f docker/docker-compose.yml up -d\n\n# Optional: Start Elasticsearch\ndocker-compose -f docker/elastic-compose.yml up -d\n```\n\n### 3. Build \u0026 Run Services\n```bash\n# Build all modules\nmvn clean install\n\n# Start messenger-core (Main API)\ncd messenger-core\nmvn spring-boot:run\n\n# Start messenger-command (Write Service)\ncd ../messenger-command\nmvn spring-boot:run\n\n# Start messenger-query (Read Service)\ncd ../messenger-query\nmvn spring-boot:run\n```\n\n### 4. Access Services\n- **Main API**: `http://localhost:9090`\n- **API Documentation**: `http://localhost:9090/messenger-swagger`\n- **H2 Console**: `http://localhost:9090/h2-console`\n- **Kafka UI**: `http://localhost:8090`\n\n---\n\n## 📡 API Endpoints\n\n### Authentication\n```\nPOST /api/v1/auth/token          # Obtain JWT token\nPOST /api/v1/users/register      # Register new user\n```\n\n### User Management\n```\nGET    /api/v1/users             # Retrieve all users\nGET    /api/v1/users/{username}  # Retrieve user by username\nPUT    /api/v1/users/{username}  # Update user details\nDELETE /api/v1/users/delete      # Delete user\n```\n\n### Session Management\n```\nPOST   /api/v1/sessions          # Create chat session\nGET    /api/v1/sessions          # Retrieve user sessions\nDELETE /api/v1/sessions/{id}     # Delete session\n```\n\n### Message Operations\n```\nPOST   /api/v1/messages          # Send message\nGET    /api/v1/messages/{sessionId} # Retrieve session messages\n```\n\n### WebSocket Connection\n```javascript\n// Connect to WebSocket\nconst socket = new SockJS('/chat');\nconst stompClient = Stomp.over(socket);\n\n// Subscribe to messages\nstompClient.subscribe('/topic/messages/' + sessionId, function(message) {\n    // Handle incoming message\n});\n\n// Send message\nstompClient.send('/app/chat/' + sessionId, {}, JSON.stringify(messageData));\n```\n\n---\n\n## 🔧 Configuration\n\n### Application Ports\n- **messenger-core**: 9090\n- **messenger-command**: 8052\n- **messenger-query**: 8051\n- **Kafka**: 9092\n- **Kafka UI**: 8090\n- **MySQL**: 3306\n- **MS SQL**: 1433\n\n### Database Configuration\n```properties\n# messenger-core (H2)\nspring.datasource.url=jdbc:h2:./data/testdb\n\n# messenger-command (MySQL + MS SQL)\nspring.datasource.mysql.url=jdbc:mysql://localhost:3306/messengerDevDb\nspring.datasource.mssql.url=jdbc:sqlserver://localhost:1433;database=messengerReadDevDb\n\n# messenger-query (MySQL)\nspring.datasource.url=jdbc:mysql://localhost:3306/messengerDevDb\n```\n\n### Kafka Configuration\n```properties\nspring.kafka.bootstrap-servers=localhost:9092\nspring.kafka.consumer.value-deserializer=JsonDeserializer\nspring.kafka.producer.value-serializer=JsonSerializer\n```\n\n---\n\n## 🔄 Event Flow\n\n### Command Flow (Write Operations)\n1. Client → REST API → `messenger-core`\n2. `messenger-core` → Kafka Producer → Command Topic\n3. `messenger-command` → Kafka Consumer → Database Write\n4. `messenger-command` → Kafka Producer → Sync Topic\n\n### Query Flow (Read Operations)\n1. Client → REST API → `messenger-core`\n2. `messenger-core` → Feign Client → `messenger-query`\n3. `messenger-query` → Read Database → Response\n\n### Real-time Flow (WebSocket)\n1. Client → WebSocket → `messenger-core`\n2. `messenger-core` → Message Broker → All Connected Clients\n\n---\n\n## 🔐 Security Features\n\n### JWT Authentication\n```java\n@PreAuthorize(\"isMatch(#username) || hasAccess('ROLE_ADMIN')\")\npublic ResponseEntity\u003c?\u003e updateUser(@PathVariable String username) {\n    // Method implementation\n}\n```\n\n### Message Encryption\n- AES-GCM encryption for message content.\n- Unique encryption keys per message.\n- Secure key storage in the database.\n\n### CORS Configuration\n```java\n@Bean\npublic CorsConfigurationSource corsConfigurationSource() {\n    CorsConfiguration config = new CorsConfiguration();\n    config.setAllowCredentials(true);\n    config.addAllowedOrigin(\"*\");\n    config.addAllowedHeader(\"*\");\n    config.addAllowedMethod(\"*\");\n    return source;\n}\n```\n\n---\n\n## 📈 Monitoring \u0026 Observability\n\n- **Kafka UI**: Monitor message broker at `http://localhost:8090`.\n- **H2 Console**: Inspect database at `http://localhost:9090/h2-console`.\n- **Spring Boot Actuator**: Access health and metrics endpoints.\n- **Swagger UI**: Test APIs at `http://localhost:9090/messenger-swagger`.\n\n### Logging Configuration\n```properties\nlogging.level.com.example.messenger=error\nlogging.level.org.springframework.kafka=info\n```\n\n---\n\n## 🧪 Testing\n\n### Run Tests\n```bash\n# Run all tests\nmvn test\n\n# Run specific module tests\ncd messenger-core \u0026\u0026 mvn test\ncd messenger-command \u0026\u0026 mvn test\ncd messenger-query \u0026\u0026 mvn test\n```\n\n### Integration Testing\n- **TestContainers**: For database testing.\n- **Kafka Test**: For event streaming validation.\n- **WebSocket Test**: For real-time communication testing.\n\n---\n\n## 🚀 Deployment\n\n### Docker Deployment\n```bash\n# Build Docker images\ndocker build -t messenger-core ./messenger-core\ndocker build -t messenger-command ./messenger-command\ndocker build -t messenger-query ./messenger-query\n\n# Run with Docker Compose\ndocker-compose up -d\n```\n\n### Production Configuration\n```properties\n# Use external databases\nspring.datasource.url=${DATABASE_URL}\nspring.kafka.bootstrap-servers=${KAFKA_SERVERS}\n\n# Security settings\njwt.secret=${JWT_SECRET}\nencryption.key=${ENCRYPTION_KEY}\n```\n\n---\n\n## 🔮 Future Roadmap\n\n### Phase 1: UI Development\n- Develop a React/Angular-based frontend.\n- Create a mobile app using React Native.\n- Implement a real-time chat interface.\n\n### Phase 2: Enhanced Features\n- Add file sharing capabilities.\n- Support group chat functionality.\n- Include message reactions and replies.\n- Implement user presence indicators.\n\n### Phase 3: Advanced Security\n- Introduce end-to-end encryption.\n- Integrate OAuth2 for authentication.\n- Implement rate limiting and message retention policies.\n\n### Phase 4: Scalability\n- Transition to RabbitMQ for message brokering.\n- Add Redis caching for performance optimization.\n- Implement load balancing and Kubernetes deployment.\n\n---\n\n## 🤝 Contributing\n\n1. Fork the repository.\n2. Create a feature branch (`git checkout -b feature/amazing-feature`).\n3. Commit changes (`git commit -m 'Add amazing feature'`).\n4. Push to the branch (`git push origin feature/amazing-feature`).\n5. Open a Pull Request.\n\n### Development Guidelines\n- Adhere to Clean Code principles.\n- Write comprehensive unit and integration tests.\n- Update documentation for all changes.\n- Follow conventional commit messages.\n\n---\n\n## 👥 Contributors\n\nThanks to these awesome people for contributing:\n\n| [\u003cimg src=\"https://github.com/morteza363831.png\" width=\"100px\" alt=\"Morteza Mahdi Zadeh\"/\u003e](https://github.com/morteza363831) |                                                                                                       [\u003cimg src=\"https://github.com/8Whoknow3.png\" width=\"100px\" alt=\"MohammadReza Asgari\"/\u003e](https://github.com/8Whoknow3) |                                                                                                                     [\u003cimg src=\"https://github.com/alisedig.png\" width=\"100px\" alt=\"Ali Sedighi\"/\u003e](https://github.com/alisedig) |                                                                                                                                     [\u003cimg src=\"https://github.com/moonwinee.png\" width=\"100px\" alt=\"Soheil Nouhi\"/\u003e](https://github.com/moonwinee) |                                                                                                                                     [\u003cimg src=\"https://github.com/anemo113.png\" width=\"100px\" alt=\"Ehsan Shahsavari\"/\u003e](https://github.com/anemo113) |                                                                                                                                      [\u003cimg src=\"https://github.com/username.png\" width=\"100px\" alt=\"name\"/\u003e](https://github.com/username) |                                                                                                                 \n| :----------------------------------------------------------------------------------------------------------------------------: | :----------------------------------------------------------------------------------------------------------------------------: | :----------------------------------------------------------------------------------------------------------------------------: | :----------------------------------------------------------------------------------------------------------------------------: |:----------------------------------------------------------------------------------------------------------------------------: | :----------------------------------------------------------------------------------------------------------------------------: |\n| [Morteza Mahdi Zadeh](https://github.com/morteza363831) |                                                                                                                                                                                 [MohammadReza Asgari](https://github.com/8Whoknow3) |                                                                                                                                                                                      [Ali Sedighi](https://github.com/alisedig) |                                                                                                                                                                                                  [Soheil Nouhi](https://github.com/moonwinee) |                                                                                                                                                                                                   [Ehsan Shahsavari](https://github.com/anemo113) |                                                                                                                                                                                                   [Danial khalaji](https://github.com/Danielkhj) |\n\n\n---\n\n## 📄 License\n\nThis project is licensed under the MIT License. See the [LICENSE](LICENSE) file for details.\n\n---\n\n## 📞 Support \u0026 Contact\n\n- **Email**: [morteza363831official@gmail.com](mailto:morteza363831official@gmail.com)\n- **Telegram**: [@m_mhzd](https://t.me/m_mhzd)\n- **LinkedIn**: [Morteza Mahdi Zadeh](https://www.linkedin.com/in/your-linkedin-profile)\n- **Issues**: [GitHub Issues](https://github.com/Morteza363831/spring-boot-chat-messenger/issues)\n- **Discussions**: [GitHub Discussions](https://github.com/Morteza363831/spring-boot-chat-messenger/discussions)\n\n⭐ **Star this repository** if you find it helpful!\n\nHappy Coding! 🚀\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmorteza363831%2Fspring-boot-chat-messenger","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmorteza363831%2Fspring-boot-chat-messenger","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmorteza363831%2Fspring-boot-chat-messenger/lists"}