Skip to content

Paweshashrestha/patient-management

Repository files navigation

Patient Management System

A microservices-based patient management system built with Spring Boot, featuring API Gateway, authentication, billing, and analytics services.

πŸ—οΈ Architecture

The system consists of multiple microservices communicating via REST APIs and gRPC:

  • API Gateway (Port 8080): Spring Cloud Gateway with rate limiting, circuit breaker, and authentication
  • Patient Service (Port 4000): Core patient management with PostgreSQL database
  • Auth Service (Port 4005): JWT-based authentication service
  • Billing Service (Port 4001, gRPC 9001): Billing operations via gRPC
  • Analytics Service (Port 4002): Event-driven analytics consuming Kafka messages

Infrastructure Components

  • PostgreSQL: Two databases for patient-service and auth-service
  • Kafka: Message broker for event-driven communication
  • Redis: Caching and rate limiting for API Gateway
  • LocalStack: Local AWS services for development (Lambda, S3, DynamoDB, etc.)

πŸ“‹ Prerequisites

  • Java 21
  • Maven 3.9+
  • Docker & Docker Compose
  • AWS CLI (for LocalStack integration)

πŸš€ Quick Start

1. Start Infrastructure Services

docker-compose up -d

This starts all required services:

  • PostgreSQL databases (ports 5000, 5001)
  • Kafka (ports 9092, 9094)
  • Redis (port 6379)
  • LocalStack (port 4566)

2. Build and Start Services

The services will be built and started automatically via Docker Compose. Alternatively, you can run them individually:

# Patient Service
cd patient-service && mvn spring-boot:run

# Auth Service
cd auth-service && mvn spring-boot:run

# Billing Service
cd billing-service && mvn spring-boot:run

# Analytics Service
cd analytics-service && mvn spring-boot:run

# API Gateway
cd api-gateway && mvn spring-boot:run

3. Verify Services

πŸ” Authentication

Get Access Token

curl -X POST http://localhost:8080/api/auth/login \
  -H "Content-Type: application/json" \
  -d '{"username":"user","password":"password"}'

Use Token in Requests

curl http://localhost:8080/api/patients \
  -H "Authorization: Bearer YOUR_TOKEN_HERE"

For detailed API testing, see api-requests/README.md.

πŸ“‘ API Endpoints

Patient Management

  • GET /api/patients - List all patients
  • POST /api/patients - Create a new patient
  • GET /api/patients/{id} - Get patient by ID
  • PUT /api/patients/{id} - Update patient
  • DELETE /api/patients/{id} - Delete patient

Authentication

  • POST /api/auth/login - Login and get JWT token
  • POST /api/auth/validate - Validate JWT token

Billing

  • POST /api/billing/accounts - Create billing account (gRPC)

Analytics

  • GET /api/analytics/stats - Get analytics statistics

πŸ› οΈ Development

Project Structure

patient-management/
β”œβ”€β”€ api-gateway/          # Spring Cloud Gateway
β”œβ”€β”€ patient-service/      # Patient CRUD operations
β”œβ”€β”€ auth-service/         # Authentication & authorization
β”œβ”€β”€ billing-service/      # Billing operations (gRPC)
β”œβ”€β”€ analytics-service/    # Event-driven analytics
β”œβ”€β”€ infrastructure/       # AWS CDK for LocalStack
β”œβ”€β”€ integration-tests/    # End-to-end integration tests
β”œβ”€β”€ api-requests/         # HTTP request files for testing
└── docker-compose.yaml   # Local development environment

Building Services

# Build all services
mvn clean install

# Build specific service
cd patient-service && mvn clean package

Running Tests

# Run all tests
mvn test

# Run integration tests
cd integration-tests && mvn test

☁️ LocalStack Setup

LocalStack provides local AWS services for development and testing.

Configure AWS CLI for LocalStack

aws configure
# AWS Access Key ID: test
# AWS Secret Access Key: test
# Default region: us-east-1
# Default output format: json

Deploy Infrastructure

cd infrastructure
./localstack-deploy.sh

Verify LocalStack Services

# List Lambda functions
aws --endpoint-url=http://localhost:4566 lambda list-functions

# List S3 buckets
aws --endpoint-url=http://localhost:4566 s3 ls

πŸ”§ Configuration

Environment Variables

Key environment variables can be set in docker-compose.yaml:

  • SPRING_DATASOURCE_URL: Database connection URL
  • SPRING_KAFKA_BOOTSTRAP_SERVERS: Kafka broker address
  • JWT_SECRET: Secret key for JWT token signing
  • REDIS_HOST & REDIS_PORT: Redis connection details
  • LOCALSTACK_AUTH_TOKEN: LocalStack authentication token (optional, set via environment variable)

Security Note

⚠️ Important: The default credentials in docker-compose.yaml and data.sql are for development only. Always change these in production environments:

  • Database passwords
  • JWT secrets
  • LocalStack auth tokens
  • Default user credentials

Service Ports

Service Port Description
API Gateway 8080 Main entry point
Patient Service 4000 Patient management API
Auth Service 4005 Authentication API
Billing Service 4001 REST API
Billing Service 9001 gRPC API
Analytics Service 4002 Analytics API
PostgreSQL (Patient) 5000 Patient database
PostgreSQL (Auth) 5001 Auth database
Kafka 9092, 9094 Message broker
Redis 6379 Cache & rate limiting
LocalStack 4566 AWS services

πŸ“Š Monitoring & Observability

Actuator Endpoints

All services expose Spring Boot Actuator endpoints:

  • /actuator/health - Health check
  • /actuator/metrics - Application metrics
  • /actuator/prometheus - Prometheus metrics
  • /actuator/gateway/routes - API Gateway routes (gateway only)

API Gateway Features

  • Rate Limiting: 10 requests/second per IP (configurable)
  • Circuit Breaker: Resilience4j with fallback responses
  • Request/Response Logging: Comprehensive logging with request IDs
  • CORS Support: Configured for cross-origin requests
  • Security Headers: Adds security headers to responses

πŸ§ͺ Testing

Integration Tests

The integration-tests module contains comprehensive end-to-end tests:

  • Authentication & Authorization (6 tests)
  • CRUD Operations (8 tests)
  • Validation & Error Handling (8 tests)
  • Edge Cases & Boundary Tests (3 tests)
  • Data Integrity (1 test)
  • Performance Tests (1 test)

Total: 26 integration tests

See integration-tests/README.md for details.

πŸ“š Additional Documentation

πŸ› Troubleshooting

Docker Issues

# Restart Docker service
sudo systemctl restart docker

# Check container logs
docker-compose logs -f [service-name]

# Rebuild containers
docker-compose up -d --build

Database Connection Issues

Ensure PostgreSQL containers are running:

docker-compose ps

Kafka Connection Issues

Verify Kafka is accessible:

docker-compose logs kafka

LocalStack Health Check

curl http://localhost:4566/_localstack/health

πŸ“ License

[Add your license information here]

🀝 Contributing

[Add contribution guidelines here]

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages