How wishall05/patient-management works
Purpose and topology
A Java 21/Spring Boot microservices system for patient registration. Patient creation synchronously provisions billing through gRPC, then asynchronously publishes a protobuf patient event for analytics. LocalStack emulates AWS deployment infrastructure; PostgreSQL is the patient data store.
Entrypoints and service boundaries
Each deployable service has a Spring Boot entrypoint and Docker image:
• Patient domain/API: patient-service/src/main/java/com/pm/PatientServiceApplication.java, patient-service/Dockerfile
• Authentication: auth-service/src/main/java/com/pm/AuthServiceApplication.java, auth-service/Dockerfile
• Edge routing: api-gateway/src/main/java/com/pm/ApiGatewayServiceApplication.java, api-gateway/Dockerfile
• Billing gRPC server: billing-service/src/main/java/com/pm/BillingServiceApplication.java, billing-service/Dockerfile
• Event analytics consumer: analytics-service/src/main/java/com/pm/AnalyticsServiceApplication.java, analytics-service/Dockerfile
Gateway and authentication
The API gateway is the external HTTP boundary and applies JWT validation before forwarding routed traffic. Its filter and production/application routing configuration are in api-gateway/src/main/java/com/pm/filter/JwtValidationGatewayFilterFactory.java, api-gateway/src/main/resources/application.yml, and api-gateway/src/main/resources/application-prod.yml.
Auth owns users, login flow, credential security, and JWT issuance. Its layered boundary is controller → service → repository/entity: auth-service/src/main/java/com/pm/controller/AuthController.java, auth-service/src/main/java/com/pm/service/AuthService.java, auth-service/src/main/java/com/pm/util/JwtUtil.java.
Patient workflow and persistence
Patient Service owns registration, validation, CRUD-facing behavior, and patient persistence. HTTP handling enters patient-service/src/main/java/com/pm/controller/PatientController.java, passes through patient-service/src/main/java/com/pm/service/PatientService.java, and persists patient-service/src/main/java/com/pm/model/Patient.java through patient-service/src/main/java/com/pm/repository/PatientRepository.java.
The request/response DTO and mapper layer separates transport contracts from the persistence model: patient-service/src/main/java/com/pm/dto/PatientRequestDTO.java, patient-service/src/main/java/com/pm/mapper/PatientMapper.java. PostgreSQL is the stated backing store; seed data is present in patient-service/src/main/resources/data.sql.
Synchronous billing integration
During registration, Patient Service invokes Billing Service over gRPC through patient-service/src/main/java/com/pm/grpc/BillingServiceGrpcClient.java. The shared wire contract is duplicated locally in patient-service/src/main/proto/billing_service.proto and billing-service/src/main/proto/billing_service.proto; Billing implements the server side in billing-service/src/main/java/com/pm/grpc/BillingGrpcService.java. This is a synchronous cross-service dependency in the patient-create path.
Asynchronous event and analytics flow
After successful patient creation, Patient Service publishes protobuf events via patient-service/src/main/java/com/pm/kafka/KafkaProducer.java, using patient-service/src/main/proto/patient_event.proto. Kafka is the decoupling boundary; Analytics independently consumes the patient topic through analytics-service/src/main/java/com/pm/kafka/KafkaConsumer.java and uses its corresponding event schema at analytics-service/src/main/proto/patient_event.proto.
Infrastructure and runtime
Maven builds each independently deployable module; Protocol Buffers/gRPC Java sources are generated at build time. Docker packages services. AWS CDK defines the LocalStack-targeted VPC, MSK, IAM, logs, ECS tasks, and gateway deployment in infrastructure/src/main/java/com/pm/stack/LocalStack.java, invoked by infrastructure/localstack-deploy.sh. Kafka UI is separately runnable through kafka-ui/docker-compose.yml.
Main entry points: LocalStack.java LocalStack CDK stack · PatientService.java Patient service · JwtValidationGatewayFilterFactory.java JWT gateway filter · KafkaProducer.java Patient event producer
Components 22
Edge & Identity
- API Gateway · External HTTP boundary with routed service traffic.
api-gateway/src/main/java/com/pm/ApiGatewayServiceApplication.java - JWT gateway filter · Validates JWTs before route forwarding.
api-gateway/src/main/java/com/pm/filter/JwtValidationGatewayFilterFactory.java - Auth Service · Owns login, users, credentials, and token issuance.
auth-service/src/main/java/com/pm/AuthServiceApplication.java - Auth controller
auth-service/src/main/java/com/pm/controller/AuthController.java - Auth service & JWT · Handles authentication and issues JWTs.
auth-service/src/main/java/com/pm/service/AuthService.java
Patient Domain
- Patient Service · Owns patient registration and CRUD behavior.
patient-service/src/main/java/com/pm/PatientServiceApplication.java - Patient controller
patient-service/src/main/java/com/pm/controller/PatientController.java - Patient service · Coordinates validation, creation, billing, and event publication.
patient-service/src/main/java/com/pm/service/PatientService.java - Patient DTO & mapper · Separates HTTP contracts from the persistence model.
patient-service/src/main/java/com/pm/dto/PatientRequestDTO.java - Patient repository
patient-service/src/main/java/com/pm/repository/PatientRepository.java - PostgreSQL · Stores patient records, with seed data loaded locally.
patient-service/src/main/resources/data.sql
Billing & Events
- Billing gRPC client · Synchronously provisions billing during registration.
patient-service/src/main/java/com/pm/grpc/BillingServiceGrpcClient.java - Billing protobuf contract · Shared locally duplicated billing wire contract.
patient-service/src/main/proto/billing_service.proto - Billing Service
billing-service/src/main/java/com/pm/BillingServiceApplication.java - Billing gRPC server
billing-service/src/main/java/com/pm/grpc/BillingGrpcService.java - Patient event producer · Publishes a protobuf event after patient creation.
patient-service/src/main/java/com/pm/kafka/KafkaProducer.java - Patient event schema
patient-service/src/main/proto/patient_event.proto - Kafka / MSK · Decoupling boundary for patient events.
- Analytics Service · Independently consumes patient events.
analytics-service/src/main/java/com/pm/AnalyticsServiceApplication.java - Analytics consumer
analytics-service/src/main/java/com/pm/kafka/KafkaConsumer.java
Deployment Runtime
- LocalStack CDK stack · Defines VPC, MSK, IAM, logs, ECS tasks, and gateway deployment.
infrastructure/src/main/java/com/pm/stack/LocalStack.java - LocalStack deploy script
infrastructure/localstack-deploy.sh
Connections 26
- API Gateway → JWT gateway filter: applies
- JWT gateway filter → Auth Service: auth routes
- JWT gateway filter → Patient Service: forwards validated requests
- Auth Service → Auth controller: serves
- Auth controller → Auth service & JWT: delegates
- Patient Service → Patient controller: serves
- Patient controller → Patient DTO & mapper: maps request/response
- Patient DTO & mapper → Patient service: invokes
- Patient service → Patient repository: persists through
- Patient repository → PostgreSQL: stores patients
- Patient service → Billing gRPC client: provisions billing
- Billing gRPC client → Billing protobuf contract: uses
- Billing protobuf contract → Billing gRPC server: defines RPC
- Billing Service → Billing gRPC server: hosts
- Patient service → Patient event producer: publishes after creation
- Patient event producer → Patient event schema: serializes
- Patient event producer → Kafka / MSK: produces patient event
- Kafka / MSK → Analytics consumer: delivers patient topic
- Analytics Service → Analytics consumer: hosts
- LocalStack deploy script → LocalStack CDK stack: invokes
- LocalStack CDK stack → API Gateway: deploys
- LocalStack CDK stack → Kafka / MSK: provisions MSK
- LocalStack CDK stack → Patient Service: deploys ECS task
- LocalStack CDK stack → Auth Service: deploys ECS task
- LocalStack CDK stack → Billing Service: deploys ECS task
- LocalStack CDK stack → Analytics Service: deploys ECS task