Skip to content

kalil-camera/java-produt-service-application

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

7 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Product Service

A Spring Boot 3.3 application with Java 25, demonstrating enterprise-grade development practices, scalable architecture, and infrastructure as code using Terraform.

Project Overview

This project showcases knowledge across:

  • Java 25 - Modern Java features and best practices
  • Spring Boot 3.3 - Layered architecture and dependency injection
  • PostgreSQL 16 - Database design and optimization
  • Terraform - Infrastructure as Code for AWS
  • Docker - Containerization and orchestration
  • AWS Services - ECS, RDS, ALB, ECR, CloudWatch
  • Design Patterns - SOLID principles, Domain-Driven Design
  • Testing - Unit and integration tests
  • Security - Secrets management, security groups, IAM roles

πŸ“‹ Table of Contents

  1. Project Structure
  2. Architecture
  3. Getting Started
  4. Development
  5. Testing
  6. Docker Deployment
  7. Terraform Infrastructure
  8. API Documentation
  9. Database Migrations
  10. Best Practices Demonstrated

πŸ“ Project Structure

product-service/
β”œβ”€β”€ src/
β”‚   β”œβ”€β”€ main/
β”‚   β”‚   β”œβ”€β”€ java/com/senior/project/
β”‚   β”‚   β”‚   β”œβ”€β”€ ProductServiceApplication.java      # Main entry point
β”‚   β”‚   β”‚   β”œβ”€β”€ application/
β”‚   β”‚   β”‚   β”‚   β”œβ”€β”€ dto/                            # Data Transfer Objects
β”‚   β”‚   β”‚   β”‚   β”œβ”€β”€ mapper/                         # MapStruct mappers
β”‚   β”‚   β”‚   β”‚   └── service/                        # Business logic
β”‚   β”‚   β”‚   β”œβ”€β”€ domain/
β”‚   β”‚   β”‚   β”‚   β”œβ”€β”€ entity/                         # JPA entities
β”‚   β”‚   β”‚   β”‚   └── exception/                      # Domain exceptions
β”‚   β”‚   β”‚   β”œβ”€β”€ infrastructure/
β”‚   β”‚   β”‚   β”‚   β”œβ”€β”€ config/                         # Spring configurations
β”‚   β”‚   β”‚   β”‚   └── repository/                     # Data access layer
β”‚   β”‚   β”‚   └── presentation/
β”‚   β”‚   β”‚       β”œβ”€β”€ controller/                     # REST endpoints
β”‚   β”‚   β”‚       └── exception/                      # Global exception handler
β”‚   β”‚   └── resources/
β”‚   β”‚       β”œβ”€β”€ application.properties              # Base configuration
β”‚   β”‚       β”œβ”€β”€ application-dev.properties          # Dev environment
β”‚   β”‚       β”œβ”€β”€ application-prod.properties         # Prod environment
β”‚   β”‚       └── db/migration/                       # Flyway migrations
β”‚   └── test/
β”‚       └── java/com/senior/project/
β”‚           └── application/service/                # Service tests
β”œβ”€β”€ terraform/
β”‚   β”œβ”€β”€ main.tf                                     # Provider configuration
β”‚   β”œβ”€β”€ variables.tf                                # Input variables
β”‚   β”œβ”€β”€ vpc.tf                                      # Network configuration
β”‚   β”œβ”€β”€ rds.tf                                      # Database setup
β”‚   β”œβ”€β”€ ecs.tf                                      # Container orchestration
β”‚   β”œβ”€β”€ alb.tf                                      # Load balancer
β”‚   β”œβ”€β”€ outputs.tf                                  # Output values
β”‚   β”œβ”€β”€ dev.tfvars                                  # Dev environment vars
β”‚   └── prod.tfvars                                 # Prod environment vars
β”œβ”€β”€ pom.xml                                         # Maven configuration
β”œβ”€β”€ Dockerfile                                      # Docker image
β”œβ”€β”€ docker-compose.yml                              # Local development
└── README.md                                       # This file

πŸ—οΈ Architecture

Layered Architecture

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚  Presentation Layer (REST API)      β”‚ ProductController
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚  Application Layer (Business Logic) β”‚ ProductService
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚  Domain Layer (Entities & Rules)    β”‚ Product, ProductStatus
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚  Infrastructure Layer (Persistence) β”‚ ProductRepository
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Key Design Patterns

  1. Repository Pattern - Data access abstraction
  2. Service Pattern - Business logic encapsulation
  3. DTO Pattern - API contract separation from domain
  4. Mapper Pattern - Object transformation using MapStruct
  5. Global Exception Handler - Centralized error management
  6. Dependency Injection - Spring IoC container
  7. Transaction Management - @Transactional for ACID compliance

Getting Started

Prerequisites

  • Java 25+
  • Maven 3.8+
  • Docker & Docker Compose
  • PostgreSQL 16 (or use Docker)
  • Terraform 1.5+
  • AWS CLI (for cloud deployment)

Local Development Setup

  1. Clone the repository
git clone <repository-url>
cd product-service
  1. Start PostgreSQL using Docker Compose
docker-compose up -d

This will:

  • Start PostgreSQL 16 on port 5432
  • Create the product_service_dev database
  • Run Flyway migrations automatically
  • Insert sample data
  1. Build the application
mvn clean install
  1. Run the application
mvn spring-boot:run -Dspring-boot.run.arguments="--spring.profiles.active=dev"

The application will start on http://localhost:8080

  1. Verify the application is running
curl http://localhost:8080/actuator/health

πŸ› οΈ Development

Running Tests

Unit Tests

mvn test

Integration Tests (requires running PostgreSQL)

mvn verify

🐳 Docker Deployment

Build Docker Image

mvn clean package
docker build -t product-service:1.0.0 .

Run with Docker Compose (Development)

docker-compose up -d

πŸ—οΈ Terraform Infrastructure

Deploy Infrastructure

Development Environment

cd terraform
terraform init
terraform plan -var-file="dev.tfvars"
terraform apply -var-file="dev.tfvars"

Production Environment

terraform plan -var-file="prod.tfvars"
terraform apply -var-file="prod.tfvars"

πŸ“‘ API Endpoints

Products API

  • POST /api/v1/products - Create product
  • GET /api/v1/products - List all products (paginated)
  • GET /api/v1/products/{id} - Get product by ID
  • GET /api/v1/products/sku/{sku} - Get product by SKU
  • GET /api/v1/products/search?q={term} - Search products
  • GET /api/v1/products/category/{category} - Get by category
  • GET /api/v1/products/low-stock - Get low stock products
  • PUT /api/v1/products/{id} - Update product
  • DELETE /api/v1/products/{id} - Delete product

βœ… Clean, layered architecture
βœ… SOLID principles and DDD
βœ… Dependency injection
βœ… Repository pattern
βœ… Service layer with business logic
βœ… DTOs for API contracts
βœ… Input validation
βœ… Global exception handling
βœ… Logging and monitoring
βœ… Transaction management
βœ… Database migrations (Flyway)
βœ… Unit and integration tests
βœ… Docker containerization
βœ… Infrastructure as Code (Terraform)
βœ… AWS best practices (VPC, Security Groups, IAM, RDS, ECS, ALB)
βœ… Auto-scaling policies
βœ… Secrets management
βœ… Health checks and monitoring


Version: 1.0.0
Java: 25
Spring Boot: 3.3.0
PostgreSQL: 16

About

A Spring Boot application with Java 25, demonstrating enterprise-grade development practices, scalable architecture, and infrastructure as code using Terraform.

Resources

Stars

Watchers

Forks

Packages

 
 
 

Contributors