A comprehensive monorepo for a cloud-native microservices architecture built with Java, Spring Boot, Docker, and AWS emulation via LocalStack.
- Overview
- Modules
- Tech Stack
- Getting Started
- Environment Variables
- Running Locally
- Testing
- API Requests & Integration Tests
- Project Structure
- Contributing
- License
This project demonstrates best practices for designing, developing, and deploying distributed systems using modern Java technologies. It includes multiple microservices, an API Gateway, infrastructure-as-code with AWS CDK (Java), and local AWS cloud emulation with LocalStack.
- api-gateway: Central entry point for all client requests, routes to services.
- auth-service: Handles authentication, JWT, and user management.
- patient-service: Manages patient data and operations.
- billing-service: Handles billing, payments, and invoicing.
- analytics-service: Processes analytics events (via Kafka/MSK).
- infra: Infrastructure as code (AWS CDK in Java).
- integration-tests: Automated integration tests.
- api-requests: Example API requests (Postman, HTTP files, etc.).
- grpc-requests: Example gRPC requests.
- Java 17+ (Spring Boot)
- Docker & Docker Compose
- AWS CDK (Java)
- LocalStack (AWS emulation)
- PostgreSQL (RDS emulation)
- Apache Kafka (MSK emulation)
- gRPC
- Maven
- Java 17 or higher
- Maven
- Docker
- LocalStack
- (Optional) Postman or HTTP client
git clone https://github.com/<your-username>/<your-repo>.git
cd java-spring-microservices-main
Each service uses environment variables for configuration.
You can set these in your IDE, Docker Compose, or as system env vars.
Variable | Description | Example Value |
---|---|---|
SPRING_DATASOURCE_URL |
JDBC URL for Postgres DB | jdbc:postgresql://localhost:5432/db |
SPRING_DATASOURCE_USERNAME |
DB username | admin_user |
SPRING_DATASOURCE_PASSWORD |
DB password | password |
SPRING_JPA_HIBERNATE_DDL_AUTO |
Hibernate DDL mode | update |
SPRING_SQL_INIT_MODE |
SQL init mode | always |
SPRING_KAFKA_BOOTSTRAP_SERVERS |
Kafka/MSK bootstrap servers | localhost:9092 |
JWT_SECRET |
JWT signing secret (Auth Service) | your-secret-key |
BILLING_SERVICE_ADDRESS |
Billing service address (Patient Service) | billing-service |
BILLING_SERVICE_GRPC_PORT |
Billing gRPC port (Patient Service) | 9001 |
SPRING_DATASOURCE_URL=jdbc:postgresql://auth-service-db:5432/auth-service-db
SPRING_DATASOURCE_USERNAME=admin_user
SPRING_DATASOURCE_PASSWORD=password
SPRING_JPA_HIBERNATE_DDL_AUTO=update
SPRING_SQL_INIT_MODE=always
JWT_SECRET=your-secret-key
SPRING_DATASOURCE_URL=jdbc:postgresql://patient-service-db:5432/patient-service-db
SPRING_DATASOURCE_USERNAME=admin_user
SPRING_DATASOURCE_PASSWORD=password
SPRING_JPA_HIBERNATE_DDL_AUTO=update
SPRING_SQL_INIT_MODE=always
SPRING_KAFKA_BOOTSTRAP_SERVERS=kafka:9092
BILLING_SERVICE_ADDRESS=billing-service
BILLING_SERVICE_GRPC_PORT=9001
docker run -d --name localaws -p 4566:4566 -p 4510-4520:4510-4520 localstack/localstack:latest
cd infra
mvn clean compile
./localstack-deploy.sh
You can use Docker Compose, or run each service with Maven:
cd auth-service
mvn spring-boot:run
# Repeat for other services
Or build Docker images and run with Docker Compose (if provided).
- Unit tests:
Each service contains its own unit tests. Run with:mvn test
- Integration tests:
Run from theintegration-tests
module:cd integration-tests mvn test
- Use the files in
api-requests/
for example HTTP requests (Postman, .http, etc.). - Use the files in
grpc-requests/
for gRPC testing.
java-spring-microservices-main/
│
├── api-gateway/ # API Gateway service
├── auth-service/ # Auth service
├── patient-service/ # Patient service
├── billing-service/ # Billing service
├── analytics-service/ # Analytics service
├── infra/ # Infrastructure as code (CDK)
├── integration-tests/ # Integration tests
├── api-requests/ # Example API requests
├── grpc-requests/ # Example gRPC requests
├── .gitignore
├── README.md
└── ...
Contributions are welcome! Please open issues or pull requests for improvements, bug fixes, or new features.
This project is licensed under the MIT License. See LICENSE for details.
Feel free to customize this README for your specific project, add more details, or ask for a version tailored to your needs!