Skip to content

A Java Spring Boot microservices monorepo with API Gateway, Auth, Patient, Billing, Analytics, and more. Includes AWS CDK infra (Java), LocalStack emulation, Docker, gRPC, Kafka, and integration tests for cloud-native development and learning.

Notifications You must be signed in to change notification settings

octorose/java-microservices

Repository files navigation

Java Spring Microservices Monorepo

A comprehensive monorepo for a cloud-native microservices architecture built with Java, Spring Boot, Docker, and AWS emulation via LocalStack.


Table of Contents


Overview

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.


Modules

  • 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.

Tech Stack

  • Java 17+ (Spring Boot)
  • Docker & Docker Compose
  • AWS CDK (Java)
  • LocalStack (AWS emulation)
  • PostgreSQL (RDS emulation)
  • Apache Kafka (MSK emulation)
  • gRPC
  • Maven

Getting Started

Prerequisites

  • Java 17 or higher
  • Maven
  • Docker
  • LocalStack
  • (Optional) Postman or HTTP client

Clone the Repository

git clone https://github.com/<your-username>/<your-repo>.git
cd java-spring-microservices-main

Environment Variables

Each service uses environment variables for configuration.
You can set these in your IDE, Docker Compose, or as system env vars.

Common Variables

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

Example for auth-service:

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

Example for patient-service:

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

Running Locally

1. Start LocalStack

docker run -d --name localaws -p 4566:4566 -p 4510-4520:4510-4520 localstack/localstack:latest

2. Build Infrastructure

cd infra
mvn clean compile
./localstack-deploy.sh

3. Build and Run Services

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).


Testing

  • Unit tests:
    Each service contains its own unit tests. Run with:
    mvn test
  • Integration tests:
    Run from the integration-tests module:
    cd integration-tests
    mvn test

API Requests & Integration Tests

  • Use the files in api-requests/ for example HTTP requests (Postman, .http, etc.).
  • Use the files in grpc-requests/ for gRPC testing.

Project Structure

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
└── ...

Contributing

Contributions are welcome! Please open issues or pull requests for improvements, bug fixes, or new features.


License

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!

About

A Java Spring Boot microservices monorepo with API Gateway, Auth, Patient, Billing, Analytics, and more. Includes AWS CDK infra (Java), LocalStack emulation, Docker, gRPC, Kafka, and integration tests for cloud-native development and learning.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published