A simple three-service microservice application with JWT authentication, built with Go, gRPC, and Docker.
- Auth Service: Handles user registration, login, and JWT token validation
- User Service: Manages user profiles and information
- Post Service: Handles post creation, retrieval, and deletion
- Separate Databases: Each service has its own PostgreSQL database
- gRPC: Internal service-to-service communication
- HTTP REST API: External client communication
POST /register- Register new userPOST /login- Login and get JWT token
GET /users/:id- Get user detailsPUT /users/:id- Update user information
POST /post- Create new postGET /post/:id- Get post detailsGET /user/:id/posts- Get user's postsDELETE /post/:id- Delete post
- Docker and Docker Compose
- Go 1.19+ (for local development)
- Make (optional, but recommended)
# Clone the repository
git clone <repository-url>
cd microservices-app
# Setup and run all services
make setup
make run
# Or simply run everything with one command
make all- Create environment file:
cp .env.example .env- Build and run services:
docker-compose up --build- Verify services are running:
curl http://localhost:8080/healthCreate a .env file with the following variables:
POSTGRES_USER=postgres
POSTGRES_PASSWORD=password
JWT_SECRET=your-super-secret-jwt-key
AUTH_HTTP_PORT=8080
USER_HTTP_PORT=8081
POST_HTTP_PORT=8082curl -X POST http://localhost:8080/register \
-H "Content-Type: application/json" \
-d '{
"email": "user@example.com",
"password": "password",
"name": "John Doe"
}'curl -X POST http://localhost:8080/login \
-H "Content-Type: application/json" \
-d '{
"email": "user@example.com",
"password": "password"
}'curl -X POST http://localhost:8082/posts \
-H "Content-Type: application/json" \
-H "Authorization: <your-jwt-token>" \
-d '{
"title": "My First Post",
"content": "This is my first post content"
}'curl -X GET http://localhost:8082/users/<user-id>/posts \
-H "Authorization: <your-jwt-token>"| Command | Description |
|---|---|
make help |
Show all available commands |
make all |
Build and run all services |
make build |
Build all Docker images |
make run |
Start all services |
make stop |
Stop all services |
make clean |
Stop and remove all containers and volumes |
make logs |
Show logs from all services |
make status |
Show service status |
make test |
Run tests for all services |
make lint |
Lint all Go code |
make protoc |
Generate gRPC code from proto files |
make db-shell |
Connect to database (specify DB=service-name) |
make logs-auth # Show auth service logs
make logs-user # Show user service logs
make logs-post # Show post service logs
make restart-single SERVICE=auth-service # Restart specific service
make build-single SERVICE=user-service # Build specific service- Install dependencies:
make dev-deps- Generate gRPC code:
make protoc- Build locally:
make dev-buildmicroservices-app/
├── auth-service/
│ ├── proto/
│ ├── main.go
│ └── Dockerfile
├── user-service/
│ ├── proto/
│ ├── main.go
│ └── Dockerfile
├── post-service/
│ ├── proto/
│ ├── main.go
│ └── Dockerfile
├── docker-compose.yml
├── Makefile
└── .env
Each service has its own PostgreSQL database:
| Service | Database | Host Port |
|---|---|---|
| Auth | auth_db | 5432 |
| User | user_db | 5433 |
| Post | post_db | 5434 |
Connect to a database:
make db-shell DB=auth-db- Update environment variables for production:
# Update .env with production values
JWT_SECRET=very-long-random-production-secret
POSTGRES_PASSWORD=strong-production-password
NODE_ENV=production- Deploy:
make deployScale specific services:
make scale SERVICE=auth-service NUM=3Check service health:
make healthView container statistics:
make stats- Port conflicts: Change ports in
.envfile - Database connection errors: Ensure databases are running with
make status - gRPC connection issues: Check service dependencies in docker-compose
View logs for debugging:
make logs
# Or for specific service
make logs-authMIT License