How laminhtam/social-media-web-app works
Main Components
• Frontend: The “social-media-fe” directory is a Next.js project that interacts with the backend via HTTP or WebSocket.
• API Gateway: Acts as a single-entry point for frontend requests and routes them to the appropriate microservices while handling authentication via JWT and other security protocols.
• Auth Service: Manages user authentication and authorization (login, sign-up, token refresh, logout).
• Chat Service: Handles real-time messaging through WebSocket, including managing conversation and message flows.
• Notification Service: Relays notifications to users and supports features such as video calls (one-to-one and group calls) via WebSocket, and integrates with RabbitMQ for message-driven communication.
• Post Service: Manages feeds, posts, comments, reactions, and integrates with both MongoDB (for document-based content) and Neo4j (for relationship-based queries like categories or friend graphs).
• User Service: Manages user-related operations such as friend requests and user profiles.
• Config Server: Centralizes all microservice configuration properties, reading from YAML files.
• Service Registry: Enables service discovery so that microservices can dynamically register and communicate.
Relationships and Data Flow
• The Frontend communicates with the API Gateway.
• The API Gateway authenticates incoming requests and then routes them to the required microservice (Auth, Chat, Post, User, etc.).
• Each microservice registers with the Service Registry and retrieves its configurations from the Config Server.
• For asynchronous communications, services like the Chat and Notification services use RabbitMQ for reliable message brokering.
• Redis is used as a caching layer across several services (e.g., the API Gateway, Auth Service, Notification Service) to improve performance.
• Real-time messaging is enabled via WebSocket on both the frontend and one or more dedicated services (Notification/Chat).
• Databases: MySQL (if used for relational components), MongoDB (in Post Service for storing posts/comments), and Neo4j (for managing graph-based relationships in the Post Service).
Architectural Patterns and Technologies
• Microservices: Each service is self-contained and communicates via RESTful endpoints and messaging queues.
• API Gateway Pattern: Centralizes request routing, authentication, and sometimes caching.
• Service Discovery: Enabled by the Service Registry for dynamic lookup.
• Centralized Configuration: Managed by the Config Server.
• Asynchronous Messaging: Provided via RabbitMQ.
• Real-time Communication: Implemented with WebSocket and Spring WebFlux for reactive, non-blocking operations.
• Caching: Redis is used to cut down on load and improve latency.