Skip to main content
The Client Service (sgivu-client) manages client (customer) accounts, profiles, and related business operations in the SGIVU platform.

Service Overview

Port

8082

Database

PostgreSQL

Migration

Flyway

Role

Client Management

Key Features

  • Client (customer) account management
  • Client profile and contact information
  • Integration with Purchase-Sale Service
  • Database migration with Flyway
  • RESTful API with OpenAPI documentation
  • Internal service authentication

Base Configuration

Server Settings

server:
  port: ${PORT:8082}

JPA Configuration

spring:
  jpa:
    open-in-view: false
Disabling open-in-view prevents lazy loading exceptions by enforcing transaction boundaries.

Flyway Migration

spring:
  flyway:
    enabled: true
    locations: classpath:db/migration
    baseline-on-migrate: ${FLYWAY_BASELINE_ON_MIGRATE:false}
    baseline-version: 0
    validate-on-migrate: true
  • enabled: true: Runs migrations automatically on startup
  • locations: Where migration scripts are stored
  • baseline-on-migrate: Handles existing databases without version history
  • baseline-version: 0: Starting version for baseline
  • validate-on-migrate: true: Ensures migration integrity

Database Configuration

spring:
  datasource:
    url: jdbc:postgresql://${DEV_CLIENT_DB_HOST:host.docker.internal}:${DEV_CLIENT_DB_PORT:5432}/${DEV_CLIENT_DB_NAME}
    username: ${DEV_CLIENT_DB_USERNAME}
    password: ${DEV_CLIENT_DB_PASSWORD}
    driver-class-name: org.postgresql.Driver
  jpa:
    hibernate:
      ddl-auto: validate
    show-sql: true
    properties:
      hibernate:
        format_sql: true
  flyway:
    locations: classpath:db/migration
    baseline-on-migrate: true
    clean-disabled: true
Development Features:
  • SQL logging with formatting for debugging
  • Baseline on migrate for existing databases
  • Clean disabled (changed from false) for safety
Note that even in development, clean-disabled: true prevents accidental database deletion. Use caution when changing this setting.

Service Integration

Eureka Registration

eureka:
  instance:
    instance-id: ${spring.cloud.client.hostname}:${spring.application.name}:${random.value}
  client:
    service-url:
      defaultZone: ${EUREKA_URL:http://sgivu-discovery:8761/eureka}
The random instance ID allows multiple instances to run for horizontal scaling.

Service Discovery Map

services:
  map:
    sgivu-auth:
      name: sgivu-auth
      url: ${SGIVU_AUTH_URL:http://sgivu-auth:9000}
The Client Service communicates with Auth Service for token validation.

Internal Service Authentication

service:
  internal:
    secret-key: "${SERVICE_INTERNAL_SECRET_KEY}"
This shared secret authenticates requests from other microservices, particularly Purchase-Sale Service.

Observability

Actuator Endpoints

management:
  endpoints:
    web:
      exposure:
        include: "*"
  endpoint:
    health:
      show-details: always
All actuator endpoints exposed for comprehensive debugging.

Distributed Tracing

management:
  tracing:
    sampling:
      probability: 0.1
  zipkin:
    tracing:
      endpoint: http://sgivu-zipkin:9411/api/v2/spans
  • probability: 0.1: Samples 10% of requests
  • Reduces overhead while maintaining visibility
  • All services use the same sampling rate
  • Traces span across service boundaries

Logging

logging:
  level:
    root: INFO

API Documentation

springdoc:
  swagger-ui:
    url: /docs/client/v3/api-docs
    configUrl: /docs/client/v3/api-docs/swagger-config
API documentation accessible through the gateway:
http://localhost:8080/docs/client/v3/api-docs
openapi:
  server:
    url: ${OPENAPI_SERVER_URL}
Production uses a custom URL for public API documentation.

Database Schema

Migration Files

src/main/resources/db/migration/
├── V1__create_clients_table.sql
├── V2__add_contact_information.sql
└── V3__add_client_preferences.sql
All migrations run automatically on startup. Use validate-on-migrate: true to ensure schema integrity.

Schema Validation

spring:
  jpa:
    hibernate:
      ddl-auto: validate
Always use validate in production. Never use create, create-drop, or update.

Required Environment Variables

All Environments

VariableDescriptionExample
SERVICE_INTERNAL_SECRET_KEYShared secret for internal APIsyour-secret-key

Development

VariableDescriptionDefault
DEV_CLIENT_DB_HOSTDatabase hosthost.docker.internal
DEV_CLIENT_DB_PORTDatabase port5432
DEV_CLIENT_DB_NAMEDatabase nameRequired
DEV_CLIENT_DB_USERNAMEDatabase usernameRequired
DEV_CLIENT_DB_PASSWORDDatabase passwordRequired

Production

VariableDescription
PROD_CLIENT_DB_HOSTDatabase host
PROD_CLIENT_DB_PORTDatabase port
PROD_CLIENT_DB_NAMEDatabase name
PROD_CLIENT_DB_USERNAMEDatabase username
PROD_CLIENT_DB_PASSWORDDatabase password
OPENAPI_SERVER_URLPublic API documentation URL

Optional

VariableDescriptionDefault
PORTService port8082
EUREKA_URLEureka server URLhttp://sgivu-discovery:8761/eureka
SGIVU_AUTH_URLAuth service URLhttp://sgivu-auth:9000
FLYWAY_BASELINE_ON_MIGRATEBaseline existing DBfalse

API Endpoints

Typical Client Service endpoints (accessed via gateway):
GET    /api/clients           - List clients
GET    /api/clients/{id}      - Get client by ID
POST   /api/clients           - Create client
PUT    /api/clients/{id}      - Update client
DELETE /api/clients/{id}      - Delete client
GET    /api/clients/search    - Search clients
All endpoints require authentication through the gateway’s OAuth2 flow.

Client Data Model

Typical client entity includes:
  • Basic information (name, ID, tax ID)
  • Contact details (phone, email, address)
  • Client preferences and settings
  • Created/updated timestamps
  • Account status

Integration with Other Services

Purchase-Sale Service

The Purchase-Sale Service queries client data:
# In sgivu-purchase-sale.yml
services:
  map:
    sgivu-client:
      name: sgivu-client
      url: ${SGIVU_CLIENT_URL:http://sgivu-client:8082}

Auth Service

Validates JWT tokens for API authorization:
services:
  map:
    sgivu-auth:
      name: sgivu-auth
      url: ${SGIVU_AUTH_URL:http://sgivu-auth:9000}

Security

OAuth2 Resource Server

The service validates JWT access tokens from the Auth Service.

Internal API Protection

Internal endpoints require the shared secret:
service:
  internal:
    secret-key: "${SERVICE_INTERNAL_SECRET_KEY}"
Keep the internal secret key secure and rotate it periodically.

Performance Tuning

Connection Pooling

Default HikariCP configuration:
spring:
  datasource:
    hikari:
      maximum-pool-size: 10
      minimum-idle: 5
      connection-timeout: 30000
      idle-timeout: 600000
      max-lifetime: 1800000

Query Optimization

  • Use @EntityGraph to avoid N+1 queries
  • Index frequently queried columns
  • Use projection DTOs for read operations

Configuration Files

  • sgivu-client.yml - Base configuration
  • sgivu-client-dev.yml - Development overrides
  • sgivu-client-prod.yml - Production overrides

Auth Service

Token validation

Purchase-Sale

Client data consumer

Gateway

API routing

Build docs developers (and LLMs) love