This example demonstrates devloop managing a microservices architecture with multiple Go services, shared libraries, and an API gateway.
- API Gateway: Routes requests to appropriate microservices (port 20201)
- Auth Service: Handles authentication and JWT tokens (port 20202)
- User Service: Manages user data and profiles (port 20203)
- Shared Libraries: Common utilities and types used across services
- Go 1.20 or higher
- devloop installed (
go install github.com/panyam/devloop@latest)
-
Install dependencies:
make deps
-
Run with devloop:
make run # Or directly: devloop -c .devloop.yaml -
Test the services:
# Health check curl http://localhost:20201/health # Get auth token curl -X POST http://localhost:20201/auth/login \ -H "Content-Type: application/json" \ -d '{"username":"demo","password":"demo123"}' # Get user info (requires token from above) curl http://localhost:20201/users/123 \ -H "Authorization: Bearer <token>"
┌─────────────┐ ┌─────────────┐ ┌─────────────┐
│ Client │────▶│ API Gateway │────▶│Auth Service │
│ │ │ :20201 │ │ :20202 │
└─────────────┘ └──────┬──────┘ └─────────────┘
│
▼
┌─────────────┐ ┌─────────────┐
│User Service │ │ Shared │
│ :20203 │────▶│ Libraries │
└─────────────┘ └─────────────┘
- API Gateway routes
/auth/*to Auth Service - API Gateway routes
/users/*to User Service - Services communicate via HTTP/REST
- Shared libraries provide common types and utilities
-
Modify shared libraries (
shared/types.go):- Add a new field to the User struct
- Watch all services rebuild automatically
-
Update the auth service (
auth-service/main.go):- Change the JWT expiration time
- Only the auth service restarts
-
Add a new endpoint to any service:
- The specific service rebuilds
- Other services remain running
- Each service has its own log prefix for easy identification
- Services are started in dependency order (shared → services → gateway)
- Use
run_on_init: trueensures all services start immediately - Process groups ensure clean shutdown of all related processes
- Port conflicts: Ensure ports 20201-20203 are available
- Service discovery: Services use hardcoded ports for simplicity
- Compilation errors: Check shared library changes don't break services