A microservices-based backend for a chat application built with Go.
This project uses a microservices architecture with:
- API Gateway: Routes HTTP and WebSocket requests to appropriate microservices
- User Service: Handles user registration, authentication, and user management
- Message Service: Handles message exchange and storage
- RabbitMQ: Used for asynchronous communication between services
- MongoDB: Used for data storage
- Docker and Docker Compose
- Go 1.21 or higher (for local development)
docker-compose up -dThis will start all the necessary services:
- MongoDB on port 27017
- RabbitMQ on ports 5672 (AMQP) and 15672 (Management UI)
- API Gateway on port 8080
- User Service on port 8081
- Message Service on port 8082
POST /api/register: Register a new userPOST /api/login: Login and receive a JWT token
GET /api/users: Search for usersGET /api/users/:id: Get user detailsGET /api/ws: WebSocket endpoint for real-time messagingGET /api/messages/:UserID: Get message history with another userPOST /api/messages: Send a message via REST API
The application uses JWT tokens for authentication. After logging in, include the token in subsequent requests as follows:
Authorization: Bearer <your-token>
After authenticating, connect to the WebSocket endpoint at /api/ws with the JWT token in the request header. WebSocket messages should be JSON objects with the following format:
{
"receiver_id": "user-id-to-send-message-to",
"content": "Message content"
}