ClientAuthApp is a Spring Boot REST API service that manages client registrations with automatic email notifications. The application provides CORS-enabled endpoints for client authentication and contact management, integrating seamlessly with AWS infrastructure for database and email services.
The service accepts client details through a REST API, persists them to AWS RDS MySQL database, and automatically sends personalized welcome emails to registered users.
- Language: Java 17
- Framework: Spring Boot 3.5.8
- Build Tool: Maven 3.9
- Database: MySQL 8.0 (via AWS RDS)
- Containerization: Docker (Alpine Linux)
- ORM: JPA/Hibernate
- Email Provider: SMTP (Gmail/AWS SES)
- spring-boot-starter-web β RESTful API support
- spring-boot-starter-data-jpa β Database persistence & ORM
- spring-boot-starter-mail β Email sending capability
- mysql-connector-j (8.0.33) β MySQL database driver
- lombok β Reduce boilerplate code
- eclipse-temurin:17 β Lightweight JDK for Docker
src/main/java/
βββ ClientApplication.java Entry point with component scanning
βββ config/
β βββ CorsConfig.java CORS configuration for React frontend
βββ controller/
β βββ ClientController.java REST endpoints (@PostMapping /api/client/saveClient)
βββ service/
β βββ ClientService.java Business logic interface
β βββ ClientServiceImpl.java Client registration & persistence
β βββ EmailService.java Email interface
β βββ EmailServiceImpl.java Welcome email implementation
βββ entity/
β βββ ClientEntity.java JPA entity mapping to 'client' table
βββ dto/
β βββ ClientDTO.java Request/response data transfer object
βββ repo/
βββ ClientRepository.java Spring Data JPA repository
src/main/resources/
βββ application.yaml Configuration for DB, mail, logging
- Request Flow: React frontend sends AJAX POST request β CORS validates origin β
ClientControllerreceives request - Processing:
ClientControllerpasses DTO toClientServiceImplβ validates data β converts toClientEntity - Persistence:
ClientRepositorysaves entity to AWS RDS MySQL database - Email Trigger:
EmailServiceImplsends welcome email via SMTP (asynchronous, non-blocking) - Response: Success/failure boolean returned to frontend
- Endpoint:
clientdb.c7gccsuya4ux.ap-south-1.rds.amazonaws.com:3306 - Database:
clientdb - Configuration (application.yaml):
spring: datasource: url: jdbc:mysql://clientdb.c7gccsuya4ux.ap-south-1.rds.amazonaws.com:3306/clientdb driver-class-name: com.mysql.cj.jdbc.Driver username: admin password: ${DB_PASSWORD} # Use environment variables
- Credentials: Managed via environment variables (never hardcoded in production)
- Origin:
http://mywebstack2025.s3-website.ap-south-1.amazonaws.com - Purpose: Hosts React frontend that sends AJAX requests to this backend
- Integrated via CORS configuration (see below)
- Region:
ap-south-1(Asia Pacific - Mumbai) - Advantage: 62,000 free emails/month from EC2 instances, highly scalable
- Configuration example:
spring: mail: host: email-smtp.ap-south-1.amazonaws.com port: 587 username: ${MAIL_USERNAME} password: ${MAIL_PASSWORD}
- Dockerized application runs on EC2 instance
- Port
8081exposed for backend API - Security group allows inbound traffic on port 8081
- Outbound traffic to RDS (port 3306) and SMTP (port 587)
- Docker images can be pushed to ECR instead of Docker Hub
- Integrated deployment via Docker Compose or ECS
The application implements CORS to allow the React frontend (S3 hosted) to communicate with this backend API.
Configuration File: src/main/java/config/CorsConfig.java
@Configuration
public class CorsConfig {
@Bean
public WebMvcConfigurer corsConfigurer() {
return new WebMvcConfigurer() {
@Override
public void addCorsMappings(CorsRegistry registry) {
registry.addMapping("/**")
.allowedOrigins("http://mywebstack2025.s3-website.ap-south-1.amazonaws.com")
.allowedMethods("GET", "POST", "PUT", "DELETE", "OPTIONS")
.allowedHeaders("*")
.allowCredentials(true);
}
};
}
}Key Features:
- β Allows requests from S3 origin only (whitelist specific origin)
- β Supports all HTTP methods (GET, POST, PUT, DELETE, OPTIONS)
- β
Allows any headers (
allowedHeaders("*")) - β Credentials (cookies, auth tokens) included in requests
- β
Applied globally to all endpoints (
"/**")
Controller-level CORS: Also configured at endpoint level
@CrossOrigin(origins = "http://mywebstack2025.s3-website.ap-south-1.amazonaws.com")
@RestController
@RequestMapping("/api/client")
public class ClientController { ... }The React frontend sends AJAX requests to the backend API endpoints.
Endpoint: POST /api/client/saveClient
Frontend Example (React):
const saveClient = async (clientData) => {
try {
const response = await fetch(
'http://<EC2-PUBLIC-IP>:8081/api/client/saveClient',
{
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
credentials: 'include', // Include cookies/credentials
body: JSON.stringify(clientData),
}
);
const result = await response.json();
console.log('Registration successful:', result);
} catch (error) {
console.error('Registration failed:', error);
}
};
// Usage
saveClient({
clientName: 'John Doe',
clientEmail: 'john@example.com',
clientSubject: 'Inquiry',
clientMessage: 'Hello, I have a question...',
});Request Payload (JSON):
{
"clientName": "John Doe",
"clientEmail": "john@example.com",
"clientSubject": "General Inquiry",
"clientMessage": "I'd like to know more about your services"
}Response:
true // Boolean indicating success/failureAJAX Features Enabled:
- β Asynchronous requests (non-blocking UI)
- β JSON serialization/deserialization
- β CORS preflight handling (automatic OPTIONS request)
- β Error handling and retry capability
- β Credentials support for authentication
- Java 17+ installed
- Maven 3.9+
- Docker (for containerized deployment)
- MySQL credentials for AWS RDS
- Email service credentials (Gmail App Password or AWS SES)
# 1. Clone the repository
git clone https://github.com/nganeshm/ClientAuthApp.git
cd ClientAuthApp
# 2. Build the application
mvn clean package -DskipTests
# 3. Run locally (development)
mvn spring-boot:run
# 4. Test the API
curl -X POST http://localhost:8080/api/client/saveClient \
-H "Content-Type: application/json" \
-d '{
"clientName": "Test User",
"clientEmail": "test@example.com",
"clientSubject": "Test",
"clientMessage": "Testing the API"
}'# 1. Build Docker image
docker build -t client-service:latest .
# 2. Run Docker container
docker run -d \
--name client-service \
-p 8081:8081 \
-e SPRING_DATASOURCE_URL="jdbc:mysql://clientdb.c7gccsuya4ux.ap-south-1.rds.amazonaws.com:3306/clientdb?useSSL=false" \
-e SPRING_DATASOURCE_USERNAME="admin" \
-e SPRING_DATASOURCE_PASSWORD="your-password" \
-e MAIL_USERNAME="your-email@gmail.com" \
-e MAIL_PASSWORD="your-app-password" \
client-service:latest
# 3. View logs
docker logs -f client-serviceSet these before running the application:
| Variable | Purpose | Example |
|---|---|---|
SPRING_DATASOURCE_URL |
RDS MySQL connection string | jdbc:mysql://clientdb.c7gccsuya4ux.ap-south-1.rds.amazonaws.com:3306/clientdb |
SPRING_DATASOURCE_USERNAME |
Database username | admin |
SPRING_DATASOURCE_PASSWORD |
Database password | YourSecurePassword |
MAIL_USERNAME |
Email sender address | ganeshnarangle@gmail.com |
MAIL_PASSWORD |
Email SMTP password | Gmail App Password or AWS SES credentials |
SERVER_PORT |
Application port (optional) | 8081 (default: 8080) |
-
Gmail (Development) β Recommended for testing
- 500 emails/day limit
- Requires App Password (not regular password)
- Setup: https://myaccount.google.com/apppasswords
-
AWS SES (Production) β Recommended for AWS deployment
- 62,000 free emails/month from EC2
- Highly scalable and reliable
- No egress charges within AWS
-
SendGrid / Mailgun - Alternative options
Default Configuration (Gmail):
spring:
mail:
host: smtp.gmail.com
port: 587
username: ${MAIL_USERNAME}
password: ${MAIL_PASSWORD}
properties:
mail:
smtp:
auth: true
starttls:
enable: true
required: trueTable: client
| Column | Type | Constraints |
|---|---|---|
clientId |
VARCHAR(36) | PRIMARY KEY (UUID) |
clientName |
VARCHAR(255) | NOT NULL, UNIQUE |
clientEmail |
VARCHAR(255) | NOT NULL |
subject |
VARCHAR(255) | NULL |
message |
TEXT | NULL |
Auto-generated by Hibernate: ddl-auto: update creates/updates schema on startup
- β CORS whitelist: Only allows requests from S3 origin
- β Credentials via environment variables: Never hardcode in code
- β AWS RDS encryption: Enable encryption at rest (recommended)
- β Security groups: Restrict inbound/outbound traffic
- β Email failure isolation: Email errors don't break registration
- β Validation: Client name and email are required fields
- Use AWS Secrets Manager for storing sensitive credentials
- Enable SSL/TLS for database connections
- Implement rate limiting on API endpoints
- Add request validation and sanitization
- Enable audit logging for registration events
- Use IAM roles instead of hardcoded credentials
Description: Register a new client and send welcome email
Request:
POST /api/client/saveClient
Content-Type: application/json
Body:
{
"clientName": "string (required)",
"clientEmail": "string (required)",
"clientSubject": "string (optional)",
"clientMessage": "string (optional)"
}Response:
200 OK
Content-Type: application/json
true // Success
false // Failure (missing required fields)
CORS: β Allowed from S3 origin
- Verify EC2 security group allows outbound on port 3306
- Verify RDS security group allows inbound from EC2 security group
- Test connection:
docker exec -it client-service mysql -h clientdb.c7gccsuya4ux.ap-south-1.rds.amazonaws.com -u admin -p
- Verify S3 origin URL matches
CorsConfig.java - Check browser console for preflight OPTIONS request status
- Ensure backend is running and accessible
- Verify SMTP credentials are correct
- Check outbound port 587 is allowed in security groups
- Review application logs:
docker logs client-service - For Gmail: Verify App Password is generated (not regular password)
docker ps -a # Check for existing containers
docker rm client-service # Remove old container- Docker Deployment Guide: See
DOCKER_DEPLOYMENT.md - Email Setup Guide: See
EMAIL_SETUP_GUIDE.md - Spring Boot Docs: https://docs.spring.io/spring-boot/
- AWS RDS: https://docs.aws.amazon.com/rds/
- AWS SES: https://docs.aws.amazon.com/ses/
Open source project. See LICENSE file for details.
Ganesh Madhavrao Narangle
Email: ganeshnarangle@gmail.com
GitHub: @nganeshm
Contributions are welcome! Please fork the repository and submit a pull request.
Last Updated: July 2026
Status: Active Development