Skip to main content
The User Service (sgivu-user) manages user accounts, profiles, and related operations in the SGIVU platform.

Service Overview

Port

8081

Database

PostgreSQL

Migration

Flyway

Role

User Management

Key Features

  • User account management (CRUD operations)
  • User profile data storage
  • Integration with Auth Service for authentication
  • Database migration with Flyway
  • RESTful API with OpenAPI documentation
  • Internal service authentication

Base Configuration

Server Settings

server:
  port: ${PORT:8081}

JPA Configuration

spring:
  jpa:
    open-in-view: false
open-in-view: false ensures all database operations happen within transaction boundaries, preventing lazy loading exceptions.

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: Automatic migrations on startup
  • locations: Migration scripts location
  • baseline-on-migrate: Initialize versioning on existing databases
  • baseline-version: 0: Start versioning from 0
  • validate-on-migrate: true: Verify migration checksums

Database Configuration

spring:
  datasource:
    url: jdbc:postgresql://${DEV_USER_DB_HOST:host.docker.internal}:${DEV_USER_DB_PORT:5432}/${DEV_USER_DB_NAME}
    username: ${DEV_USER_DB_USERNAME}
    password: ${DEV_USER_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, classpath:db/seed
    baseline-on-migrate: true
    clean-disabled: false
Development Features:
  • SQL logging enabled with formatting
  • Seed data included (classpath:db/seed)
  • Flyway clean allowed for testing
  • Baseline on migrate for existing databases
Always use ddl-auto: validate in production to prevent Hibernate from modifying the schema. Flyway manages migrations.

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 value in the instance ID allows running multiple instances for load balancing.

Service Discovery Map

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

Internal Service Authentication

service:
  internal:
    secret-key: "${SERVICE_INTERNAL_SECRET_KEY}"
This shared secret authenticates internal API calls from other services (particularly Auth Service).

Observability

Actuator Endpoints

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

Distributed Tracing

management:
  tracing:
    sampling:
      probability: 0.1
  zipkin:
    tracing:
      endpoint: http://sgivu-zipkin:9411/api/v2/spans
Samples 10% of requests to balance observability with performance overhead.

Logging

logging:
  level:
    root: INFO

API Documentation

springdoc:
  swagger-ui:
    url: /docs/user/v3/api-docs
    configUrl: /docs/user/v3/api-docs/swagger-config
Access the API documentation through the gateway:
http://localhost:8080/docs/user/v3/api-docs
openapi:
  server:
    url: ${OPENAPI_SERVER_URL}
Production overrides the server URL for public documentation.

Database Schema Management

Migration Strategy

  1. Development: Flyway applies migrations and seed data on startup
  2. Production: Flyway applies migrations only (no seed data)

Migration Locations

flyway:
  locations: classpath:db/migration, classpath:db/seed
Includes test data for development.

Example Migration Structure

src/main/resources/
├── db/
│   ├── migration/
│   │   ├── V1__create_users_table.sql
│   │   ├── V2__add_email_verification.sql
│   │   └── V3__add_user_profiles.sql
│   └── seed/
│       └── R__seed_test_users.sql
Repeatable migrations (prefix R__) run on every startup if their checksum changes.

Required Environment Variables

All Environments

VariableDescriptionExample
SERVICE_INTERNAL_SECRET_KEYShared secret for internal APIsyour-secret-key

Development

VariableDescriptionDefault
DEV_USER_DB_HOSTDatabase hosthost.docker.internal
DEV_USER_DB_PORTDatabase port5432
DEV_USER_DB_NAMEDatabase nameRequired
DEV_USER_DB_USERNAMEDatabase usernameRequired
DEV_USER_DB_PASSWORDDatabase passwordRequired

Production

VariableDescription
PROD_USER_DB_HOSTDatabase host
PROD_USER_DB_PORTDatabase port
PROD_USER_DB_NAMEDatabase name
PROD_USER_DB_USERNAMEDatabase username
PROD_USER_DB_PASSWORDDatabase password
OPENAPI_SERVER_URLPublic API docs URL

Optional

VariableDescriptionDefault
PORTService port8081
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 User Service endpoints (accessed via gateway):
GET    /api/users           - List users
GET    /api/users/{id}      - Get user by ID
POST   /api/users           - Create user
PUT    /api/users/{id}      - Update user
DELETE /api/users/{id}      - Delete user
GET    /api/users/me        - Get current user profile
PUT    /api/users/me        - Update current user profile
All endpoints require authentication via the gateway’s OAuth2 flow.

Security

OAuth2 Resource Server

The service validates JWT tokens from the Auth Service:
services:
  map:
    sgivu-auth:
      name: sgivu-auth
      url: ${SGIVU_AUTH_URL:http://sgivu-auth:9000}

Internal API Protection

Internal endpoints use the shared secret key:
service:
  internal:
    secret-key: "${SERVICE_INTERNAL_SECRET_KEY}"

Performance Considerations

Database Connection Pooling

Spring Boot auto-configures HikariCP for connection pooling:
spring:
  datasource:
    hikari:
      maximum-pool-size: 10
      minimum-idle: 5
      connection-timeout: 30000
Adjust pool sizes based on expected load and database resources.

JPA Optimization

spring:
  jpa:
    open-in-view: false
Disabling open-in-view forces explicit transaction boundaries, improving performance.

Configuration Files

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

Auth Service

Authenticates users

Gateway

Routes user API requests

Purchase-Sale

Retrieves user data

Build docs developers (and LLMs) love