This document describes the migration from the monolithic server to a microservices architecture using Traefik as the API Gateway.
The application has been split into the following microservices:
- Port: 8083
- Database:
auth_db - Responsibilities:
- User registration and login
- JWT token generation and validation
- User profile management
- Password management
- Endpoints:
POST /auth/register- User registrationPOST /auth/login- User loginPOST /auth/refresh- Token refreshGET /auth/me- Get current userPUT /auth/me- Update user profilePOST /auth/me/password- Change password
- Port: 8084
- Database:
document_db - Responsibilities:
- Document upload and storage
- Document metadata management
- File operations (download, list)
- Document status tracking
- Endpoints:
POST /documents/upload- Upload documentsGET /documents- List user documentsGET /documents/{id}/status- Get document statusGET /documents/{id}/content- Get document contentGET /documents/{id}/download- Download documentPUT /documents/{id}/content- Update document content
- Port: 8085
- Database: None (stateless)
- Responsibilities:
- Orchestrate GenAI requests
- Handle business logic
- Rate limiting
- Communication with GenAI backend
- Endpoints:
POST /genai/process- Process document with AIGET /genai/status/{requestId}- Get processing statusPOST /genai/chat- Chat with AIGET /genai/health- Health check
- Port: 8761
- Responsibilities:
- Service registration and discovery
- Load balancing
- Health monitoring
- Dashboard:
http://localhost:8761
- Ports: 80 (HTTP), 443 (HTTPS), 8080 (Dashboard)
- Responsibilities:
- Request routing
- Load balancing
- SSL termination
- Rate limiting
- Authentication validation
- Dashboard:
http://localhost:8080
- Services communicate via HTTP/REST APIs
- Service discovery through Eureka
- JWT tokens for authentication between services
- All external requests go through Traefik
- Traefik routes requests based on path prefixes:
/auth/*β Authentication Service/documents/*β Document Service/genai/*β GenAI Gateway Service/β Client (React App)
- auth_db: User authentication and profile data
- document_db: Document storage and metadata
- mydb: Legacy database (for backward compatibility)
- Each service has its own database
- No direct database sharing between services
- Data consistency through service APIs
- Centralized authentication in Auth Service
- JWT tokens contain user information
- Token validation in each service
- User ID extraction from tokens for authorization
- Internal service communication via HTTP
- JWT token validation for service calls
- User context propagation via headers
# Start microservices
docker-compose -f docker-compose.microservices.yml up -d
# View logs
docker-compose -f docker-compose.microservices.yml logs -f
# Stop services
docker-compose -f docker-compose.microservices.yml down# Build auth service
cd server/auth-service
./gradlew build
docker build -t auth-service .
# Build document service
cd server/document-service
./gradlew build
docker build -t document-service .
# Build GenAI service
cd server/genai-service
./gradlew build
docker build -t genai-service .
# Build Eureka server
cd server/eureka-server
./gradlew build
docker build -t eureka-server .POST /auth/register
POST /auth/login
POST /auth/refresh
GET /auth/me
PUT /auth/me
POST /auth/me/password
GET /auth/users/{id}
GET /auth/stats
POST /documents/upload
GET /documents
GET /documents/{id}/status
GET /documents/{id}/content
GET /documents/{id}/download
PUT /documents/{id}/content
POST /genai/process
GET /genai/status/{requestId}
POST /genai/chat
GET /genai/health
- Each service exposes
/actuator/healthendpoint - Eureka monitors service health
- Traefik dashboard shows service status
- Centralized logging through Docker
- Service-specific log levels configurable
- Structured logging for better debugging
- Extract authentication logic to Auth Service
- Extract document management to Document Service
- Create GenAI Gateway Service
- Set up Eureka Service Discovery
- Configure Traefik routing
- Implement JWT validation
- Set up load balancing
- Configure SSL/TLS
- Create separate databases
- Migrate data
- Update service configurations
- Test data consistency
- Update client API calls
- Implement new authentication flow
- Test all functionality
- Deploy to production
- Independent scaling of services
- Load balancing across instances
- Resource optimization
- Smaller, focused codebases
- Independent deployments
- Technology flexibility
- Service isolation
- Fault tolerance
- Health monitoring
- Team autonomy
- Parallel development
- Technology diversity
-
Service Discovery Issues
- Check Eureka server status
- Verify service registration
- Check network connectivity
-
Authentication Issues
- Verify JWT token validity
- Check JWT secret configuration
- Validate user permissions
-
Database Connection Issues
- Check database availability
- Verify connection strings
- Check database permissions
-
Traefik Routing Issues
- Check service labels
- Verify port configurations
- Check Traefik dashboard
# Check service status
docker-compose -f docker-compose.microservices.yml ps
# View service logs
docker-compose -f docker-compose.microservices.yml logs [service-name]
# Check Eureka registry
curl http://localhost:8761/eureka/apps
# Test service endpoints
curl http://localhost:8083/auth/health
curl http://localhost:8084/actuator/health
curl http://localhost:8085/genai/health- Circuit Breakers: Implement resilience patterns
- Distributed Tracing: Add observability
- Message Queues: Implement async communication
- Caching: Add Redis for performance
- Monitoring: Implement comprehensive monitoring
- CI/CD: Automated deployment pipelines
- Consider gRPC for service communication
- Implement GraphQL for flexible APIs
- Add Kubernetes for orchestration
- Implement service mesh (Istio/Linkerd)