A microservices-based messenger backend built with Go, gRPC, PostgreSQL, and Redis.
The system consists of the following services:
- Gateway Service (Port 8000): HTTP API gateway that routes requests to appropriate services
- Auth Service (Ports 50001/8001): Authentication and authorization service
- User Service (Ports 50002/8002): User management service
- Chat Service (Ports 50003/8003): Chat and messaging service
- Subscriber Service (Ports 50004/8004): Subscription and notification service
- Docker and Docker Compose
- Go 1.23.2 or later (for local development)
- Protocol Buffers compiler (protoc)
- Make
git clone <repository-url>
cd messenger# Start all services in development mode
make dev-up
# Or start individual services
make docker-up-user # Start only user service with dependencies# Check service status
docker-compose ps
# View logs
make docker-logs# Gateway service health check
curl http://localhost:8000/health
# User service health check (direct access)
curl http://localhost:8002/health
# Auth service health check (direct access)
curl http://localhost:8001/healthmake dev-up # Start full development environment
make dev-down # Stop development environment
make dev-logs # Show logs from all services
make dev-build # Build all Docker imagesmake build # Build all services
make build-user # Build user service only
make build-auth # Build auth service only
make proto # Generate protobuf filesmake docker-build # Build Docker images
make docker-up # Start services (production mode)
make docker-down # Stop all services
make docker-clean # Clean Docker images and volumes
make docker-migrate # Run database migrationsmake deps # Download Go dependencies
make test # Run tests
make clean # Clean build artifacts
make setup # Setup development environmentmake db-connect # Connect to PostgreSQL
make redis-connect # Connect to RedisAll API endpoints are versioned under /api/v1:
- Health:
GET /health - Authentication:
POST /api/v1/auth/register- Register new userPOST /api/v1/auth/login- User loginPOST /api/v1/auth/refresh- Refresh tokenPOST /api/v1/auth/logout- Logout (requires auth)GET /api/v1/auth/validate- Validate token (requires auth)
- Users:
POST /api/v1/users- Create user (public)GET /api/v1/users/:id- Get user by ID (requires auth)PUT /api/v1/users/:id- Update user (requires auth)DELETE /api/v1/users/:id- Delete user (requires auth)GET /api/v1/users/search- Search users (requires auth)POST /api/v1/users/batch- Get users by IDs (requires auth)
- Chat:
POST /api/v1/chats- Create chat (requires auth)GET /api/v1/chats- List user's chats (requires auth)GET /api/v1/chats/:id- Get chat details (requires auth)POST /api/v1/chats/:id/messages- Send message (requires auth)GET /api/v1/chats/:id/messages- Get chat messages (requires auth)POST /api/v1/chats/join- Join chat (requires auth)POST /api/v1/chats/leave- Leave chat (requires auth)
- Friends/Subscribers:
POST /api/v1/friends/requests- Make friend request (requires auth)POST /api/v1/friends/requests/confirm- Confirm friend request (requires auth)POST /api/v1/friends/requests/decline- Decline friend request (requires auth)GET /api/v1/friends/requests- Get friend requests (requires auth)GET /api/v1/friends- Get user's friends (requires auth)DELETE /api/v1/friends- Remove friend (requires auth)
Each service exposes both gRPC and HTTP endpoints:
- Auth Service: gRPC(50001), HTTP(8001)
- User Service: gRPC(50002), HTTP(8002)
- Chat Service: gRPC(50003), HTTP(8003)
- Subscriber Service: gRPC(50004), HTTP(8004)
- PostgreSQL: localhost:5432
- Redis: localhost:6379
- Adminer (Database UI): http://localhost:8080
Copy .env.example to .env and modify as needed:
cp .env.example .envKey configuration options:
- Database connections
- Redis settings
- JWT secrets
- Service ports
- Logging levels
Development (docker-compose.override.yml):
- All services enabled by default
- Hot reload capabilities
- Debug logging
- Exposed ports for direct access
Production (docker-compose.yml):
- Services organized with profiles
- Optimized for production deployment
- Health checks enabled
- Resource limits applied
Migrations are automatically run when starting the development environment. To run manually:
make docker-migrateEach service has its own database:
messenger_auth- Auth servicemessenger_user- User servicemessenger_chat- Chat servicemessenger_subscriber- Subscriber service
# Register a new user
curl -X POST http://localhost:8000/api/v1/auth/register \
-H "Content-Type: application/json" \
-d '{"email": "[email protected]", "password": "password123"}'
# Login
curl -X POST http://localhost:8000/api/v1/auth/login \
-H "Content-Type: application/json" \
-d '{"email": "[email protected]", "password": "password123"}'
# Refresh token
curl -X POST http://localhost:8000/api/v1/auth/refresh \
-H "Content-Type: application/json" \
-H "Authorization: Bearer <refresh_token>" \
-d '{}'
# Logout
curl -X POST http://localhost:8000/api/v1/auth/logout \
-H "Authorization: Bearer <access_token>"
# Validate token
curl -X GET http://localhost:8000/api/v1/auth/validate \
-H "Authorization: Bearer <access_token>"# Create user (public endpoint)
curl -X POST http://localhost:8000/api/v1/users \
-H "Content-Type: application/json" \
-d '{"name": "John Doe", "email": "[email protected]"}'
# Get user by ID
curl http://localhost:8000/api/v1/users/1 \
-H "Authorization: Bearer <access_token>"
# Update user
curl -X PUT http://localhost:8000/api/v1/users/1 \
-H "Content-Type: application/json" \
-H "Authorization: Bearer <access_token>" \
-d '{"name": "John Updated", "email": "[email protected]"}'
# Search users
curl "http://localhost:8000/api/v1/users/search?query=john" \
-H "Authorization: Bearer <access_token>"# Create a chat
curl -X POST http://localhost:8000/api/v1/chats \
-H "Content-Type: application/json" \
-H "Authorization: Bearer <access_token>" \
-d '{"name": "My Chat Room", "type": "group"}'
# List user's chats
curl http://localhost:8000/api/v1/chats \
-H "Authorization: Bearer <access_token>"
# Send a message
curl -X POST http://localhost:8000/api/v1/chats/1/messages \
-H "Content-Type: application/json" \
-H "Authorization: Bearer <access_token>" \
-d '{"content": "Hello, world!", "type": "text"}'
# Get chat messages
curl http://localhost:8000/api/v1/chats/1/messages \
-H "Authorization: Bearer <access_token>"# Send friend request
curl -X POST http://localhost:8000/api/v1/friends/requests \
-H "Content-Type: application/json" \
-H "Authorization: Bearer <access_token>" \
-d '{"user_id": 2}'
# Get friend requests
curl http://localhost:8000/api/v1/friends/requests \
-H "Authorization: Bearer <access_token>"
# Confirm friend request
curl -X POST http://localhost:8000/api/v1/friends/requests/confirm \
-H "Content-Type: application/json" \
-H "Authorization: Bearer <access_token>" \
-d '{"request_id": 1}'
# Get friends list
curl http://localhost:8000/api/v1/friends \
-H "Authorization: Bearer <access_token>"-
Start development environment:
make dev-up
-
Make changes to code
-
Rebuild specific service:
docker-compose build <service-name> docker-compose up -d <service-name>
-
View logs:
make docker-logs
-
Stop environment:
make docker-down
- Port conflicts: Ensure ports 5432, 6379, 8000-8004, and 50001-50004 are available
- Database connection issues: Wait for PostgreSQL to be fully ready before starting services
- Proto generation fails: Ensure protoc and Go protobuf plugins are installed
- 404 errors: Make sure to use the correct API path with
/api/v1prefix
-
Check service logs:
docker logs messenger-<service-name>
-
Access service containers:
docker exec -it messenger-<service-name> /bin/sh
-
Check database:
make db-connect
-
Test health endpoints:
# Gateway health curl http://localhost:8000/health # Individual service health (if exposed) curl http://localhost:8002/health # User service curl http://localhost:8001/health # Auth service
# Complete reset
make docker-down
make docker-clean
docker-compose up -d