System Architecture
SGIVU follows a microservices architecture pattern with centralized configuration management using Spring Cloud Config. The system consists of multiple specialized services that communicate through a combination of service discovery, API gateway, and OAuth2 authentication.Core Components
Config Server
Centralized configuration management serving YAML configs from this repository
Discovery Service
Eureka-based service registry for dynamic service discovery
API Gateway
Single entry point handling routing, OAuth2 authentication, and session management
Auth Service
OAuth2 authorization server managing authentication and JWT token issuance
Business Services
User Service
User management and profile operations (Port 8081)
Client Service
Client entity management (Port 8082)
Vehicle Service
Vehicle inventory with AWS S3 integration (Port 8083)
Purchase-Sale Service
Transaction orchestration across multiple services (Port 8084)
Spring Cloud Config Architecture
Configuration Resolution Flow
Spring Cloud Config Server exposes this repository to all microservices, allowing centralized and versioned configuration management.Service Startup
Microservice starts and connects to Config Server (typically
http://sgivu-config:8888)Configuration Request
Service requests config using its
spring.application.name and active profile (e.g., /sgivu-auth/dev)Configuration Merge
Config Server merges base configuration (
sgivu-auth.yml) with profile-specific overrides (sgivu-auth-dev.yml)Property Resolution
Environment variables and placeholders are resolved (e.g.,
${EUREKA_URL:http://sgivu-discovery:8761/eureka})Configuration Layering
The repository uses a base + override pattern for environment-specific configuration: Base Configuration ({service}.yml)
- Common properties shared across all environments
- Default values for placeholders
- Standard Spring Boot configuration (JPA, Flyway, Eureka)
- Service discovery and inter-service URLs
- Management and monitoring endpoints
{service}-{profile}.yml)
- Environment-specific database connections
- Profile-specific feature flags
- Debug and logging levels
- External service URLs (Angular frontend, OpenAPI docs)
Example: Auth Service Configuration
Profile-specific files only contain properties that differ from the base configuration. This reduces duplication and makes environment differences explicit.
Service Discovery with Eureka
Discovery Server Configuration
The Eureka server acts as the service registry for all microservices:sgivu-discovery.yml
The discovery service runs in standalone mode (
registerWithEureka: false) since it is the registry itself.Client Registration Pattern
All business services register with Eureka using a consistent pattern:- Dynamic Instance IDs: Uses hostname, application name, and random value to support multiple instances
- Environment Variable Override:
EUREKA_URLcan be customized per deployment - Default Fallback: Provides sensible defaults for Docker Compose environments
OAuth2 Authentication Architecture
Authorization Server (sgivu-auth)
The auth service implements Spring Authorization Server to provide:- User authentication and session management (JDBC-backed sessions)
- OAuth2 authorization code flow
- JWT token generation using keystore-based signing
- Token introspection for resource servers
Gateway OAuth2 Client
The gateway acts as an OAuth2 client, handling user authentication:Resource Servers
Business services (user, client, vehicle, purchase-sale) validate tokens by referencing the auth service:Inter-Service Authentication
Services use internal secret keys for direct service-to-service communication:Authentication Flow
Service Communication Patterns
1. Client-to-Service (via Gateway)
External clients (Angular frontend) communicate exclusively through the API Gateway:- OAuth2 authentication flow
- Session management (Redis-backed)
- Request routing to registered services
- CORS configuration
2. Service-to-Service (Direct)
Business services communicate directly using configured service URLs:- User service (8081) for user validation
- Client service (8082) for client information
- Vehicle service (8083) for vehicle data
3. Service-to-Discovery
All services register with and query Eureka for service discovery, enabling:- Dynamic service location
- Load balancing across instances
- Health monitoring
- Automatic failover
Network Topology
Docker Compose Environment
Port Allocation
| Service | Port | Purpose |
|---|---|---|
| API Gateway | 8080 | External entry point |
| User Service | 8081 | User management |
| Client Service | 8082 | Client management |
| Vehicle Service | 8083 | Vehicle inventory |
| Purchase-Sale | 8084 | Transaction orchestration |
| Config Server | 8888 | Configuration distribution |
| Auth Service | 9000 | OAuth2 authorization |
| Zipkin | 9411 | Distributed tracing |
| Eureka Discovery | 8761 | Service registry |
| Redis | 6379 | Session storage |
| PostgreSQL | 5432 | Databases (per service) |
Configuration Refresh
Actuator Endpoints
All services expose actuator endpoints for health monitoring and configuration refresh:Dynamic Configuration Updates
To update configuration without restarting services:In development, actuator endpoints expose all operations (
include: "*"). In production, only essential endpoints are exposed for security.Observability
Distributed Tracing
All services integrate with Zipkin for distributed tracing:- Request flow visualization across services
- Performance bottleneck identification
- Error propagation tracking
- Service dependency mapping
Logging Strategy
Logging is configured per environment:Database Architecture
Database-per-Service Pattern
Each business service maintains its own PostgreSQL database:- Each service owns its database schema
- Flyway manages versioned migrations
ddl-auto: validateensures schema matches expectationsbaseline-on-migrateenabled in dev for existing databases
Session Storage
Auth Service: JDBC-backed sessions for OAuth2 state managementExternal Integrations
AWS S3 (Vehicle Service)
The vehicle service integrates with AWS S3 for image storage:Best Practices
Configuration Security
Never commit secrets to YAML files. Use environment variables with placeholders:
${VAR_NAME:default}Profile Strategy
Keep base configs minimal and use profile overrides only for environment-specific differences
Service URLs
Use DNS names (Docker service names) rather than IPs for inter-service communication
Port Consistency
Maintain consistent port allocation across environments using
${PORT:default} patternDeployment Considerations
Docker Compose
Services communicate using Docker network DNS resolution:- Service name = hostname (e.g.,
sgivu-auth:9000) - Config server accessible at
sgivu-config:8888 - Eureka at
sgivu-discovery:8761
EC2 / Production
For cloud deployments:- Override service URLs via environment variables
- Use external secret management (AWS Secrets Manager, HashiCorp Vault)
- Configure proper DNS or service mesh
- Enable SSL/TLS for inter-service communication
- Adjust Eureka hostnames for public/private IP scenarios