A comprehensive Spring Boot Cloud microservices application for managing patient data with authentication, billing, and analytics capabilities.
- Project Overview
- Architecture
- Services
- Technology Stack
- Prerequisites
- Getting Started
- Building Services
- Running with Docker Compose
- API Documentation
- Configuration
- Security
- Messaging
- Monitoring
- Troubleshooting
This is an enterprise-grade microservices application built with Spring Boot 3 and Spring Cloud. It provides a complete patient management system with:
- Patient Management - CRUD operations for patient records
- Authentication & Authorization - JWT-based security with role management
- API Gateway - Centralized routing with request validation
- Billing - gRPC-based inter-service communication
- Analytics - Real-time event processing via Kafka and RabbitMQ
- Distributed Tracing - Zipkin integration for observability
- Service Discovery - Eureka for dynamic service registration
- Configuration Management - Spring Cloud Config Server
┌─────────────────────┐
│ API Gateway │
│ (Port: 4004) │
└──────────┬──────────┘
│
┌──────────────────────────┼─────────────────────────┐
│ │ │
┌─────────▼─────────┐ ┌─────────▼─────────┐ ┌────────▼────────┐
│ Auth Service │ │ Patient Service │ │ Billing Service │
│ (Port: 4005) │ │ (Port: 4000) │ │ (Port: 4001) │
└─────────┬─────────┘ └─────────┬─────────┘ └────────┬────────┘
│ │ │
│ ┌────────────┼────────────┐ │
│ │ │ │ │
┌────────▼─────────┐ │ ┌───────▼──────┐ │ ┌───────▼───────────┐
│ Auth Database │ │ │ Kafka │ │ │ gRPC Communication│
│ (PostgreSQL) │ │ └───────▲──────┘ │ └───────────────────┘
└──────────────────┘ │ │ │
│ ┌──────┴──────┐ │
│ │ │ │
┌────────▼─────▼─────┐ ┌─────▼─────┴─┐
│Analytics Service │ │ RabbitMQ │
│ (Port: 4003) │ │ │
└────────────────────┘ └─────────────┘
┌─────────────────────────────────────────────────────────────────────────────┐
│ Docker Network (app-network) │
├─────────────────────────────────────────────────────────────────────────────┤
│ │
│ ┌─────────────┐ ┌─────────────┐ ┌─────────────┐ ┌─────────────────┐ │
│ │ PostgreSQL │ │ PostgreSQL │ │ Kafka │ │ Zipkin │ │
│ │ patient-db │ │ auth-db │ │ (9092/9093)│ │ (9411) │ │
│ │ :5432 │ │ :5432 │ │ │ │ │ │
│ └─────────────┘ └─────────────┘ └─────────────┘ └─────────────────┘ │
│ │
│ ┌─────────────┐ ┌─────────────┐ ┌─────────────┐ ┌─────────────────┐ │
│ │ Eureka │ │ Config │ │ RabbitMQ │ │ API Gateway │ │
│ │ Service Reg │ │ Server │ │ (5672/15672)│ │ │ │
│ │ :8761 │ │ :8888 │ │ │ │ │ │
│ └─────────────┘ └─────────────┘ └─────────────┘ └─────────────────┘ │
│ │
│ ┌─────────────┐ ┌─────────────┐ ┌─────────────┐ │
│ │ Patient │ │ Auth │ │ Analytics │ │
│ │ Service │ │ Service │ │ Service │ │
│ │ :4000 │ │ :4005 │ │ :4003 │ │
│ └─────────────┘ └─────────────┘ └─────────────┘ │
│ │
│ ┌─────────────┐ │
│ │ Billing │ │
│ │ Service │ │
│ │ :4001 │ │
│ └─────────────┘ │
│ │
└─────────────────────────────────────────────────────────────────────────────┘
- Port: 8761
- Technology: Spring Boot + Netflix Eureka Server
- Purpose: Service discovery and registration
- URL: http://localhost:8761
- Port: 8888
- Technology: Spring Cloud Config Server
- Purpose: Centralized configuration management
- URL: http://localhost:8888
- Port: 4004
- Technology: Spring Cloud Gateway
- Purpose: Request routing, JWT validation, rate limiting
- Features:
- JWT token validation
- Route to auth-service (/auth/**)
- Route to patient-service (/api/patients/**)
- OpenAPI documentation proxy
- Port: 4005
- Technology: Spring Boot + Spring Security
- Database: PostgreSQL (auth_db)
- Purpose: User authentication and JWT token generation
- Endpoints:
- POST /login - User login
- POST /validate - Token validation
- Port: 4000
- Technology: Spring Boot + Spring Data JPA
- Database: PostgreSQL (patient_db)
- Purpose: Patient CRUD operations
- Features:
- RESTful API with OpenAPI/Swagger
- Circuit breaker (Resilience4j)
- Kafka event publishing
- RabbitMQ messaging
- gRPC client for billing service
- Endpoints:
- GET /patients - List all patients
- GET /patients/{id} - Get patient by ID
- POST /patients - Create new patient
- PUT /patients/{id} - Update patient
- DELETE /patients/{id} - Delete patient
- Port: 4001
- Technology: Spring Boot + gRPC
- Purpose: Billing account management
- Communication: gRPC
- Features:
- gRPC server for billing operations
- Protobuf message definitions
- Port: 4003
- Technology: Spring Boot + Kafka + RabbitMQ
- Purpose: Event processing and analytics
- Features:
- Kafka consumer for patient events
- RabbitMQ consumer for messages
- gRPC client for billing data
- Spring Boot: 3.3.3
- Spring Cloud: 2023.0.3 (Release Train)
- Java: 17
- API Gateway: Spring Cloud Gateway
- Service Discovery: Netflix Eureka
- Config Server: Spring Cloud Config
- Load Balancing: Spring Cloud LoadBalancer
- PostgreSQL: 15 (patient_db, auth_db)
- Apache Kafka: 4.1.1 (Event streaming)
- RabbitMQ: 3 (Message broker)
- REST: Spring Web
- gRPC: grpc-netty-shaded, grpc-protobuf
- OpenFeign: Service-to-service HTTP calls
- JWT: JWT token-based authentication
- Spring Security: Authorization and authentication
- Resilience4j: Circuit breaker, retry, rate limiter
- Zipkin: Distributed tracing
- Micrometer: Metrics collection
- Spring Actuator: Health checks and management
- Maven: Build and dependency management
- Docker: Containerization
- Java Development Kit (JDK): Version 17 or higher
- Maven: Version 3.8+
- Docker: Latest version
- Docker Compose: V2 or higher
git clone <repository-url>
cd mark-patient-spring-boot-cloudBuild each microservice using Maven:
# Service Registry
cd service-reg && ./mvnw clean package -DskipTests
# Config Server
cd config-server && ./mvnw clean package -DskipTests
# API Gateway
cd api-gateway && ./mvnw clean package -DskipTests
# Auth Service
cd auth-service && ./mvnw clean package -DskipTests
# Patient Service
cd patient-service && ./mvnw clean package -DskipTests
# Billing Service
cd billing-service && ./mvnw clean package -DskipTests
# Analytics Service
cd analytics-service && ./mvnw clean package -DskipTestsOr use the provided Maven wrapper:
# From project root, build all services
for service in service-reg config-server api-gateway auth-service patient-service billing-service analytics-service; do
cd $service && ../mvnw clean package -DskipTests && cd ..;
done# Build and push each service
cd service-reg
sudo ../mvnw spring-boot:build-image -Dspring-boot.build-image.imageName=markcus0526/service-reg -DskipTests
docker push markcus0526/service-reg
cd ../config-server
sudo ../mvnw spring-boot:build-image -Dspring-boot.build-image.imageName=markcus0526/config-server -DskipTests
docker push markcus0526/config-server
cd ../api-gateway
sudo ../mvnw spring-boot:build-image -Dspring-boot.build-image.imageName=markcus0526/api-gateway -DskipTests
docker push markcus0526/api-gateway
cd ../auth-service
sudo ../mvnw spring-boot:build-image -Dspring-boot.build-image.imageName=markcus0526/auth-service -DskipTests
docker push markcus0526/auth-service
cd ../patient-service
sudo ../mvnw spring-boot:build-image -Dspring-boot.build-image.imageName=markcus0526/patient-service -DskipTests
docker push markcus0526/patient-service
cd ../billing-service
sudo ../mvnw spring-boot:build-image -Dspring-boot.build-image.imageName=markcus0526/billing-service -DskipTests
docker push markcus0526/billing-service
cd ../analytics-service
sudo ../mvnw spring-boot:build-image -Dspring-boot.build-image.imageName=markcus0526/analytics-service -DskipTests
docker push markcus0526/analytics-service# Example for each service
cd service-reg
docker build -t markcus0526/service-reg:latest .
docker push markcus0526/service-reg:latest
# Repeat for other services...# From project root
docker-compose up -d# Check all containers
docker-compose ps
# View logs
docker-compose logs -f [service-name]
# Example: Check patient-service logs
docker-compose logs -f patient-service| Service | Port | URL |
|---|---|---|
| Service Registry | 8761 | http://localhost:8761 |
| Config Server | 8888 | http://localhost:8888 |
| API Gateway | 4004 | http://localhost:4004 |
| Auth Service | 4005 | http://localhost:4005 |
| Patient Service | 4000 | http://localhost:4000 |
| Billing Service | 4001 | http://localhost:4001 |
| Analytics | 4003 | http://localhost:4003 |
| Zipkin | 9411 | http://localhost:9411 |
| RabbitMQ | 5672 | amqp://localhost:5672 |
| RabbitMQ Admin | 15672 | http://localhost:15672 |
docker-compose downdocker-compose down -v- Login: POST /auth/login
curl -X POST http://localhost:4004/auth/login \
-H "Content-Type: application/json" \
-d '{"email": "admin@hospital.com", "password": "admin123"}'Response:
{
"token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..."
}- Use Token: Include JWT in Authorization header
curl -X GET http://localhost:4004/api/patients \
-H "Authorization: Bearer <your-token>"curl -X POST http://localhost:4004/api/patients \
-H "Authorization: Bearer <token>" \
-H "Content-Type: application/json" \
-d '{
"name": "John Doe",
"email": "john.doe@example.com",
"phone": "+1234567890",
"address": "123 Main St",
"dateOfBirth": "1990-01-15",
"gender": "MALE"
}'curl -X GET http://localhost:4004/api/patients \
-H "Authorization: Bearer <token>"curl -X GET http://localhost:4004/api/patients/{id} \
-H "Authorization: Bearer <token>"curl -X PUT http://localhost:4004/api/patients/{id} \
-H "Authorization: Bearer <token>" \
-H "Content-Type: application/json" \
-d '{
"name": "John Updated",
"email": "john.updated@example.com"
}'curl -X DELETE http://localhost:4004/api/patients/{id} \
-H "Authorization: Bearer <token>"- Patient Service: http://localhost:4004/api-docs/patients/v3/api-docs
- Auth Service: http://localhost:4004/api-docs/auth/v3/api-docs
Each service can be configured using environment variables:
# Example configuration
spring:
config:
import: optional:configserver:http://config-server:8888
profiles:
active: docker
eureka:
client:
serviceUrl:
defaultZone: http://service-reg:8761/eureka/
management:
tracing:
sampling:
probability: 1.0
zipkin:
tracing:
endpoint: http://zipkin:9411/api/v2/spansKey configuration files:
service-reg/src/main/resources/application.propertiesconfig-server/src/main/resources/application.propertiesapi-gateway/src/main/resources/application.ymlauth-service/src/main/resources/application.propertiespatient-service/src/main/resources/application.propertiesbilling-service/src/main/resources/application.propertiesanalytics-service/src/main/resources/application.properties
The project uses Spring Cloud Config Server for centralized configuration. Configuration files are stored in application-config/ directory.
The JWT secret key is configured in the API Gateway:
jwt:
secret: "9a4f2c8d3b7a1e6f5d8c3a2b1e6f5d8c3a2b1e6f5d8c3a2b1e6f5d8c3a2b1e6f"
expiration: 86400000 # 24 hours in millisecondsImportant: Change the JWT secret in production!
The auth-service initializes default users from auth-service/src/main/resources/data.sql:
- Email:
admin@hospital.com - Password:
admin123
All /api/patients/** routes require valid JWT token. The /auth/** routes are public.
Patient events are published to Kafka topics:
- Topic:
patient-events - Message Format: Protobuf (defined in
patient_event.proto)
- Exchange: patient-exchange (topic)
- Queue: patient-queue
- Routing Key: patient.#
Patient Service ──publishes──> Kafka ──consumes──> Analytics Service
│
└──publishes──> RabbitMQ ──consumes──> Analytics Service
All services expose actuator health endpoints:
# Check service health
curl http://localhost:4000/actuator/healthAccess Zipkin UI at http://localhost:9411 to view distributed traces.
# Patient service circuit breaker state
curl http://localhost:4000/actuator/healthCircuit breaker configuration (Resilience4j):
- Sliding window size: 10 calls
- Failure rate threshold: 50%
- Wait duration in open state: 10 seconds
Solution: Ensure Eureka server is running first:
docker-compose up -d service-reg
# Wait for Eureka to be healthy
docker-compose up -dSolution: Increase Git timeout:
spring.cloud.config.server.git.timeout: 30Solution: Check PostgreSQL containers:
docker-compose logs patient-db
docker-compose logs auth-dbSolution: Verify Kafka is running:
docker-compose logs kafkaSolution: Ensure auth-service is running and accessible:
docker-compose logs auth-service# View all logs
docker-compose logs -f
# View specific service
docker-compose logs -f patient-service
# View last 100 lines
docker-compose logs --tail=100 patient-service# Restart specific service
docker-compose restart patient-service
# Rebuild and restart
docker-compose up -d --build patient-servicemark-patient-spring-boot-cloud/
├── service-reg/ # Eureka Service Registry
│ ├── src/main/java/
│ └── pom.xml
├── config-server/ # Spring Cloud Config Server
│ ├── src/main/java/
│ └── pom.xml
├── api-gateway/ # API Gateway (Spring Cloud Gateway)
│ ├── src/main/java/
│ │ └── com/pm/apigateway/
│ │ ├── filter/ # JWT Validation Filter
│ │ ├── client/ # Feign Clients
│ │ └── exception/ # Exception Handling
│ └── pom.xml
├── auth-service/ # Authentication Service
│ ├── src/main/java/
│ │ └── com/pm/authservice/
│ │ ├── controller/ # REST Controllers
│ │ ├── service/ # Business Logic
│ │ ├── model/ # Entities
│ │ ├── dto/ # Data Transfer Objects
│ │ └── util/ # JWT Utilities
│ ├── src/main/resources/
│ │ └── data.sql # Default Users
│ └── pom.xml
├── patient-service/ # Patient Management Service
│ ├── src/main/java/
│ │ └── com/pm/patientservice/
│ │ ├── controller/ # REST Controllers
│ │ ├── service/ # Business Logic
│ │ ├── model/ # Entities
│ │ ├── dto/ # Data Transfer Objects
│ │ ├── repository/ # Data Access
│ │ ├── mapper/ # Entity Mappers
│ │ ├── kafka/ # Kafka Producers
│ │ ├── rabbitmq/ # RabbitMQ Producers
│ │ ├── grpc/ # gRPC Clients
│ │ ├── config/ # Configuration
│ │ └── exception/ # Exception Handling
│ ├── src/main/proto/ # Protocol Buffers
│ ├── src/main/resources/
│ │ └── data.sql # Sample Data
│ └── pom.xml
├── billing-service/ # Billing Service (gRPC Server)
│ ├── src/main/java/
│ │ └── com/pm/billingservice/
│ │ └── grpc/ # gRPC Implementation
│ ├── src/main/proto/
│ └── pom.xml
├── analytics-service/ # Analytics Service
│ ├── src/main/java/
│ │ └── com/pm/analyticsservice/
│ │ ├── kafka/ # Kafka Consumers
│ │ ├── rabbitmq/ # RabbitMQ Consumers
│ │ └── config/ # Configuration
│ ├── src/main/proto/
│ └── pom.xml
├── application-config/ # External Configurations
│ ├── *-service-docker.properties
│ └── *-service-docker.yml
├── api-requests/ # HTTP Request Examples
│ ├── auth-service/
│ └── patient-service/
├── grpc-requests/ # gRPC Request Examples
│ └── billing-service/
├── docker-compose.yml # Docker Compose Configuration
├── docker-commands.txt # Build Commands
└── README.md # This File
- Fork the repository
- Create a feature branch
- Make your changes
- Submit a pull request
This project is proprietary and confidential.
For issues and questions, please contact the development team.